-
Notifications
You must be signed in to change notification settings - Fork 5
/
temp.js
52 lines (38 loc) · 2.06 KB
/
temp.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
module.exports = function(RED) {
function TempInputNode(config) {
RED.nodes.createNode(this,config);
var node = this;
node.gateway = RED.nodes.getNode(config.gateway);
node.group = config.group;
node.node = config.node;
node.name = config.name;
this.status({fill: "grey", shape: "dot", text: "not connected"});
node.statusReceived = function(data)
{
node.status(data)
}
node.messageReceived = function(data)
{
var hapcanMessage = data.payload;
if( (Number(node.node)!== 0 && hapcanMessage.node != node.node) || (Number(node.group)!== 0 && hapcanMessage.group != node.group) )
return;
hapcanMessage.type = hapcanMessage.frame[7];
if( hapcanMessage.type !== 0x11 && hapcanMessage.type !== 0x01)
return;
let {deviceName, channelName} = node.gateway.getDeviceInfo(hapcanMessage.node, hapcanMessage.group, 'temperature', 1)
hapcanMessage.channelName = channelName
hapcanMessage.deviceName = deviceName
hapcanMessage.temp = Number(Number(((hapcanMessage.frame[8] * 256) + hapcanMessage.frame[9]) * 0.0625).toFixed(1));
hapcanMessage.setpoint = Number(Number(((hapcanMessage.frame[10] * 256) + hapcanMessage.frame[11]) * 0.0625).toFixed(2));
hapcanMessage.hysteresis = Number(Number(hapcanMessage.frame[12] * 0.0625).toFixed(4));
node.send({topic: 'Temperature sensor message', payload: hapcanMessage});
}
node.gateway.eventEmitter.on('messageReceived_304', node.messageReceived)
node.gateway.eventEmitter.on('statusChanged', node.statusReceived)
this.on('close', function() {
node.gateway.eventEmitter.removeListener('messageReceived_304', node.messageReceived)
node.gateway.eventEmitter.removeListener('statusChanged', node.statusReceived)
});
}
RED.nodes.registerType("temp-input",TempInputNode);
}