diff --git a/config.json b/config.json index 11b1830..c6f3347 100644 --- a/config.json +++ b/config.json @@ -45,8 +45,12 @@ "// Number of simultaneous bluetooth connection the device can handle (PI Zero=4)":0, "max_connections" : 4, + "// How long to wait before we disconnect an inactive bluetooth device":0, "connection_timeout": 20, + "// When a device sends data down a bluetooth 'notify' characteristic, should we keep the connection alive?":0, + "connection_alive_on_notify": false, + "// MQTT path for history requests and output. Default is Empty (to disable).":0, "//history_path": "/ble/hist/", diff --git a/lib/config.js b/lib/config.js index cf1dd4c..618d9f2 100644 --- a/lib/config.js +++ b/lib/config.js @@ -39,8 +39,12 @@ exports.ble_timeout = 10; /** How many seconds to wait for emitting a presence event, after latest time polled */ exports.presence_timeout = 60; +/** How long to wait before we disconnect an inactive bluetooth device */ exports.connection_timeout = 20; +/** When a device sends data down a bluetooth 'notify' characteristic, should we keep the connection alive? */ +exports.connection_alive_on_notify = false; + exports.max_connections = 4; exports.min_rssi = -100; @@ -97,6 +101,8 @@ exports.init = function () { exports.presence_timeout = json.presence_timeout; if (json.hasOwnProperty("connection_timeout")) exports.connection_timeout = json.connection_timeout; + if (json.hasOwnProperty("connection_alive_on_notify")) + exports.connection_alive_on_notify = !!json.connection_alive_on_notify; if (json.max_connections) exports.max_connections = json.max_connections; if (json.history_path) diff --git a/lib/connect.js b/lib/connect.js index d3fa8ee..ae82e0b 100644 --- a/lib/connect.js +++ b/lib/connect.js @@ -423,7 +423,9 @@ exports.notify = function (device, service, characteristic, callback) { if (DEBUG) log(connection.name + ": notification on " + JSON.stringify(data.toString("binary"))); if (connection.services[serviceUUID][characteristicUUID].notifyCallback) connection.services[serviceUUID][characteristicUUID].notifyCallback(data.toString("binary")); - connection.setUsed(); // Reset 'secondsSinceUsed' on notifyCallback triggered. + // If configured, reset 'secondsSinceUsed' on notifyCallback triggered. + if (config.connection_alive_on_notify) + connection.setUsed(); }); char.subscribe(function (err) { //if (DEBUG) log("> notify 3 "+(err||"success")+isBusy); diff --git a/lib/discovery.js b/lib/discovery.js index f131ccd..d18be00 100644 --- a/lib/discovery.js +++ b/lib/discovery.js @@ -226,7 +226,7 @@ exports.init = function () { exports.inRange = inRange; exports.startScan = function () { - log("caller if " + exports.startScan.caller); + log("caller is " + exports.startScan.caller); wishToScan = true; if ( config.ble_timeout > 0 && checkBrokenInterval === undefined) { log("Spawning check-broken interval");