nkolban / esp32-snippets

Sample ESP32 snippets and code fragments
https://leanpub.com/kolban-ESP32
Apache License 2.0
2.37k stars 710 forks source link

mysterious issue using client notify code - only works after connecting with BLE scanner ios/android app #1029

Closed rabee05 closed 4 years ago

rabee05 commented 4 years ago

I have a mysterious issue using client notify code (https://github.com/nkolban/ESP32_BLE_Arduino/tree/master/examples/BLE_notify) on ESP32. I am connecting to the chip using multiple languages. In particular nodejs using NOBLE module. I can connect to the device and almost do everything, but I keep having issues with notification. The only way I managed to have notification to work was by connecting to the ESP32 using an app called BLE scanner on iPhone first, then notification worked just fine using the node app. If I unpower the device, notification stops working and I have to connect first using the iPhone app. I can connect, read data, get notification, write data using the app without any issues.

As I do not have access to the iPhone app source code, but I am guessing that the app sends some sort of flags which trigger the notification characteristic as soon as it connects to the devices and stays active until turning off the ESP32 or pressing the reboot button. to re-enable notification to work with node, I just need to connect only using the app without even retrieving any data.At the same time I am using the same nodejs app with the off the shelf Bluetooth device which works fine without any issue. I tried to use a different ESP32 and got the same issue.

I have been searching for a fix for a while and tried every possible recommendation I found. I would be very thankful if you recommend some steps I can take to figure out what is really happening. IOS APP I use: https://apps.apple.com/us/app/ble-scanner-4-0/id1221763603 @nkolban Best, RZ

rabee05 commented 4 years ago

@nkolban, I found your post about NOBLE, both read and write work just fine, but I cannot manage to have notification working

https://esp32.com/viewtopic.php?t=3808

Any thoughs?

Thank you, RZ

rabee05 commented 4 years ago

It seems my app was not setting descriptor 0x2902. I was able to fix the issue by calling setNotifications(true).

Thank you very much @chegewara for your tips.