In GattCharacteristic.js, in the startNotifications method :
async startNotifications () {
await this.helper.callMethod('StartNotify')
const cb = (propertiesChanged) => {
if ('Value' in propertiesChanged) {
const { value } = propertiesChanged.Value
this.emit('valuechanged', Buffer.from(value))
}
}
this.helper.on('PropertiesChanged', cb)
}
The startNotify method is called before attaching the callback / event handler. Depending on how your system is busy / scheduled, you might loose 0, 1 or more event notifications.
Environment
I'm using the following code to connect to a Lego Powered Up Hub using
node-ble
on a Framework Laptop 13 AMD running Fedora 40.Code to reproduce the issue
Expected behavior
Upon startNotifications, exactly 5 notifications are received.
Current behavior
Only 3 to 4 notifications are received.
Possible explanation
In
GattCharacteristic.js
, in thestartNotifications
method :The
startNotify
method is called before attaching the callback / event handler. Depending on how your system is busy / scheduled, you might loose 0, 1 or more event notifications.Possible fix
Applying this fix on the supplied sample code produces the expected behavior :