Posts: 38
Registered: ‎02-27-2017

Project Completed and Working a Treat (TB Sense and Pi)



Whilst I've received much assistance from this community I thought it time I give back and feedback on my working project (thanks all who helped along the way). 


Essentially I have a TB Sense connected up via BLE to a RPi3. I did some changing to the code on the TB Sense to make it continuously advertise and then have a Python script on the Pi to collect data once every 10 minutes. 


This data is fed to Thingspeak (considering alternative options here) and graphed for viewing. I'm still in the phase of looking at some daily / weekly averages and seeing what changes it would make to general lifestyle. I'm collecting data from 6 enviromental sensors (sound, temp., humidity, pressure, TVOC and eCO2). 


Board holder

Board holder


Overall 3D printed enclosure (enough to let some air in for measurement)



I've also got a cool 3D printed enclosure made which houses the TB Sense in a nice looking (and acceptable by the wife) designed box whilst on the table top. The Pi is sitting next to my router collecting the data. 


So far I've collected a couple of days of data as shown below. It all seems to be working and is ready for a powercut and suitable reboot / reconnect if that happens (common here in South Africa). 




Happy to answer any questions on this, and share details. It is by no means a complex project however did keep me busy for a few weekends. There are still some areas I'd like to improve and then work from there (probably on the efficiency of the Python code). 



Posts: 2,821
Registered: ‎08-25-2015

Re: Project Completed and Working a Treat (TB Sense and Pi)



Is this a hobby project or are there commercial ambitions here? If you want to share your code and 3D file that would be great, I might want to print a couple of those holders myself.




Posts: 38
Registered: ‎02-27-2017

Re: Project Completed and Working a Treat (TB Sense and Pi)

@tmonte / Tiago, 


Thanks for the note. At the moment the project doesn't have any commercial ambition, it was merely an interest in the sensor-packed board and the use of data, from a personal use.


Code is attached (might need some tweaking) and I'll speak to my mate who did the 3D print, and get the STL file from him (the original file I think was download from Thingiverse, but obviously had some adjustments for the board-carrying portion of it).






from __future__ import division
import sys
from bluepy.btle import *
import struct
import thread
from time import sleep
import urllib2


# Base URL of Thingspeak
baseURL = ''

def vReadSENSE():
    scanner = Scanner(0)
    devices = scanner.scan(2)
    for dev in devices:
        print "Device %s (%s), RSSI=%d dB" % (dev.addr, dev.addrType, dev.rssi)

        for (adtype, desc, value) in dev.getScanData():
            print "  %s = %s" % (desc, value)
    num_ble = len(devices)
    print num_ble
    if num_ble == 0:
        return None
    ble_service = []
    char_sensor = 0
    non_sensor = 0
    TVOC_char = Characteristic
    eCO2_char = Characteristic
    Pressure_char = Characteristic
    Sound_char = Characteristic
    temperature_char = Characteristic
    humidity_char = Characteristic

    #bat_char = Characteristic
    count = 15

    for i in range(num_ble):
            #ble_service[char_sensor].connect(devices[i].addr, devices[i].addrType)
            char_sensor = char_sensor + 1
            print "Connected %s device with addr %s " % (char_sensor, devices[i].addr)
            non_sensor = non_sensor + 1
        for i in range(char_sensor):

            services = ble_service[i].getServices()
            characteristics = ble_service[i].getCharacteristics()
            for k in characteristics:
                print k
                if k.uuid == "efd658ae-c401-ef33-76e7-91b00019103b":
                    print "eCO2 Level"
                    TVOC_char = k
                if k.uuid == "efd658ae-c402-ef33-76e7-91b00019103b":
                    print "TVOC Level"
                    TVOC_char = k
                if k.uuid == "00002a6d-0000-1000-8000-00805f9b34fb":
                    print "Pressure Level"
                    Pressure_char = k
                if k.uuid == "c8546913-bf02-45eb-8dde-9f8754f4a32e":
                    print "Sound Level"
                    Sound_char = k
                if k.uuid == "00002a6e-0000-1000-8000-00805f9b34fb":
                    print "Temperature"
                    temperature_char = k
                if k.uuid == "00002a6f-0000-1000-8000-00805f9b34fb":
                    print "Humidity"
                    humidity_char = k

                #if k.uuid == "2a19":
                    #print "Battery Level"
                    #bat_char = k

        return None
    while True:
        # units of ppb
        TVOC_data =
        TVOC_data_value = ord(TVOC_data/100)

        #units of ppm
        eCO2_data =
        eCO2_data_value = ord(eCO2_data[0])

        # pressure is in units of 0.1Pa
        Pressure_data =
        Pressure_data_value = (Pressure_data * 10)

        # units of 0.01dB
        Sound_data =
        Sound_data_value = (Sound_data * 100)

        #bat_data =
        #bat_data_value = ord(bat_data[0])

        #convert from farenheit
        temperature_data =
        temperature_data_value = (ord(temperature_data[1]) << 8) + ord(temperature_data[0])
        float_temperature_data_value = (temperature_data_value / 100)

        humidity_data =
	humidity_data_value =(ord(humidity_data[1])<<8)+ord(humidity_data[0])

	print "TVOC: ", TVOC_data_value
	print “eCO2: ", eCO2_data_value
	print “Pressure: ", Pressure_data_value
	print “Sound: ", Sound_data_value
	print “Temperature: “, float_temperature_data_value
	print “Humidity: “, humidity_data_value

	if count > 14:

        	f = urllib.urlopen(baseURL + PRIVATE_KEY + "&field1=%s&field2=%s&field3=%s&field4=%s&field5=%s&field6=%s" % (TVOC_data_value, eCO2_data_value, Pressure_data_value, Sound_data_value, float_temperature_data_value, humidity_data_value))
        	count = 0
        	count = count + 1

while True:
Posts: 2,821
Registered: ‎08-25-2015

Re: Project Completed and Working a Treat (TB Sense and Pi)



I would strongly encourage you to make a more elaborate post in the community project section. There you will get more attention from other enthusiasts like you, these discussion boards are more to discuss technical problems.