Create a gist now

Instantly share code, notes, and snippets.

@jpmens /
Last active Dec 3, 2017

What would you like to do?
CC2650 read via BLE and publish to MQTT
#!/usr/bin/env python
# read CC2650 SensorTag by JP Mens
# follow
# to get started, but use
import time
import json
import struct
import Sensortag2650 as sensortag
import paho.mqtt.publish as mqtt
# don't even bother starting until you see your SensorTag
# $ hcitool -i hci1 lescan
# LE Scan ...
# B0:B4:48:BD:B8:05 CC2650 SensorTag
my_sensor = 'B0:B4:48:BD:B8:05'
tag = sensortag.SensorTag(my_sensor)
print "Connected to SensorTag", my_sensor
sensorOn = struct.pack("B", 0x01)
sensorbarcal = struct.pack("B", 0x02)
sensorMagOn = struct.pack("H", 0x0007)
sensorGyrOn = struct.pack("H", 0x0007)
sensorAccOn = struct.pack("H", 0x0038)
# tag.magnetometer.enable(sensorMagOn)
# tag.gyroscope.enable(sensorGyrOn)
base_topic = 'jpmens/cc2650/%s' % my_sensor.replace(':', '').lower()
while True:
msgs = []
ambient_temp, target_temp =
x_accel, y_accel, z_accel =
ambient_temp, rel_humidity =
lux =
ambient_temp, pressure_millibars =
data = {
'ambient_temp' : ambient_temp,
'target_temp' : target_temp,
'humidity' : rel_humidity,
'lux' : lux,
'millibars' : pressure_millibars,
'tst' : int(time.time()),
payload = json.dumps(data)
print payload
msgs.append((base_topic, payload, 0, False))
for k in data:
msgs.append( ( "%s/%s" % (base_topic, k), data[k], 0, False ) )
mqtt.multiple(msgs, hostname='')

SoonSYJ commented Mar 28, 2016

Nice script. Have you ever tried to read link RSSI between a RPi and a SensorTag? I am trying to read sensor data and RSSI synchronised. But it seems that Bluez does not have any API to get RSSI data. Could you give me some advice? Thank you

Hi All,

Can anyone please let me know from where we are referring, as we have imported it.

Thanking in anticipation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment