- Silicon Labs Community
- Welcome and Announcements
- Silicon Labs Knowledge Base
- 8-bit MCU
- 32-bit MCU
- Bluetooth / Wi-Fi
- Other Products Category
- Optical/RH/Temp Sensor
- Other Products
- Hardware and Software Tools
- Simplicity Studio and Software
- General Discussions and Suggestions
- Chinese Forum
- Software Libraries
- Development Kits
- Reference Designs
- Third Party Tools
- White Papers
- Official Blog of Silicon Labs
- Chinese Blog
12-17-2016 08:56 AM - last edited on 12-19-2016 09:26 AM by Nari
First of all I would like to Thank you Silicon Labs for the Thunderboard Sense Kit ! Tiny but Swiss Knife of Sensors.
Trust me it is !
I have decided to go with IoT demo using this kit which sends Temperature, Humidity and Battery Level to Cloud.
I choose RaspberryPi 3 Model B to collect the data from Sense Kit and then upload it to https://thingspeak.com/ portal.
Thingspeak is very easy to create and use platform. I have created my channel there with three fields. It gives you unique API Key using which you can push data to cloud and on Thingspeak you can view the graph of your logged data. There is limit on it so you can push data once at every 15 seconds only.
Thingspeak Dashboard !
Thingspeak Graph !
Project posted by @Namo_Aton helped me to to start things and find characteristics I want to read out and push data to cloud.
As I want to read Battery Level, Temperature and Humidity I have find out those three characteristics first and then read it. It will read parameters at every 1 second but push to cloud at 15 second interval.
Here is the python script to connect with Sense Kit, Read data and push to Cloud.
from __future__ import division import sys from bluepy.btle import * import struct import thread from time import sleep import urllib2 # PRIVATE_KEY = '2HL151HLWNJNENQD' #Base URL of Thingspeak baseURL = 'https://api.thingspeak.com/update?api_key=' def vReadSENSE(): scanner = Scanner(0) devices = scanner.scan(3) 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 bat_char = Characteristic temperature_char = Characteristic humidity_char = Characteristic count = 15 for i in range(num_ble): try: devices[i].getScanData() ble_service.append(Peripheral()) 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) except: non_sensor = non_sensor + 1 try: 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=="2a19": print "Battery Level" bat_char = k if k.uuid == "2a6e": print "Temperature" temperature_char = k if k.uuid == "2a6f": print "Humidity" humidity_char = k except: return None while True: bat_data = bat_char.read() bat_data_value = ord(bat_data) temperature_data = temperature_char.read() temperature_data_value =(ord(temperature_data)<<8)+ord(temperature_data) float_temperature_data_value = (temperature_data_value / 100) humidity_data = humidity_char.read() humidity_data_value =(ord(humidity_data)<<8)+ord(humidity_data) print "Battery: ", bat_data_value print "Temperature: ", float_temperature_data_value print "Humidity: ", humidity_data_value if count > 14: f = urllib2.urlopen(baseURL + PRIVATE_KEY +"&field1=%s&field2=%s&field3=%s" % (bat_data_value, float_temperature_data_value, humidity_data_value)) print f.read() f.close() count = 0 count = count + 1 sleep(1) while True: vReadSENSE()
Here is the video for the same.
02-27-2017 07:59 AM
HallMark - great project and thanks for sharing all the detail. If you don't mind I have a couple of questions (am a Sense newbie);
1. Do you know if there is anyway to get access to sensor data without going through BLE? Ideally would like to pick it up through I2C bus and handle the upload to the cloud from there (using another dev board).
2. Did you have to modify any of the code on the Sense board itself? Does it have good standalone performance (i.e. running for 24 hours, reporting every 15 seconds)?
Ideally I'd like to make a standalone sensor board, which updates every now and then, to the cloud, and stores necessary data. I understand the Thunderboard Sense doesn't have Wifi, so trying to work out how to do this without my phone / PC being around all the time.
Thanks and look forward to hearing from you.
06-02-2017 11:22 AM
I'm going through your code and seem to be getting somewhere (good news).
How would one adjust your code to connect only to the Thunderboard Sense, and not any other BLE device around..? I imagine we would just need the MAC address (00:0B:57:36:63:FF).
06-02-2017 11:41 AM
Battery: 61 Temperature: 20.73 Humidity: 4050 Battery: 61 Temperature: 20.73 Humidity: 4050
It's working! Thanks, seem to have figured it out. It connects only the Thunderboard Sense now, and nothing else. Information flowing through!
06-02-2017 11:50 AM
In your code, can you explain to me the reading and conversion of the humidity data?
humidity_data = humidity_char.read() humidity_data_value =(ord(humidity_data)<<8)+ord(humidity_data)
I'm really not sure that the above does (obviously converting it from one form to the other) however the number I get out doesn't seem right with vales of 4096...
Is that perhaps 40.96% humidity? It did rise from 3840 when I blew on it ... so there is valid stream of data coming through.
Humidity: 4096 Battery: 60 Temperature: 20.65 Humidity: 4096 Battery: 59 Temperature: 20.65 Humidity: 4096
06-02-2017 12:09 PM
humidity_data = humidity_char.read() humidity_data_value =((ord(humidity_data) <<8)+ord(humidity_data))/100
Essentially I just divided the whole thing by 100 and am getting a number which might be closer to normal (perhaps as I don't understand).
Let me know what you see, or what you suggest.
06-02-2017 02:00 PM
Having a look through the android app source code, it looks like they too just divide the result by 100. I have compared the results I'm getting with another manufactures sensor,and on one sample reads low, 10-15%. If I use n I use another Thundersense, it compares well, within 5%.
Yours Simon M.
06-03-2017 04:02 AM
I haven't checked with accurate reading. But here it was looking like something similar only. Once I got some time I will surely give it a shot to make sure it is accurate enough or not.
06-03-2017 06:44 AM
@HallMark - thanks, appreciate the time, when you find it.
I've also been trying to understand the pressure reading. Mine outputs 254 and I'm 100% sure on the metric / unit of this. The iPhone app shows 800 mbar, so seems there is some internal calculation on the "raw" pressure number from the Tsense.
Any idea as I'm sure there is a calculation step I'm missing out here.
As reference in the BMP280 datasheet they have a rather complex calculation, however I'd assume this is handled somewhere on the Tsense?
Any ideas? I'm trying to source the code for the app to confirm.
06-03-2017 06:55 AM
I would say instead of using this conversation. Try to read raw data and then make your formula based on known value to Raw data. I know it's bit difficult to get calibrated one test input for the pressure specifically.
06-03-2017 07:42 AM
I found that the 'stock' Thunderboard Sense pressure reading was miles out. ( do a search for 'Thunderboard Sense and pressure reading' ). However when I used Simplicity Studio V4 with Bluetooth Smart SDK 184.108.40.206 or greater, and updated the devices, the problem went away, and agrees with my other devices.
Yours Simon M.
06-03-2017 11:17 AM
I seem to have a working version now... I looked at some other code as to conversion factors and got out the same data as when one connects to the TBSense with your iPhone.
Thanks for the help here, very happy to finally be connected to the board and publishing data to ThingSpeak. Happy to publish the code if you'd like.
As an aside, would any of you know how to have the TBSense board constantly advertising? I only ask as it will be connected to a Raspberry Pi 3, and if there is a break in the connection it'll need advertise until reconnected again?
06-03-2017 12:53 PM
I asked just the same question, and have managed to get it to advertise any time it is not connected, look at the following link...
As to how to get the RPi to auto connect, that is the problem I'm working on at the moment. (My code is a real mess so will need to tidy that up a lot first though I think)
Yours Simon M.