Closed martin-doyle closed 8 years ago
@martin-doyle what makes you say onDiscover
is still running?
@sandeepmistry
If I skip the process.exit(0)
in the test.js
than the program keeps running and needs to be stopped by Ctrl C
.
sensorTag.on('disconnect', function() {
console.log('disconnected!');
process.exit(0);
});
In my application I do a reconnect in case of a lost connection (for example if I change the battery):
sensorTag.on('disconnect', function () {
console.log('Sensortag disconnected.');
SensorTag.discoverAll(onDiscover);
});
Then, with every reconnect the disconnect message 'Sensortag disconnected.' gets fired multiple times telling me all onDiscover
functions are still running. I have not found any solution in the samples other than process.exit(0)
.
@martin-doyle for the exit question, let's move the discussion here: https://github.com/sandeepmistry/noble/issues/299
It looks like you want to use .once
instead of .on
as your are not removing the listener, and noble re-uses the peripheral / sensor tag instance so multiple listeners are added.
sensorTag.once('disconnect', function () {
console.log('Sensortag disconnected.');
SensorTag.discoverAll(onDiscover);
});
@sandeepmistry Just cool ! This is exactly I was looking for. The noble framework works like a charm. Thanks a lot.
If a SensorTag gets disconnected the
onDiscover
function is still running. Intest.js
of SensorTag, the script is closed viaprocess.exit(0)
. This is OK, if you have only 1 SensorTag running and you want to stop the whole script in case of a disconnect. Is it possible to close theonDiscover
function when a disconnect happens?