@bitpoolos/edge-bacnet 1.1.0 → 1.1.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/bacnet_client.js CHANGED
@@ -96,6 +96,7 @@ class BacnetClient extends EventEmitter {
96
96
 
97
97
  setTimeout(() => {
98
98
  that.queryDevices();
99
+ that.sanitizeDeviceList();
99
100
  }, "5000")
100
101
 
101
102
  } catch(e) {
@@ -132,7 +133,6 @@ class BacnetClient extends EventEmitter {
132
133
  newBacnetDevice.setLastSeen(Date.now());
133
134
  that.updateDeviceName(newBacnetDevice);
134
135
  that.deviceList.push(newBacnetDevice);
135
-
136
136
  } else if(foundIndex !== -1) {
137
137
  that.deviceList[foundIndex].updateDeviceConfig(device);
138
138
  that.deviceList[foundIndex].setLastSeen(Date.now());
@@ -189,7 +189,6 @@ class BacnetClient extends EventEmitter {
189
189
  .acquire()
190
190
  .then(function(release) {
191
191
  try {
192
-
193
192
  that.getDevicePointList(device).then(function() {
194
193
  that.buildJsonObject(device).then(function() {
195
194
  release();
@@ -208,7 +207,6 @@ class BacnetClient extends EventEmitter {
208
207
  });
209
208
  release();
210
209
  });
211
-
212
210
  } catch(e) {
213
211
  that.logOut("Error while querying devices: ", e);
214
212
  release();
@@ -220,30 +218,38 @@ class BacnetClient extends EventEmitter {
220
218
 
221
219
  sanitizeDeviceList() {
222
220
  let that = this;
221
+
222
+ //1 hour in seconds
223
+ let timeoutThreshold = 3600;
223
224
 
224
- that.deviceList.forEach(function(device, index) {
225
- if(((Date.now() - device.getLastSeen()) / 1000) > 3600) {
226
- //device hasnt responded to whoIs for over an hour
225
+ that.renderList.forEach(function(item, index) {
226
+ if(((Date.now() - item.lastSeen) / 1000) > timeoutThreshold) {
227
+ //render item hasnt responded to whoIs for over an hour
228
+
229
+ let deviceIndex = that.deviceList.findIndex(ele => ele.deviceId == item.deviceId);
230
+ let device = that.deviceList[deviceIndex];
231
+
232
+ let ipAddr = typeof device.getAddress() == "object" ? device.getAddress().address : device.getAddress();
233
+ let deviceKey = ipAddr + "-" + device.getDeviceId();
227
234
 
228
- let deviceKey = (typeof device.getAddress() == "object") ? device.getAddress().address + "-" + device.getDeviceId() : device.getAddress() + "-" + device.getDeviceId();
229
235
  delete that.networkTree[deviceKey];
230
236
 
231
- if(that.renderList){
232
- let foundIndex = that.renderList.findIndex(ele => ele.ipAddr == device.getAddress() && ele.deviceId == device.getDeviceId());
233
- if(foundIndex !== -1) {
234
- that.renderList.splice(foundIndex, 1);
235
- }
237
+ if(((Date.now() - device.getLastSeen()) / 1000) > timeoutThreshold) {
238
+ that.deviceList.splice(deviceIndex, 1);
236
239
  }
237
240
 
238
- that.deviceList.splice(index, 1);
241
+ that.renderList.splice(index, 1);
239
242
  }
240
243
  });
244
+
241
245
  }
242
246
 
243
247
  updateDeviceName(device) {
244
248
  let that = this;
245
249
  that._getDeviceName(device.getAddress(), device.getDeviceId()).then(function(deviceName) {
246
- device.setDeviceName(deviceName);
250
+ if(typeof deviceName == "string") {
251
+ device.setDeviceName(deviceName);
252
+ }
247
253
  });
248
254
  }
249
255
 
@@ -322,16 +328,29 @@ class BacnetClient extends EventEmitter {
322
328
  let bacnetResults = {};
323
329
  devicesToRead.forEach(function(key, index) {
324
330
  let device = that.deviceList.find(ele => `${that.getDeviceAddress(ele)}-${ele.getDeviceId()}` == key);
325
- let deviceName = device.getDeviceName();
326
- bacnetResults[deviceName] = readConfig.pointsToRead[key];
327
- if(index == devicesToRead.length - 1) that.emit('values', bacnetResults, outputType, objectPropertyType);
331
+ if(device) {
332
+ let deviceName = device.getDeviceName();
333
+ let deviceKey = (typeof device.getAddress() == "object") ? device.getAddress().address + "-" + device.getDeviceId() : device.getAddress() + "-" + device.getDeviceId();
334
+ let deviceObject = that.networkTree[deviceKey];
335
+ if(!bacnetResults[deviceName]) bacnetResults[deviceName] = {};
336
+ if(deviceObject) {
337
+ for(const pointName in readConfig.pointsToRead[key]) {
338
+ let bac_obj = that.getObjectType(readConfig.pointsToRead[key][pointName].objectID.type);
339
+ let objectId = pointName + "_" + bac_obj + '_' + readConfig.pointsToRead[key][pointName].objectID.instance;
340
+ let point = deviceObject[objectId];
341
+ bacnetResults[deviceName][pointName] = point;
342
+ }
343
+ }
344
+ }
345
+
346
+ if(index == devicesToRead.length - 1 && Object.keys(readConfig.pointsToRead).length > 0) that.emit('values', bacnetResults, outputType, objectPropertyType);
328
347
  });
329
348
  } catch(e) {
330
349
  that.logOut("Issue doing read, see error: ", e);
331
350
  }
332
351
  }
333
352
 
334
- getDeviceAddress(device){
353
+ getDeviceAddress(device) {
335
354
  switch(typeof device.getAddress()) {
336
355
  case "object":
337
356
  return device.getAddress().address;
@@ -364,10 +383,7 @@ class BacnetClient extends EventEmitter {
364
383
  let objectName = that._findValueById(point.values, baEnum.PropertyIdentifier.OBJECT_NAME);
365
384
  //checks for error code json structure, returned for invalid bacnet requests
366
385
  if(!object.value.value && toReadProperty !== -1 && objectName !== "") {
367
- var currobjectId = point.objectId.type
368
- let bac_obj = that.getObjectType(currobjectId);
369
- let objectId;
370
- objectId = objectName;
386
+ let objectId = objectName;
371
387
 
372
388
  //init json object
373
389
  if(!values[objectId]) values[objectId] = {};
@@ -918,7 +934,7 @@ class BacnetClient extends EventEmitter {
918
934
  let isMstpDevice = deviceInfo.getIsMstpDevice();
919
935
  let manualDiscoveryMode = deviceInfo.getManualDiscoveryMode();
920
936
 
921
- if(deviceObject) {
937
+ if(deviceObject && typeof deviceName !== "object") {
922
938
  let children = [];
923
939
  let pointIndex = 0;
924
940
 
@@ -971,7 +987,7 @@ class BacnetClient extends EventEmitter {
971
987
  children.push({"key": `${index}-${pointIndex}`, "label": displayName, "data": displayName, "pointName": pointName, "icon": that.getPointIcon(values.meta.objectId.type), "children": pointProperties, "type": "point", "parentDevice": deviceName, "showAdded": false, "bacnetType": values.meta.objectId.type})
972
988
  pointIndex++;
973
989
  }
974
- let foundIndex = that.renderList.findIndex(ele => ele.key == index && ele.deviceId == deviceId);
990
+ let foundIndex = that.renderList.findIndex(ele => ele.deviceId == deviceId && ele.ipAddr == ipAddr);
975
991
  if(foundIndex !== -1) {
976
992
  that.renderList[foundIndex] = {"key": index, "label": deviceName, "data": deviceName, "icon": that.getDeviceIcon(isMstpDevice, manualDiscoveryMode), "children": children.sort(that.sortPoints), "type": "device", "lastSeen": deviceInfo.getLastSeen(), "showAdded": false, "ipAddr": ipAddr, "deviceId": deviceId, "isMstpDevice": isMstpDevice};
977
993
  } else if(foundIndex == -1) {
@@ -985,7 +1001,7 @@ class BacnetClient extends EventEmitter {
985
1001
  resolve({renderList: that.renderList, deviceList: that.deviceList, pointList: that.networkTree, pollFrequency: that.discover_polling_schedule});
986
1002
  }
987
1003
  }
988
-
1004
+
989
1005
  release();
990
1006
  });
991
1007
  });
@@ -1071,10 +1087,8 @@ class BacnetClient extends EventEmitter {
1071
1087
  try {
1072
1088
  pointProperty.values.forEach(function(object, objectIndex) {
1073
1089
  //checks for error code json structure, returned for invalid bacnet requests
1074
- //if(!object.value.value && !object.value[0].value.errorClass && !object.value.errorClass) {
1075
1090
  if(object && object.value && !object.value.errorClass) {
1076
1091
 
1077
-
1078
1092
  if(!values[objectId]) values[objectId] = {};
1079
1093
  values[objectId].meta = {
1080
1094
  objectId: pointProperty.objectId
package/bacnet_read.html CHANGED
@@ -210,7 +210,7 @@
210
210
  //force a deploy state
211
211
  node.hiddenDeployToggle = !node.prevHiddenToggleState;
212
212
 
213
- } catch(e){
213
+ } catch(e) {
214
214
  console.log("removeAllClicked error: ", e);
215
215
  }
216
216
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bitpoolos/edge-bacnet",
3
- "version": "1.1.0",
3
+ "version": "1.1.2",
4
4
  "description": "A bacnet gateway for node-red",
5
5
  "dependencies": {
6
6
  "async-mutex": "^0.4.0",