bt-sensors-plugin-sk 1.2.0-beta.0.0.3 → 1.2.0-beta.0.0.4
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/BTSensor.js +1 -1
- package/Queue.js +3 -3
- package/package.json +1 -1
- package/sensor_classes/JBDBMS.js +2 -4
- package/testqueue.js +64 -0
package/BTSensor.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
const { Variant } = require('dbus-next');
|
|
2
2
|
const { log } = require('node:console');
|
|
3
3
|
const EventEmitter = require('node:events');
|
|
4
|
-
const AutoQueue =
|
|
4
|
+
const AutoQueue = require("./Queue.js")
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* @author Andrew Gerngross <oh.that.andy@gmail.com>
|
package/Queue.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
/*
|
|
2
2
|
see: https://stackoverflow.com/questions/53540348/js-async-await-tasks-queue
|
|
3
3
|
*/
|
|
4
|
-
class Queue {
|
|
4
|
+
class Queue {
|
|
5
5
|
constructor() { this._items = []; }
|
|
6
6
|
enqueue(item) { this._items.push(item); }
|
|
7
7
|
dequeue() { return this._items.shift(); }
|
|
8
8
|
get size() { return this._items.length; }
|
|
9
9
|
}
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
class AutoQueue extends Queue {
|
|
12
12
|
constructor() {
|
|
13
13
|
super();
|
|
14
14
|
this._pendingPromise = false;
|
|
@@ -45,4 +45,4 @@ class Queue {
|
|
|
45
45
|
return true;
|
|
46
46
|
}
|
|
47
47
|
}
|
|
48
|
-
module.exports = AutoQueue
|
|
48
|
+
module.exports = AutoQueue
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bt-sensors-plugin-sk",
|
|
3
|
-
"version": "1.2.0-beta.0.0.
|
|
3
|
+
"version": "1.2.0-beta.0.0.4",
|
|
4
4
|
"description": "Bluetooth Sensors for Signalk -- support for Victron devices, RuuviTag, Xiaomi, ATC and Inkbird, Ultrasonic wind meters, Mopeka tank readers, Renogy Battery and Solar Controllers, Aranet4 environment sensors, SwitchBot temp and humidity sensors, KilovaultHLXPlus smart batteries, and Govee GVH51xx temp sensors",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"dependencies": {
|
package/sensor_classes/JBDBMS.js
CHANGED
|
@@ -73,15 +73,13 @@ class JBDBMS extends BTSensor {
|
|
|
73
73
|
hasGATT(){
|
|
74
74
|
return true
|
|
75
75
|
}
|
|
76
|
-
initCharacteristics(){
|
|
77
|
-
return new Promise( async (resolve,reject )=>{
|
|
76
|
+
async initCharacteristics(){
|
|
78
77
|
const gattServer = await this.device.gatt()
|
|
79
78
|
const txRxService= await gattServer.getPrimaryService(this.constructor.TX_RX_SERVICE)
|
|
80
79
|
this.rxChar = await txRxService.getCharacteristic(this.constructor.NOTIFY_CHAR_UUID)
|
|
81
80
|
this.txChar = await txRxService.getCharacteristic(this.constructor.WRITE_CHAR_UUID)
|
|
82
81
|
await this.rxChar.startNotifications()
|
|
83
|
-
|
|
84
|
-
.catch((e)=>{ reject(e.message) }) })
|
|
82
|
+
return this
|
|
85
83
|
}
|
|
86
84
|
|
|
87
85
|
async initGATTNotifications(){
|
package/testqueue.js
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
import {createBluetooth} from 'node-ble'
|
|
4
|
+
|
|
5
|
+
import {AutoQueue} from "./Queue.js"
|
|
6
|
+
import {Variant} from 'dbus-next'
|
|
7
|
+
|
|
8
|
+
const {bluetooth, destroy} = createBluetooth()
|
|
9
|
+
const connectQueue = new AutoQueue()
|
|
10
|
+
const adapter = await bluetooth.getAdapter("hci0")
|
|
11
|
+
await adapter.startDiscovery()
|
|
12
|
+
|
|
13
|
+
function deviceConnect(mac) {
|
|
14
|
+
|
|
15
|
+
/* CAUTION: HACK AHEAD
|
|
16
|
+
|
|
17
|
+
Bluez for some cockamamie reason (It's 2025 for chrissake.
|
|
18
|
+
BLUETOOTH ISN'T JUST FOR DESKTOPS ANYMORE, BLUEZ DEVS!)
|
|
19
|
+
SUSPENDS scanning while connected to a device.
|
|
20
|
+
|
|
21
|
+
The next line of code gives the scanner a kick in the arse,
|
|
22
|
+
starting it up again so, I dunno, another device might be able
|
|
23
|
+
to connect and sensor classes could maybe get beacon updates.
|
|
24
|
+
|
|
25
|
+
You know, the little things.
|
|
26
|
+
*/
|
|
27
|
+
adapter.waitDevice(mac,(30000)).then((device) =>{
|
|
28
|
+
|
|
29
|
+
return connectQueue.enqueue( async ()=>{
|
|
30
|
+
console.log("Connecting to "+mac)
|
|
31
|
+
try {await device.connect()} catch {(e)=>console.log(e)}
|
|
32
|
+
try {
|
|
33
|
+
console.log("Connected to "+mac)
|
|
34
|
+
console.log("Stopping discovery for "+mac)
|
|
35
|
+
|
|
36
|
+
await adapter.helper.callMethod('StopDiscovery')
|
|
37
|
+
console.log("Discovery stopped for "+mac)
|
|
38
|
+
await adapter.helper.callMethod('SetDiscoveryFilter', {
|
|
39
|
+
Transport: new Variant('s', "le")
|
|
40
|
+
})
|
|
41
|
+
console.log("Starting discovery for "+mac)
|
|
42
|
+
await adapter.helper.callMethod('StartDiscovery')
|
|
43
|
+
console.log("Discovery started for "+mac)
|
|
44
|
+
|
|
45
|
+
} catch (e){
|
|
46
|
+
//probably ignorable error. probably.
|
|
47
|
+
console.log(e)
|
|
48
|
+
}
|
|
49
|
+
})
|
|
50
|
+
})
|
|
51
|
+
/* END HACK*/
|
|
52
|
+
}
|
|
53
|
+
setInterval( ()=>{
|
|
54
|
+
deviceConnect("D1:06:00:C6:16:4A")
|
|
55
|
+
}, 5000)
|
|
56
|
+
setInterval( ()=>{
|
|
57
|
+
|
|
58
|
+
for (const mac of (["D1:06:01:46:49:39","A4:C1:38:3E:7E:94"])){
|
|
59
|
+
try { deviceConnect(mac) } catch { (e)=>console.log(e) }
|
|
60
|
+
}
|
|
61
|
+
}, 10000)
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
|