@rhizomatics/signalk-bluetti-plugin 1.0.7-alpha → 1.0.8-alpha

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.js CHANGED
@@ -192,9 +192,10 @@ module.exports = function (app) {
192
192
  pending.delete(normalise(address));
193
193
  app.setPluginStatus(`Found ${name} [${address}] — connecting …`);
194
194
  // Noble cannot scan and connect simultaneously — stop scan first.
195
+ // A short delay lets the BlueZ adapter finish scanning before we connect.
195
196
  // The scanComplete handler will restart scanning for any remaining pending devices.
196
197
  scanner.stopScan();
197
- startDevice(cfg, peripheral, name, deps);
198
+ setTimeout(() => startDevice(cfg, peripheral, name, deps), 500);
198
199
  } else {
199
200
  log(`Discovered unconfigured Bluetti device: ${name} [${address}]`);
200
201
  }
package/lib/device.js CHANGED
@@ -13,6 +13,7 @@ const ALT_SERVICE_UUID = 'ffe0';
13
13
  const ALT_CHAR_UUID = 'ffe1';
14
14
 
15
15
  const RECONNECT_DELAYS = [5000, 10000, 20000, 30000, 60000]; // ms, capped at last value
16
+ const CONNECT_TIMEOUT_MS = 15000;
16
17
 
17
18
  class BluettiDevice extends EventEmitter {
18
19
  constructor({ address, name, peripheral, fields, pollIntervalMs = 10000, xorKey = null, log }) {
@@ -60,7 +61,18 @@ class BluettiDevice extends EventEmitter {
60
61
  if (this._stopped) return;
61
62
  this._log(`[${this._name}] Connecting to ${this._address} …`);
62
63
 
64
+ let settled = false;
65
+ const connectTimer = setTimeout(() => {
66
+ if (settled) return;
67
+ settled = true;
68
+ this._log(`[${this._name}] Connect timed out after ${CONNECT_TIMEOUT_MS / 1000}s — will retry`);
69
+ this._scheduleReconnect();
70
+ }, CONNECT_TIMEOUT_MS);
71
+
63
72
  this._peripheral.connect((err) => {
73
+ if (settled) return;
74
+ settled = true;
75
+ clearTimeout(connectTimer);
64
76
  if (err) {
65
77
  this._log(`[${this._name}] Connect error: ${err.message}`);
66
78
  this._scheduleReconnect();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rhizomatics/signalk-bluetti-plugin",
3
- "version": "1.0.7-alpha",
3
+ "version": "1.0.8-alpha",
4
4
  "signalk": {
5
5
  "displayName": "Bluetti Monitoring"
6
6
  },