WIPY 3.0 can't read device NOTIFY characteristic

  • Hi Everyone. Thanks in advance to any help you can give me.

    I just received my Wipy 3.0 and Track last Friday. I watched some 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

    A google hasn't turned up much. Is it possible to read notify and indicate properties with the Wipy?

    Here is my code, slightly modified from the Pycom repo:

    from network import Bluetooth
    import binascii
    import time
    bt = Bluetooth()
    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:
                    if type(service.uuid()) == bytes:
                        print('Reading bytes from service: {}'.format(service.uuid()))
                        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)):
                            #below returns the expected uuid
                            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()))
            #print('ADV does not exist')

  • In case someone else comes along looking for a solution to this problem. Simply add this callback before the while loop:

    def char_notify_callback(char):
        char_value = (char.value())
        print("Got new char: {} value: {}".format(char.uuid(), char_value))

    And update the char condition:

    if ((char.properties()) & (Bluetooth.PROP_NOTIFY)):

Pycom on Twitter