bt-sensors-plugin-sk 1.1.0-beta.2.1.4.4 → 1.1.0-beta.2.1.4.5

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
@@ -1,9 +1,11 @@
1
1
  const fs = require('fs')
2
2
  const util = require('util')
3
3
  const path = require('path')
4
+ const packageInfo = require("./package.json")
5
+
4
6
  const {createBluetooth} = require('node-ble')
5
7
  const {bluetooth, destroy} = createBluetooth()
6
- const packageInfo = require("./package.json")
8
+
7
9
  const BTSensor = require('./BTSensor.js')
8
10
  const BLACKLISTED = require('./sensor_classes/BlackListedDevice.js')
9
11
 
@@ -152,8 +154,8 @@ module.exports = function (app) {
152
154
  classMap = utilities_sk.loadClasses(path.join(__dirname, 'sensor_classes'))
153
155
  }
154
156
 
155
- app.debug(`Loading plugin ${packageInfo.version}`)
156
-
157
+ app.debug(`Loading plugin ${packageInfo.version}`)
158
+
157
159
  plugin.schema = {
158
160
  type: "object",
159
161
  description: "NOTE: \n 1) Plugin must be enabled to configure your sensors. \n"+
@@ -414,7 +416,7 @@ module.exports = function (app) {
414
416
  if (plugin.schema.properties.peripherals.items.dependencies)
415
417
  plugin.schema.properties.peripherals.items.dependencies.mac_address.oneOf=[]
416
418
  } else {
417
- app.debug('Plugin build Beta 2.4.1.2 started');
419
+ app.debug(`Loading plugin ${packageInfo.version} started` )
418
420
 
419
421
  }
420
422
  starts++
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bt-sensors-plugin-sk",
3
- "version": "1.1.0-beta.2.1.4.4",
3
+ "version": "1.1.0-beta.2.1.4.5",
4
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": {
@@ -258,22 +258,20 @@ class MopekaTankSensor extends BTSensor{
258
258
  const md = this.valueIfVariant(this.getManufacturerData(this.constructor.manufacturerID))
259
259
  this.modelID = md[0]
260
260
  this.initMetadata()
261
+
261
262
  }
262
263
 
263
264
  getMedium(){
264
265
  return Media[this?.medium??'PROPANE']
265
266
  }
266
- getTankHeight(){
267
- return this?.tankHeight??304.8 //Assume a foot
268
- }
269
267
 
270
268
  _tankLevel( rawLevel ){
271
269
  const coefs= this.getMedium().coefficients
272
- return rawLevel * (coefs[0] + (coefs[1] * (this.temp-233.15)) + (coefs[2] * ((this.temp-233.15)^2)))
270
+ return rawLevel * (coefs[0] + (coefs[1] * (this.temp-273.15)) + (coefs[2] * ((this.temp-273.15)^2)))
273
271
  }
274
272
 
275
273
  initMetadata(){
276
- var md = this.addMetadatum("medium","","type of liquid in tank")
274
+ const md = this.addMetadatum("medium","","type of liquid in tank")
277
275
  md.isParam=true
278
276
  md.enum=Object.keys(Media)
279
277
 
@@ -295,8 +293,8 @@ class MopekaTankSensor extends BTSensor{
295
293
  return this.temp
296
294
  }).bind(this)
297
295
  )
298
- this.addMetadatum("tankLevel","ratio","tank level",
299
- (buffer)=>{ return (this._tankLevel(((buffer.readUInt16LE(3))&0x3FFF)))/this.getTankHeight()}
296
+ this.addMetadatum("tankLevel","m","tank level",
297
+ (buffer)=>{ return this._tankLevel(((buffer.readUInt16LE(3))&0x3FFF))}
300
298
  )
301
299
  this.addMetadatum("readingQuality","","quality of read",
302
300
  (buffer)=>{ return buffer.readUInt8(4)>>6}
@@ -314,7 +312,6 @@ class MopekaTankSensor extends BTSensor{
314
312
  if (props.ManufacturerData)
315
313
  this.emitValuesFrom( this.getManufacturerData(this.constructor.manufacturerID) )
316
314
  }
317
-
318
315
  getName(){
319
316
  if (this.name)
320
317
  return this.name
@@ -67,7 +67,7 @@ class VictronACCharger extends VictronSensor{
67
67
  this.emit("batt3", this.NaNif(br.read_unsigned_int(13),0x1FFF)/100)
68
68
  this.emit("curr3", this.NaNif(br.read_unsigned_int(11),0x7FF)/10)
69
69
  this.emit("temp", this.NaNif(br.read_unsigned_int(7),0x7F)+233.15)
70
- this.emit("acCurr", this.NaNif(br.read_unsigned_int(9),0x1FF)/10)
70
+ this.emit("acCurr", this.NaNif(br.read_unsigned_int(9),0x1FF)/100)
71
71
  }
72
72
  }
73
73
  module.exports=VictronACCharger
File without changes
@@ -1,107 +0,0 @@
1
- const BTSensor = require("../../BTSensor.js");
2
- const VC = require('./RenogyConstants.js');
3
- function sleep(x) {
4
- return new Promise((resolve) => {
5
- setTimeout(() => {
6
- resolve(x);
7
- }, x);
8
- });
9
- }
10
- class RenogySensor extends BTSensor{
11
-
12
- constructor(device,config,gattConfig){
13
- super(device,config,gattConfig)
14
- this.encryptionKey = config?.encryptionKey
15
- }
16
-
17
- static async identifyMode(device, mode){
18
-
19
- var md = await this.getDeviceProp(device,'ManufacturerData')
20
- if (md==undefined || !Object.hasOwn(md,0x2e1))
21
- return null
22
- else {
23
-
24
- if (md[0x2e1].value[0]==0x10) {
25
- if (md[0x2e1].value[4]==mode)
26
- return this
27
- else
28
- return null
29
- }
30
-
31
- var hasDataPacket=false
32
- device.helper._prepare()
33
- device.helper.on("PropertiesChanged",
34
- (props)=> {
35
- if (Object.hasOwn(props,'ManufacturerData')){
36
- md = props['ManufacturerData'].value
37
- hasDataPacket=md[0x2e1].value[0]==0x10
38
- }
39
- })
40
- while (!hasDataPacket) {
41
- await sleep(500)
42
- }
43
- device.helper.removeListeners()
44
- if (md[0x2e1].value[4]==mode)
45
- return this
46
- else
47
- return null
48
- }
49
- }
50
-
51
- async init(){
52
- await super.init()
53
- }
54
- alarmReason(alarmValue){
55
- return this.constructor.AlarmReason[alarmValue]
56
- }
57
- getModelName(){
58
- return VC?.MODEL_ID_MAP[this.model_id]??this.constructor.name+" (Model ID:"+this.model_id+")"
59
- }
60
-
61
- decrypt(data){
62
- if (!this.encryptionKey)
63
- throw Error("Unable to decrypt: no encryption key set")
64
-
65
- const encMethod = 'aes-128-ctr';
66
- const iv = data.readUInt16LE(5);
67
- const key = Buffer.from(this.encryptionKey,'hex')
68
- const ivBuffer = Buffer.alloc(16); // 128 bits = 16 bytes
69
-
70
- ivBuffer.writeUInt16LE(iv)
71
-
72
- var encData = Buffer.from([...data.slice(8)])
73
-
74
- const decipher = crypto.createDecipheriv(encMethod, key, ivBuffer)
75
-
76
- const decData=decipher.update(encData)
77
-
78
- return Buffer.from(decData)
79
-
80
- }
81
- getName(){
82
- return `Victron ${this.getModelName()}`
83
- }
84
- propertiesChanged(props){
85
- super.propertiesChanged(props)
86
- if (this.usingGATT()) return
87
-
88
- try{
89
- const md = this.getManufacturerData(0x2e1)
90
- if (md && md.length && md[0]==0x10){
91
- const decData=this.decrypt(md)
92
- this.emitValuesFrom(decData)
93
- }
94
- }
95
- catch (error) {
96
- throw new Error(`Unable to read data from ${ this.getDisplayName()}: ${error}` )
97
- }
98
- }
99
-
100
- initGATTConnection(){
101
- throw new Error( "GATT Connection unimplemented for "+this.getDisplayName())
102
- }
103
-
104
-
105
-
106
- }
107
- module.exports=RenogySensor