Hi Everyone. Thanks in advance to any help you can give me.
I just received my Wipy 3.0 and Track on Friday. I watched Chris’ awesome videos Saturday morning and got lat long and modified the class to give me atomic clock time within a couple of hours, awesome! Connected to a BLE device and read out the services and characteristics in an hour, great!
I’ve got stuck though, trying to read the value of a notify property. I can detect that the property exists and get it’s UUID, properties, instance. But can’t read the actual value of the data. I can connect with a BLE scanner on my phone and with an arduino+HM10 and read the value so know the device is working.
It is giving me this error: OSError: the requested operation failed
Here is my code:
from network import Bluetooth
import binascii
import time
bt = Bluetooth()
#bt.start_scan(-1)
bt.stop_scan()
bt.start_scan(-1)
while True:
adv = bt.get_adv()
if adv:
mfg_data = bt.resolve_adv_data(adv.data, Bluetooth.ADV_MANUFACTURER_DATA)
if bt.resolve_adv_data(adv.data, Bluetooth.ADV_NAME_CMPL) == 'earconnect':
print('connected to: {}'.format(bt.resolve_adv_data(adv.data, Bluetooth.ADV_NAME_CMPL)))
conn = bt.connect(adv.mac)
services = conn.services()
for service in services:
time.sleep(0.050)
if type(service.uuid()) == bytes:
print('Reading bytes from service: {}'.format(service.uuid()))
else:
print('Reading chars from service: %x' % service.uuid())
chars = service.characteristics()
for char in chars:
#if ((char.properties()) & (Bluetooth.PROP_READ or Bluetooth.PROP_INDICATE or Bluetooth.PROP_NOTIFY)):
if ((char.properties()) & (Bluetooth.PROP_NOTIFY)):
print('char uuid: {}'.format(char.uuid()))
print('char instance: {}'.format(char.instance()))
print('char properties: {}'.format(char.properties()))
#line below fails with error: OSError: the requested operation failed
print('char read: {}'.format(char.read()))
conn.disconnect()
break
else:
#print('ADV does not exist')
time.sleep(0.050)