You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
BLE registerForNotify not working (with workaround) #628
I'm using v0.4.16 of the ESP32 BLE Arduino Library.
I have created a BLE server on an ESP32 board with 2 characteristics based on the BLE_notify example. This works as expected with the nRF Connect app on my phone: I can read values and get notifications.
I have created a BLE client on a second ESP32 board based on the BLE_client example, to connect to the server, register for notifications and output the value (on LEDs). This connects to the server and reads the initial value correctly. However this line does not work: pRemoteCharacteristic->registerForNotify(notifyCallback);
I don't get an error, it just doesn't receive any notifications.
Is 'registerForNotify()' supposed to work when called without also writing to the descriptor manually?
If I first connect with the nRF Connect app, register for notifications, disconnect and reboot the client board, 'registerForNotify()' on its own works fine and receives the notifications. Simply connecting and disconnecting in nRF Connect didn't make it work, I had to register for the notifications.
I think there is something wrong with the server side of things, because I built a seperate project last week to display the output from a Speed/Cadence sensor, and only used 'registerForNotify()', and it works great.
I've attached the server code as a text file - can't upload an ino file. BLE_server.txt
This register for notifications only on local esp32 device only: pRemoteCharacteristic->registerForNotify(notifyCallback);
On arduino you still need this workaround. Its been added to this repository, but no new arduino version has been generated for some time and changes are not included yet.
apparently (according to debug message) there is one last readValue()-call but it's not followed by those gattClientEventHandler() and dumpGattClientEvent() calls which are occuring on the manual reading. can someone tell me what i'm missing here??
@EBZ-Krisemendt I have one question, because logs shows that notification is received, are you trying to read characteristic value from within notificationCallback? If yes then it wont work, because for some reason (im guessing its some issue with semaphores) any action (read/write) called from notification callback is blocking whole app. You need to set some bool variable when you receive notification and in loop if variable is true then read characteristic.
Activity
chegewara commentedon Aug 18, 2018
This register for notifications only on local esp32 device only:
pRemoteCharacteristic->registerForNotify(notifyCallback);On arduino you still need this workaround. Its been added to this repository, but no new arduino version has been generated for some time and changes are not included yet.
petereverett commentedon Aug 18, 2018
Thankyou chegewara, that makes sense.
EBZ-Krisemendt commentedon Aug 31, 2018
Unfortunatly the workaround isn't working on my device...
I'm doing a manual reading of the characteristic to make sure measurement is working:
which results in this output:
all fine here.
now i try to activate notification (with workaround)
output:
apparently (according to debug message) there is one last
readValue()-call but it's not followed by thosegattClientEventHandler()anddumpGattClientEvent()calls which are occuring on the manual reading. can someone tell me what i'm missing here??Notification work fine with nRF-Connect.
chegewara commentedon Aug 31, 2018
@EBZ-Krisemendt I have one question, because logs shows that notification is received, are you trying to read characteristic value from within notificationCallback? If yes then it wont work, because for some reason (im guessing its some issue with semaphores) any action (read/write) called from notification callback is blocking whole app. You need to set some bool variable when you receive notification and in loop if variable is true then read characteristic.
EBZ-Krisemendt commentedon Sep 6, 2018
@chegewara to anwser your question: yes, i did indeed. changed it to a volatile bool "trigger" variable and now it works like a charm. thx very much.
maybe this is worth noting in the comments within the example code to prevent others from falling in this pit.
chegewara commentedon Sep 6, 2018
To be honest it was very annoying, i lost many hours before i found it by myself.