Reply
Posts: 34
Registered: ‎09-19-2012

IoT demo using Thunderboard

[ Edited ]

Hello,

 

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 !

SENSE.jpg

 

 

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 Dashboard !

 

Thingspeak_Graph

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[0])
		
		temperature_data = temperature_char.read()
		temperature_data_value =(ord(temperature_data[1])<<8)+ord(temperature_data[0])
		float_temperature_data_value = (temperature_data_value / 100)
		
		humidity_data = humidity_char.read()
		humidity_data_value =(ord(humidity_data[1])<<8)+ord(humidity_data[0])

		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.

 

 

Cheers !

 

Posts: 4
Registered: ‎08-04-2014

Re: IoT demo using Thunderboard

Superb Harshadbhai! Smiley Happy

Posts: 34
Registered: ‎09-19-2012

Re: IoT demo using Thunderboard

Setup for this demo !

 

Setup

Posts: 2
Registered: ‎01-09-2017

Re: IoT demo using Thunderboard

Great job.

Is the sensors starting the advertise without any setup needed ?

Had you to modify the factory set firmware ?

Thanks, nice day

Marco

Posts: 19
Registered: ‎07-20-2015

Re: IoT demo using Thunderboard

Thanks!

This works like a charm, and is a great help in getting me started with my project..

 

Simon M

Highlighted
Posts: 38
Registered: ‎02-27-2017

Re: IoT demo using Thunderboard

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. 

Posts: 38
Registered: ‎02-27-2017

Re: IoT demo using Thunderboard

@HallMark

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). 

 

Thanks, 

Neal. 

Posts: 38
Registered: ‎02-27-2017

Re: IoT demo using Thunderboard

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!

Posts: 38
Registered: ‎02-27-2017

Re: IoT demo using Thunderboard

@HallMark

 

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[1])<<8)+ord(humidity_data[0])

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
Posts: 19
Registered: ‎07-20-2015

Re: IoT demo using Thunderboard

Hi Neal,

Since the humidity and temp sensor are the same unit I treated the data in the same way, and divided by 100, but now you have got me thinking...

 

Yours Simon M.

Posts: 38
Registered: ‎02-27-2017

Re: IoT demo using Thunderboard

@samarkh 

 

humidity_data = humidity_char.read()
		humidity_data_value =((ord(humidity_data[1]) <<8)+ord(humidity_data[0]))/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). 

 

 

Battery: 58
Temperature: 23.12
Humidity: 39.56

 

Let me know what you see, or what you suggest. 

 

Neal. 

 

Posts: 19
Registered: ‎07-20-2015

Re: IoT demo using Thunderboard

Hi Neal

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.

Posts: 34
Registered: ‎09-19-2012

Re: IoT demo using Thunderboard

Neal,
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.

Posts: 38
Registered: ‎02-27-2017

Re: IoT demo using Thunderboard

@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?

 

BMP280 Datasheet - See page 23

 

Any ideas? I'm trying to source the code for the app to confirm. 

Posts: 34
Registered: ‎09-19-2012

Re: IoT demo using Thunderboard

@neal_tommy:


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.

Posts: 19
Registered: ‎07-20-2015

Re: IoT demo using Thunderboard

Hi Neal,

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 2.1.1.0 or greater, and updated the devices, the problem went away, and agrees with my other devices.

 

Yours Simon M.

Posts: 38
Registered: ‎02-27-2017

Re: IoT demo using Thunderboard

@samarkh@HallMark

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?

Posts: 19
Registered: ‎07-20-2015

Re: IoT demo using Thunderboard

Hi Neal

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...

 

http://community.silabs.com/t5/Bluetooth-Wi-Fi/How-do-I-Increase-the-ThunderBoard-sense-advertising-...

 

 

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.