pycom / pycom-micropython-sigfox

A fork of MicroPython with the ESP32 port customized to run on Pycom's IoT multi-network modules.
MIT License
200 stars 166 forks source link

BLE Notification/Notify operation OSError: the requested operation failed #517

Open salvacnj opened 3 years ago

salvacnj commented 3 years ago

Hello,

When I tried to configure notify operation for BLE in 1.20.2.r4 I'm always getting the following error:

OSError: the requested operation failed

By downgrading the firmware version from 1.20.2.r4 to 1.20.2.r0 or 1.20.1.r1 It still fail to some characteristics, but is working for the most of them.

Here is my code of initialization:

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

And when device is paired and chars discovered:

if ((char.properties()) & (Bluetooth.PROP_NOTIFY)) :
    print("Notify start on " + char_uuid)
    char.callback(trigger=Bluetooth.CHAR_NOTIFY_EVENT, handler=char_notify_callback, arg=char)

Thank you!

UPDATED:

On 1.20.2.r0 doesn't give error but doesn't receive data, so only working for 1.20.2.r1

stevieraysean commented 3 years ago

At some point they changed the arguments that the callback gets called with to a tuple. the micropython layer seems to just throw away the callback function if it does not accept a tuple, it should really throw an argument error (function with 1 arg called with 2... or similar). but it just gives no error for this, and the callback is lost.

if you modified your callback function to: def char_notify_callback(*args): then if you print(args) your will get something like "char, (char, data)"

i think as whatever you pass as a callback arg=xx gets put into a tuple with the normal callback args, which are a tuple of the gatt characteristic and data for that characteristic

there's a lack of documentation in this area..