-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.js
56 lines (50 loc) · 1.85 KB
/
index.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
49
50
51
52
53
54
55
56
module.exports = function (RED) {
"use strict";
var luxtronik = require('luxtronik2');
function Luxtronik2ReadNode(config) {
RED.nodes.createNode(this, config);
var node = this;
var pump = luxtronik.createConnection(config.host, config.port);
node.on('input', function (msg) {
pump.read(function (err, data) {
if (err) {
msg.payload = err;
return node.send(msg);
}
msg.payload = data;
node.send(msg);
});
});
}
RED.nodes.registerType("luxtronik2 read", Luxtronik2ReadNode);
function Luxtronik2WriteNode(config) {
RED.nodes.createNode(this, config);
var node = this;
var pump = luxtronik.createConnection(config.host, config.port);
node.on('input', function (msg) {
var parameterName = config.parameter || msg.parameter;
var parameterValue = msg.payload;
var rawParameter = msg.raw_parameter;
if(rawParameter !== undefined) {
pump.writeRaw(rawParameter, parameterValue, function (err, data) {
if (err) {
node.error(err, msg);
} else {
msg.payload = data;
node.send(msg);
}
});
} else {
pump.write(parameterName, parameterValue, function (err, data) {
if (err) {
msg.payload = err;
return node.send(msg);
}
msg.payload = data;
node.send(msg);
});
}
});
}
RED.nodes.registerType("luxtronik2 write", Luxtronik2WriteNode);
}