-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmetadata.js
48 lines (42 loc) · 1.25 KB
/
metadata.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
module.exports = function(RED) {
function attachMetadataNode(config) {
RED.nodes.createNode(this, config);
this.config = config;
let node = this;
node.on("input", function(msg) {
let payloadLength = 1;
if (Array.isArray(msg.payload)) {
payloadLength = msg.payload.length;
}
if (payloadLength !== node.config.valueTypes.length) {
this.status({
fill: "red",
shape: "dot",
text: "Ungültige Werte " + JSON.stringify(payload)
});
node.error(
"Es wurde eine falsche Anzahl von Werten übergeben. Erhalten: " +
payloadLength +
" Erwartet: " +
node.config.valueTypes.length,
msg
);
return;
}
msg.sensorid = msg.sensorid || node.config.sensorid;
msg.sensorname = msg.sensorname || node.config.sensorname;
msg.valueTypes = node.config.valueTypes || [];
node.send(msg);
node.status({
fill: "green",
shape: "dot",
text: "Last Value received: " + JSON.stringify(msg.payload)
});
});
node.on("close", function() {
node.status({});
node.done();
});
}
RED.nodes.registerType("od-attach-metadata", attachMetadataNode);
};