bt-sensors-plugin-sk 1.1.0-beta.1 → 1.1.0-beta.2

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 CHANGED
@@ -10,10 +10,15 @@ const BTCompanies = require('./bt_co.json')
10
10
  */
11
11
 
12
12
  const BTCompanyMap=new Map()
13
+
13
14
  BTCompanies.company_identifiers.forEach( (v) =>{
14
15
  BTCompanyMap.set(v.value, v.name)
15
16
  })
16
17
 
18
+ /**
19
+ * https://www.intuitibits.com/2016/03/23/dbm-to-percent-conversion/
20
+ */
21
+
17
22
  function signalQualityPercentQuad(rssi, perfect_rssi=-20, worst_rssi=-85) {
18
23
  const nominal_rssi=(perfect_rssi - worst_rssi);
19
24
  var signal_quality =
@@ -31,6 +36,7 @@ function signalQualityPercentQuad(rssi, perfect_rssi=-20, worst_rssi=-85) {
31
36
  }
32
37
  return Math.ceil(signal_quality);
33
38
  }
39
+
34
40
  class BTSensor extends EventEmitter {
35
41
  static metadata=new Map()
36
42
  constructor(device, config={}, gattConfig={}) {
@@ -84,35 +90,58 @@ class BTSensor extends EventEmitter {
84
90
  }
85
91
  }
86
92
 
87
- static getMetadata(){
88
- return this.metadata
89
- }
90
-
91
- static {
92
- var md = this.addMetadatum("name", "string","Name of sensor" )
93
- md.isParam=true
94
-
95
-
93
+
94
+ static async getPropsProxy(device){
95
+
96
+ if (!device._propsProxy) {
97
+ const objectProxy = await device.helper.dbus.getProxyObject(device.helper.service, device.helper.object)
98
+ device._propsProxy = await objectProxy.getInterface('org.freedesktop.DBus.Properties')
99
+ }
100
+ return device._propsProxy
101
+ }
102
+ static async getDeviceProps(device, propNames=[]){
103
+ const _propsProxy = await this.getPropsProxy(device)
104
+ const rawProps = await _propsProxy.GetAll(device.helper.iface)
105
+ const props = {}
106
+ for (const propKey in rawProps) {
107
+ if (propNames.length==0 || propNames.indexOf(propKey)>=0)
108
+ props[propKey] = rawProps[propKey].value
109
+ }
110
+ return props
111
+ }
112
+ static async getDeviceProp(device, prop){
113
+ const _propsProxy = await this.getPropsProxy(device)
114
+ try{
115
+ const rawProps = await _propsProxy.Get(device.helper.iface,prop)
116
+ return rawProps?.value
117
+ }
118
+ catch(e){
119
+ return null //Property $prop (probably) doesn't exist in $device
120
+ }
121
+ }
96
122
 
97
- }
98
- static addMetadatum(tag, ...args){
99
- var metadatum = new this.Metadatum(tag, ...args)
100
- this.getMetadata().set(tag,metadatum)
101
- return metadatum
102
- }
103
123
 
104
- emitData(tag, buffer, ...args){
105
- this.emit(tag, this.getMetadatum(tag).read(buffer, ...args))
124
+ static async getManufacturerID(device){
125
+ const md = await this.getDeviceProp(device,'ManufacturerData')
126
+ if (!md) return null
127
+ const keys = Object.keys(md)
128
+ if (keys && keys.length>0){
129
+ return parseInt(keys[0])
130
+ }
131
+ return null
106
132
  }
133
+ static NaNif(v1,v2) { return (v1==v2)?NaN:v1 }
107
134
 
108
135
  async init(){
136
+ var md = this.addMetadatum("name", "string","Name of sensor" )
137
+ md.isParam=true
109
138
  this.currentProperties = await this.constructor.getDeviceProps(this.device)
110
139
  this.addMetadatum("RSSI","db","Signal strength in db")
111
140
  this.getMetadatum("RSSI").default=`sensors.${this.getMacAddress().replaceAll(':', '')}.rssi`
112
141
  this.getMetadatum("RSSI").read=()=>{return this.getRSSI()}
113
142
  this.getMetadatum("RSSI").read.bind(this)
114
- if (this.canUseGATT()) {
115
- var md = this.addMetadatum("useGATT", "boolean", "Use GATT connection")
143
+ if (this.hasGATT()) {
144
+ md = this.addMetadatum("useGATT", "boolean", "Use GATT connection")
116
145
  md.type="boolean"
117
146
  md.isParam=true
118
147
  md.isGATT=true
@@ -123,21 +152,9 @@ class BTSensor extends EventEmitter {
123
152
  md.isGATT=true
124
153
  }
125
154
  }
126
-
127
- static async getManufacturerID(device){
128
- const md = await this.getDeviceProp(device,'ManufacturerData')
129
- if (!md) return null
130
- const keys = Object.keys(md)
131
- if (keys && keys.length>0){
132
- return parseInt(keys[0])
133
- }
134
- return null
135
- }
136
- static NaNif(v1,v2) { return (v1==v2)?NaN:v1 }
137
155
 
138
156
  NaNif(v1,v2) { return this.constructor.NaNif(v1,v2) }
139
157
 
140
-
141
158
  addMetadatum(tag, ...args){
142
159
  var metadatum = new this.Metadatum(tag, ...args)
143
160
  this.getMetadata().set(tag, metadatum)
@@ -193,6 +210,8 @@ class BTSensor extends EventEmitter {
193
210
  return bars
194
211
 
195
212
  }
213
+
214
+
196
215
  getDescription(){
197
216
  return `${this.getName()} from ${this.getManufacturer()}`
198
217
  }
@@ -213,7 +232,7 @@ class BTSensor extends EventEmitter {
213
232
  getRSSI(){
214
233
  return this.currentProperties?.RSSI??NaN
215
234
  }
216
- canUseGATT(){
235
+ hasGATT(){
217
236
  return false
218
237
  }
219
238
  usingGATT(){
@@ -226,35 +245,10 @@ class BTSensor extends EventEmitter {
226
245
  return obj
227
246
 
228
247
  }
229
-
230
- static async getPropsProxy(device){
231
-
232
- const objectProxy = await device.helper.dbus.getProxyObject(device.helper.service, device.helper.object)
233
- if (!device._propsProxy)
234
- device._propsProxy = await objectProxy.getInterface('org.freedesktop.DBus.Properties')
235
- return device._propsProxy
236
- }
237
- static async getDeviceProps(device, propNames=[]){
238
- const _propsProxy = await this.getPropsProxy(device)
239
- const rawProps = await _propsProxy.GetAll(device.helper.iface)
240
- const props = {}
241
- for (const propKey in rawProps) {
242
- if (propNames.length==0 || propNames.indexOf(propKey)>=0)
243
- props[propKey] = rawProps[propKey].value
244
- }
245
- return props
248
+ emitData(tag, buffer, ...args){
249
+ this.emit(tag, this.getMetadatum(tag).read(buffer, ...args))
246
250
  }
247
- static async getDeviceProp(device, prop){
248
- const _propsProxy = await this.getPropsProxy(device)
249
- try{
250
- const rawProps = await _propsProxy.Get(device.helper.iface,prop)
251
- return rawProps?.value
252
- }
253
- catch(e){
254
- return null //Property $prop (probably) doesn't exist in $device
255
- }
256
- }
257
-
251
+
258
252
  /**
259
253
  * callback function on device properties changing
260
254
  */
@@ -294,9 +288,13 @@ class BTSensor extends EventEmitter {
294
288
  const id = this.getManufacturerID()
295
289
  return (id==null)?"Unknown manufacturer":BTCompanyMap.get(parseInt(id))
296
290
  }
297
- getManufacturerData(key){
291
+
292
+ getManufacturerData(key=null){
298
293
  if (this.currentProperties.ManufacturerData)
299
- return this.valueIfVariant (this.currentProperties.ManufacturerData[key])
294
+ if (key)
295
+ return this.valueIfVariant (this.currentProperties.ManufacturerData[key])
296
+ else
297
+ return(this.valueIfVariant (this.currentProperties.ManufacturerData))
300
298
  else
301
299
  return null
302
300
  }
package/index.js CHANGED
@@ -30,7 +30,7 @@ class MissingSensor {
30
30
  this.mac_address = config.mac_address
31
31
 
32
32
  }
33
- canUseGATT(){
33
+ hasGATT(){
34
34
  return false
35
35
  }
36
36
  getMetadata(){
@@ -257,7 +257,7 @@ module.exports = function (app) {
257
257
  oneOf.properties.params.properties[tag]=metadatum.asJSONSchema()
258
258
  })
259
259
 
260
- if (sensor.canUseGATT()){
260
+ if (sensor.hasGATT()){
261
261
 
262
262
  oneOf.properties.gattParams={
263
263
  title:`GATT Specific device parameters`,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "bt-sensors-plugin-sk",
3
- "version": "1.1.0-beta.1",
4
- "description": "Bluetooth Sensors for Signalk - Beta 20241012",
3
+ "version": "1.1.0-beta.2",
4
+ "description": "Bluetooth Sensors for Signalk -- support for Victron devices, RuuviTag, Xiaomi, ATC and Inkbird",
5
5
  "main": "index.js",
6
6
  "dependencies": {
7
7
  "dbus-next": "^0.10.2",
@@ -14,8 +14,8 @@ class ATC extends BTSensor{
14
14
  return null
15
15
  }
16
16
 
17
- static {
18
- this.metadata = new Map(super.getMetadata())
17
+ async init() {
18
+ await super.init()
19
19
  this.addMetadatum('temp','K', 'temperature',
20
20
  (buff,offset)=>{return ((buff.readInt16LE(offset))/100) + 273.1})
21
21
  this.addMetadatum('humidity','ratio', 'humidity',
@@ -16,14 +16,10 @@ class Inkbird extends BTSensor{
16
16
  return null
17
17
  }
18
18
 
19
- static {
20
- this.metadata = new Map(super.getMetadata())
21
- this.addMetadatum('temp','K', 'temperature')
22
- this.addMetadatum('battery','ratio', 'battery strength')
23
- }
24
-
25
19
  async init(){
26
20
  await super.init()
21
+ this.addMetadatum('temp','K', 'temperature')
22
+ this.addMetadatum('battery','ratio', 'battery strength')
27
23
  if (this.getName() == 'sps'){
28
24
  this.addMetadatum('humidity','ratio', 'humidity')
29
25
  }
@@ -11,11 +11,7 @@ class RuuviTag extends BTSensor{
11
11
  }
12
12
  return null
13
13
  }
14
-
15
- static {
16
- this.metadata = new Map(super.getMetadata())
17
- }
18
-
14
+
19
15
  async init(){
20
16
  await super.init()
21
17
  const md = this.valueIfVariant(this.getManufacturerData(this.constructor.manufacturerID))
@@ -11,12 +11,6 @@ const VC = require('./VictronConstants.js')
11
11
  this.encryptionKey = config?.encryptionKey
12
12
  }
13
13
 
14
- static {
15
- this.metadata = new Map(super.getMetadata())
16
- const md = this.addMetadatum('encryptionKey','', "Encryption Key")
17
- md.isParam = true
18
- }
19
-
20
14
  static async identifyMode(device, mode){
21
15
 
22
16
  try{
@@ -51,6 +45,11 @@ const VC = require('./VictronConstants.js')
51
45
 
52
46
  async init(){
53
47
  await super.init()
48
+ var md = this.addMetadatum('encryptionKey','', "Encryption Key")
49
+ md.isParam = true
50
+ this.metadata = new Map(super.getMetadata())
51
+ md = this.addMetadatum('encryptionKey','', "Encryption Key")
52
+ md.isParam = true
54
53
  this.model_id=this.getManufacturerData(0x2e1).readUInt16LE(2)
55
54
  }
56
55
  alarmReason(alarmValue){
@@ -28,9 +28,8 @@ class VictronACCharger extends VictronSensor{
28
28
  return await this.identifyMode(device, 0x0A)
29
29
  }
30
30
 
31
- static {
32
- this.metadata = new Map(super.getMetadata())
33
-
31
+ async init(){
32
+ await super.init()
34
33
  this.addMetadatum('state','', 'device state',
35
34
  (buff)=>{return VC.OperationMode.get(buff.readUInt8(0))})
36
35
  this.addMetadatum('error','', 'error code',
@@ -48,8 +47,8 @@ class VictronACCharger extends VictronSensor{
48
47
  this.addMetadatum('curr2','A', 'battery 2 current',
49
48
  (buff)=>{return this.NaNif(buff.readUInt16BE(7)&0x7FF,0x7FF)/10})
50
49
 
51
- this.addMetadatum('batt3','V', 'battery 3 voltage',
52
- (buff)=>{return this.NaNif((buff.readUInt16BE(8)>>3), 0x1FFF)/100})
50
+ this.addMetadatum('batt3','V', 'battery 3 voltage',
51
+ (buff)=>{return this.NaNif((buff.readUInt16BE(8)>>3), 0x1FFF)/100})
53
52
 
54
53
  this.addMetadatum('curr3','A', 'battery 3 current',
55
54
  (buff)=>{return this.NaNif(buff.readUInt16BE(9)&0x7FF,0x7FF)/10})
@@ -1,11 +1,18 @@
1
1
  const VictronSensor = require("./Victron/VictronSensor.js");
2
2
  const VC=require("./Victron/VictronConstants.js")
3
3
  class VictronBatteryMonitor extends VictronSensor{
4
- static {
5
- this.metadata = new Map(super.getMetadata())
4
+
5
+
6
+ static async identify(device){
7
+ return await this.identifyMode(device, 0x02)
8
+ }
9
+
10
+ characteristics=[]
11
+ async init(){
12
+ await super.init()
6
13
  this.addMetadatum('current', 'A', 'house battery amperage',
7
- (buff,offset=0)=>{return buff.readInt32LE(offset)/1000},
8
- '6597ed8c-4bda-4c1e-af4b-551c4cf74769')
14
+ (buff,offset=0)=>{return buff.readInt32LE(offset)/1000},
15
+ '6597ed8c-4bda-4c1e-af4b-551c4cf74769')
9
16
  this.addMetadatum('power','W', 'house battery wattage',
10
17
  (buff,offset=0)=>{return buff.readInt16LE(offset)},
11
18
  '6597ed8e-4bda-4c1e-af4b-551c4cf74769')
@@ -27,15 +34,6 @@ class VictronBatteryMonitor extends VictronSensor{
27
34
  this.addMetadatum( 'ttg','s','time to go',
28
35
  (buff,offset=0)=>{return this.NaNif(buff.readUInt16LE(offset),0xFFFF)*60},
29
36
  '65970ffe-4bda-4c1e-af4b-551c4cf74769')
30
- }
31
-
32
- static async identify(device){
33
- return await this.identifyMode(device, 0x02)
34
- }
35
-
36
- characteristics=[]
37
- async init(){
38
- await super.init()
39
37
  const modecurrent = this.getAuxModeAndCurrent()
40
38
  this.auxMode= modecurrent.auxMode
41
39
  switch(this.auxMode){
@@ -138,7 +136,7 @@ class VictronBatteryMonitor extends VictronSensor{
138
136
  propertiesChanged(props){
139
137
  super.propertiesChanged(props)
140
138
  }
141
- canUseGATT(){
139
+ hasGATT(){
142
140
  return true
143
141
  }
144
142
 
@@ -7,8 +7,8 @@ class VictronDCDCConverter extends VictronSensor{
7
7
  return await this.identifyMode(device,0x04)
8
8
  }
9
9
 
10
- static {
11
- this.metadata= new Map(super.getMetadata())
10
+ async init(){
11
+ await super.init()
12
12
  this.addMetadatum('deviceState','', 'device state',
13
13
  (buff)=>{return VC.OperationMode.get(buff.readUInt8(0))})
14
14
  this.addMetadatum('chargerError','', 'charger error',
@@ -8,6 +8,13 @@ class VictronDCEnergyMeter extends VictronSensor{
8
8
  }
9
9
  async init(){
10
10
  await super.init()
11
+ this.addMetadatum('meterType','', 'meter type',
12
+ (buff)=>{return VC.MeterType.get( buff.readInt16LE(0))})
13
+ this.addMetadatum('voltage','','voltage',
14
+ (buff)=>{return buff.readInt16LE(2)/100})
15
+ this.addMetadatum('alarm','', 'alarm',
16
+ (buff)=>{return buff.readUInt16LE(4)})
17
+ this.addMetadatum('current','A', 'current')
11
18
  const modeCurrent = this.getAuxModeAndCurrent()
12
19
  this.auxMode= modeCurrent.auxMode
13
20
  switch(this.auxMode){
@@ -30,16 +37,7 @@ class VictronDCEnergyMeter extends VictronSensor{
30
37
  break
31
38
  }
32
39
  }
33
- static {
34
- this.metadata = new Map(super.getMetadata())
35
- this.addMetadatum('meterType','', 'meter type',
36
- (buff)=>{return VC.MeterType.get( buff.readInt16LE(0))})
37
- this.addMetadatum('voltage','','voltage',
38
- (buff)=>{return buff.readInt16LE(2)/100})
39
- this.addMetadatum('alarm','', 'alarm',
40
- (buff)=>{return buff.readUInt16LE(4)})
41
- this.addMetadatum('current','A', 'current')
42
- }
40
+
43
41
  emitValuesFrom(decData){
44
42
  this.emitData("meterType",decData,0)
45
43
  this.emitData("voltage",decData,2);
@@ -26,8 +26,8 @@ TBD
26
26
  return await this.identifyMode(device, 0x07)
27
27
  }
28
28
 
29
- static {
30
- this.metadata = new Map(super.getMetadata())
29
+ async init() {
30
+ super.init()
31
31
  this.addMetadatum('voltage','V', 'channel #1 voltage',
32
32
  (buff)=>{return this.NaNif(buff.readInt16LE(0),0xFFFF)/100})
33
33
  this.addMetadatum('pvPower','W','DC input power in watts',
@@ -7,12 +7,11 @@ class VictronInverter extends VictronSensor{
7
7
  return await this.identifyMode(device, 0x03)
8
8
  }
9
9
 
10
- static {
11
- var md
12
- this.metadata= new Map(super.getMetadata())
10
+ async init() {
11
+ await super.init()
13
12
  this.addMetadatum('deviceState','', 'inverter device state',
14
13
  (buff)=>{return VC.OperationMode.get(buff.readIntU8(0))})
15
- md = this.addMetadatum('alarmReason','', 'reason for alarm',
14
+ const md = this.addMetadatum('alarmReason','', 'reason for alarm',
16
15
  (buff)=>{return buff.readIntU16LE(1)})
17
16
  md.notify=true
18
17
 
@@ -10,12 +10,12 @@ class VictronInverterRS extends VictronSensor{
10
10
  }
11
11
 
12
12
 
13
- static {
14
- var md
15
- this.metadata= new Map(super.getMetadata())
13
+ async init() {
14
+ await super.init()
15
+
16
16
  this.addMetadatum('deviceState','', 'inverter device state',
17
17
  (buff)=>{return VC.OperationMode.get(buff.readIntU8(0))})
18
- md = this.addMetadatum('chargerError','', 'charger error',
18
+ const md = this.addMetadatum('chargerError','', 'charger error',
19
19
  (buff)=>{return VC.ChargerError(buff.readIntU8(1))})
20
20
  md.notify=true
21
21
 
@@ -23,9 +23,8 @@ class VictronLynxSmartBMS extends VictronSensor{
23
23
  return await this.identifyMode(device, 0x0A)
24
24
  }
25
25
 
26
- static {
27
- this.metadata = new Map(super.getMetadata())
28
-
26
+ async init() {
27
+ await super.init()
29
28
  this.addMetadatum('error','', 'error code',
30
29
  (buff)=>{return buff.readUInt8(0)})
31
30
 
@@ -8,9 +8,8 @@ class VictronOrionXS extends VictronSensor{
8
8
  static async identify(device){
9
9
  return await this.identifyMode(device, 0x0F)
10
10
  }
11
- static {
12
- this.metadata = new Map(super.getMetadata())
13
-
11
+ async init() {
12
+ await super.init()
14
13
  this.addMetadatum('deviceState','', 'device state',
15
14
  (buff)=>{return VC.OperationMode.get(buff.readUInt8(0))})
16
15
  this.addMetadatum('chargerError','', 'charger error',
@@ -23,9 +23,8 @@ class VictronSmartBatteryProtect extends VictronSensor{
23
23
  return await this.identifyMode(device, 0x09)
24
24
  }
25
25
 
26
- static {
27
- this.metadata = new Map(super.getMetadata())
28
-
26
+ async init() {
27
+ await super.init()
29
28
  this.addMetadatum('deviceState','', 'device state',
30
29
  (buff)=>{return VC.OperationMode.get(buff.readUInt8(1))})
31
30
  this.addMetadatum('outputStatus','', 'output status', //TODO
@@ -25,16 +25,14 @@ class VictronSmartLithium extends VictronSensor{
25
25
  return await this.identifyMode(device, 0x05)
26
26
  }
27
27
 
28
- static {
29
-
28
+ async init() {
29
+ await super.init()
30
30
  function _toCellVoltage(val){
31
31
  return val==0x7F?NaN:2.6+(val/100)
32
32
  }
33
- this.metadata = new Map(super.getMetadata())
34
-
35
33
  this.addMetadatum('bmsFlags','', 'BMS Flags',
36
34
  (buff)=>{return buff.readUInt32BE(0)})
37
- /
35
+
38
36
  this.addMetadatum('smartLithiumErrors','', 'Smart Lithium Errors Flags',
39
37
  (buff)=>{return buff.readUInt16BE(3)})
40
38
  this.addMetadatum('cell1Voltage','V', 'cell #1 voltage',
@@ -58,9 +56,7 @@ class VictronSmartLithium extends VictronSensor{
58
56
  this.addMetadatum('balancerStatus','', 'balancer status', //TODO
59
57
  (buff)=>{return this.NaNif((buff.readUInt16BE(14)&0xf),0xF)})
60
58
  this.addMetadatum('batteryTemp','K', 'battery temperature',
61
- (buff)=>{return this.NaNif((buff.readInt8(15)>>1),0x7F)+233.15})
62
-
63
-
59
+ (buff)=>{return this.NaNif((buff.readInt8(15)>>1),0x7F)+233.15})
64
60
  }
65
61
  }
66
62
  module.exports=VictronSmartLithium
@@ -6,8 +6,8 @@ class VictronSolarCharger extends VictronSensor{
6
6
  return await this.identifyMode(device, 0x01)
7
7
  }
8
8
 
9
- static {
10
- this.metadata = new Map(super.getMetadata())
9
+ async init() {
10
+ await super.init()
11
11
 
12
12
  this.addMetadatum('chargeState','', 'charge state',
13
13
  (buff)=>{return VC.OperationMode.get(buff.readUInt8(0))})
@@ -9,8 +9,8 @@ class VictronVEBus extends VictronSensor{
9
9
  return await this.identifyMode(device, 0x0C)
10
10
  }
11
11
 
12
- static {
13
- this.metadata = new Map(super.getMetadata())
12
+ async init() {
13
+ await super.init()
14
14
 
15
15
  this.addMetadatum('chargeState','', 'charge state',
16
16
  (buff)=>{return VC.OperationMode.get(buff.readUInt8(0))})
@@ -91,21 +91,7 @@ class XiaomiMiBeacon extends BTSensor{
91
91
  }
92
92
  return null
93
93
  }
94
- static {
95
- this.metadata = new Map(super.getMetadata())
96
- //3985f4ebc032f276cc316f1f6ecea085
97
- //8a1dadfa832fef54e9c1d190
98
94
 
99
- const md = this.addMetadatum("encryptionKey", "", "encryptionKey (AKA bindKey) for decryption")
100
- md.isParam=true
101
- this.addMetadatum('temp','K', 'temperature',
102
- (buff,offset)=>{return ((buff.readInt16LE(offset))/100) + 273.1})
103
- this.addMetadatum('humidity','ratio', 'humidity',
104
- (buff,offset)=>{return ((buff.readUInt8(offset))/100)})
105
- this.addMetadatum('voltage', 'V', 'sensor battery voltage',
106
- (buff,offset)=>{return ((buff.readUInt16LE(offset))/1000)})
107
-
108
- }
109
95
  GATTwarning = "WARNING: Xiaomi GATT connections are known to be unreliable on Debian distributions with Bluez 5.55 and up (earlier BlueZ versions are untested). Using GATT on the Xiaomi may put the system Bluetooth stack into an inconsistent state disrupting and disabling other plugin Bluetooth connections. If by some chance you're successful using GATT with the Xiaomi, let the plugin developer know your configuration. Refer to the plugin documentation for getting the Xiamoi bindKey for non-GATT connections and more information on Xiaomi GATT issues."
110
96
 
111
97
  emitValues(buffer){
@@ -168,7 +154,7 @@ class XiaomiMiBeacon extends BTSensor{
168
154
  return cipher.update(encryptedPayload)
169
155
  }
170
156
 
171
- canUseGATT(){
157
+ hasGATT(){
172
158
  return true
173
159
  }
174
160
 
@@ -202,6 +188,15 @@ class XiaomiMiBeacon extends BTSensor{
202
188
 
203
189
  async init(){
204
190
  await super.init()
191
+ const md = this.addMetadatum("encryptionKey", "", "encryptionKey (AKA bindKey) for decryption")
192
+ md.isParam=true
193
+ this.addMetadatum('temp','K', 'temperature',
194
+ (buff,offset)=>{return ((buff.readInt16LE(offset))/100) + 273.1})
195
+ this.addMetadatum('humidity','ratio', 'humidity',
196
+ (buff,offset)=>{return ((buff.readUInt8(offset))/100)})
197
+ this.addMetadatum('voltage', 'V', 'sensor battery voltage',
198
+ (buff,offset)=>{return ((buff.readUInt16LE(offset))/1000)})
199
+
205
200
  const data = this.getServiceData(this.constructor.SERVICE_MIBEACON)
206
201
  const frameControl = data[0] + (data[1] << 8)
207
202
  this.deviceID = data[2] + (data[3] << 8)