node-red-contrib-mobius-flow-base 3.1.1 → 3.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/dist/engine-api-calls.js +12 -5
- package/dist/engine-websocket.js +5 -3
- package/dist/node-red-ui-funcs.js +53 -25
- package/dist/nodes/mobius-change-admin-password.js +1 -1
- package/dist/nodes/mobius-clear-resource.js +29 -6
- package/dist/nodes/mobius-connection.js +167 -62
- package/dist/nodes/mobius-get-multi-object.js +14 -10
- package/dist/nodes/mobius-get-multi-resource.js +10 -2
- package/dist/nodes/mobius-get-object.js +19 -4
- package/dist/nodes/mobius-get-resource.js +24 -5
- package/dist/nodes/mobius-send-dcmd.js +43 -19
- package/dist/nodes/mobius-set-multi-resource.js +51 -26
- package/dist/nodes/mobius-set-resource.js +132 -58
- package/package.json +1 -1
package/dist/engine-api-calls.js
CHANGED
|
@@ -3,8 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.EngineApiCalls = void 0;
|
|
4
4
|
class EngineApiCalls {
|
|
5
5
|
apiClient = null;
|
|
6
|
-
constructor() {
|
|
7
|
-
}
|
|
6
|
+
constructor() { }
|
|
8
7
|
setApiClient = (apiClient) => {
|
|
9
8
|
this.apiClient = apiClient;
|
|
10
9
|
};
|
|
@@ -111,7 +110,7 @@ class EngineApiCalls {
|
|
|
111
110
|
});
|
|
112
111
|
}
|
|
113
112
|
catch (err) {
|
|
114
|
-
throw `Failed to send broadcast command: ${
|
|
113
|
+
throw `Failed to send broadcast command: ${err.code}, ${err.message ? err.message : ''}`;
|
|
115
114
|
}
|
|
116
115
|
};
|
|
117
116
|
sendDirectCommand = async (uri, cid, commandData, timeout, callback) => {
|
|
@@ -194,10 +193,18 @@ class EngineApiCalls {
|
|
|
194
193
|
objects.push(object.data.data);
|
|
195
194
|
}
|
|
196
195
|
if (objects.length >= limit) {
|
|
197
|
-
return callback(null, {
|
|
196
|
+
return callback(null, {
|
|
197
|
+
uri,
|
|
198
|
+
ts: new Date().toISOString(),
|
|
199
|
+
value: objects,
|
|
200
|
+
});
|
|
198
201
|
}
|
|
199
202
|
}
|
|
200
|
-
return callback(null, {
|
|
203
|
+
return callback(null, {
|
|
204
|
+
uri,
|
|
205
|
+
ts: new Date().toISOString(),
|
|
206
|
+
value: objects,
|
|
207
|
+
});
|
|
201
208
|
}
|
|
202
209
|
catch (err) {
|
|
203
210
|
callback(err);
|
package/dist/engine-websocket.js
CHANGED
|
@@ -70,7 +70,7 @@ class EngineWebSocket extends stream_1.EventEmitter {
|
|
|
70
70
|
}
|
|
71
71
|
}
|
|
72
72
|
catch (e) {
|
|
73
|
-
console.log(`(${this.hostname}) -> Error parsing message
|
|
73
|
+
console.log(`(${this.hostname}) -> Error parsing message: ${e.code}, ${e.message ? e.message : ''}`);
|
|
74
74
|
}
|
|
75
75
|
};
|
|
76
76
|
this.webSocket.on('error', (e) => {
|
|
@@ -78,7 +78,7 @@ class EngineWebSocket extends stream_1.EventEmitter {
|
|
|
78
78
|
this.emit('disconnected');
|
|
79
79
|
}
|
|
80
80
|
else {
|
|
81
|
-
console.error(`(${this.hostname}) -> Engine API Subscription WebSocket Client Error:
|
|
81
|
+
console.error(`(${this.hostname}) -> Engine API Subscription WebSocket Client Error: ${e.code}, ${e.message ? e.message : ''}`);
|
|
82
82
|
}
|
|
83
83
|
});
|
|
84
84
|
};
|
|
@@ -114,7 +114,9 @@ class EngineWebSocket extends stream_1.EventEmitter {
|
|
|
114
114
|
.filter((cb) => cb.topic === message.topic)
|
|
115
115
|
.map((cb) => cb.callback);
|
|
116
116
|
if (!message.payload.timestamp) {
|
|
117
|
-
message.payload.timestamp = message.timestamp
|
|
117
|
+
message.payload.timestamp = message.timestamp
|
|
118
|
+
? message.timestamp
|
|
119
|
+
: new Date().toISOString();
|
|
118
120
|
}
|
|
119
121
|
callbacks.forEach((cb) => cb(message.payload));
|
|
120
122
|
};
|
|
@@ -30,9 +30,8 @@ const _ = require('lodash');
|
|
|
30
30
|
const excludedSpids = ['0004', '0012'];
|
|
31
31
|
|
|
32
32
|
module.exports = {
|
|
33
|
-
|
|
34
33
|
// Promisified version of discover
|
|
35
|
-
discover
|
|
34
|
+
discover(connection, uri) {
|
|
36
35
|
return new Promise((resolve, reject) => {
|
|
37
36
|
connection.discover(uri, (err, response) => {
|
|
38
37
|
if (err) {
|
|
@@ -45,7 +44,7 @@ module.exports = {
|
|
|
45
44
|
},
|
|
46
45
|
|
|
47
46
|
// Promisified version of getServiceConfig
|
|
48
|
-
getNodeConfig
|
|
47
|
+
getNodeConfig(connection, hid) {
|
|
49
48
|
return new Promise((resolve, reject) => {
|
|
50
49
|
connection.getNodeConfig(hid, (err, response) => {
|
|
51
50
|
if (!err) {
|
|
@@ -58,7 +57,7 @@ module.exports = {
|
|
|
58
57
|
},
|
|
59
58
|
|
|
60
59
|
// Promisified version of getServiceConfig
|
|
61
|
-
getServiceConfig
|
|
60
|
+
getServiceConfig(connection, hid, sid) {
|
|
62
61
|
return new Promise((resolve, reject) => {
|
|
63
62
|
connection.getServiceConfig(hid, sid, (err, response) => {
|
|
64
63
|
if (!err) {
|
|
@@ -71,7 +70,7 @@ module.exports = {
|
|
|
71
70
|
},
|
|
72
71
|
|
|
73
72
|
// Promisified version of getNodeConfigTree
|
|
74
|
-
getNodeConfigTree
|
|
73
|
+
getNodeConfigTree(connection, hid) {
|
|
75
74
|
return new Promise((resolve, reject) => {
|
|
76
75
|
connection.getNodeConfigTree(hid, (err, response) => {
|
|
77
76
|
if (!err) {
|
|
@@ -84,7 +83,7 @@ module.exports = {
|
|
|
84
83
|
},
|
|
85
84
|
|
|
86
85
|
// Promisified version of getProfileByPid
|
|
87
|
-
getProfileByPid
|
|
86
|
+
getProfileByPid(connection, hid, pid) {
|
|
88
87
|
return new Promise((resolve, reject) => {
|
|
89
88
|
connection.getProfileByPid(hid, pid, (err, response) => {
|
|
90
89
|
if (!err) {
|
|
@@ -97,7 +96,7 @@ module.exports = {
|
|
|
97
96
|
},
|
|
98
97
|
|
|
99
98
|
// Promisified version of getAllObjectProfiles
|
|
100
|
-
getAllObjectProfiles
|
|
99
|
+
getAllObjectProfiles(connection, hid) {
|
|
101
100
|
return new Promise((resolve, reject) => {
|
|
102
101
|
connection.getAllObjectProfiles(hid, (err, response) => {
|
|
103
102
|
if (!err) {
|
|
@@ -110,7 +109,7 @@ module.exports = {
|
|
|
110
109
|
},
|
|
111
110
|
|
|
112
111
|
// Discover object by By PID
|
|
113
|
-
async discoverDevicesByPID
|
|
112
|
+
async discoverDevicesByPID(RED, connection, hid, spids, pid) {
|
|
114
113
|
let devices = [];
|
|
115
114
|
if (!hid || hid === '') {
|
|
116
115
|
hid = connection.service.hubId;
|
|
@@ -123,12 +122,19 @@ module.exports = {
|
|
|
123
122
|
throw new Error(`Discover devices failed (${hid}) - ${err.message}`);
|
|
124
123
|
}
|
|
125
124
|
for (let srvcLoop = 0; srvcLoop < services.data.length; srvcLoop++) {
|
|
126
|
-
if (
|
|
127
|
-
|
|
125
|
+
if (
|
|
126
|
+
services.data[srvcLoop].status === 'online' &&
|
|
127
|
+
(spids.length === 0 || spids.includes(services.data[srvcLoop].spid))
|
|
128
|
+
) {
|
|
129
|
+
let insURI = `${hid}/${
|
|
130
|
+
services.data[srvcLoop].id.split('/')[1]
|
|
131
|
+
}/${pid}`;
|
|
128
132
|
try {
|
|
129
133
|
let instances = await this.discover(connection, insURI);
|
|
130
134
|
for (let insLoop = 0; insLoop < instances.data.length; insLoop++) {
|
|
131
|
-
let deviceURI = `${hid}/${
|
|
135
|
+
let deviceURI = `${hid}/${
|
|
136
|
+
services.data[srvcLoop].id.split('/')[1]
|
|
137
|
+
}/${pid}/${instances.data[insLoop]}`;
|
|
132
138
|
let device = await this.discover(connection, deviceURI);
|
|
133
139
|
let resourcesByName = _.keyBy(device.data[0].resources, 'name');
|
|
134
140
|
let deviceName = resourcesByName['name'].pv;
|
|
@@ -147,7 +153,7 @@ module.exports = {
|
|
|
147
153
|
},
|
|
148
154
|
|
|
149
155
|
// Discover services by SPID
|
|
150
|
-
async discoverServicesBySPID
|
|
156
|
+
async discoverServicesBySPID(RED, connection, hid, spid) {
|
|
151
157
|
if (!hid || hid === '') {
|
|
152
158
|
hid = connection.service.hubId;
|
|
153
159
|
}
|
|
@@ -160,7 +166,10 @@ module.exports = {
|
|
|
160
166
|
}
|
|
161
167
|
let srvcs = [];
|
|
162
168
|
for (let srvcLoop = 0; srvcLoop < services.data.length; srvcLoop++) {
|
|
163
|
-
if (
|
|
169
|
+
if (
|
|
170
|
+
services.data[srvcLoop].status === 'online' &&
|
|
171
|
+
services.data[srvcLoop].spid === spid
|
|
172
|
+
) {
|
|
164
173
|
srvcs.push(`${hid}/${services.data[srvcLoop].id.split('/')[1]}`);
|
|
165
174
|
}
|
|
166
175
|
}
|
|
@@ -190,7 +199,9 @@ module.exports = {
|
|
|
190
199
|
}
|
|
191
200
|
return services;
|
|
192
201
|
} catch (err) {
|
|
193
|
-
throw
|
|
202
|
+
throw `Error getting service list for Flows UI: ${err.code}, ${
|
|
203
|
+
err.message ? err.message : ''
|
|
204
|
+
}`;
|
|
194
205
|
}
|
|
195
206
|
},
|
|
196
207
|
|
|
@@ -201,7 +212,10 @@ module.exports = {
|
|
|
201
212
|
const serviceResponse = await this.discover(connection, `${hid}/${sid}`);
|
|
202
213
|
const pids = [...new Set(serviceResponse.data)];
|
|
203
214
|
for (let i = 0; i < pids.length; i++) {
|
|
204
|
-
const inssResponse = await this.discover(
|
|
215
|
+
const inssResponse = await this.discover(
|
|
216
|
+
connection,
|
|
217
|
+
`${hid}/${sid}/${pids[i]}`
|
|
218
|
+
);
|
|
205
219
|
const inss = inssResponse.data;
|
|
206
220
|
for (let j = 0; j < inss.length; j++) {
|
|
207
221
|
const objResponse = await this.discover(
|
|
@@ -213,7 +227,9 @@ module.exports = {
|
|
|
213
227
|
}
|
|
214
228
|
return objectList;
|
|
215
229
|
} catch (err) {
|
|
216
|
-
throw
|
|
230
|
+
throw `Error getting object list for Flows UI: ${err.code}, ${
|
|
231
|
+
err.message ? err.message : ''
|
|
232
|
+
}`;
|
|
217
233
|
}
|
|
218
234
|
},
|
|
219
235
|
|
|
@@ -221,15 +237,24 @@ module.exports = {
|
|
|
221
237
|
try {
|
|
222
238
|
let objectList = [];
|
|
223
239
|
const configTreeResponse = await this.getNodeConfigTree(connection, hid);
|
|
224
|
-
const service = configTreeResponse.data.find(
|
|
240
|
+
const service = configTreeResponse.data.find(
|
|
241
|
+
(service) => service.sid === sid
|
|
242
|
+
);
|
|
225
243
|
for (let i = 0; i < service.objects.length; i++) {
|
|
226
244
|
objectList = objectList.concat(service.objects[i].objects);
|
|
227
245
|
}
|
|
228
246
|
let formattedObjectList = [];
|
|
229
|
-
const getProfilesResponse = await this.getAllObjectProfiles(
|
|
247
|
+
const getProfilesResponse = await this.getAllObjectProfiles(
|
|
248
|
+
connection,
|
|
249
|
+
hid
|
|
250
|
+
);
|
|
230
251
|
const objectProfiles = getProfilesResponse.data;
|
|
231
252
|
for (let i = 0; i < objectList.length; i++) {
|
|
232
|
-
const profile = Object.values(objectProfiles).find(
|
|
253
|
+
const profile = Object.values(objectProfiles).find(
|
|
254
|
+
(profile) =>
|
|
255
|
+
profile.header.pid === parseInt(objectList[i].pid, 16) ||
|
|
256
|
+
profile.header.pid === `${parseInt(objectList[i].pid, 16)}`
|
|
257
|
+
);
|
|
233
258
|
const profileName = profile ? profile.header.uiname : '';
|
|
234
259
|
// const rids = objectList[i].rids;
|
|
235
260
|
// let resources = [];
|
|
@@ -248,8 +273,11 @@ module.exports = {
|
|
|
248
273
|
// pv: rids[j].pv,
|
|
249
274
|
// })
|
|
250
275
|
// }
|
|
251
|
-
const foundObjectName = objectList[i].rids.filter(
|
|
252
|
-
|
|
276
|
+
const foundObjectName = objectList[i].rids.filter(
|
|
277
|
+
(rid) => rid.rid === '01'
|
|
278
|
+
);
|
|
279
|
+
const objName =
|
|
280
|
+
foundObjectName.length > 0 ? foundObjectName[0].settings.pv : '';
|
|
253
281
|
formattedObjectList.push({
|
|
254
282
|
pid: objectList[i].pid,
|
|
255
283
|
ins: objectList[i].ins,
|
|
@@ -259,7 +287,9 @@ module.exports = {
|
|
|
259
287
|
}
|
|
260
288
|
return formattedObjectList;
|
|
261
289
|
} catch (err) {
|
|
262
|
-
throw
|
|
290
|
+
throw `Error getting config objects list for Flows UI: ${err.code}, ${
|
|
291
|
+
err.message ? err.message : ''
|
|
292
|
+
}`;
|
|
263
293
|
}
|
|
264
294
|
},
|
|
265
295
|
|
|
@@ -277,7 +307,5 @@ module.exports = {
|
|
|
277
307
|
});
|
|
278
308
|
}
|
|
279
309
|
return result;
|
|
280
|
-
}
|
|
281
|
-
|
|
310
|
+
},
|
|
282
311
|
};
|
|
283
|
-
|
|
@@ -63,7 +63,7 @@ module.exports = function (RED) {
|
|
|
63
63
|
shape: 'dot',
|
|
64
64
|
text: 'Error: ' + JSON.stringify(err.code),
|
|
65
65
|
});
|
|
66
|
-
node.error(
|
|
66
|
+
node.error(`Mobius error setting admin password: ${err.code}, ${err.message ? err.message : ''}`);
|
|
67
67
|
}
|
|
68
68
|
else {
|
|
69
69
|
node.status({
|
|
@@ -45,7 +45,10 @@ module.exports = function (RED) {
|
|
|
45
45
|
node.on('input', function (msg) {
|
|
46
46
|
let uri = node.resource;
|
|
47
47
|
let pri = parseInt(node.priority);
|
|
48
|
-
if (
|
|
48
|
+
if (
|
|
49
|
+
msg.hasOwnProperty('topic') &&
|
|
50
|
+
require('./validateURI')(msg.topic, 5)
|
|
51
|
+
) {
|
|
49
52
|
uri = msg.topic;
|
|
50
53
|
}
|
|
51
54
|
if (msg.hasOwnProperty('priority')) {
|
|
@@ -66,13 +69,21 @@ module.exports = function (RED) {
|
|
|
66
69
|
shape: 'dot',
|
|
67
70
|
text: 'Error: ' + JSON.stringify(err.code),
|
|
68
71
|
});
|
|
69
|
-
node.error(
|
|
72
|
+
node.error(
|
|
73
|
+
`Mobius error clearing resource priority: ${err.code}, ${
|
|
74
|
+
err.message ? err.message : ''
|
|
75
|
+
}`
|
|
76
|
+
);
|
|
70
77
|
if (node.detailedOutput === true) {
|
|
71
78
|
node.send([
|
|
72
79
|
null,
|
|
73
80
|
null,
|
|
74
81
|
null,
|
|
75
|
-
{
|
|
82
|
+
{
|
|
83
|
+
...msg,
|
|
84
|
+
topic: uri,
|
|
85
|
+
payload: { error: true, response: err },
|
|
86
|
+
},
|
|
76
87
|
]);
|
|
77
88
|
}
|
|
78
89
|
} else {
|
|
@@ -84,14 +95,26 @@ module.exports = function (RED) {
|
|
|
84
95
|
if (node.detailedOutput === true) {
|
|
85
96
|
node.send([
|
|
86
97
|
{ ...msg, topic: uri, payload: response.data.pv },
|
|
87
|
-
{
|
|
98
|
+
{
|
|
99
|
+
...msg,
|
|
100
|
+
topic: uri,
|
|
101
|
+
payload: { pv: response.data.pv, name: response.data.name },
|
|
102
|
+
},
|
|
88
103
|
{ ...msg, topic: uri, payload: response.data },
|
|
89
|
-
{
|
|
104
|
+
{
|
|
105
|
+
...msg,
|
|
106
|
+
topic: uri,
|
|
107
|
+
payload: { error: false, response: response },
|
|
108
|
+
},
|
|
90
109
|
]);
|
|
91
110
|
} else {
|
|
92
111
|
node.send([
|
|
93
112
|
{ ...msg, topic: uri, payload: response.data.pv },
|
|
94
|
-
{
|
|
113
|
+
{
|
|
114
|
+
...msg,
|
|
115
|
+
topic: uri,
|
|
116
|
+
payload: { pv: response.data.pv, name: response.data.name },
|
|
117
|
+
},
|
|
95
118
|
]);
|
|
96
119
|
}
|
|
97
120
|
}
|
|
@@ -72,15 +72,24 @@ module.exports = function (RED) {
|
|
|
72
72
|
this.password
|
|
73
73
|
);
|
|
74
74
|
this.apiClient.EngineWebSocket.clearAllCallbacks();
|
|
75
|
-
this.apiClient.EngineWebSocket.registerCallback(
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
this.apiClient.EngineWebSocket.registerCallback(
|
|
82
|
-
|
|
83
|
-
|
|
75
|
+
this.apiClient.EngineWebSocket.registerCallback(
|
|
76
|
+
'resource-cov',
|
|
77
|
+
(response) => {
|
|
78
|
+
this.handleCOVEvents(response);
|
|
79
|
+
}
|
|
80
|
+
);
|
|
81
|
+
this.apiClient.EngineWebSocket.registerCallback(
|
|
82
|
+
'object-cov',
|
|
83
|
+
(response) => {
|
|
84
|
+
this.handleObjectCOVEvents(response);
|
|
85
|
+
}
|
|
86
|
+
);
|
|
87
|
+
this.apiClient.EngineWebSocket.registerCallback(
|
|
88
|
+
'broadcast-command',
|
|
89
|
+
(response) => {
|
|
90
|
+
this.handleBCMDEvents(response);
|
|
91
|
+
}
|
|
92
|
+
);
|
|
84
93
|
var node = this;
|
|
85
94
|
node.serviceList = [];
|
|
86
95
|
node.hasStarted = false;
|
|
@@ -98,12 +107,20 @@ module.exports = function (RED) {
|
|
|
98
107
|
this.log(`Connected to ${n.host}`);
|
|
99
108
|
this.apiClient.getHubId((err, hubId) => {
|
|
100
109
|
if (err) {
|
|
101
|
-
node.error(
|
|
110
|
+
node.error(
|
|
111
|
+
`Mobius error getting hub ID: ${err.code}, ${
|
|
112
|
+
err.message ? err.message : ''
|
|
113
|
+
}`
|
|
114
|
+
);
|
|
102
115
|
} else {
|
|
103
116
|
node.hubId = hubId;
|
|
104
117
|
this.apiClient.discover(node.hubId, (err, response) => {
|
|
105
118
|
if (err) {
|
|
106
|
-
node.error(
|
|
119
|
+
node.error(
|
|
120
|
+
`Mobius error discovering service list: ${err.code}, ${
|
|
121
|
+
err.message ? err.message : ''
|
|
122
|
+
}`
|
|
123
|
+
);
|
|
107
124
|
} else {
|
|
108
125
|
node.serviceList = response.data;
|
|
109
126
|
node.hasStarted = true;
|
|
@@ -380,8 +397,22 @@ module.exports = function (RED) {
|
|
|
380
397
|
* @param {Function} func - The function used to test the resource values
|
|
381
398
|
* @param {Function} callback - function(err, [object]) {}
|
|
382
399
|
*/
|
|
383
|
-
node.filterObjectsByRIDValue = function (
|
|
384
|
-
|
|
400
|
+
node.filterObjectsByRIDValue = function (
|
|
401
|
+
uri,
|
|
402
|
+
pids,
|
|
403
|
+
rid,
|
|
404
|
+
limit,
|
|
405
|
+
func,
|
|
406
|
+
callback
|
|
407
|
+
) {
|
|
408
|
+
this.apiClient.filterObjectsByRIDValue(
|
|
409
|
+
uri,
|
|
410
|
+
pids,
|
|
411
|
+
rid,
|
|
412
|
+
limit,
|
|
413
|
+
func,
|
|
414
|
+
callback
|
|
415
|
+
);
|
|
385
416
|
};
|
|
386
417
|
|
|
387
418
|
/**
|
|
@@ -389,9 +420,9 @@ module.exports = function (RED) {
|
|
|
389
420
|
* @param {*} password - The new password
|
|
390
421
|
* @param {*} callback - Callback when complete, function(err, [object]) {}
|
|
391
422
|
*/
|
|
392
|
-
node.changeAdminPassword = function(password, callback) {
|
|
423
|
+
node.changeAdminPassword = function (password, callback) {
|
|
393
424
|
this.apiClient.changeAdminPassword(password, callback);
|
|
394
|
-
}
|
|
425
|
+
};
|
|
395
426
|
|
|
396
427
|
/**
|
|
397
428
|
* Subscribe to a resource COV
|
|
@@ -523,8 +554,20 @@ module.exports = function (RED) {
|
|
|
523
554
|
* @param {number} timeout - Optional timeout in ms which overrides the default timeout if > 0
|
|
524
555
|
* @param {Function} callback - Callback when complete
|
|
525
556
|
*/
|
|
526
|
-
node.sendDirectCommand = function (
|
|
527
|
-
|
|
557
|
+
node.sendDirectCommand = function (
|
|
558
|
+
uri,
|
|
559
|
+
cid,
|
|
560
|
+
commandData,
|
|
561
|
+
timeout,
|
|
562
|
+
callback
|
|
563
|
+
) {
|
|
564
|
+
this.apiClient.sendDirectCommand(
|
|
565
|
+
uri,
|
|
566
|
+
cid,
|
|
567
|
+
commandData,
|
|
568
|
+
timeout,
|
|
569
|
+
callback
|
|
570
|
+
);
|
|
528
571
|
};
|
|
529
572
|
|
|
530
573
|
/**
|
|
@@ -546,8 +589,19 @@ module.exports = function (RED) {
|
|
|
546
589
|
* @param {Object} config - The new object configuration, structure given by {ins: string, pid: string, uiname: string, rids: array}
|
|
547
590
|
* @param {Function} callback - Callback when complete
|
|
548
591
|
*/
|
|
549
|
-
node.updateObjectInServiceConfig = function (
|
|
550
|
-
|
|
592
|
+
node.updateObjectInServiceConfig = function (
|
|
593
|
+
hid,
|
|
594
|
+
sid,
|
|
595
|
+
pid,
|
|
596
|
+
ins,
|
|
597
|
+
config,
|
|
598
|
+
callback
|
|
599
|
+
) {
|
|
600
|
+
this.apiClient.updateObject(
|
|
601
|
+
`${hid}/${sid}/${pid}/${ins}`,
|
|
602
|
+
config,
|
|
603
|
+
callback
|
|
604
|
+
);
|
|
551
605
|
};
|
|
552
606
|
|
|
553
607
|
/**
|
|
@@ -557,7 +611,7 @@ module.exports = function (RED) {
|
|
|
557
611
|
*/
|
|
558
612
|
node.getNodeConfig = function (uri, callback) {
|
|
559
613
|
this.apiClient.getNodeConfig(uri, callback);
|
|
560
|
-
}
|
|
614
|
+
};
|
|
561
615
|
|
|
562
616
|
/**
|
|
563
617
|
* Get the list of services on a hub
|
|
@@ -566,7 +620,7 @@ module.exports = function (RED) {
|
|
|
566
620
|
*/
|
|
567
621
|
node.getNodeConfigTree = function (hid, callback) {
|
|
568
622
|
this.apiClient.getNodeConfigTree(hid, callback);
|
|
569
|
-
}
|
|
623
|
+
};
|
|
570
624
|
|
|
571
625
|
/**
|
|
572
626
|
* Get the list of services on a hub
|
|
@@ -575,11 +629,11 @@ module.exports = function (RED) {
|
|
|
575
629
|
*/
|
|
576
630
|
node.getProfileByPid = function (hid, pid, callback) {
|
|
577
631
|
this.apiClient.getProfileByPid(hid, pid, callback);
|
|
578
|
-
}
|
|
632
|
+
};
|
|
579
633
|
|
|
580
634
|
node.getAllObjectProfiles = function (hid, callback) {
|
|
581
635
|
this.apiClient.getAllObjectProfiles(hid, callback);
|
|
582
|
-
}
|
|
636
|
+
};
|
|
583
637
|
}
|
|
584
638
|
|
|
585
639
|
RED.nodes.registerType('mobius connection', MobiusConnectionNode);
|
|
@@ -602,8 +656,12 @@ module.exports = function (RED) {
|
|
|
602
656
|
|
|
603
657
|
let pid = req.query.pid;
|
|
604
658
|
if (conn === null || !conn.connected) {
|
|
605
|
-
RED.log.error(
|
|
606
|
-
|
|
659
|
+
RED.log.error(
|
|
660
|
+
'Discover objects failed - could not to connect to MOBiUS hub.'
|
|
661
|
+
);
|
|
662
|
+
throw new Error(
|
|
663
|
+
'Discover objects failed - could not to connect to MOBiUS hub.'
|
|
664
|
+
);
|
|
607
665
|
} else {
|
|
608
666
|
uiFuncs
|
|
609
667
|
.discoverDevicesByPID(RED, conn, hid, spids, pid)
|
|
@@ -626,8 +684,12 @@ module.exports = function (RED) {
|
|
|
626
684
|
let hid = req.query.hid;
|
|
627
685
|
let spid = req.query.spid;
|
|
628
686
|
if (conn === null || !conn.connected) {
|
|
629
|
-
RED.log.error(
|
|
630
|
-
|
|
687
|
+
RED.log.error(
|
|
688
|
+
'Discover services failed - could not to connect to MOBiUS hub.'
|
|
689
|
+
);
|
|
690
|
+
throw new Error(
|
|
691
|
+
'Discover services failed - could not to connect to MOBiUS hub.'
|
|
692
|
+
);
|
|
631
693
|
} else {
|
|
632
694
|
uiFuncs
|
|
633
695
|
.discoverServicesBySPID(RED, conn, hid, spid)
|
|
@@ -641,13 +703,20 @@ module.exports = function (RED) {
|
|
|
641
703
|
}
|
|
642
704
|
);
|
|
643
705
|
|
|
644
|
-
|
|
645
|
-
|
|
706
|
+
// Register the endpoint for node-red mobius discovery in node-red node config pages
|
|
707
|
+
RED.httpAdmin.get(
|
|
708
|
+
'/mdiscover',
|
|
709
|
+
RED.auth.needsPermission('serial.read'),
|
|
710
|
+
function (req, res) {
|
|
646
711
|
let conn = RED.nodes.getNode(req.query.mobius);
|
|
647
712
|
let uri = req.query.uri;
|
|
648
713
|
if (conn === null || !conn.connected) {
|
|
649
|
-
RED.log.error(
|
|
650
|
-
|
|
714
|
+
RED.log.error(
|
|
715
|
+
'Discover services failed - could not to connect to MOBiUS hub.'
|
|
716
|
+
);
|
|
717
|
+
throw new Error(
|
|
718
|
+
'Discover services failed - could not to connect to MOBiUS hub.'
|
|
719
|
+
);
|
|
651
720
|
} else {
|
|
652
721
|
uiFuncs
|
|
653
722
|
.discover(conn, uri)
|
|
@@ -658,16 +727,24 @@ module.exports = function (RED) {
|
|
|
658
727
|
throw err;
|
|
659
728
|
});
|
|
660
729
|
}
|
|
661
|
-
}
|
|
730
|
+
}
|
|
731
|
+
);
|
|
662
732
|
|
|
663
|
-
|
|
664
|
-
|
|
733
|
+
// Register the endpoint for node-red get resource options for object type
|
|
734
|
+
RED.httpAdmin.get(
|
|
735
|
+
'/mgetresourceoptions',
|
|
736
|
+
RED.auth.needsPermission('serial.read'),
|
|
737
|
+
function (req, res) {
|
|
665
738
|
let conn = RED.nodes.getNode(req.query.mobius);
|
|
666
739
|
let hid = req.query.hid;
|
|
667
740
|
let pid = req.query.pid;
|
|
668
741
|
if (conn === null || !conn.connected) {
|
|
669
|
-
RED.log.error(
|
|
670
|
-
|
|
742
|
+
RED.log.error(
|
|
743
|
+
'Fetching resource options failed - could not to connect to MOBiUS hub.'
|
|
744
|
+
);
|
|
745
|
+
throw new Error(
|
|
746
|
+
'Fetching resource options failed - could not to connect to MOBiUS hub.'
|
|
747
|
+
);
|
|
671
748
|
} else {
|
|
672
749
|
uiFuncs
|
|
673
750
|
.getResourceOptions(conn, hid, pid)
|
|
@@ -678,15 +755,23 @@ module.exports = function (RED) {
|
|
|
678
755
|
throw err;
|
|
679
756
|
});
|
|
680
757
|
}
|
|
681
|
-
}
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
758
|
+
}
|
|
759
|
+
);
|
|
760
|
+
|
|
761
|
+
// Register the endpoint for node-red mobius discovery in node-red node config pages
|
|
762
|
+
RED.httpAdmin.get(
|
|
763
|
+
'/mgetservices',
|
|
764
|
+
RED.auth.needsPermission('serial.read'),
|
|
765
|
+
function (req, res) {
|
|
685
766
|
let conn = RED.nodes.getNode(req.query.mobius);
|
|
686
767
|
let hid = req.query.hid;
|
|
687
768
|
if (conn === null || !conn.connected) {
|
|
688
|
-
RED.log.error(
|
|
689
|
-
|
|
769
|
+
RED.log.error(
|
|
770
|
+
'Get services failed - could not to connect to MOBiUS hub.'
|
|
771
|
+
);
|
|
772
|
+
throw new Error(
|
|
773
|
+
'Get services failed - could not to connect to MOBiUS hub.'
|
|
774
|
+
);
|
|
690
775
|
} else {
|
|
691
776
|
uiFuncs
|
|
692
777
|
.getServiceList(conn, hid)
|
|
@@ -697,15 +782,23 @@ module.exports = function (RED) {
|
|
|
697
782
|
RED.log.warn(`Get services failed - ${err}`);
|
|
698
783
|
});
|
|
699
784
|
}
|
|
700
|
-
}
|
|
701
|
-
|
|
702
|
-
|
|
785
|
+
}
|
|
786
|
+
);
|
|
787
|
+
|
|
788
|
+
RED.httpAdmin.get(
|
|
789
|
+
'/mgetobjects',
|
|
790
|
+
RED.auth.needsPermission('serial.read'),
|
|
791
|
+
function (req, res) {
|
|
703
792
|
let conn = RED.nodes.getNode(req.query.mobius);
|
|
704
793
|
let hid = req.query.hid;
|
|
705
794
|
let sid = req.query.sid;
|
|
706
795
|
if (conn === null || !conn.connected) {
|
|
707
|
-
RED.log.error(
|
|
708
|
-
|
|
796
|
+
RED.log.error(
|
|
797
|
+
'Get objects failed - could not to connect to MOBiUS hub.'
|
|
798
|
+
);
|
|
799
|
+
throw new Error(
|
|
800
|
+
'Get objects failed - could not to connect to MOBiUS hub.'
|
|
801
|
+
);
|
|
709
802
|
} else {
|
|
710
803
|
uiFuncs
|
|
711
804
|
.getConfigObjectsList(conn, hid, sid)
|
|
@@ -713,12 +806,20 @@ module.exports = function (RED) {
|
|
|
713
806
|
res.json(response);
|
|
714
807
|
})
|
|
715
808
|
.catch((err) => {
|
|
716
|
-
RED.log.warn(
|
|
809
|
+
RED.log.warn(
|
|
810
|
+
`Get objects failed on service ${req.query.sid}: ${err.code}, ${
|
|
811
|
+
err.message ? err.message : ''
|
|
812
|
+
}`
|
|
813
|
+
);
|
|
717
814
|
});
|
|
718
815
|
}
|
|
719
|
-
}
|
|
720
|
-
|
|
721
|
-
|
|
816
|
+
}
|
|
817
|
+
);
|
|
818
|
+
|
|
819
|
+
RED.httpAdmin.get(
|
|
820
|
+
'/mgethid',
|
|
821
|
+
RED.auth.needsPermission('serial.read'),
|
|
822
|
+
function (req, res) {
|
|
722
823
|
let conn = RED.nodes.getNode(req.query.mobius);
|
|
723
824
|
if (conn === null || !conn.connected) {
|
|
724
825
|
RED.log.error('Get hid failed - could not to connect to MOBiUS hub.');
|
|
@@ -726,23 +827,27 @@ module.exports = function (RED) {
|
|
|
726
827
|
} else {
|
|
727
828
|
res.json(conn.hubId);
|
|
728
829
|
}
|
|
729
|
-
}
|
|
830
|
+
}
|
|
831
|
+
);
|
|
730
832
|
|
|
731
|
-
|
|
833
|
+
RED.httpAdmin.get(
|
|
834
|
+
'/mgetconnected',
|
|
835
|
+
RED.auth.needsPermission('serial.read'),
|
|
836
|
+
function (req, res) {
|
|
732
837
|
let conn = RED.nodes.getNode(req.query.mobius);
|
|
733
838
|
if (conn === null) {
|
|
734
839
|
res.json(false);
|
|
735
840
|
} else {
|
|
736
841
|
res.json(conn.connected);
|
|
737
842
|
}
|
|
738
|
-
}
|
|
739
|
-
|
|
740
|
-
RED.httpAdmin.get('/common/*', function (req, res) {
|
|
741
|
-
var options = {
|
|
742
|
-
root: __dirname + '/common/',
|
|
743
|
-
dotfiles: 'deny',
|
|
744
|
-
};
|
|
745
|
-
res.sendFile(req.params[0], options);
|
|
746
|
-
});
|
|
843
|
+
}
|
|
844
|
+
);
|
|
747
845
|
|
|
846
|
+
RED.httpAdmin.get('/common/*', function (req, res) {
|
|
847
|
+
var options = {
|
|
848
|
+
root: __dirname + '/common/',
|
|
849
|
+
dotfiles: 'deny',
|
|
850
|
+
};
|
|
851
|
+
res.sendFile(req.params[0], options);
|
|
852
|
+
});
|
|
748
853
|
};
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
'use strict';
|
|
29
29
|
|
|
30
30
|
module.exports = function (RED) {
|
|
31
|
-
function MobiusFlowNode
|
|
31
|
+
function MobiusFlowNode(n) {
|
|
32
32
|
RED.nodes.createNode(this, n);
|
|
33
33
|
this.mobjects = n.mobjects;
|
|
34
34
|
this.serviceConn = RED.nodes.getNode(n.connection);
|
|
@@ -38,7 +38,7 @@ module.exports = function (RED) {
|
|
|
38
38
|
node.status({
|
|
39
39
|
fill: 'red',
|
|
40
40
|
shape: 'ring',
|
|
41
|
-
text: 'Disconnected'
|
|
41
|
+
text: 'Disconnected',
|
|
42
42
|
});
|
|
43
43
|
|
|
44
44
|
node.serviceConn.register(node);
|
|
@@ -47,7 +47,7 @@ module.exports = function (RED) {
|
|
|
47
47
|
node.status({
|
|
48
48
|
fill: 'green',
|
|
49
49
|
shape: 'ring',
|
|
50
|
-
text: 'Busy'
|
|
50
|
+
text: 'Busy',
|
|
51
51
|
});
|
|
52
52
|
|
|
53
53
|
for (const mobject of node.mobjects) {
|
|
@@ -55,7 +55,7 @@ module.exports = function (RED) {
|
|
|
55
55
|
node.status({
|
|
56
56
|
fill: 'yellow',
|
|
57
57
|
shape: 'dot',
|
|
58
|
-
text: 'URIs not Valid'
|
|
58
|
+
text: 'URIs not Valid',
|
|
59
59
|
});
|
|
60
60
|
if (done) {
|
|
61
61
|
return done();
|
|
@@ -71,17 +71,21 @@ module.exports = function (RED) {
|
|
|
71
71
|
node.status({
|
|
72
72
|
fill: 'green',
|
|
73
73
|
shape: 'dot',
|
|
74
|
-
text: 'Done'
|
|
74
|
+
text: 'Done',
|
|
75
75
|
});
|
|
76
|
-
node.send({ ...msg, topic: msg.topic, payload: values});
|
|
76
|
+
node.send({ ...msg, topic: msg.topic, payload: values });
|
|
77
77
|
})
|
|
78
78
|
.catch((err) => {
|
|
79
79
|
node.status({
|
|
80
80
|
fill: 'yellow',
|
|
81
81
|
shape: 'dot',
|
|
82
|
-
text: 'Error: ' + JSON.stringify(err.code)
|
|
82
|
+
text: 'Error: ' + JSON.stringify(err.code),
|
|
83
83
|
});
|
|
84
|
-
node.error(
|
|
84
|
+
node.error(
|
|
85
|
+
`Mobius error reading object: ${err.code}, ${
|
|
86
|
+
err.message ? err.message : ''
|
|
87
|
+
}`
|
|
88
|
+
);
|
|
85
89
|
})
|
|
86
90
|
.finally(() => {
|
|
87
91
|
if (done) {
|
|
@@ -98,7 +102,7 @@ module.exports = function (RED) {
|
|
|
98
102
|
}
|
|
99
103
|
}
|
|
100
104
|
|
|
101
|
-
function validateResourceURI
|
|
105
|
+
function validateResourceURI(uri) {
|
|
102
106
|
let parts = uri.split('/');
|
|
103
107
|
for (let lp = 0; lp < parts.length; lp++) {
|
|
104
108
|
if (parts[lp] === null || parts[lp] === '') {
|
|
@@ -111,7 +115,7 @@ module.exports = function (RED) {
|
|
|
111
115
|
return false;
|
|
112
116
|
}
|
|
113
117
|
|
|
114
|
-
function readObject
|
|
118
|
+
function readObject(node, uri) {
|
|
115
119
|
return new Promise((resolve, reject) => {
|
|
116
120
|
node.serviceConn.readObject(uri, (err, response) => {
|
|
117
121
|
if (err) {
|
|
@@ -90,7 +90,11 @@ module.exports = function (RED) {
|
|
|
90
90
|
shape: 'dot',
|
|
91
91
|
text: 'Error: ' + JSON.stringify(err.code),
|
|
92
92
|
});
|
|
93
|
-
node.error(
|
|
93
|
+
node.error(
|
|
94
|
+
`Mobius error reading resource: ${err.code}, ${
|
|
95
|
+
err.message ? err.message : ''
|
|
96
|
+
}`
|
|
97
|
+
);
|
|
94
98
|
})
|
|
95
99
|
.finally(() => {
|
|
96
100
|
if (done) {
|
|
@@ -129,7 +133,11 @@ module.exports = function (RED) {
|
|
|
129
133
|
if (node.sendFormat === 'array') {
|
|
130
134
|
resolve(response.data.pv);
|
|
131
135
|
} else {
|
|
132
|
-
resolve({
|
|
136
|
+
resolve({
|
|
137
|
+
uri: uri,
|
|
138
|
+
pv: response.data.pv,
|
|
139
|
+
name: response.data.name,
|
|
140
|
+
});
|
|
133
141
|
}
|
|
134
142
|
}
|
|
135
143
|
});
|
|
@@ -47,7 +47,10 @@ module.exports = function (RED) {
|
|
|
47
47
|
|
|
48
48
|
node.on('input', function (msg) {
|
|
49
49
|
let uri = node.mobject;
|
|
50
|
-
if (
|
|
50
|
+
if (
|
|
51
|
+
msg.hasOwnProperty('topic') &&
|
|
52
|
+
require('./validateURI')(msg.topic, 4)
|
|
53
|
+
) {
|
|
51
54
|
uri = msg.topic;
|
|
52
55
|
}
|
|
53
56
|
|
|
@@ -63,9 +66,17 @@ module.exports = function (RED) {
|
|
|
63
66
|
shape: 'dot',
|
|
64
67
|
text: 'Error: ' + JSON.stringify(err.code),
|
|
65
68
|
});
|
|
66
|
-
node.error(
|
|
69
|
+
node.error(
|
|
70
|
+
`Mobius error reading object: ${err.code}, ${
|
|
71
|
+
err.message ? err.message : ''
|
|
72
|
+
}`
|
|
73
|
+
);
|
|
67
74
|
if (node.detailedOutput === true) {
|
|
68
|
-
node.send([
|
|
75
|
+
node.send([
|
|
76
|
+
null,
|
|
77
|
+
null,
|
|
78
|
+
{ ...msg, topic: uri, payload: { error: true, response: err } },
|
|
79
|
+
]);
|
|
69
80
|
}
|
|
70
81
|
} else {
|
|
71
82
|
node.status({
|
|
@@ -82,7 +93,11 @@ module.exports = function (RED) {
|
|
|
82
93
|
node.send([
|
|
83
94
|
{ ...msg, topic: uri, payload: allResources },
|
|
84
95
|
{ ...msg, topic: uri, payload: response.data },
|
|
85
|
-
{
|
|
96
|
+
{
|
|
97
|
+
...msg,
|
|
98
|
+
topic: uri,
|
|
99
|
+
payload: { error: false, response: response },
|
|
100
|
+
},
|
|
86
101
|
]);
|
|
87
102
|
} else {
|
|
88
103
|
node.send({ ...msg, topic: uri, payload: allResources });
|
|
@@ -44,7 +44,10 @@ module.exports = function (RED) {
|
|
|
44
44
|
|
|
45
45
|
node.on('input', function (msg) {
|
|
46
46
|
let uri = node.resource;
|
|
47
|
-
if (
|
|
47
|
+
if (
|
|
48
|
+
msg.hasOwnProperty('topic') &&
|
|
49
|
+
require('./validateURI')(msg.topic, 5)
|
|
50
|
+
) {
|
|
48
51
|
uri = msg.topic;
|
|
49
52
|
}
|
|
50
53
|
|
|
@@ -60,7 +63,11 @@ module.exports = function (RED) {
|
|
|
60
63
|
shape: 'dot',
|
|
61
64
|
text: 'Error: ' + JSON.stringify(err.code),
|
|
62
65
|
});
|
|
63
|
-
node.error(
|
|
66
|
+
node.error(
|
|
67
|
+
`Mobius error reading resource : ${err.code}, ${
|
|
68
|
+
err.message ? err.message : ''
|
|
69
|
+
}`
|
|
70
|
+
);
|
|
64
71
|
if (node.detailedOutput === true) {
|
|
65
72
|
node.send([
|
|
66
73
|
null,
|
|
@@ -78,14 +85,26 @@ module.exports = function (RED) {
|
|
|
78
85
|
if (node.detailedOutput === true) {
|
|
79
86
|
node.send([
|
|
80
87
|
{ ...msg, topic: uri, payload: response.data.pv },
|
|
81
|
-
{
|
|
88
|
+
{
|
|
89
|
+
...msg,
|
|
90
|
+
topic: uri,
|
|
91
|
+
payload: { pv: response.data.pv, name: response.data.name },
|
|
92
|
+
},
|
|
82
93
|
{ ...msg, topic: uri, payload: response.data },
|
|
83
|
-
{
|
|
94
|
+
{
|
|
95
|
+
...msg,
|
|
96
|
+
topic: uri,
|
|
97
|
+
payload: { error: false, response: response },
|
|
98
|
+
},
|
|
84
99
|
]);
|
|
85
100
|
} else {
|
|
86
101
|
node.send([
|
|
87
102
|
{ ...msg, topic: uri, payload: response.data.pv },
|
|
88
|
-
{
|
|
103
|
+
{
|
|
104
|
+
...msg,
|
|
105
|
+
topic: uri,
|
|
106
|
+
payload: { pv: response.data.pv, name: response.data.name },
|
|
107
|
+
},
|
|
89
108
|
]);
|
|
90
109
|
}
|
|
91
110
|
}
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
'use strict';
|
|
29
29
|
|
|
30
30
|
module.exports = function (RED) {
|
|
31
|
-
function MobiusSendDCMDNode
|
|
31
|
+
function MobiusSendDCMDNode(n) {
|
|
32
32
|
RED.nodes.createNode(this, n);
|
|
33
33
|
this.cid = n.cid;
|
|
34
34
|
this.uri = n.uri;
|
|
@@ -40,29 +40,53 @@ module.exports = function (RED) {
|
|
|
40
40
|
node.status({
|
|
41
41
|
fill: 'red',
|
|
42
42
|
shape: 'ring',
|
|
43
|
-
text: 'Disconnected'
|
|
43
|
+
text: 'Disconnected',
|
|
44
44
|
});
|
|
45
45
|
|
|
46
46
|
node.on('input', function (msg) {
|
|
47
47
|
if (msg.hasOwnProperty('payload')) {
|
|
48
|
-
node.serviceConn.sendDirectCommand(
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
48
|
+
node.serviceConn.sendDirectCommand(
|
|
49
|
+
node.uri,
|
|
50
|
+
node.cid,
|
|
51
|
+
msg.payload,
|
|
52
|
+
node.timeout,
|
|
53
|
+
(err, response) => {
|
|
54
|
+
if (err) {
|
|
55
|
+
node.status({
|
|
56
|
+
fill: 'yellow',
|
|
57
|
+
shape: 'dot',
|
|
58
|
+
text: 'Error: ' + JSON.stringify(err.code),
|
|
59
|
+
});
|
|
60
|
+
node.error(
|
|
61
|
+
`Mobius error sending DCMD command: ${err.code}, ${
|
|
62
|
+
err.message ? err.message : ''
|
|
63
|
+
}`
|
|
64
|
+
);
|
|
65
|
+
node.send([
|
|
66
|
+
null,
|
|
67
|
+
{
|
|
68
|
+
...msg,
|
|
69
|
+
topic: node.uri,
|
|
70
|
+
payload: { error: true, response: err },
|
|
71
|
+
},
|
|
72
|
+
]);
|
|
73
|
+
} else {
|
|
74
|
+
node.status({
|
|
75
|
+
fill: 'green',
|
|
76
|
+
shape: 'dot',
|
|
77
|
+
text: 'OK',
|
|
78
|
+
});
|
|
79
|
+
node.send([
|
|
80
|
+
{ ...msg, topic: node.uri, payload: response.data },
|
|
81
|
+
{
|
|
82
|
+
...msg,
|
|
83
|
+
topic: node.uri,
|
|
84
|
+
payload: { error: false, response: response },
|
|
85
|
+
},
|
|
86
|
+
]);
|
|
87
|
+
}
|
|
64
88
|
}
|
|
65
|
-
|
|
89
|
+
);
|
|
66
90
|
}
|
|
67
91
|
});
|
|
68
92
|
|
|
@@ -45,7 +45,10 @@ module.exports = function (RED) {
|
|
|
45
45
|
node.on('input', function (msg) {
|
|
46
46
|
let uri = node.mobject;
|
|
47
47
|
let value = null;
|
|
48
|
-
if (
|
|
48
|
+
if (
|
|
49
|
+
msg.hasOwnProperty('topic') &&
|
|
50
|
+
require('./validateURI')(msg.topic, 4)
|
|
51
|
+
) {
|
|
49
52
|
uri = msg.topic;
|
|
50
53
|
}
|
|
51
54
|
if (msg.hasOwnProperty('payload')) {
|
|
@@ -58,33 +61,52 @@ module.exports = function (RED) {
|
|
|
58
61
|
text: 'Busy',
|
|
59
62
|
});
|
|
60
63
|
|
|
61
|
-
node.serviceConn.multiWriteResourceValue(
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
64
|
+
node.serviceConn.multiWriteResourceValue(
|
|
65
|
+
uri,
|
|
66
|
+
value,
|
|
67
|
+
(err, response) => {
|
|
68
|
+
if (err) {
|
|
69
|
+
node.status({
|
|
70
|
+
fill: 'yellow',
|
|
71
|
+
shape: 'dot',
|
|
72
|
+
text: 'Error: ' + JSON.stringify(err.code),
|
|
73
|
+
});
|
|
74
|
+
node.error(
|
|
75
|
+
`Mobius error writing multiple resources: ${err.code}, ${
|
|
76
|
+
err.message ? err.message : ''
|
|
77
|
+
}`
|
|
78
|
+
);
|
|
79
|
+
if (node.detailedOutput === true) {
|
|
80
|
+
node.send([
|
|
81
|
+
null,
|
|
82
|
+
{
|
|
83
|
+
...msg,
|
|
84
|
+
topic: uri,
|
|
85
|
+
payload: { error: true, response: err },
|
|
86
|
+
},
|
|
87
|
+
]);
|
|
88
|
+
}
|
|
83
89
|
} else {
|
|
84
|
-
node.
|
|
90
|
+
node.status({
|
|
91
|
+
fill: 'green',
|
|
92
|
+
shape: 'dot',
|
|
93
|
+
text: 'OK',
|
|
94
|
+
});
|
|
95
|
+
if (node.detailedOutput === true) {
|
|
96
|
+
node.send([
|
|
97
|
+
{ ...msg, topic: uri, payload: response.data },
|
|
98
|
+
{
|
|
99
|
+
...msg,
|
|
100
|
+
topic: uri,
|
|
101
|
+
payload: { error: false, response: response },
|
|
102
|
+
},
|
|
103
|
+
]);
|
|
104
|
+
} else {
|
|
105
|
+
node.send([{ ...msg, topic: uri, payload: response.data }]);
|
|
106
|
+
}
|
|
85
107
|
}
|
|
86
108
|
}
|
|
87
|
-
|
|
109
|
+
);
|
|
88
110
|
}
|
|
89
111
|
});
|
|
90
112
|
|
|
@@ -98,5 +120,8 @@ module.exports = function (RED) {
|
|
|
98
120
|
}
|
|
99
121
|
}
|
|
100
122
|
|
|
101
|
-
RED.nodes.registerType(
|
|
123
|
+
RED.nodes.registerType(
|
|
124
|
+
'mobius set multi-resource',
|
|
125
|
+
MobiusSetMultiResourceNode
|
|
126
|
+
);
|
|
102
127
|
};
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
'use strict';
|
|
29
29
|
|
|
30
30
|
module.exports = function (RED) {
|
|
31
|
-
function MobiusSetResourceNode
|
|
31
|
+
function MobiusSetResourceNode(n) {
|
|
32
32
|
RED.nodes.createNode(this, n);
|
|
33
33
|
this.detailedOutput = n.detailedOutput;
|
|
34
34
|
this.resource = n.resource;
|
|
@@ -40,14 +40,17 @@ module.exports = function (RED) {
|
|
|
40
40
|
node.status({
|
|
41
41
|
fill: 'red',
|
|
42
42
|
shape: 'ring',
|
|
43
|
-
text: 'Disconnected'
|
|
43
|
+
text: 'Disconnected',
|
|
44
44
|
});
|
|
45
45
|
|
|
46
46
|
node.on('input', function (msg) {
|
|
47
47
|
let uri = node.resource;
|
|
48
48
|
let value = null;
|
|
49
49
|
let pri = parseInt(node.priority);
|
|
50
|
-
if (
|
|
50
|
+
if (
|
|
51
|
+
msg.hasOwnProperty('topic') &&
|
|
52
|
+
require('./validateURI')(msg.topic, 5)
|
|
53
|
+
) {
|
|
51
54
|
uri = msg.topic;
|
|
52
55
|
}
|
|
53
56
|
if (msg.hasOwnProperty('payload')) {
|
|
@@ -60,73 +63,144 @@ module.exports = function (RED) {
|
|
|
60
63
|
node.status({
|
|
61
64
|
fill: 'green',
|
|
62
65
|
shape: 'ring',
|
|
63
|
-
text: 'Busy'
|
|
66
|
+
text: 'Busy',
|
|
64
67
|
});
|
|
65
68
|
|
|
66
69
|
if (value === null) {
|
|
67
|
-
node.serviceConn.clearResourcePriority(
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
70
|
+
node.serviceConn.clearResourcePriority(
|
|
71
|
+
uri,
|
|
72
|
+
pri,
|
|
73
|
+
(err, response) => {
|
|
74
|
+
if (err) {
|
|
75
|
+
node.status({
|
|
76
|
+
fill: 'yellow',
|
|
77
|
+
shape: 'dot',
|
|
78
|
+
text: 'Error: ' + JSON.stringify(err.code),
|
|
79
|
+
});
|
|
80
|
+
node.error(
|
|
81
|
+
`Mobius error clearing resource priority: ${err.code}, ${
|
|
82
|
+
err.message ? err.message : ''
|
|
83
|
+
}`
|
|
84
|
+
);
|
|
85
|
+
if (node.detailedOutput === true) {
|
|
86
|
+
node.send([
|
|
87
|
+
null,
|
|
88
|
+
null,
|
|
89
|
+
null,
|
|
90
|
+
{
|
|
91
|
+
...msg,
|
|
92
|
+
topic: uri,
|
|
93
|
+
payload: { error: true, response: err },
|
|
94
|
+
},
|
|
95
|
+
]);
|
|
96
|
+
}
|
|
91
97
|
} else {
|
|
92
|
-
node.
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
98
|
+
node.status({
|
|
99
|
+
fill: 'green',
|
|
100
|
+
shape: 'dot',
|
|
101
|
+
text: JSON.stringify(response.data.pv),
|
|
102
|
+
});
|
|
103
|
+
if (node.detailedOutput === true) {
|
|
104
|
+
node.send([
|
|
105
|
+
{ ...msg, topic: uri, payload: response.data.pv },
|
|
106
|
+
{
|
|
107
|
+
...msg,
|
|
108
|
+
topic: uri,
|
|
109
|
+
payload: {
|
|
110
|
+
pv: response.data.pv,
|
|
111
|
+
name: response.data.name,
|
|
112
|
+
},
|
|
113
|
+
},
|
|
114
|
+
{ ...msg, topic: uri, payload: response.data },
|
|
115
|
+
{
|
|
116
|
+
...msg,
|
|
117
|
+
topic: uri,
|
|
118
|
+
payload: { error: false, response: response },
|
|
119
|
+
},
|
|
120
|
+
]);
|
|
121
|
+
} else {
|
|
122
|
+
node.send([
|
|
123
|
+
{ ...msg, topic: uri, payload: response.data.pv },
|
|
124
|
+
{
|
|
125
|
+
...msg,
|
|
126
|
+
topic: uri,
|
|
127
|
+
payload: {
|
|
128
|
+
pv: response.data.pv,
|
|
129
|
+
name: response.data.name,
|
|
130
|
+
},
|
|
131
|
+
},
|
|
132
|
+
]);
|
|
133
|
+
}
|
|
96
134
|
}
|
|
97
135
|
}
|
|
98
|
-
|
|
136
|
+
);
|
|
99
137
|
} else {
|
|
100
|
-
node.serviceConn.writeResourceValue(
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
138
|
+
node.serviceConn.writeResourceValue(
|
|
139
|
+
uri,
|
|
140
|
+
value,
|
|
141
|
+
pri,
|
|
142
|
+
(err, response) => {
|
|
143
|
+
if (err) {
|
|
144
|
+
node.status({
|
|
145
|
+
fill: 'yellow',
|
|
146
|
+
shape: 'dot',
|
|
147
|
+
text: 'Error: ' + JSON.stringify(err.code),
|
|
148
|
+
});
|
|
149
|
+
node.error(
|
|
150
|
+
`Mobius error writing resource: ${err.code}, ${
|
|
151
|
+
err.message ? err.message : ''
|
|
152
|
+
}`
|
|
153
|
+
);
|
|
116
154
|
node.send([
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
{
|
|
155
|
+
null,
|
|
156
|
+
null,
|
|
157
|
+
null,
|
|
158
|
+
{
|
|
159
|
+
...msg,
|
|
160
|
+
topic: uri,
|
|
161
|
+
payload: { error: true, response: err },
|
|
162
|
+
},
|
|
121
163
|
]);
|
|
122
164
|
} else {
|
|
123
|
-
node.
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
165
|
+
node.status({
|
|
166
|
+
fill: 'green',
|
|
167
|
+
shape: 'dot',
|
|
168
|
+
text: JSON.stringify(response.data.pv),
|
|
169
|
+
});
|
|
170
|
+
if (node.detailedOutput === true) {
|
|
171
|
+
node.send([
|
|
172
|
+
{ ...msg, topic: uri, payload: response.data.pv },
|
|
173
|
+
{
|
|
174
|
+
...msg,
|
|
175
|
+
topic: uri,
|
|
176
|
+
payload: {
|
|
177
|
+
pv: response.data.pv,
|
|
178
|
+
name: response.data.name,
|
|
179
|
+
},
|
|
180
|
+
},
|
|
181
|
+
{ ...msg, topic: uri, payload: response.data },
|
|
182
|
+
{
|
|
183
|
+
...msg,
|
|
184
|
+
topic: uri,
|
|
185
|
+
payload: { error: false, response: response },
|
|
186
|
+
},
|
|
187
|
+
]);
|
|
188
|
+
} else {
|
|
189
|
+
node.send([
|
|
190
|
+
{ ...msg, topic: uri, payload: response.data.pv },
|
|
191
|
+
{
|
|
192
|
+
...msg,
|
|
193
|
+
topic: uri,
|
|
194
|
+
payload: {
|
|
195
|
+
pv: response.data.pv,
|
|
196
|
+
name: response.data.name,
|
|
197
|
+
},
|
|
198
|
+
},
|
|
199
|
+
]);
|
|
200
|
+
}
|
|
127
201
|
}
|
|
128
202
|
}
|
|
129
|
-
|
|
203
|
+
);
|
|
130
204
|
}
|
|
131
205
|
}
|
|
132
206
|
});
|