Skip to content

Commit

Permalink
temperature, humidity, count adv
Browse files Browse the repository at this point in the history
  • Loading branch information
andete committed May 7, 2014
1 parent c54f203 commit 07788a4
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 4 deletions.
6 changes: 5 additions & 1 deletion ble.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ def start(self, port = None):
self.ble.ble_evt_attclient_procedure_completed += self.handle_attclient_procedure_completed
self.ble.ble_evt_attclient_find_information_found += self.handle_attclient_information_found
self.ble.ble_evt_attclient_attribute_value += self.handle_attclient_attribute_value
self.ble.ble_evt_attclient_read_multiple_response += self.handle_attclient_read_multiple_response

def send_command(self, cmd):
return self.ble.send_command(self.ser, cmd)
Expand Down Expand Up @@ -257,7 +258,7 @@ def read_handles(self, handle, h1, h2):
self.send_command(self.ble.ble_cmd_attclient_read_by_handle(handle, h1))

def handle_attclient_attribute_value(self, sender, args):
#print args
print args
chandle = args['atthandle']
handle = args['connection']
t = args['type']
Expand All @@ -269,6 +270,9 @@ def handle_attclient_attribute_value(self, sender, args):
if self.handles_to_read == []: return
self.send_command(self.ble.ble_cmd_attclient_read_by_handle(handle, self.handles_to_read[0]))

def handle_attclient_read_multiple_response(self, sender, args):
print "read_multiple", args

def write_handle(self, handle, chandle, value):
self.send_command(self.ble.ble_cmd_attclient_write_command(handle, chandle, value))
time.sleep(0.1)
Expand Down
2 changes: 2 additions & 0 deletions data/bluetooth.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@
Attr([0x2A, 0x04], "Peripheral Preferred Connection Parameters"),
Attr([0x2A, 0x05], "Service Changed"),

Attr([0x2A, 0x19], "Battery level", printers.BatteryLevel),

Attr([0x2A, 0x5B], "CSC Measurement", printers.CSCMeasurement),
Attr([0x2A, 0x5C], "CSC Feature", printers.CSCFeature),
]
Expand Down
15 changes: 15 additions & 0 deletions data/printers.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,21 @@ class Int32:
def printv(self, val):
return str(val[0] + 256*val[1] + 256*256*val[2] + 256*256*256*val[3])

class Int16:

def printv(self, val):
return str(val[0] + 256*val[1])

class Int8:

def printv(self, val):
return str(val[0])

class BatteryLevel:

def printv(self, val):
return "%s%%" % (str(val[0]))

class Char(Default):

def printv(self, val):
Expand Down
33 changes: 30 additions & 3 deletions data/productize.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,27 @@
from attr import Attr
import printers

class HumidityPrinter(printers.Default):

def printv(self, val):
i = val[0] + 256*val[1]
return "raw:%d, calc:%d" % (i, -6.0+125.0*i/1024)

class TemperaturePrinter(printers.Default):

def printv(self, val):
i = val[0] + 256*val[1]
return "raw:%d, calc:%d" % (i, -46.85+175.72*i/4096)


attrs = [
Attr("ac842717-f24c-46f7-bf49-5393f0124f8d", "Count Service"),
Attr("5b97ab09-9065-478c-9ce8-9c9dcb2c5922", "Count", printers.Int32),
Attr("47bb55a0-6af8-11e3-981f-0800200c9a66", "Module Temperature", printers.Int8),
Attr("234b35f7-0bff-47b9-b567-43ff304d62cf", "Module Temperature ADC", printers.Int16),
Attr("8c1cc1fd-6062-48aa-93e4-35dc351c3487", "Humidity ADC", HumidityPrinter),
Attr("4f99a937-c182-4956-92ff-34bc8ec10644", "Temperature ADC", TemperaturePrinter),
Attr("4707d070-5e5c-4e1f-b026-535071b43190", "Blink", printers.Int8),
]

class Vendor:
Expand All @@ -21,9 +39,18 @@ def _parse_product(self, product_id, data):
luxf = 10 **luxf
return "lux:%d" % int(luxf)
elif product_id == 2:
raw_temp = data[0] + 256*data[1]
raw_hum = data[2]
return "hum:%d temp:%d" % (int(raw_hum), int(raw_temp))
print data
raw_temp = data[0]
temp = -46.85+175.72*raw_temp/256
raw_hum = data[1]
hum = -6+125*raw_hum/256
mod_temp = data[2]
return "hum:%d temp:%d mod-temp:%d" % (int(hum), int(temp), int(mod_temp))
elif product_id == 3:
print data
count = data[0] + 256*data[1] + 256*256*data[2] + 256*256*256*data[3]
return "count:%d" % (count)

return "unknown"

def to_string(self, data):
Expand Down

0 comments on commit 07788a4

Please sign in to comment.