Nano 33 BLE - Problem with setEventHandler callback

I am new to Arduino so feeling my way with this. Created a BLE server running on the Nano, and an Android app as the client to communicate with it.

Android scans OK and finds the BLE server, and can connect to the server and discover the available services. All good.

The server has 10 readable and notifiable characteristics representing switches. Value changes for each are basically the state (up or down) of a particular Nano digital input. The Android app can set up notifications on all these, and - sure enough - as the digital pins are toggled up and down, the app receives and displays the new switch state. All very good.

But ....

Added two more characteristics - testread (readable and notifiable on client) and testwrite (writable by client). Purpose of these was to measure the 'round trip' time of a write by the Android app to the testwrite characteristic, receipt on the server, immediate update of the testread characteristic and detection of the testread value change on the Android app. In order to do this I have hooked on a callback handler in the server to testwrite using setEventHandler() on the testwrite characteristic.

But, won't work. As soon as I hook on the event handler to the testwrite characteristic, I can no longer set up the 10 switch characteristics for notification (the Android CCCD write for each fails - the reported error code is GATT_WRITE_NOT_PERMITTED). The Android code is unchanged. Comment out that server line of code, and the switch characteristics are all happy again and accept notification requests. The line of code is:

testWriteCharacteristic.setEventHandler(BLEWritten, cbTestWrite);

Cannot see the connection here. The callback event handler is only supposed to be for the testWriteCharacteristic, so why is its presence affecting the switch characteristic notifications?

Any help in understanding this appreciated.

Please post a complete example of your code. Just one line of code is often not useful to find an answer.

Thanks for you reply.

The problem appears to have gone away for reasons that are not at all clear.

If it returns I will post again.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.