noble: Subscribe and Notify are not working on Linux
Hi I really appreciate your work to get noble working again on the Raspberry Pi. The code seems to compile alright, and my BLE device (an ESP32) can connect, but none of the methods of the characteristic objects seem to work.
characteristic.on('data', function(data) {
// no events
});
characteristic.subscribe(function(err) {
// never gets called
});
otherCharacteristic.read(function(error, data) {
// never gets called
});
otherCharacteristic.write(buffer, false, function(error) {
// never gets called and nothing received on device
});
My code works on MacOSX using the “noble-mac” fork but is not working with yours on a Pi3 (respbian), so perhaps there is something still missing for this to work on the Pi3 ?
About this issue
- Original URL
- State: open
- Created 5 years ago
- Reactions: 1
- Comments: 27
I should have updated this.
I was able to avoid this problem by migrating my Arduino firmware to use Adafruit’s Bluefruit BLE library rather than the “old” BLEPeripheral library which is no longer maintained. Bluefruit is maintained and does work as expected with noble (this abandonware fork).
The peripheral-explorer.js was the most helpful for my situation and here is the result when connecting my device:
This all looks good to me. It finds my 3 characteristics (1 notify, 1 write, and 1 read/write). It turns out I was mistaken, the read() method is working correctly because that last line result “MYESP” is coming from my BLE firmware. The write() also works.
But then I tried modifying that example by adding a .subscribe() and .on(‘data’) and then it fails, I replaced lines 131 through 133 with the following to add a subscribe() and ‘data’ event listener:
The example continues to run, but all communication to/from the BLE device seems to halt after that .subscribe() call is made.
I also realized this noble module is indeed working on my Mac as well, so I was able to go back and forth between my Mac and a Raspberry Pi 3 to determine that this is exactly where the problem lies and it works on my Mac, but fails on my Raspberry Pi3. The .subscribe() call never returns, and somehow is shutting down.
I’ll probably drill down in a bit to that that .subscribe() call and find the exact root cause.