Skip to content

Commit

Permalink
Fix #116 - ensure that we can still disconnect from a device if it's …
Browse files Browse the repository at this point in the history
…repeatedly transmitting
  • Loading branch information
gfwilliams committed Dec 18, 2023
1 parent 713b8b4 commit d642196
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 2 deletions.
4 changes: 4 additions & 0 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -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/",

Expand Down
6 changes: 6 additions & 0 deletions lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 3 additions & 1 deletion lib/connect.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion lib/discovery.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down

0 comments on commit d642196

Please sign in to comment.