node-red-contrib-mobius-flow-base 2.5.90 → 3.0.0-beta.12
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 +18 -0
- package/dist/engine-api-calls.js +214 -0
- package/dist/engine-api-client.d.ts +7 -0
- package/dist/engine-api-client.js +92 -0
- package/dist/engine-websocket.d.ts +58 -0
- package/dist/engine-websocket.js +226 -0
- package/dist/node-red-ui-funcs.js +180 -0
- package/dist/nodes/common/mobsearch.js +576 -0
- package/dist/nodes/mobius-clear-resource.html +22 -3
- package/dist/nodes/mobius-clear-resource.js +17 -12
- package/dist/nodes/mobius-connection.html +30 -8
- package/dist/nodes/mobius-connection.js +194 -85
- package/dist/nodes/mobius-discover-object-list.html +185 -126
- package/dist/nodes/mobius-discover-object-list.js +27 -8
- package/dist/nodes/mobius-discover.js +7 -7
- package/dist/nodes/mobius-filter-by-rid-value.html +57 -41
- 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 +36 -4
- package/dist/nodes/mobius-get-multi-resource.js +13 -12
- package/dist/nodes/mobius-get-object.html +25 -3
- package/dist/nodes/mobius-get-object.js +12 -9
- package/dist/nodes/mobius-get-resource.html +26 -3
- package/dist/nodes/mobius-get-resource.js +17 -12
- package/dist/nodes/mobius-object-cov.html +27 -3
- package/dist/nodes/mobius-object-cov.js +9 -6
- package/dist/nodes/mobius-resource-cov.html +23 -3
- package/dist/nodes/mobius-resource-cov.js +5 -5
- package/dist/nodes/mobius-set-multi-resource.html +24 -3
- package/dist/nodes/mobius-set-multi-resource.js +9 -11
- package/dist/nodes/mobius-set-resource.html +24 -3
- package/package.json +13 -7
- package/dist/nodes/node-red-ui-discover-devices.js +0 -103
|
@@ -26,28 +26,50 @@ POSSIBILITY OF SUCH DAMAGE.
|
|
|
26
26
|
|
|
27
27
|
<script type="text/x-red" data-template-name="mobius connection">
|
|
28
28
|
<div class="form-row">
|
|
29
|
-
<label for="node-config-input-host"><i class="fa fa-globe"></i> Host
|
|
29
|
+
<div style="white-space: nowrap; display: inline-block;"><label for="node-config-input-host" style="width: 100px;" ><i class="fa fa-globe"></i> Host <span id="hostLabel" style="color: grey;">?</span></label></div>
|
|
30
30
|
<input class="input-append-left" type="text" id="node-config-input-host" placeholder="e.g. localhost" style="width: 40%;" >
|
|
31
31
|
<label for="node-config-input-port" style="margin-left: 10px; width: 35px; "> Port</label>
|
|
32
32
|
<input type="text" id="node-config-input-port" placeholder="1890" style="width:50px">
|
|
33
33
|
</div>
|
|
34
34
|
<div class="form-row">
|
|
35
|
-
<label for="node-config-input-
|
|
36
|
-
<input type="text" id="node-config-input-
|
|
35
|
+
<label for="node-config-input-username"><i class="fa fa-user"></i> Username</label>
|
|
36
|
+
<input class="input-append-left" type="text" id="node-config-input-username" style="width: 40%;" >
|
|
37
|
+
</div>
|
|
38
|
+
<div class="form-row">
|
|
39
|
+
<label for="node-config-input-password"><i class="fa fa-key"></i> Password</label>
|
|
40
|
+
<input class="input-append-left" type="text" id="node-config-input-password" style="width: 40%;" >
|
|
41
|
+
</div>
|
|
42
|
+
<div class="form-row">
|
|
43
|
+
<label for="node-config-input-secure" style="width: 100px;"> Use SSL/TLS</label>
|
|
44
|
+
<input type="checkbox" id="node-config-input-secure" style="display: inline-block; width: auto; vertical-align: top;">
|
|
45
|
+
|
|
37
46
|
</div>
|
|
38
47
|
</script>
|
|
39
48
|
|
|
40
49
|
<script type="text/javascript">
|
|
50
|
+
hostLabel = 'test';
|
|
41
51
|
RED.nodes.registerType('mobius connection', {
|
|
42
52
|
category: 'config',
|
|
43
53
|
defaults: {
|
|
44
|
-
host: {required: true, value: 'localhost'},
|
|
45
|
-
port: {required: true, value:
|
|
46
|
-
|
|
54
|
+
host: { required: true, value: 'localhost' },
|
|
55
|
+
port: { required: true, value: 8443, validate: RED.validators.number() },
|
|
56
|
+
username: { required: true, value: 'admin' },
|
|
57
|
+
password: { required: true, value: 'adm123' },
|
|
58
|
+
secure: { required: true, value: true },
|
|
47
59
|
},
|
|
48
|
-
label: function() {
|
|
60
|
+
label: function () {
|
|
49
61
|
return `${this.host}:${this.port}`;
|
|
50
|
-
}
|
|
62
|
+
},
|
|
63
|
+
oneditprepare: function () {
|
|
64
|
+
$('#node-config-input-secure').change(function () {
|
|
65
|
+
let secure = $('#node-config-input-secure').is(':checked');
|
|
66
|
+
if (secure) {
|
|
67
|
+
document.getElementById('hostLabel').innerHTML = 'https://';
|
|
68
|
+
} else {
|
|
69
|
+
document.getElementById('hostLabel').innerHTML = 'http://';
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
},
|
|
51
73
|
});
|
|
52
74
|
</script>
|
|
53
75
|
|
|
@@ -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 } = 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) {
|
|
@@ -215,47 +233,44 @@ module.exports = function (RED) {
|
|
|
215
233
|
*/
|
|
216
234
|
node.deregister = function (mobiusNode, done) {
|
|
217
235
|
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);
|
|
236
|
+
try {
|
|
237
|
+
node.resourceSubscriptions.forEach((subs, key) => {
|
|
238
|
+
subs.forEach((sub, index) => {
|
|
239
|
+
if (mobiusNode.id === sub.node) {
|
|
240
|
+
subs.splice(index, 1);
|
|
229
241
|
}
|
|
230
242
|
});
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
243
|
+
if (subs.length === 0) {
|
|
244
|
+
webSocketCalls.unsubscribeToResourceCOV(key);
|
|
245
|
+
node.resourceSubscriptions.delete(key);
|
|
246
|
+
}
|
|
247
|
+
});
|
|
248
|
+
node.objectSubscriptions.forEach((subs, key) => {
|
|
249
|
+
subs.forEach((sub, index) => {
|
|
250
|
+
if (mobiusNode.id === sub.node) {
|
|
251
|
+
subs.splice(index, 1);
|
|
240
252
|
}
|
|
241
253
|
});
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
254
|
+
if (subs.length === 0) {
|
|
255
|
+
webSocketCalls.unsubscribeToObjectCOV(key);
|
|
256
|
+
node.objectSubscriptions.delete(key);
|
|
257
|
+
}
|
|
258
|
+
});
|
|
259
|
+
node.bcmdSubscriptions.forEach((subs, key) => {
|
|
260
|
+
subs.forEach((sub, index) => {
|
|
261
|
+
if (mobiusNode.id === sub.node) {
|
|
262
|
+
subs.splice(index, 1);
|
|
251
263
|
}
|
|
252
264
|
});
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
265
|
+
if (subs.length === 0) {
|
|
266
|
+
webSocketCalls.unsubscribeToBCMD(key);
|
|
267
|
+
node.bcmdSubscriptions.delete(key);
|
|
268
|
+
}
|
|
269
|
+
});
|
|
270
|
+
} catch (err) {
|
|
271
|
+
console.log(`Failed to unsubscribe from event: ${err.message}`);
|
|
257
272
|
}
|
|
258
|
-
done();
|
|
273
|
+
return done();
|
|
259
274
|
};
|
|
260
275
|
|
|
261
276
|
/**
|
|
@@ -273,16 +288,15 @@ module.exports = function (RED) {
|
|
|
273
288
|
node.unsubscribeTimeout > 50
|
|
274
289
|
) {
|
|
275
290
|
clearInterval(waitForCleanup);
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
done();
|
|
280
|
-
});
|
|
291
|
+
webSocket.disconnectFromWebSocket();
|
|
292
|
+
setLoggedIn(false);
|
|
293
|
+
done();
|
|
281
294
|
}
|
|
282
295
|
node.unsubscribeTimeout++;
|
|
283
296
|
}, 100);
|
|
284
297
|
} else {
|
|
285
|
-
|
|
298
|
+
setLoggedIn(false);
|
|
299
|
+
webSocket.disconnectFromWebSocket();
|
|
286
300
|
done();
|
|
287
301
|
}
|
|
288
302
|
});
|
|
@@ -296,7 +310,7 @@ module.exports = function (RED) {
|
|
|
296
310
|
* the response message event
|
|
297
311
|
*/
|
|
298
312
|
node.discover = function (uri, callback) {
|
|
299
|
-
|
|
313
|
+
apiCalls.discover(this.apiClient, uri, callback);
|
|
300
314
|
};
|
|
301
315
|
|
|
302
316
|
/**
|
|
@@ -307,7 +321,7 @@ module.exports = function (RED) {
|
|
|
307
321
|
* @param {Function} callback - Callback when complete
|
|
308
322
|
*/
|
|
309
323
|
node.writeResourceValue = function (uri, value, priority, callback) {
|
|
310
|
-
|
|
324
|
+
apiCalls.writeResource(this.apiClient, uri, value, priority, callback);
|
|
311
325
|
};
|
|
312
326
|
|
|
313
327
|
/**
|
|
@@ -320,7 +334,7 @@ module.exports = function (RED) {
|
|
|
320
334
|
* the response message event
|
|
321
335
|
*/
|
|
322
336
|
node.multiWriteResourceValue = function (uri, updates, callback) {
|
|
323
|
-
|
|
337
|
+
apiCalls.writeMultiResource(this.apiClient, uri, updates, callback);
|
|
324
338
|
};
|
|
325
339
|
|
|
326
340
|
/**
|
|
@@ -330,7 +344,7 @@ module.exports = function (RED) {
|
|
|
330
344
|
* @param {Function} callback - Callback when complete
|
|
331
345
|
*/
|
|
332
346
|
node.clearResourcePriority = function (uri, priority, callback) {
|
|
333
|
-
|
|
347
|
+
apiCalls.clearResource(this.apiClient, uri, priority, callback);
|
|
334
348
|
};
|
|
335
349
|
|
|
336
350
|
/**
|
|
@@ -339,7 +353,7 @@ module.exports = function (RED) {
|
|
|
339
353
|
* @param {Function} callback - Callback when complete
|
|
340
354
|
*/
|
|
341
355
|
node.readResource = function (uri, callback) {
|
|
342
|
-
|
|
356
|
+
apiCalls.readResource(this.apiClient, uri, callback);
|
|
343
357
|
};
|
|
344
358
|
|
|
345
359
|
/**
|
|
@@ -348,7 +362,7 @@ module.exports = function (RED) {
|
|
|
348
362
|
* @param {Function} callback - Callback when complete
|
|
349
363
|
*/
|
|
350
364
|
node.readObject = function (uri, callback) {
|
|
351
|
-
|
|
365
|
+
apiCalls.readObject(this.apiClient, uri, callback);
|
|
352
366
|
};
|
|
353
367
|
|
|
354
368
|
/**
|
|
@@ -361,7 +375,7 @@ module.exports = function (RED) {
|
|
|
361
375
|
* @param {Function} callback - function(err, [object]) {}
|
|
362
376
|
*/
|
|
363
377
|
node.filterObjectsByRIDValue = function (uri, pids, rid, limit, func, callback) {
|
|
364
|
-
|
|
378
|
+
apiCalls.filterObjectsByRIDValue(this.apiClient, uri, pids, rid, limit, func, callback);
|
|
365
379
|
};
|
|
366
380
|
|
|
367
381
|
/**
|
|
@@ -376,7 +390,7 @@ module.exports = function (RED) {
|
|
|
376
390
|
cb: callback,
|
|
377
391
|
};
|
|
378
392
|
if (!node.resourceSubscriptions.has(uri)) {
|
|
379
|
-
|
|
393
|
+
webSocketCalls.subscribeToResourceCOV(uri);
|
|
380
394
|
node.resourceSubscriptions.set(uri, [sub]);
|
|
381
395
|
} else {
|
|
382
396
|
// _.pullAllBy(node.resourceSubscriptions.get(uri), [{node: ref}], node);
|
|
@@ -397,7 +411,7 @@ module.exports = function (RED) {
|
|
|
397
411
|
);
|
|
398
412
|
}
|
|
399
413
|
if (node.resourceSubscriptions.get(uri).length === 0) {
|
|
400
|
-
|
|
414
|
+
webSocketCalls.unsubscribeToResourceCOV(uri);
|
|
401
415
|
node.resourceSubscriptions.delete(uri);
|
|
402
416
|
}
|
|
403
417
|
};
|
|
@@ -414,7 +428,7 @@ module.exports = function (RED) {
|
|
|
414
428
|
cb: callback,
|
|
415
429
|
};
|
|
416
430
|
if (!node.objectSubscriptions.has(uri)) {
|
|
417
|
-
|
|
431
|
+
webSocketCalls.subscribeToObjectCOV(uri);
|
|
418
432
|
node.objectSubscriptions.set(uri, [sub]);
|
|
419
433
|
} else {
|
|
420
434
|
// _.pullAllBy(node.objectSubscriptions.get(uri), [{node: ref}], node);
|
|
@@ -435,7 +449,7 @@ module.exports = function (RED) {
|
|
|
435
449
|
);
|
|
436
450
|
}
|
|
437
451
|
if (node.objectSubscriptions.get(uri).length === 0) {
|
|
438
|
-
|
|
452
|
+
webSocketCalls.unsubscribeToObjectCOV(uri);
|
|
439
453
|
node.objectSubscriptions.delete(uri);
|
|
440
454
|
}
|
|
441
455
|
};
|
|
@@ -452,7 +466,7 @@ module.exports = function (RED) {
|
|
|
452
466
|
cb: callback,
|
|
453
467
|
};
|
|
454
468
|
if (!node.bcmdSubscriptions.has(uri)) {
|
|
455
|
-
|
|
469
|
+
webSocketCalls.subscribeToBCMD(uri);
|
|
456
470
|
node.bcmdSubscriptions.set(uri, [sub]);
|
|
457
471
|
} else {
|
|
458
472
|
node.bcmdSubscriptions.get(uri).push(sub);
|
|
@@ -472,7 +486,7 @@ module.exports = function (RED) {
|
|
|
472
486
|
);
|
|
473
487
|
}
|
|
474
488
|
if (node.bcmdSubscriptions.get(uri).length === 0) {
|
|
475
|
-
|
|
489
|
+
webSocketCalls.unsubscribeToBCMD(uri);
|
|
476
490
|
node.bcmdSubscriptions.delete(uri);
|
|
477
491
|
}
|
|
478
492
|
};
|
|
@@ -483,7 +497,7 @@ module.exports = function (RED) {
|
|
|
483
497
|
* @param {Object} commandData - An object containing the command data
|
|
484
498
|
*/
|
|
485
499
|
node.sendBroadcastCommand = function (cid, commandData) {
|
|
486
|
-
|
|
500
|
+
apiCalls.sendBroadcastCommand(this.apiClient, cid, commandData);
|
|
487
501
|
};
|
|
488
502
|
|
|
489
503
|
/**
|
|
@@ -495,7 +509,7 @@ module.exports = function (RED) {
|
|
|
495
509
|
* @param {Function} callback - Callback when complete
|
|
496
510
|
*/
|
|
497
511
|
node.sendDirectCommand = function (uri, cid, commandData, timeout, callback) {
|
|
498
|
-
|
|
512
|
+
apiCalls.sendDirectCommand(uri, cid, commandData, timeout, callback);
|
|
499
513
|
};
|
|
500
514
|
|
|
501
515
|
/**
|
|
@@ -505,7 +519,7 @@ module.exports = function (RED) {
|
|
|
505
519
|
* @param {Function} callback - Callback when complete
|
|
506
520
|
*/
|
|
507
521
|
node.getServiceConfig = function (hid, sid, callback) {
|
|
508
|
-
|
|
522
|
+
apiCalls.getServiceConfig(this.apiClient, `${hid}/${sid}`, callback);
|
|
509
523
|
};
|
|
510
524
|
|
|
511
525
|
/**
|
|
@@ -518,8 +532,17 @@ module.exports = function (RED) {
|
|
|
518
532
|
* @param {Function} callback - Callback when complete
|
|
519
533
|
*/
|
|
520
534
|
node.updateObjectInServiceConfig = function (hid, sid, pid, ins, config, callback) {
|
|
521
|
-
|
|
535
|
+
apiCalls.updateObject(this.apiClient, `${hid}/${sid}/${pid}/${ins}`, config, callback);
|
|
522
536
|
};
|
|
537
|
+
|
|
538
|
+
/**
|
|
539
|
+
* Get hub configuration
|
|
540
|
+
* @param {string} uri - The URI of the hub (hid)
|
|
541
|
+
* @param {Function} callback - Callback when complete
|
|
542
|
+
*/
|
|
543
|
+
node.getNodeConfig = function (uri, callback) {
|
|
544
|
+
apiCalls.getNodeConfig(this.apiClient, uri, callback);
|
|
545
|
+
}
|
|
523
546
|
}
|
|
524
547
|
|
|
525
548
|
RED.nodes.registerType('mobius connection', MobiusConnectionNode);
|
|
@@ -541,11 +564,11 @@ module.exports = function (RED) {
|
|
|
541
564
|
}
|
|
542
565
|
|
|
543
566
|
let pid = req.query.pid;
|
|
544
|
-
if (conn === null || !conn.
|
|
567
|
+
if (conn === null || !conn.connected) {
|
|
545
568
|
RED.log.error('Discover objects failed - could not to connect to MOBiUS hub.');
|
|
546
569
|
throw new Error('Discover objects failed - could not to connect to MOBiUS hub.');
|
|
547
570
|
} else {
|
|
548
|
-
|
|
571
|
+
uiFuncs
|
|
549
572
|
.discoverDevicesByPID(RED, conn, hid, spids, pid)
|
|
550
573
|
.then((devices) => {
|
|
551
574
|
res.json(devices);
|
|
@@ -565,11 +588,11 @@ module.exports = function (RED) {
|
|
|
565
588
|
let conn = RED.nodes.getNode(req.query.mobius);
|
|
566
589
|
let hid = req.query.hid;
|
|
567
590
|
let spid = req.query.spid;
|
|
568
|
-
if (conn === null || !conn.
|
|
591
|
+
if (conn === null || !conn.connected) {
|
|
569
592
|
RED.log.error('Discover services failed - could not to connect to MOBiUS hub.');
|
|
570
593
|
throw new Error('Discover services failed - could not to connect to MOBiUS hub.');
|
|
571
594
|
} else {
|
|
572
|
-
|
|
595
|
+
uiFuncs
|
|
573
596
|
.discoverServicesBySPID(RED, conn, hid, spid)
|
|
574
597
|
.then((services) => {
|
|
575
598
|
res.json(services);
|
|
@@ -580,4 +603,90 @@ module.exports = function (RED) {
|
|
|
580
603
|
}
|
|
581
604
|
}
|
|
582
605
|
);
|
|
606
|
+
|
|
607
|
+
// Register the endpoint for node-red mobius discovery in node-red node config pages
|
|
608
|
+
RED.httpAdmin.get('/mdiscover', RED.auth.needsPermission('serial.read'), function (req, res) {
|
|
609
|
+
let conn = RED.nodes.getNode(req.query.mobius);
|
|
610
|
+
let uri = req.query.uri;
|
|
611
|
+
if (conn === null || !conn.connected) {
|
|
612
|
+
RED.log.error('Discover services failed - could not to connect to MOBiUS hub.');
|
|
613
|
+
throw new Error('Discover services failed - could not to connect to MOBiUS hub.');
|
|
614
|
+
} else {
|
|
615
|
+
uiFuncs
|
|
616
|
+
.discover(conn, uri)
|
|
617
|
+
.then((response) => {
|
|
618
|
+
res.json(response);
|
|
619
|
+
})
|
|
620
|
+
.catch((err) => {
|
|
621
|
+
throw err;
|
|
622
|
+
});
|
|
623
|
+
}
|
|
624
|
+
});
|
|
625
|
+
|
|
626
|
+
// Register the endpoint for node-red mobius discovery in node-red node config pages
|
|
627
|
+
RED.httpAdmin.get('/mgetservices', RED.auth.needsPermission('serial.read'), function (req, res) {
|
|
628
|
+
let conn = RED.nodes.getNode(req.query.mobius);
|
|
629
|
+
let hid = req.query.hid;
|
|
630
|
+
if (conn === null || !conn.connected) {
|
|
631
|
+
RED.log.error('Get services failed - could not to connect to MOBiUS hub.');
|
|
632
|
+
throw new Error('Get services failed - could not to connect to MOBiUS hub.');
|
|
633
|
+
} else {
|
|
634
|
+
uiFuncs
|
|
635
|
+
.getServiceList(conn, hid)
|
|
636
|
+
.then((response) => {
|
|
637
|
+
res.json(response);
|
|
638
|
+
})
|
|
639
|
+
.catch((err) => {
|
|
640
|
+
RED.log.warn(`Get services failed - ${err}`);
|
|
641
|
+
});
|
|
642
|
+
}
|
|
643
|
+
});
|
|
644
|
+
|
|
645
|
+
RED.httpAdmin.get('/mgetobjects', RED.auth.needsPermission('serial.read'), function (req, res) {
|
|
646
|
+
let conn = RED.nodes.getNode(req.query.mobius);
|
|
647
|
+
let hid = req.query.hid;
|
|
648
|
+
let sid = req.query.sid;
|
|
649
|
+
if (conn === null || !conn.connected) {
|
|
650
|
+
RED.log.error('Get objects failed - could not to connect to MOBiUS hub.');
|
|
651
|
+
throw new Error('Get objects failed - could not to connect to MOBiUS hub.');
|
|
652
|
+
} else {
|
|
653
|
+
uiFuncs
|
|
654
|
+
.getObjectList(conn, hid, sid)
|
|
655
|
+
.then((response) => {
|
|
656
|
+
res.json(response);
|
|
657
|
+
})
|
|
658
|
+
.catch((err) => {
|
|
659
|
+
RED.log.warn(`Get objects failed - ${err}`);
|
|
660
|
+
});
|
|
661
|
+
}
|
|
662
|
+
});
|
|
663
|
+
|
|
664
|
+
RED.httpAdmin.get('/mgethid', RED.auth.needsPermission('serial.read'), function (req, res) {
|
|
665
|
+
let conn = RED.nodes.getNode(req.query.mobius);
|
|
666
|
+
if (conn === null || !conn.connected) {
|
|
667
|
+
RED.log.error('Get hid failed - could not to connect to MOBiUS hub.');
|
|
668
|
+
throw new Error('Get hid failed - could not to connect to MOBiUS hub.');
|
|
669
|
+
} else {
|
|
670
|
+
res.json(conn.hubId);
|
|
671
|
+
}
|
|
672
|
+
});
|
|
673
|
+
|
|
674
|
+
RED.httpAdmin.get('/mgetconnected', RED.auth.needsPermission('serial.read'), function (req, res) {
|
|
675
|
+
let conn = RED.nodes.getNode(req.query.mobius);
|
|
676
|
+
if (conn === null) {
|
|
677
|
+
RED.log.error('Get hid failed - could not to connect to MOBiUS hub.');
|
|
678
|
+
throw new Error('Get hid failed - could not to connect to MOBiUS hub.');
|
|
679
|
+
} else {
|
|
680
|
+
res.json(conn.connected);
|
|
681
|
+
}
|
|
682
|
+
});
|
|
683
|
+
|
|
684
|
+
RED.httpAdmin.get('/common/*', function (req, res) {
|
|
685
|
+
var options = {
|
|
686
|
+
root: __dirname + '/common/',
|
|
687
|
+
dotfiles: 'deny',
|
|
688
|
+
};
|
|
689
|
+
res.sendFile(req.params[0], options);
|
|
690
|
+
});
|
|
691
|
+
|
|
583
692
|
};
|