chrvadala / node-ble

Bluetooth Low Energy (BLE) library written with pure Node.js (no bindings) - baked by Bluez via DBus
https://www.npmjs.com/package/node-ble
MIT License
310 stars 45 forks source link

Cannot intercept dev_disconnected() event #27

Closed erezbuchnik closed 1 year ago

erezbuchnik commented 3 years ago

My use-case involves multiple devices which may sporadically disconnect, and I need to intercept the disconnection event - as it appears in the bluetooth logs:

src/adapter.c:dev_disconnected()

How can I assign a callback on this event using node-ble? I mean, something similar to the callback for intercepting notifications (once registered to a Notifications characteristic), e.g.:

characteristic.on('valuechanged', buffer => {
  console.log(buffer);
});

Does the current version support this? If not, is there an easy way to add such a feature? It's an absolute must for noisy Bluetooth environments.

chrvadala commented 1 year ago

Yes, you can subscribe connection and disconnection events. Follow these following links

https://github.com/chrvadala/node-ble/blob/main/docs/api.md#Device+event_connect https://github.com/chrvadala/node-ble/blob/main/docs/api.md#disconnect