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

Most upvoted comments

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:

(node:19638) [DEP0005] DeprecationWarning: Buffer() is deprecated due to security and usability issues. Please use the Buffer.alloc(), Buffer.allocUnsafe(), or Buffer.from() methods instead.
peripheral with ID 240ac4121576 found
  Local Name        = ESP32
  TX Power Level    = -21
  Service Data      = []
  Service UUIDs     = c799a4c153ae45b6a37ae277e7485b5a

services and characteristics:
1801 (Generic Attribute)
  2a05 (Service Changed)
    properties  indicate
1800 (Generic Access)
  2a00 (Device Name)
    properties  read
    value       4553503332 | 'ESP32'
  2a01 (Appearance)
    properties  read
    value       0000 | ''
  2aa6 (Central Address Resolution)
    properties  read
    value       00 | ''
c799a4c153ae45b6a37ae277e7485b5a
found notify
  234e7d9d2cef4026891f9e893edfb06e
    properties  notify
  848f7ba939f8408faa85216c35362d79
    properties  write
  64289ec7619042c6a172beba419e6752
    properties  read, write
    value       4d59455350 | 'MYESP'

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:

} else if (characteristic.properties.indexOf('notify') !== -1) {
	console.log('found notify');
	
	characteristic.on('data', function (data) {
		console.log('data:::', data); // never gets called
	});
	
	characteristic.subscribe(function () {
		console.log('subscribed'); // never gets called
	});
	
	console.log('after subscribe'); // does get called but all BLE communication stops here
	
	callback();
} else {
	callback();
}

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.