node-red-contrib-mobius-flow-base 2.5.91 → 3.0.0-beta.13
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/.github/ISSUE_TEMPLATE/bug_report.md +16 -0
- package/.github/ISSUE_TEMPLATE/feature_request.md +16 -0
- package/.github/ISSUE_TEMPLATE/general.md +7 -0
- package/.github/workflows/build_publish.yml +80 -0
- package/README.md +4 -10
- package/dist/engine-api-calls.d.ts +19 -0
- package/dist/engine-api-calls.js +235 -0
- package/dist/engine-api-client.d.ts +8 -0
- package/dist/engine-api-client.js +106 -0
- package/dist/engine-websocket.d.ts +60 -0
- package/dist/engine-websocket.js +264 -0
- package/dist/node-red-ui-funcs.js +180 -0
- package/dist/nodes/common/mobsearch.js +602 -0
- package/dist/nodes/mobius-change-admin-password.d.ts +26 -0
- package/dist/nodes/mobius-change-admin-password.html +98 -0
- package/dist/nodes/mobius-change-admin-password.js +87 -0
- package/dist/nodes/mobius-clear-resource.html +37 -12
- package/dist/nodes/mobius-clear-resource.js +17 -13
- package/dist/nodes/mobius-connection-interface.d.ts +45 -0
- package/dist/nodes/mobius-connection-interface.js +2 -0
- package/dist/nodes/mobius-connection.html +30 -8
- package/dist/nodes/mobius-connection.js +216 -85
- package/dist/nodes/mobius-discover-object-list.html +185 -126
- package/dist/nodes/mobius-discover-object-list.js +24 -5
- package/dist/nodes/mobius-discover.js +7 -7
- package/dist/nodes/mobius-filter-by-rid-value.html +62 -42
- package/dist/nodes/mobius-filter-by-rid-value.js +38 -31
- package/dist/nodes/mobius-flow-inject.html +32 -2
- package/dist/nodes/mobius-get-multi-object.html +39 -5
- package/dist/nodes/mobius-get-multi-resource.html +37 -4
- package/dist/nodes/mobius-get-multi-resource.js +13 -12
- package/dist/nodes/mobius-get-object.html +39 -11
- package/dist/nodes/mobius-get-object.js +12 -9
- package/dist/nodes/mobius-get-resource.html +41 -12
- package/dist/nodes/mobius-get-resource.js +17 -12
- package/dist/nodes/mobius-object-cov.html +40 -11
- package/dist/nodes/mobius-object-cov.js +9 -6
- package/dist/nodes/mobius-resource-cov.html +37 -11
- package/dist/nodes/mobius-resource-cov.js +5 -5
- package/dist/nodes/mobius-set-multi-resource.html +39 -12
- package/dist/nodes/mobius-set-multi-resource.js +9 -11
- package/dist/nodes/mobius-set-resource.html +38 -11
- package/package.json +15 -8
- package/dist/nodes/node-red-ui-discover-devices.js +0 -103
|
@@ -27,8 +27,12 @@
|
|
|
27
27
|
'use strict';
|
|
28
28
|
|
|
29
29
|
var _ = require('lodash');
|
|
30
|
-
var
|
|
31
|
-
|
|
30
|
+
var uiFuncs = require('../node-red-ui-funcs');
|
|
31
|
+
|
|
32
|
+
const webSocket = require('../engine-websocket');
|
|
33
|
+
const apiCalls = require('../engine-api-calls');
|
|
34
|
+
const webSocketCalls = require('../engine-websocket');
|
|
35
|
+
const { getApiClient, setLoggedIn, closeApiClient } = require('../engine-api-client');
|
|
32
36
|
|
|
33
37
|
module.exports = function (RED) {
|
|
34
38
|
/**
|
|
@@ -62,18 +66,25 @@ module.exports = function (RED) {
|
|
|
62
66
|
RED.nodes.createNode(this, n);
|
|
63
67
|
this.host = n.host;
|
|
64
68
|
this.port = n.port;
|
|
65
|
-
this.
|
|
66
|
-
this.
|
|
67
|
-
this.
|
|
68
|
-
this.
|
|
69
|
-
|
|
70
|
-
|
|
69
|
+
this.username = n.username;
|
|
70
|
+
this.password = n.password;
|
|
71
|
+
this.secure = n.secure;
|
|
72
|
+
this.apiClient = getApiClient(
|
|
73
|
+
this.secure ? 'https' : 'http',
|
|
74
|
+
this.host,
|
|
75
|
+
this.port,
|
|
76
|
+
this.username,
|
|
77
|
+
this.password
|
|
78
|
+
);
|
|
79
|
+
// webSocket.connectToWebSocket();
|
|
80
|
+
webSocket.clearAllCallbacks();
|
|
81
|
+
webSocket.registerCallback('resource-cov', (response) => {
|
|
71
82
|
this.handleCOVEvents(response);
|
|
72
83
|
});
|
|
73
|
-
|
|
84
|
+
webSocket.registerCallback('object-cov', (response) => {
|
|
74
85
|
this.handleObjectCOVEvents(response);
|
|
75
86
|
});
|
|
76
|
-
|
|
87
|
+
webSocket.registerCallback('broadcast-command', (response) => {
|
|
77
88
|
this.handleBCMDEvents(response);
|
|
78
89
|
});
|
|
79
90
|
var node = this;
|
|
@@ -85,11 +96,27 @@ module.exports = function (RED) {
|
|
|
85
96
|
node.bcmdSubscriptions = new Map();
|
|
86
97
|
node.connected = false;
|
|
87
98
|
node.unsubscribeTimeout = 0;
|
|
99
|
+
node.hubId = null;
|
|
88
100
|
|
|
89
101
|
// Connected to the mobius TCPIP spoke
|
|
90
102
|
// Update the status indicators
|
|
91
|
-
|
|
103
|
+
webSocket.on('connected', () => {
|
|
92
104
|
this.log(`Connected to ${n.host} : ${n.port}`);
|
|
105
|
+
apiCalls.getHubId(this.apiClient, (err, hubId) => {
|
|
106
|
+
if (err) {
|
|
107
|
+
node.error('Mobius error getting hub ID' + JSON.stringify(err));
|
|
108
|
+
} else {
|
|
109
|
+
node.hubId = hubId;
|
|
110
|
+
apiCalls.discover(this.apiClient, node.hubId, (err, response) => {
|
|
111
|
+
if (err) {
|
|
112
|
+
node.error('Mobius error discovering service list' + JSON.stringify(err));
|
|
113
|
+
} else {
|
|
114
|
+
node.serviceList = response.data;
|
|
115
|
+
node.hasStarted = true;
|
|
116
|
+
}
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
});
|
|
93
120
|
node.connected = true;
|
|
94
121
|
_.forEach(node.users, (user, id) => {
|
|
95
122
|
if (node.users.hasOwnProperty(id)) {
|
|
@@ -102,30 +129,21 @@ module.exports = function (RED) {
|
|
|
102
129
|
});
|
|
103
130
|
// Subscribe to all COVs
|
|
104
131
|
this.resourceSubscriptions.forEach((subs, key) => {
|
|
105
|
-
|
|
132
|
+
webSocketCalls.subscribeToResourceCOV(key);
|
|
106
133
|
});
|
|
107
134
|
// Subscribe to all object COVs
|
|
108
135
|
node.objectSubscriptions.forEach((subs, key) => {
|
|
109
|
-
|
|
136
|
+
webSocketCalls.subscribeToObjectCOV(key);
|
|
110
137
|
});
|
|
111
138
|
// Subscribe to all BCMDs
|
|
112
139
|
node.bcmdSubscriptions.forEach((subs, key) => {
|
|
113
|
-
|
|
114
|
-
});
|
|
115
|
-
// Discover all service IDs
|
|
116
|
-
node.service.srvcAPI.discover(node.service.srvcAPI.status.hubId, (err, response) => {
|
|
117
|
-
if (err) {
|
|
118
|
-
node.error('Mobius error discovering service list' + JSON.stringify(err));
|
|
119
|
-
} else {
|
|
120
|
-
node.serviceList = response.value;
|
|
121
|
-
node.hasStarted = true;
|
|
122
|
-
}
|
|
140
|
+
webSocketCalls.subscribeToBCMD(key);
|
|
123
141
|
});
|
|
124
142
|
});
|
|
125
143
|
|
|
126
144
|
// Disconnected from the mobius TCPIP spoke
|
|
127
145
|
// Update the status indicators
|
|
128
|
-
|
|
146
|
+
webSocket.on('disconnected', () => {
|
|
129
147
|
this.log(`Disconnected from ${n.host} : ${n.port}`);
|
|
130
148
|
node.connected = false;
|
|
131
149
|
for (var id in node.users) {
|
|
@@ -214,54 +232,69 @@ module.exports = function (RED) {
|
|
|
214
232
|
* @param {Function} done - A callback to be run by the node after it has been deregistered
|
|
215
233
|
*/
|
|
216
234
|
node.deregister = function (mobiusNode, done) {
|
|
235
|
+
node.users[mobiusNode.id].status({
|
|
236
|
+
fill: 'red',
|
|
237
|
+
shape: 'ring',
|
|
238
|
+
text: 'Disconnected',
|
|
239
|
+
});
|
|
217
240
|
delete node.users[mobiusNode.id];
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
subs.splice(index, 1);
|
|
224
|
-
}
|
|
225
|
-
});
|
|
226
|
-
if (subs.length === 0) {
|
|
227
|
-
node.service.srvcAPI.unsubscribeToCOV(key);
|
|
228
|
-
node.resourceSubscriptions.delete(key);
|
|
241
|
+
try {
|
|
242
|
+
node.resourceSubscriptions.forEach((subs, key) => {
|
|
243
|
+
subs.forEach((sub, index) => {
|
|
244
|
+
if (mobiusNode.id === sub.node) {
|
|
245
|
+
subs.splice(index, 1);
|
|
229
246
|
}
|
|
230
247
|
});
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
248
|
+
if (subs.length === 0) {
|
|
249
|
+
webSocketCalls.unsubscribeToResourceCOV(key);
|
|
250
|
+
node.resourceSubscriptions.delete(key);
|
|
251
|
+
}
|
|
252
|
+
});
|
|
253
|
+
node.objectSubscriptions.forEach((subs, key) => {
|
|
254
|
+
subs.forEach((sub, index) => {
|
|
255
|
+
if (mobiusNode.id === sub.node) {
|
|
256
|
+
subs.splice(index, 1);
|
|
240
257
|
}
|
|
241
258
|
});
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
259
|
+
if (subs.length === 0) {
|
|
260
|
+
webSocketCalls.unsubscribeToObjectCOV(key);
|
|
261
|
+
node.objectSubscriptions.delete(key);
|
|
262
|
+
}
|
|
263
|
+
});
|
|
264
|
+
node.bcmdSubscriptions.forEach((subs, key) => {
|
|
265
|
+
subs.forEach((sub, index) => {
|
|
266
|
+
if (mobiusNode.id === sub.node) {
|
|
267
|
+
subs.splice(index, 1);
|
|
251
268
|
}
|
|
252
269
|
});
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
270
|
+
if (subs.length === 0) {
|
|
271
|
+
webSocketCalls.unsubscribeToBCMD(key);
|
|
272
|
+
node.bcmdSubscriptions.delete(key);
|
|
273
|
+
}
|
|
274
|
+
});
|
|
275
|
+
} catch (err) {
|
|
276
|
+
console.log(`Failed to unsubscribe from event: ${err.message}`);
|
|
257
277
|
}
|
|
258
|
-
done();
|
|
278
|
+
return done();
|
|
259
279
|
};
|
|
260
280
|
|
|
261
281
|
/**
|
|
262
282
|
* Register the close connection handler
|
|
263
283
|
*/
|
|
264
284
|
node.on('close', (done) => {
|
|
285
|
+
webSocket.killWebSocket();
|
|
286
|
+
closeApiClient();
|
|
287
|
+
setLoggedIn(false);
|
|
288
|
+
this.log(`Connection to MOBiUS closed.`);
|
|
289
|
+
for (var id in node.users) {
|
|
290
|
+
if (node.users.hasOwnProperty(id)) {
|
|
291
|
+
node.users[id].status({
|
|
292
|
+
fill: 'red',
|
|
293
|
+
shape: 'ring',
|
|
294
|
+
text: 'Disconnected',
|
|
295
|
+
});
|
|
296
|
+
}
|
|
297
|
+
}
|
|
265
298
|
if (node.connected) {
|
|
266
299
|
// Wait for all nodes to unsubscribe before terminating the connection
|
|
267
300
|
node.unsubscribeTimeout = 0;
|
|
@@ -273,16 +306,11 @@ module.exports = function (RED) {
|
|
|
273
306
|
node.unsubscribeTimeout > 50
|
|
274
307
|
) {
|
|
275
308
|
clearInterval(waitForCleanup);
|
|
276
|
-
|
|
277
|
-
node.service.once('disconnected', () => {
|
|
278
|
-
node.connected = false;
|
|
279
|
-
done();
|
|
280
|
-
});
|
|
309
|
+
done();
|
|
281
310
|
}
|
|
282
311
|
node.unsubscribeTimeout++;
|
|
283
312
|
}, 100);
|
|
284
313
|
} else {
|
|
285
|
-
node.service.end();
|
|
286
314
|
done();
|
|
287
315
|
}
|
|
288
316
|
});
|
|
@@ -296,7 +324,7 @@ module.exports = function (RED) {
|
|
|
296
324
|
* the response message event
|
|
297
325
|
*/
|
|
298
326
|
node.discover = function (uri, callback) {
|
|
299
|
-
|
|
327
|
+
apiCalls.discover(this.apiClient, uri, callback);
|
|
300
328
|
};
|
|
301
329
|
|
|
302
330
|
/**
|
|
@@ -307,7 +335,7 @@ module.exports = function (RED) {
|
|
|
307
335
|
* @param {Function} callback - Callback when complete
|
|
308
336
|
*/
|
|
309
337
|
node.writeResourceValue = function (uri, value, priority, callback) {
|
|
310
|
-
|
|
338
|
+
apiCalls.writeResource(this.apiClient, uri, value, priority, callback);
|
|
311
339
|
};
|
|
312
340
|
|
|
313
341
|
/**
|
|
@@ -320,7 +348,7 @@ module.exports = function (RED) {
|
|
|
320
348
|
* the response message event
|
|
321
349
|
*/
|
|
322
350
|
node.multiWriteResourceValue = function (uri, updates, callback) {
|
|
323
|
-
|
|
351
|
+
apiCalls.writeMultiResource(this.apiClient, uri, updates, callback);
|
|
324
352
|
};
|
|
325
353
|
|
|
326
354
|
/**
|
|
@@ -330,7 +358,7 @@ module.exports = function (RED) {
|
|
|
330
358
|
* @param {Function} callback - Callback when complete
|
|
331
359
|
*/
|
|
332
360
|
node.clearResourcePriority = function (uri, priority, callback) {
|
|
333
|
-
|
|
361
|
+
apiCalls.clearResource(this.apiClient, uri, priority, callback);
|
|
334
362
|
};
|
|
335
363
|
|
|
336
364
|
/**
|
|
@@ -339,7 +367,7 @@ module.exports = function (RED) {
|
|
|
339
367
|
* @param {Function} callback - Callback when complete
|
|
340
368
|
*/
|
|
341
369
|
node.readResource = function (uri, callback) {
|
|
342
|
-
|
|
370
|
+
apiCalls.readResource(this.apiClient, uri, callback);
|
|
343
371
|
};
|
|
344
372
|
|
|
345
373
|
/**
|
|
@@ -348,7 +376,7 @@ module.exports = function (RED) {
|
|
|
348
376
|
* @param {Function} callback - Callback when complete
|
|
349
377
|
*/
|
|
350
378
|
node.readObject = function (uri, callback) {
|
|
351
|
-
|
|
379
|
+
apiCalls.readObject(this.apiClient, uri, callback);
|
|
352
380
|
};
|
|
353
381
|
|
|
354
382
|
/**
|
|
@@ -361,9 +389,18 @@ module.exports = function (RED) {
|
|
|
361
389
|
* @param {Function} callback - function(err, [object]) {}
|
|
362
390
|
*/
|
|
363
391
|
node.filterObjectsByRIDValue = function (uri, pids, rid, limit, func, callback) {
|
|
364
|
-
|
|
392
|
+
apiCalls.filterObjectsByRIDValue(this.apiClient, uri, pids, rid, limit, func, callback);
|
|
365
393
|
};
|
|
366
394
|
|
|
395
|
+
/**
|
|
396
|
+
* Change the password of the admin user
|
|
397
|
+
* @param {*} password - The new password
|
|
398
|
+
* @param {*} callback - Callback when complete, function(err, [object]) {}
|
|
399
|
+
*/
|
|
400
|
+
node.changeAdminPassword = function(password, callback) {
|
|
401
|
+
apiCalls.changeAdminPassword(this.apiClient, password, callback);
|
|
402
|
+
}
|
|
403
|
+
|
|
367
404
|
/**
|
|
368
405
|
* Subscribe to a resource COV
|
|
369
406
|
* @param {string} uri - The full URI of the resource
|
|
@@ -376,7 +413,7 @@ module.exports = function (RED) {
|
|
|
376
413
|
cb: callback,
|
|
377
414
|
};
|
|
378
415
|
if (!node.resourceSubscriptions.has(uri)) {
|
|
379
|
-
|
|
416
|
+
webSocketCalls.subscribeToResourceCOV(uri);
|
|
380
417
|
node.resourceSubscriptions.set(uri, [sub]);
|
|
381
418
|
} else {
|
|
382
419
|
// _.pullAllBy(node.resourceSubscriptions.get(uri), [{node: ref}], node);
|
|
@@ -397,7 +434,7 @@ module.exports = function (RED) {
|
|
|
397
434
|
);
|
|
398
435
|
}
|
|
399
436
|
if (node.resourceSubscriptions.get(uri).length === 0) {
|
|
400
|
-
|
|
437
|
+
webSocketCalls.unsubscribeToResourceCOV(uri);
|
|
401
438
|
node.resourceSubscriptions.delete(uri);
|
|
402
439
|
}
|
|
403
440
|
};
|
|
@@ -414,7 +451,7 @@ module.exports = function (RED) {
|
|
|
414
451
|
cb: callback,
|
|
415
452
|
};
|
|
416
453
|
if (!node.objectSubscriptions.has(uri)) {
|
|
417
|
-
|
|
454
|
+
webSocketCalls.subscribeToObjectCOV(uri);
|
|
418
455
|
node.objectSubscriptions.set(uri, [sub]);
|
|
419
456
|
} else {
|
|
420
457
|
// _.pullAllBy(node.objectSubscriptions.get(uri), [{node: ref}], node);
|
|
@@ -435,7 +472,7 @@ module.exports = function (RED) {
|
|
|
435
472
|
);
|
|
436
473
|
}
|
|
437
474
|
if (node.objectSubscriptions.get(uri).length === 0) {
|
|
438
|
-
|
|
475
|
+
webSocketCalls.unsubscribeToObjectCOV(uri);
|
|
439
476
|
node.objectSubscriptions.delete(uri);
|
|
440
477
|
}
|
|
441
478
|
};
|
|
@@ -452,7 +489,7 @@ module.exports = function (RED) {
|
|
|
452
489
|
cb: callback,
|
|
453
490
|
};
|
|
454
491
|
if (!node.bcmdSubscriptions.has(uri)) {
|
|
455
|
-
|
|
492
|
+
webSocketCalls.subscribeToBCMD(uri);
|
|
456
493
|
node.bcmdSubscriptions.set(uri, [sub]);
|
|
457
494
|
} else {
|
|
458
495
|
node.bcmdSubscriptions.get(uri).push(sub);
|
|
@@ -472,7 +509,7 @@ module.exports = function (RED) {
|
|
|
472
509
|
);
|
|
473
510
|
}
|
|
474
511
|
if (node.bcmdSubscriptions.get(uri).length === 0) {
|
|
475
|
-
|
|
512
|
+
webSocketCalls.unsubscribeToBCMD(uri);
|
|
476
513
|
node.bcmdSubscriptions.delete(uri);
|
|
477
514
|
}
|
|
478
515
|
};
|
|
@@ -483,7 +520,7 @@ module.exports = function (RED) {
|
|
|
483
520
|
* @param {Object} commandData - An object containing the command data
|
|
484
521
|
*/
|
|
485
522
|
node.sendBroadcastCommand = function (cid, commandData) {
|
|
486
|
-
|
|
523
|
+
apiCalls.sendBroadcastCommand(this.apiClient, cid, commandData);
|
|
487
524
|
};
|
|
488
525
|
|
|
489
526
|
/**
|
|
@@ -495,7 +532,7 @@ module.exports = function (RED) {
|
|
|
495
532
|
* @param {Function} callback - Callback when complete
|
|
496
533
|
*/
|
|
497
534
|
node.sendDirectCommand = function (uri, cid, commandData, timeout, callback) {
|
|
498
|
-
|
|
535
|
+
apiCalls.sendDirectCommand(uri, cid, commandData, timeout, callback);
|
|
499
536
|
};
|
|
500
537
|
|
|
501
538
|
/**
|
|
@@ -505,7 +542,7 @@ module.exports = function (RED) {
|
|
|
505
542
|
* @param {Function} callback - Callback when complete
|
|
506
543
|
*/
|
|
507
544
|
node.getServiceConfig = function (hid, sid, callback) {
|
|
508
|
-
|
|
545
|
+
apiCalls.getServiceConfig(this.apiClient, `${hid}/${sid}`, callback);
|
|
509
546
|
};
|
|
510
547
|
|
|
511
548
|
/**
|
|
@@ -518,8 +555,17 @@ module.exports = function (RED) {
|
|
|
518
555
|
* @param {Function} callback - Callback when complete
|
|
519
556
|
*/
|
|
520
557
|
node.updateObjectInServiceConfig = function (hid, sid, pid, ins, config, callback) {
|
|
521
|
-
|
|
558
|
+
apiCalls.updateObject(this.apiClient, `${hid}/${sid}/${pid}/${ins}`, config, callback);
|
|
522
559
|
};
|
|
560
|
+
|
|
561
|
+
/**
|
|
562
|
+
* Get hub configuration
|
|
563
|
+
* @param {string} uri - The URI of the hub (hid)
|
|
564
|
+
* @param {Function} callback - Callback when complete
|
|
565
|
+
*/
|
|
566
|
+
node.getNodeConfig = function (uri, callback) {
|
|
567
|
+
apiCalls.getNodeConfig(this.apiClient, uri, callback);
|
|
568
|
+
}
|
|
523
569
|
}
|
|
524
570
|
|
|
525
571
|
RED.nodes.registerType('mobius connection', MobiusConnectionNode);
|
|
@@ -541,11 +587,11 @@ module.exports = function (RED) {
|
|
|
541
587
|
}
|
|
542
588
|
|
|
543
589
|
let pid = req.query.pid;
|
|
544
|
-
if (conn === null || !conn.
|
|
590
|
+
if (conn === null || !conn.connected) {
|
|
545
591
|
RED.log.error('Discover objects failed - could not to connect to MOBiUS hub.');
|
|
546
592
|
throw new Error('Discover objects failed - could not to connect to MOBiUS hub.');
|
|
547
593
|
} else {
|
|
548
|
-
|
|
594
|
+
uiFuncs
|
|
549
595
|
.discoverDevicesByPID(RED, conn, hid, spids, pid)
|
|
550
596
|
.then((devices) => {
|
|
551
597
|
res.json(devices);
|
|
@@ -565,11 +611,11 @@ module.exports = function (RED) {
|
|
|
565
611
|
let conn = RED.nodes.getNode(req.query.mobius);
|
|
566
612
|
let hid = req.query.hid;
|
|
567
613
|
let spid = req.query.spid;
|
|
568
|
-
if (conn === null || !conn.
|
|
614
|
+
if (conn === null || !conn.connected) {
|
|
569
615
|
RED.log.error('Discover services failed - could not to connect to MOBiUS hub.');
|
|
570
616
|
throw new Error('Discover services failed - could not to connect to MOBiUS hub.');
|
|
571
617
|
} else {
|
|
572
|
-
|
|
618
|
+
uiFuncs
|
|
573
619
|
.discoverServicesBySPID(RED, conn, hid, spid)
|
|
574
620
|
.then((services) => {
|
|
575
621
|
res.json(services);
|
|
@@ -580,4 +626,89 @@ module.exports = function (RED) {
|
|
|
580
626
|
}
|
|
581
627
|
}
|
|
582
628
|
);
|
|
629
|
+
|
|
630
|
+
// Register the endpoint for node-red mobius discovery in node-red node config pages
|
|
631
|
+
RED.httpAdmin.get('/mdiscover', RED.auth.needsPermission('serial.read'), function (req, res) {
|
|
632
|
+
let conn = RED.nodes.getNode(req.query.mobius);
|
|
633
|
+
let uri = req.query.uri;
|
|
634
|
+
if (conn === null || !conn.connected) {
|
|
635
|
+
RED.log.error('Discover services failed - could not to connect to MOBiUS hub.');
|
|
636
|
+
throw new Error('Discover services failed - could not to connect to MOBiUS hub.');
|
|
637
|
+
} else {
|
|
638
|
+
uiFuncs
|
|
639
|
+
.discover(conn, uri)
|
|
640
|
+
.then((response) => {
|
|
641
|
+
res.json(response);
|
|
642
|
+
})
|
|
643
|
+
.catch((err) => {
|
|
644
|
+
throw err;
|
|
645
|
+
});
|
|
646
|
+
}
|
|
647
|
+
});
|
|
648
|
+
|
|
649
|
+
// Register the endpoint for node-red mobius discovery in node-red node config pages
|
|
650
|
+
RED.httpAdmin.get('/mgetservices', RED.auth.needsPermission('serial.read'), function (req, res) {
|
|
651
|
+
let conn = RED.nodes.getNode(req.query.mobius);
|
|
652
|
+
let hid = req.query.hid;
|
|
653
|
+
if (conn === null || !conn.connected) {
|
|
654
|
+
RED.log.error('Get services failed - could not to connect to MOBiUS hub.');
|
|
655
|
+
throw new Error('Get services failed - could not to connect to MOBiUS hub.');
|
|
656
|
+
} else {
|
|
657
|
+
uiFuncs
|
|
658
|
+
.getServiceList(conn, hid)
|
|
659
|
+
.then((response) => {
|
|
660
|
+
res.json(response);
|
|
661
|
+
})
|
|
662
|
+
.catch((err) => {
|
|
663
|
+
RED.log.warn(`Get services failed - ${err}`);
|
|
664
|
+
});
|
|
665
|
+
}
|
|
666
|
+
});
|
|
667
|
+
|
|
668
|
+
RED.httpAdmin.get('/mgetobjects', RED.auth.needsPermission('serial.read'), function (req, res) {
|
|
669
|
+
let conn = RED.nodes.getNode(req.query.mobius);
|
|
670
|
+
let hid = req.query.hid;
|
|
671
|
+
let sid = req.query.sid;
|
|
672
|
+
if (conn === null || !conn.connected) {
|
|
673
|
+
RED.log.error('Get objects failed - could not to connect to MOBiUS hub.');
|
|
674
|
+
throw new Error('Get objects failed - could not to connect to MOBiUS hub.');
|
|
675
|
+
} else {
|
|
676
|
+
uiFuncs
|
|
677
|
+
.getObjectList(conn, hid, sid)
|
|
678
|
+
.then((response) => {
|
|
679
|
+
res.json(response);
|
|
680
|
+
})
|
|
681
|
+
.catch((err) => {
|
|
682
|
+
RED.log.warn(`Get objects failed - ${err}`);
|
|
683
|
+
});
|
|
684
|
+
}
|
|
685
|
+
});
|
|
686
|
+
|
|
687
|
+
RED.httpAdmin.get('/mgethid', RED.auth.needsPermission('serial.read'), function (req, res) {
|
|
688
|
+
let conn = RED.nodes.getNode(req.query.mobius);
|
|
689
|
+
if (conn === null || !conn.connected) {
|
|
690
|
+
RED.log.error('Get hid failed - could not to connect to MOBiUS hub.');
|
|
691
|
+
throw new Error('Get hid failed - could not to connect to MOBiUS hub.');
|
|
692
|
+
} else {
|
|
693
|
+
res.json(conn.hubId);
|
|
694
|
+
}
|
|
695
|
+
});
|
|
696
|
+
|
|
697
|
+
RED.httpAdmin.get('/mgetconnected', RED.auth.needsPermission('serial.read'), function (req, res) {
|
|
698
|
+
let conn = RED.nodes.getNode(req.query.mobius);
|
|
699
|
+
if (conn === null) {
|
|
700
|
+
res.json(false);
|
|
701
|
+
} else {
|
|
702
|
+
res.json(conn.connected);
|
|
703
|
+
}
|
|
704
|
+
});
|
|
705
|
+
|
|
706
|
+
RED.httpAdmin.get('/common/*', function (req, res) {
|
|
707
|
+
var options = {
|
|
708
|
+
root: __dirname + '/common/',
|
|
709
|
+
dotfiles: 'deny',
|
|
710
|
+
};
|
|
711
|
+
res.sendFile(req.params[0], options);
|
|
712
|
+
});
|
|
713
|
+
|
|
583
714
|
};
|