Need some help with access to BLE services & characteristics with the Hexiwear dev platformpje !?
from __future__ import print_function
import cb
import sound
import time
import struct
import console
console.set_color(0, 0, 1)
print("""
_ _ _____ _
| || |___ _ _ * | __ | |_ _ ___
| -- | -_| \/ | | __ -| | | | -_|
|_||_|___|_/\__|_ _____|_|___|___|
""")
console.set_color()
class HeartRateManager (object):
def __init__(self):
self.peripheral = None
def did_discover_peripheral(self, p):
if p.name and 'HEXIWEAR' in p.name and not self.peripheral:
self.peripheral = p
print('Connecting to Hexiwear...')
cb.connect_peripheral(p)
def did_connect_peripheral(self, p):
print('Connected:', p.name)
print('Discovering services...')
p.discover_services()
def did_discover_services(self, p, error):
print('did_discover_services({})'.format(p.name))
cb.get_state()
print("Name:", p.name)
print("UUID:", p.uuid)
try:
state = 'Disconnected Connecting Connected'.split()[p.state]
except IndexError:
state = 'Invalid state ({})'.format(p.state)
print("STAT: ", state)
time.sleep(0.4)
print("AUTH:", cb.CH_PROP_AUTHENTICATED_SIGNED_WRITES)
time.sleep(0.4)
print("Properties:", cb.CH_PROP_EXTENDED_PROPERTIES)
time.sleep(0.4)
print("Indicate:", cb.CH_PROP_INDICATE)
time.sleep(0.4)
print("Encryption:", cb.CH_PROP_NOTIFY_ENCRYPTION_REQUIRED)
time.sleep(0.4)
print("{} Services:".format(len(p.services)))
for s in p.services:
print("-" + str(s.uuid))
p.discover_characteristics(s)
def did_discover_characteristics(self, s, error):
print("Characteristics:")
for c in s.characteristics:
print("-" + str(c.uuid))
# s.set_notify_value(c, True)
s.read_characteristic_value(c)
data = s.read_characteristic_value(c)
print(c.value, data)
def did_write_value(self, c, error):
print(self.peripheral.properties)
time.sleep(0.5)
def did_update_value(self, c, error):
time.sleep(0.5)
def did_fail_to_connect_peripheral(self, p, error):
print('Failed to connect: %s' % (error,))
def did_disconnect_peripheral(self, p, error):
print('Disconnected, error: %s' % (error,))
self.peripheral = None
mngr = HeartRateManager()
cb.set_central_delegate(mngr)
print('Scanning for Hexiwear...')
cb.scan_for_peripherals()
try:
while True: pass
except KeyboardInterrupt:
cb.reset()
Can’t get access to all characteristics need some pointers!?
Thx in advance