Skip to content

Commit d642196

Browse files
committed
Fix #116 - ensure that we can still disconnect from a device if it's repeatedly transmitting
1 parent 713b8b4 commit d642196

File tree

4 files changed

+14
-2
lines changed

4 files changed

+14
-2
lines changed

config.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,12 @@
4545
"// Number of simultaneous bluetooth connection the device can handle (PI Zero=4)":0,
4646
"max_connections" : 4,
4747

48+
"// How long to wait before we disconnect an inactive bluetooth device":0,
4849
"connection_timeout": 20,
4950

51+
"// When a device sends data down a bluetooth 'notify' characteristic, should we keep the connection alive?":0,
52+
"connection_alive_on_notify": false,
53+
5054
"// MQTT path for history requests and output. Default is Empty (to disable).":0,
5155
"//history_path": "/ble/hist/",
5256

lib/config.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,12 @@ exports.ble_timeout = 10;
3939
/** How many seconds to wait for emitting a presence event, after latest time polled */
4040
exports.presence_timeout = 60;
4141

42+
/** How long to wait before we disconnect an inactive bluetooth device */
4243
exports.connection_timeout = 20;
4344

45+
/** When a device sends data down a bluetooth 'notify' characteristic, should we keep the connection alive? */
46+
exports.connection_alive_on_notify = false;
47+
4448
exports.max_connections = 4;
4549

4650
exports.min_rssi = -100;
@@ -97,6 +101,8 @@ exports.init = function () {
97101
exports.presence_timeout = json.presence_timeout;
98102
if (json.hasOwnProperty("connection_timeout"))
99103
exports.connection_timeout = json.connection_timeout;
104+
if (json.hasOwnProperty("connection_alive_on_notify"))
105+
exports.connection_alive_on_notify = !!json.connection_alive_on_notify;
100106
if (json.max_connections)
101107
exports.max_connections = json.max_connections;
102108
if (json.history_path)

lib/connect.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,9 @@ exports.notify = function (device, service, characteristic, callback) {
423423
if (DEBUG) log(connection.name + ": notification on " + JSON.stringify(data.toString("binary")));
424424
if (connection.services[serviceUUID][characteristicUUID].notifyCallback)
425425
connection.services[serviceUUID][characteristicUUID].notifyCallback(data.toString("binary"));
426-
connection.setUsed(); // Reset 'secondsSinceUsed' on notifyCallback triggered.
426+
// If configured, reset 'secondsSinceUsed' on notifyCallback triggered.
427+
if (config.connection_alive_on_notify)
428+
connection.setUsed();
427429
});
428430
char.subscribe(function (err) {
429431
//if (DEBUG) log("> notify 3 "+(err||"success")+isBusy);

lib/discovery.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ exports.init = function () {
226226
exports.inRange = inRange;
227227

228228
exports.startScan = function () {
229-
log("caller if " + exports.startScan.caller);
229+
log("caller is " + exports.startScan.caller);
230230
wishToScan = true;
231231
if ( config.ble_timeout > 0 && checkBrokenInterval === undefined) {
232232
log("Spawning check-broken interval");

0 commit comments

Comments
 (0)