bt-sensors-plugin-sk 1.2.0-beta.0.1.2 → 1.2.0-beta.0.1.2.b
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/README.md +9 -0
- package/bt-sensors-plugin-sk.json.bak +121 -0
- package/index.js +12 -7
- package/package.json +1 -1
- package/public/159.js +1 -1
- package/public/239.js +11 -5
- package/public/540.js +1 -1
- package/public/778.js +1 -1
- package/public/main.js +1 -1
- package/public/remoteEntry.js +1 -1
- package/.vscode/launch.json +0 -7
- package/testqueue.js +0 -64
package/README.md
CHANGED
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
{
|
|
2
|
+
"configuration": {
|
|
3
|
+
"discoveryTimeout": 30,
|
|
4
|
+
"discoveryInterval": 0,
|
|
5
|
+
"peripherals": [
|
|
6
|
+
{
|
|
7
|
+
"active": true,
|
|
8
|
+
"mac_address": "D4:50:46:39:38:C5",
|
|
9
|
+
"discoveryTimeout": 30,
|
|
10
|
+
"params": {
|
|
11
|
+
"name": "Victron Smart Shunt",
|
|
12
|
+
"encryptionKey": "8cce8529307cf9dd0c85611c4fef42d9"
|
|
13
|
+
},
|
|
14
|
+
"paths": {
|
|
15
|
+
"RSSI": "sensors.smartshunt.rssi",
|
|
16
|
+
"current": "electrical.battery.house.current",
|
|
17
|
+
"power": "electrical.battery.house.power",
|
|
18
|
+
"voltage": "electrical.battery.house.voltage",
|
|
19
|
+
"alarm": "electrical.battery.house.alarm",
|
|
20
|
+
"consumed": "electrical.battery.house.consumedAh",
|
|
21
|
+
"soc": "electrical.battery.house.soc",
|
|
22
|
+
"ttg": "electrical.battery.house.ttg",
|
|
23
|
+
"starterVoltage": "electrical.battery.starter.voltage",
|
|
24
|
+
"__state__": "sensors.smartshunt.state"
|
|
25
|
+
},
|
|
26
|
+
"gattParams": {
|
|
27
|
+
"useGATT": false
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
"active": true,
|
|
32
|
+
"mac_address": "F9:B0:6E:63:BC:7E",
|
|
33
|
+
"discoveryTimeout": 30,
|
|
34
|
+
"params": {
|
|
35
|
+
"name": "Ruuvi sensor for cabin"
|
|
36
|
+
},
|
|
37
|
+
"paths": {
|
|
38
|
+
"RSSI": "sensors.ruuviBC7E.rssi",
|
|
39
|
+
"temp": "environment.cabin.temperature",
|
|
40
|
+
"humidity": "environment.cabin.humidity",
|
|
41
|
+
"pressure": "environment.cabin.pressure",
|
|
42
|
+
"battV": "sensors.ruuviBC7E.voltage",
|
|
43
|
+
"mc": "sensors.ruuviBC7E.movementCounter",
|
|
44
|
+
"battery": "sensors.temperature.reefer.batterystrength",
|
|
45
|
+
"__state__": "sensors.ruuviBC7E.state"
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
"active": true,
|
|
50
|
+
"mac_address": "49:22:05:17:2B:AE",
|
|
51
|
+
"discoveryTimeout": 120,
|
|
52
|
+
"params": {
|
|
53
|
+
"name": "Inkbird temperature sensor"
|
|
54
|
+
},
|
|
55
|
+
"paths": {
|
|
56
|
+
"RSSI": "sensors.inkbird-th2.rssi",
|
|
57
|
+
"temp": "environment.refrigerator.temperature",
|
|
58
|
+
"battery": "sensors.inkbird-th2.battery",
|
|
59
|
+
"__state__": "sensors.inkbird-th2.state"
|
|
60
|
+
}
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
"active": true,
|
|
64
|
+
"mac_address": "A4:C1:38:9F:F7:7E",
|
|
65
|
+
"discoveryTimeout": 300,
|
|
66
|
+
"params": {
|
|
67
|
+
"name": "ATC Temp/Humidity sensor for Deck",
|
|
68
|
+
"parser": "ATC-LE"
|
|
69
|
+
},
|
|
70
|
+
"paths": {
|
|
71
|
+
"RSSI": "sensors.ATC_9FF77E.rssi",
|
|
72
|
+
"temp": "environment.deck.temperature",
|
|
73
|
+
"humidity": "environment.deck.humidity",
|
|
74
|
+
"voltage": "sensors.ATC_9FF77E.voltage",
|
|
75
|
+
"batteryStrength": "sensors.ATC_9FF77E.batteryStrength",
|
|
76
|
+
"__state__": "sensors.ATC_9FF77E.state"
|
|
77
|
+
}
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
"active": true,
|
|
81
|
+
"mac_address": "D4:40:59:BE:2A:8C",
|
|
82
|
+
"discoveryTimeout": 30,
|
|
83
|
+
"params": {
|
|
84
|
+
"medium": "PROPANE",
|
|
85
|
+
"tankHeight": "304.8",
|
|
86
|
+
"name": "Galley propane level"
|
|
87
|
+
},
|
|
88
|
+
"paths": {
|
|
89
|
+
"RSSI": "sensors.mopeka-59be8c.rssi",
|
|
90
|
+
"battVolt": "sensors.mopeka-59be8c.battery.voltage",
|
|
91
|
+
"battStrength": "sensors.mopeka-59be8c.battery.strength",
|
|
92
|
+
"temp": "sensors.mopeka-59be8c.temperature",
|
|
93
|
+
"tankLevel": "sensors.mopeka-59be8c.tankLevel",
|
|
94
|
+
"readingQuality": "sensors.mopeka-59be8c.quality",
|
|
95
|
+
"__state__": "sensors.mopeka-59be8c.state"
|
|
96
|
+
}
|
|
97
|
+
},
|
|
98
|
+
{
|
|
99
|
+
"active": true,
|
|
100
|
+
"mac_address": "A4:C1:38:3E:7E:94",
|
|
101
|
+
"discoveryTimeout": 30,
|
|
102
|
+
"params": {
|
|
103
|
+
"encryptionKey": "3985f4ebc032f276cc316f1f6ecea085",
|
|
104
|
+
"__state__": "sensors.xiaomi.state"
|
|
105
|
+
},
|
|
106
|
+
"paths": {
|
|
107
|
+
"RSSI": "sensors.xiaomi.rssi",
|
|
108
|
+
"temp": "sensors.xiaomi.temp",
|
|
109
|
+
"humidity": "sensors.xiaomi.humidity",
|
|
110
|
+
"voltage": "sensors.xiaomi.voltage",
|
|
111
|
+
"__state__": "sensors.xiaomi.state"
|
|
112
|
+
},
|
|
113
|
+
"gattParams": {
|
|
114
|
+
"useGATT": false
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
]
|
|
118
|
+
},
|
|
119
|
+
"enabled": true,
|
|
120
|
+
"enableDebug": true
|
|
121
|
+
}
|
package/index.js
CHANGED
|
@@ -106,6 +106,7 @@ module.exports = function (app) {
|
|
|
106
106
|
type: "string", default: "hci0"},
|
|
107
107
|
transport: {title: "Transport ",
|
|
108
108
|
type: "string", enum: ["auto","le","bredr"], default: "le", enumNames:["Auto", "LE-Bluetooth Low Energy", "BR/EDR Bluetooth basic rate/enhanced data rate"]},
|
|
109
|
+
duplicateData: {title: "Set scanner to report duplicate data", type: "boolean", default: false, },
|
|
109
110
|
discoveryTimeout: {title: "Default device discovery timeout (in seconds)",
|
|
110
111
|
type: "integer", default: 30,
|
|
111
112
|
minimum: 10,
|
|
@@ -227,6 +228,7 @@ module.exports = function (app) {
|
|
|
227
228
|
data: {
|
|
228
229
|
adapter: options.adapter,
|
|
229
230
|
transport: options.transport,
|
|
231
|
+
duplicateData: options.duplicateData,
|
|
230
232
|
discoveryTimeout: options.discoveryTimeout,
|
|
231
233
|
discoveryInterval: options.discoveryInterval
|
|
232
234
|
}
|
|
@@ -291,8 +293,11 @@ module.exports = function (app) {
|
|
|
291
293
|
config: config?config:{}
|
|
292
294
|
}
|
|
293
295
|
}
|
|
294
|
-
|
|
296
|
+
|
|
297
|
+
async function startScanner(options) {
|
|
295
298
|
|
|
299
|
+
const transport = options?.transport??"le"
|
|
300
|
+
const duplicateData = options?.duplicateData??false
|
|
296
301
|
app.debug("Starting scan...");
|
|
297
302
|
//Use adapter.helper directly to get around Adapter::startDiscovery()
|
|
298
303
|
//filter options which can cause issues with Device::Connect()
|
|
@@ -300,9 +305,10 @@ module.exports = function (app) {
|
|
|
300
305
|
//try {await adapter.startDiscovery()}
|
|
301
306
|
try{
|
|
302
307
|
if (transport) {
|
|
303
|
-
app.debug(`Setting Bluetooth transport option to ${transport}`)
|
|
308
|
+
app.debug(`Setting Bluetooth transport option to ${transport}. DuplicateData to ${duplicateData}`)
|
|
304
309
|
await adapter.helper.callMethod('SetDiscoveryFilter', {
|
|
305
|
-
Transport: new Variant('s', transport)
|
|
310
|
+
Transport: new Variant('s', transport),
|
|
311
|
+
DuplicateData: new Variant('b', duplicateData)
|
|
306
312
|
})
|
|
307
313
|
}
|
|
308
314
|
await adapter.helper.callMethod('StartDiscovery')
|
|
@@ -311,8 +317,7 @@ module.exports = function (app) {
|
|
|
311
317
|
app.debug(error)
|
|
312
318
|
}
|
|
313
319
|
|
|
314
|
-
}
|
|
315
|
-
|
|
320
|
+
}
|
|
316
321
|
function updateSensor(sensor){
|
|
317
322
|
channel.broadcast(getSensorInfo(sensor), "sensorchanged")
|
|
318
323
|
}
|
|
@@ -549,7 +554,7 @@ module.exports = function (app) {
|
|
|
549
554
|
plugin.schema.properties.adapter.enumNames.push(`${a.adapter} @ ${ await a.getAddress()} (${await a.getName()})`)
|
|
550
555
|
}
|
|
551
556
|
|
|
552
|
-
await startScanner(options
|
|
557
|
+
await startScanner(options)
|
|
553
558
|
if (starts>0){
|
|
554
559
|
app.debug(`Plugin ${packageInfo.version} restarting...`);
|
|
555
560
|
} else {
|
|
@@ -559,7 +564,7 @@ module.exports = function (app) {
|
|
|
559
564
|
starts++
|
|
560
565
|
if (!await adapter.isDiscovering())
|
|
561
566
|
try{
|
|
562
|
-
await startScanner()
|
|
567
|
+
await startScanner(options)
|
|
563
568
|
} catch (e){
|
|
564
569
|
app.debug(`Error starting scan: ${e.message}`)
|
|
565
570
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bt-sensors-plugin-sk",
|
|
3
|
-
"version": "1.2.0-beta.0.1.2",
|
|
3
|
+
"version": "1.2.0-beta.0.1.2.b",
|
|
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/public/159.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";(self.webpackChunkbt_sensors_plugin_sk=self.webpackChunkbt_sensors_plugin_sk||[]).push([[159],{
|
|
1
|
+
"use strict";(self.webpackChunkbt_sensors_plugin_sk=self.webpackChunkbt_sensors_plugin_sk||[]).push([[159],{62995:(e,t,n)=>{n.r(t),n.d(t,{default:()=>A});var a=n(73490),s=n(74810),o=n(86528),r=n.n(o),l=n(27606),c=n(86452),i=n(3768),u=n(71431),g=n(39676),d=n(47041),m=n(86038),f=n(95027),p=n(43540),h=n(24712),E=n(75056),w=n(96890),S=n(23399);const v=e=>console.log.bind(console,e);var y,b={};const A=e=>{const[t,n]=(0,o.useState)({}),[A,D]=(0,o.useState)({}),[$,_]=(0,o.useState)({}),[k,C]=(0,o.useState)({"ui:submitButtonOptions":{props:{disabled:!1,className:"btn btn-info"},norender:!0,submitText:"Submit"}}),[x,T]=(0,o.useState)([]),[j,M]=(0,o.useState)(),[O,N]=(0,o.useState)(new Map),[B,U]=(0,o.useState)({progress:0,maxTimeout:100,deviceCount:0,totalDevices:0}),[J,L]=(0,o.useState)("unknown"),[P,K]=(0,o.useState)();function z(e,t){console.log(`sending ${e}`),console.log(t);const n=new Headers;return n.append("Content-Type","application/json"),fetch(`/plugins/bt-sensors-plugin-sk/${e}`,{credentials:"include",method:"POST",body:JSON.stringify(t),headers:n})}async function H(e){return console.log(`fetching ${e}`),fetch(`/plugins/bt-sensors-plugin-sk/${e}`,{credentials:"include"})}async function I(){console.log("getProgress");const e=await H("getProgress");if(200!=e.status)throw new Error(`Unable get progres: ${e.statusText} (${e.status}) `);const t=await e.json();return console.log(t),t}function R(){console.log("refreshing sensor map"),async function(){console.log("getSensors");const e=await H("getSensors");if(200!=e.status)throw new Error(`Unable get sensor data: ${e.statusText} (${e.status}) `);const t=await e.json();return console.log(t),t}().then((e=>{N(new Map(e.map((e=>[e.info.mac,e]))))})).catch((e=>{K(e)}))}function W(e){return Object.keys(e.config).length>0}function Y(e){const t=W(e);return r().createElement(w.A,{action:!0,onClick:()=>{e.config.mac_address=e.info.mac,_(e.schema),M(e.config)}},r().createElement("div",{class:"d-flex justify-content-between align-items-center",style:t?{fontWeight:"normal"}:{fontStyle:"italic"}},`${e._changesMade?"*":""}${e.info.name} MAC: ${e.info.mac} RSSI: ${n=e.info.RSSI,null==n?NaN:n}`,r().createElement("div",{class:"d-flex justify-content-between "},function(e){return null==e.info.lastContactDelta||e.info.lastContactDelta>e.config.discoveryTimeout?r().createElement(i.A,null):e.info.signalStrength>80?r().createElement(u.A,null):e.info.signalStrength>60?r().createElement(g.A,null):e.info.signalStrength>40?r().createElement(d.A,null):e.info.signalStrength>20?r().createElement(m.A,null):r().createElement(f.A,null)}(e))));var n}return(0,o.useEffect)((()=>{console.log("useEffect([])");let e=null;return H("getPluginState").then((async t=>{if(404==t.status)throw L("unknown"),new Error("unable to get plugin state");const n=await t.json();console.log("Setting up eventsource"),e=new EventSource("/plugins/bt-sensors-plugin-sk/sse",{withCredentials:!0}),L(n.state),await async function(){console.log("getDomains");const e=await H("getDomains");if(200!=e.status)throw new Error(`Unable get domain data: ${e.statusText} (${e.status}) `);const t=await e.json();return console.log(t),t}(),e.addEventListener("newsensor",(e=>{console.log("newsensor");let t=JSON.parse(e.data);y.has(t.info.mac)||(console.log(`New sensor: ${t.info.mac}`),N(new Map(y.set(t.info.mac,t))))})),e.addEventListener("sensorchanged",(e=>{let t=JSON.parse(e.data);if(console.log("sensorchanged"),console.log(t),y.has(t.mac)){let e=y.get(t.mac);Object.assign(e.info,t),N(new Map(y))}})),e.addEventListener("progress",(e=>{console.log("progress");const t=JSON.parse(e.data);U(t),console.log(t)})),e.addEventListener("pluginstate",(e=>{console.log("pluginstate");const t=JSON.parse(e.data);L(t.state)}))})).catch((e=>{K(e)})),()=>{console.log("Closing connection to SSE"),e.close()}}),[]),(0,o.useEffect)((()=>{console.log("useEffect([pluginState])"),"started"==J?(R(),async function(){console.log("getBaseData");const e=await H("getBaseData");if(200!=e.status)throw new Error(`Unable get base data: ${e.statusText} (${e.status}) `);const t=await e.json();return console.log(t),t}().then((e=>{n(e.schema),D(e.data)})).catch((e=>{K(e)})),I().then((e=>{U(e)})).catch((e=>{K(e)}))):(N(new Map),n({}),D({}))}),[J]),(0,o.useEffect)((()=>{console.log("useEffect([sensorMap])"),y=O;const e=new Set(O.entries().map((e=>e[1].info.domain))),t={_configured:Array.from(O.entries()).filter((e=>W(e[1]))).map((e=>Y(O.get(e[0]))))};e.forEach((e=>{var n;t[e]=(n=e,Array.from(O.entries()).filter((e=>e[1].info.domain===n))).map((e=>Y(O.get(e[0]))))})),b=t}),[O]),"stopped"==J||"unknown"==J?r().createElement("h1",null,"Enable plugin to see configuration (if plugin is Enabled and you're seeing this message, restart SignalK)"):r().createElement("div",null,P?r().createElement("h2",{style:"color: red;"},P):"",r().createElement(a.Ay,{schema:t,validator:s.Ay,onChange:e=>D(e.formData),onSubmit:({formData:e},t)=>{var n;n=e,console.log("updateBaseData"),z("updateBaseData",n).then((e=>{200!=e.status?K(new Error(`Unable to update base data: ${e.statusText} (${e.status})`)):(I().then((e=>{U(e)})).catch((e=>{K(e)})),R())})),_({})},onError:v("errors"),formData:A}),r().createElement("p",null),r().createElement("p",null),B.deviceCount<B.totalDevices?r().createElement(S.A,{max:B.maxTimeout,now:B.progress}):"",r().createElement("h2",null,O.size>0?"Bluetooth Devices - Select to configure":""),r().createElement("h2",null,O.size>0?"(* = sensor has unsaved changes)":""),r().createElement("p",null),r().createElement(h.A,{defaultActiveKey:"_configured",id:"domain-tabs",className:"mb-3"},Object.keys(b).map((e=>{return n=(t=e).slice("_"===t.charAt(0)?1:0),r().createElement(E.A,{eventKey:t,title:n.charAt(0).toUpperCase()+n.slice(1)},r().createElement("div",{style:{paddingBottom:20},class:"d-flex flex-wrap justify-content-start align-items-start"},r().createElement(p.A,{style:{maxHeight:"300px",overflowY:"auto"}},function(e){return b[e]}(t)),r().createElement("div",{style:{paddingLeft:10,paddingTop:10,display:0==Object.keys($).length?"none":""}},r().createElement(a.Ay,{schema:$,validator:s.Ay,uiSchema:k,onChange:e=>{O.get(e.formData.mac_address)._changesMade=!0,M(e.formData)},onSubmit:({formData:e},t)=>{var n;console.log(e),n=e,console.log("updateSensorData"),z("updateSensorData",n).then((e=>{if(200!=e.status)throw new Error(e.statusText);O.get(n.mac_address)._changesMade=!1,O.get(n.mac_address).config=n})),_({}),alert("Changes saved")},onError:v("errors"),formData:j},r().createElement("div",null,r().createElement(l.A,{direction:"row",style:{spacing:5}},r().createElement(c.A,{type:"submit",color:"primary",variant:"contained"},"Save"),r().createElement(c.A,{variant:"contained",onClick:()=>{var e;e=j.mac_address,console.log("undoChanges"),O.get(e)._changesMade=!1,M(O.get(e).config)}},"Undo"),r().createElement(c.A,{variant:"contained",color:"secondary",onClick:e=>{return t=j.mac_address,void(window.confirm(`Delete configuration for ${t}?`)&&function(e){console.log("removeSensorData");try{z("removeSensorData",{mac_address:e}).then((e=>{if(200!=e.status)throw new Error(e.statusText)})),y.delete(e),N(new Map(y)),_({})}catch{}}(t));var t}},"Delete")))))));var t,n}))))}}}]);
|