bt-sensors-plugin-sk 1.1.0-beta.2.1.4 → 1.1.0-beta.2.1.4.1
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/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bt-sensors-plugin-sk",
|
|
3
|
-
"version": "1.1.0-beta.2.1.4",
|
|
4
|
-
"description": "Bluetooth Sensors for Signalk -- support for Victron devices, RuuviTag, Xiaomi, ATC and Inkbird, Ultrasonic, Mopeka tank reader ",
|
|
3
|
+
"version": "1.1.0-beta.2.1.4.1",
|
|
4
|
+
"description": "Bluetooth Sensors for Signalk -- support for Victron devices, RuuviTag, Xiaomi, ATC and Inkbird, Ultrasonic, Mopeka tank reader and preliminary support for Govee GVH51xx temp sensors",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"dependencies": {
|
|
7
7
|
"dbus-next": "^0.10.2",
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
const BTSensor = require("../BTSensor");
|
|
2
|
+
function decodeTempHumid(tempHumidBytes) {
|
|
3
|
+
// Convert the bytes to a 24-bit integer
|
|
4
|
+
const baseNum = (tempHumidBytes[0] << 16) + (tempHumidBytes[1] << 8) + tempHumidBytes[2];
|
|
5
|
+
|
|
6
|
+
// Check if the temperature is negative
|
|
7
|
+
const isNegative = (baseNum & 0x800000) !== 0;
|
|
8
|
+
|
|
9
|
+
// Extract the temperature and humidity values
|
|
10
|
+
const tempAsInt = baseNum & 0x7FFFFF;
|
|
11
|
+
const tempAsFloat = (tempAsInt / 1000) / 10.0;
|
|
12
|
+
const humid = (tempAsInt % 1000) / 10.0;
|
|
13
|
+
|
|
14
|
+
// Apply the negative sign if necessary
|
|
15
|
+
if (isNegative) {
|
|
16
|
+
return {t:-tempAsFloat, h: humid};
|
|
17
|
+
} else {
|
|
18
|
+
return {t: tempAsFloat, h: humid};
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
class GoveeTH extends BTSensor{
|
|
22
|
+
|
|
23
|
+
static async identify(device){
|
|
24
|
+
const regex = /^GVH5[0-9]{3}_[a-f,A-F,0-9]{4}$/
|
|
25
|
+
const name = await this.getDeviceProp(device,"Name")
|
|
26
|
+
const uuids = await this.getDeviceProp(device,'UUIDs')
|
|
27
|
+
|
|
28
|
+
if (name && name.match(regex) &&
|
|
29
|
+
uuids && uuids.length > 0 &&
|
|
30
|
+
uuids[0] == '0000ec88-0000-1000-8000-00805f9b34fb')
|
|
31
|
+
return this
|
|
32
|
+
else
|
|
33
|
+
return null
|
|
34
|
+
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
async init(){
|
|
38
|
+
await super.init()
|
|
39
|
+
}
|
|
40
|
+
initMetadata(){
|
|
41
|
+
this.addMetadatum('temp','K', 'temperature')
|
|
42
|
+
this.addMetadatum('battery','ratio', 'battery strength')
|
|
43
|
+
this.addMetadatum('humidity','ratio', 'humidity')
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
emitValuesFrom(buffer){
|
|
47
|
+
const th = decodeTempHumid(buffer.subarray(2,5))
|
|
48
|
+
this.emit("temp", parseFloat((273.15+th.t).toFixed(2))) ;
|
|
49
|
+
this.emit("humidity", th.h/100 )
|
|
50
|
+
this.emit('battery', buffer[5]/100)
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
getManufacturer(){
|
|
54
|
+
return "Govee"
|
|
55
|
+
}
|
|
56
|
+
async propertiesChanged(props){
|
|
57
|
+
super.propertiesChanged(props)
|
|
58
|
+
if (props.ManufacturerData) {
|
|
59
|
+
const buffer = this.getManufacturerData(0x0001)
|
|
60
|
+
if (buffer) {
|
|
61
|
+
this.emitValuesFrom(buffer)
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
module.exports=GoveeTH
|
|
@@ -24,7 +24,7 @@ class VictronSolarCharger extends VictronSensor{
|
|
|
24
24
|
this.addMetadatum('solarPower','W', 'solar power',
|
|
25
25
|
(buff)=>{return this.NaNif(buff.readUInt16LE(8),0xFFFF)})
|
|
26
26
|
this.addMetadatum('externalDeviceLoad','A', 'external device load',
|
|
27
|
-
(buff)=>{return this.NaNif(buff.
|
|
27
|
+
(buff)=>{return this.NaNif(buff.readUInt16LE(10)&0x1FF,0x1FF)/10})
|
|
28
28
|
}
|
|
29
29
|
}
|
|
30
30
|
module.exports=VictronSolarCharger
|