@bitpoolos/edge-bacnet 1.2.3 → 1.2.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/bacnet_client.js CHANGED
@@ -319,7 +319,6 @@ class BacnetClient extends EventEmitter {
319
319
  }
320
320
 
321
321
  } else {
322
- that.logOut("queryPriorityDevices: invalid device found: ", device);
323
322
  query(index);
324
323
  }
325
324
  } else if(index == priorityDevices.length) {
@@ -359,12 +358,12 @@ class BacnetClient extends EventEmitter {
359
358
  sanitizeDeviceList() {
360
359
  let that = this;
361
360
 
362
- //1 hour in seconds
363
- let timeoutThreshold = parseInt(that.discover_polling_schedule);
361
+ //Discover frequencey x 2
362
+ let timeoutThreshold = parseInt(that.discover_polling_schedule) * 2;
364
363
 
365
364
  that.deviceList.forEach(function(device, index) {
366
- if(((Date.now() - device.getLastSeen()) / 1000) > timeoutThreshold && device.getPriorityQueueIsActive() == false) {
367
- //render device hasnt responded to whoIs for over an hour
365
+ if(((Date.now() - device.getLastSeen()) / 1000) > timeoutThreshold && device.getPriorityQueueIsActive() == false) {
366
+ //render device hasnt responded to whoIs for disover frequency x 2
368
367
 
369
368
  let renderListIndex = that.renderList.findIndex(ele => ele.deviceId == device.getDeviceId());
370
369
 
@@ -988,16 +987,18 @@ class BacnetClient extends EventEmitter {
988
987
  });
989
988
  }
990
989
 
991
- updatePriorityQueue(req) {
990
+ updatePriorityQueue(priorityDevices) {
992
991
  let that = this;
993
992
  return new Promise(async function(resolve, reject) {
994
993
  try {
995
- let keys = Object.keys(req.body);
994
+ let keys = Object.keys(priorityDevices);
996
995
  if(keys.length > 0) {
997
996
  keys.forEach(function(key) {
998
997
  let device = that.deviceList.find(ele => `${that.getDeviceAddress(ele)}-${ele.getDeviceId()}` == key);
999
- let points = req.body[key];
1000
- device.setPriorityQueue(points);
998
+ let points = priorityDevices[key];
999
+ if(device) {
1000
+ device.setPriorityQueue(points);
1001
+ }
1001
1002
  });
1002
1003
  } else if(keys.length == 0) {
1003
1004
  that.clearPriorityQueues();
@@ -1309,7 +1310,8 @@ class BacnetClient extends EventEmitter {
1309
1310
  }
1310
1311
  }
1311
1312
  }
1312
- reject("Unexpectedly found end of loop, line 1214");
1313
+ that.networkTree[deviceKey] = values;
1314
+ resolve(that.networkTree);
1313
1315
  });
1314
1316
  }
1315
1317
 
package/bacnet_gateway.js CHANGED
@@ -177,6 +177,11 @@ module.exports = function (RED) {
177
177
  } else if (msg.payload == "BindEvents") {
178
178
  node.bacnetClient.removeAllListeners();
179
179
  bindEventListeners();
180
+ } else if (msg.doUpdatePriorityDevices == true && msg.priorityDevices !== null) {
181
+ node.bacnetClient.updatePriorityQueue(msg.priorityDevices).then(function (result) {
182
+ }).catch(function (error) {
183
+ logOut("Error updating priorityQueue: ", error);
184
+ });
180
185
  }
181
186
 
182
187
  });
@@ -264,21 +269,6 @@ module.exports = function (RED) {
264
269
  }
265
270
  });
266
271
 
267
- //route handler for priority queue
268
- RED.httpAdmin.post('/bitpool-bacnet-data/priorityQueue', function (req, res) {
269
- if (!node.bacnetClient) {
270
- logOut("Issue with the bacnetClient while getting device list: ", node.bacnetClient);
271
- res.send(false);
272
- } else {
273
- node.bacnetClient.updatePriorityQueue(req).then(function (result) {
274
- res.send(result);
275
- }).catch(function (error) {
276
- res.send(error);
277
- logOut("Error updating priorityQueue: ", error);
278
- });
279
- }
280
- });
281
-
282
272
  node.on('close', function () {
283
273
  //do nothing
284
274
  });
package/bacnet_read.html CHANGED
@@ -159,7 +159,13 @@
159
159
  this.$forceUpdate()
160
160
 
161
161
  //update node-red data structure to forward to gateway
162
- let device = this.deviceList.find(ele => ele.deviceName == slotProps.node.label);
162
+ let device = this.deviceList.find(ele => {
163
+ if(ele.address.address) {
164
+ return ele.address.address == slotProps.node.ipAddr && ele.deviceId == slotProps.node.deviceId;
165
+ } else {
166
+ return ele.address == slotProps.node.ipAddr && ele.deviceId == slotProps.node.deviceId;
167
+ }
168
+ });
163
169
  let deviceAddress = app.getDeviceAddress(device.address);
164
170
  let key = `${deviceAddress}-${device.deviceId}`;
165
171
  let points = this.pointList[key];
@@ -208,7 +214,13 @@
208
214
  this.$forceUpdate();
209
215
 
210
216
  //update node-red data structure
211
- let device = this.deviceList.find(ele => ele.deviceName == slotProps.node.label);
217
+ let device = this.deviceList.find(ele => {
218
+ if(ele.address.address) {
219
+ return ele.address.address == slotProps.node.ipAddr && ele.deviceId == slotProps.node.deviceId;
220
+ } else{
221
+ return ele.address == slotProps.node.ipAddr && ele.deviceId == slotProps.node.deviceId;
222
+ }
223
+ });
212
224
  let deviceAddress = app.getDeviceAddress(device.address);
213
225
  let key = `${deviceAddress}-${device.deviceId}`;
214
226
  if (this.pointsToRead[key]) {
@@ -254,7 +266,13 @@
254
266
  this.$forceUpdate();
255
267
 
256
268
  //update node-red data structure
257
- let device = this.deviceList.find(ele => ele.deviceName == parentDeviceName);
269
+ let device = this.deviceList.find(ele => {
270
+ if(ele.address.address) {
271
+ return ele.address.address == parentDevice.ipAddr && ele.deviceId == parentDevice.deviceId;
272
+ } else {
273
+ return ele.address == parentDevice.ipAddr && ele.deviceId == parentDevice.deviceId;
274
+ }
275
+ });
258
276
  let deviceAddress = app.getDeviceAddress(device.address);
259
277
  let key = `${deviceAddress}-${device.deviceId}`;
260
278
 
@@ -292,7 +310,13 @@
292
310
  this.$forceUpdate();
293
311
 
294
312
  //update node-red data stucture
295
- let device = this.deviceList.find(ele => ele.deviceName == parentDeviceName);
313
+ let device = this.deviceList.find(ele => {
314
+ if(ele.address.address) {
315
+ return ele.address.address == parentDevice.ipAddr && ele.deviceId == parentDevice.deviceId;
316
+ } else {
317
+ return ele.address == parentDevice.ipAddr && ele.deviceId == parentDevice.deviceId;
318
+ }
319
+ });
296
320
  let deviceAddress = app.getDeviceAddress(device.address);
297
321
  let key = `${deviceAddress}-${device.deviceId}`;
298
322
  let point = this.pointList[key][slotProps.node.pointName];
package/bacnet_read.js CHANGED
@@ -60,14 +60,12 @@ module.exports = function (RED) {
60
60
  rejectUnauthorized: false
61
61
  });
62
62
 
63
- fetch('http://localhost:1880/bitpool-bacnet-data/priorityQueue', {method: 'POST', headers: headers, agent: agent, body: JSON.stringify(node.pointsToRead)})
64
- .then(function(res) {
65
- //do nothing
66
- }).catch(function(error) {
67
- //do nothing
68
- });
63
+ let priorityDevicesMsg = {
64
+ doUpdatePriorityDevices: true,
65
+ priorityDevices: node.pointsToRead
66
+ };
69
67
 
70
-
68
+ node.send(priorityDevicesMsg);
71
69
 
72
70
  node.on('input', function(msg) {
73
71
 
package/bacnet_write.html CHANGED
@@ -108,7 +108,13 @@
108
108
  this.$forceUpdate()
109
109
 
110
110
  //update node-red data structure to forward to gateway
111
- let device = this.deviceList.find(ele => ele.deviceName == slotProps.node.label);
111
+ let device = this.deviceList.find(ele => {
112
+ if(ele.address.address) {
113
+ return ele.address.address == slotProps.node.ipAddr && ele.deviceId == slotProps.node.deviceId;
114
+ } else{
115
+ return ele.address == slotProps.node.ipAddr && ele.deviceId == slotProps.node.deviceId;
116
+ }
117
+ });
112
118
  let key = `${device.address}-${device.deviceId}`;
113
119
  let points = this.pointList[key];
114
120
 
@@ -133,7 +139,13 @@
133
139
  this.$forceUpdate()
134
140
 
135
141
  //update node-red data structure
136
- let device = this.deviceList.find(ele => ele.deviceName == slotProps.node.label);
142
+ let device = this.deviceList.find(ele => {
143
+ if(ele.address.address) {
144
+ return ele.address.address == slotProps.node.ipAddr && ele.deviceId == slotProps.node.deviceId;
145
+ } else{
146
+ return ele.address == slotProps.node.ipAddr && ele.deviceId == slotProps.node.deviceId;
147
+ }
148
+ });
137
149
  let key = `${device.address}-${device.deviceId}`;
138
150
  if (this.pointsToWrite[key]) {
139
151
  delete this.pointsToWrite[key];
@@ -147,10 +159,10 @@
147
159
  //update UI
148
160
  let parentDeviceName = slotProps.node.parentDevice;
149
161
  let foundDeviceIndex = this.writeDevices ? this.writeDevices.findIndex(ele => ele.label == parentDeviceName) : -1;
162
+ let parentDevice = this.devices.find(ele => ele.label == parentDeviceName);
150
163
 
151
164
  if (foundDeviceIndex == -1) {
152
165
  //no read devices present, add new
153
- let parentDevice = this.devices.find(ele => ele.label == parentDeviceName);
154
166
  let newReadParent = {...parentDevice};
155
167
  newReadParent.children = [];
156
168
  newReadParent.children.push(slotProps.node);
@@ -171,7 +183,13 @@
171
183
  this.$forceUpdate();
172
184
 
173
185
  //update node-red data structure
174
- let device = this.deviceList.find(ele => ele.deviceName == parentDeviceName);
186
+ let device = this.deviceList.find(ele => {
187
+ if(ele.address.address) {
188
+ return ele.address.address == parentDevice.ipAddr && ele.deviceId == parentDevice.deviceId;
189
+ } else {
190
+ return ele.address == parentDevice.ipAddr && ele.deviceId == parentDevice.deviceId;
191
+ }
192
+ });
175
193
  let key = `${device.address}-${device.deviceId}`;
176
194
  let point = this.pointList[key][slotProps.node.pointName];
177
195
  point.deviceId = device.deviceId;
@@ -197,6 +215,7 @@
197
215
  //update UI
198
216
  let parentDeviceName = slotProps.node.parentDevice;
199
217
  let foundDeviceIndex = this.writeDevices ? this.writeDevices.findIndex(ele => ele.label == parentDeviceName) : -1;
218
+ let parentDevice = this.devices.find(ele => ele.label == parentDeviceName);
200
219
 
201
220
  if (foundDeviceIndex !== -1) {
202
221
  let foundIndex = this.writeDevices[foundDeviceIndex].children.findIndex(ele => ele.key == slotProps.node.key && ele.label == slotProps.node.label);
@@ -211,7 +230,13 @@
211
230
  this.$forceUpdate();
212
231
 
213
232
  //update node-red data stucture
214
- let device = this.deviceList.find(ele => ele.deviceName == parentDeviceName);
233
+ let device = this.deviceList.find(ele => {
234
+ if(ele.address.address) {
235
+ return ele.address.address == parentDevice.ipAddr && ele.deviceId == parentDevice.deviceId;
236
+ } else {
237
+ return ele.address == parentDevice.ipAddr && ele.deviceId == parentDevice.deviceId;
238
+ }
239
+ });
215
240
  let key = `${device.address}-${device.deviceId}`;
216
241
  let point = this.pointList[key][slotProps.node.pointName];
217
242
  point.deviceId = device.deviceId;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bitpoolos/edge-bacnet",
3
- "version": "1.2.3",
3
+ "version": "1.2.5",
4
4
  "description": "A bacnet gateway for node-red",
5
5
  "dependencies": {
6
6
  "@plus4nodered/ts-node-bacnet": "^1.0.0-beta.2",