-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathnodered.json
183 lines (183 loc) · 5.53 KB
/
nodered.json
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
[
{
"id": "subflow-powermeter",
"type": "subflow",
"name": "B2500",
"info": "This subflow handles UDP and TCP communications for powermeter data.",
"in": [
{
"x": 80,
"y": 80,
"wires": [
{
"id": "send-powermeter-values"
}
]
}
],
"out": [],
"env": [],
"color": "#DDAA99"
},
{
"id": "udp-in",
"type": "udp in",
"z": "subflow-powermeter",
"name": "",
"iface": "",
"port": "12345",
"ipv": "udp4",
"multicast": "false",
"group": "",
"datatype": "utf8",
"x": 140,
"y": 160,
"wires": [
[
"udp-handler"
]
]
},
{
"id": "udp-out",
"type": "udp out",
"z": "subflow-powermeter",
"name": "",
"iface": "",
"port": "",
"ipv": "udp4",
"outport": "",
"base64": false,
"multicast": "false",
"group": "",
"x": 660,
"y": 160,
"wires": []
},
{
"id": "tcp-in",
"type": "tcp in",
"z": "subflow-powermeter",
"name": "",
"server": "server",
"host": "",
"port": "12345",
"datamode": "stream",
"datatype": "utf8",
"newline": "",
"topic": "",
"base64": false,
"x": 140,
"y": 240,
"wires": [
[
"tcp-handler"
]
]
},
{
"id": "tcp-out",
"type": "tcp out",
"z": "subflow-powermeter",
"host": "",
"port": "",
"beserver": "reply",
"base64": false,
"end": false,
"name": "",
"x": 660,
"y": 240,
"wires": []
},
{
"id": "udp-handler",
"type": "function",
"z": "subflow-powermeter",
"name": "Handle UDP",
"func": "node.log(`Received UDP message: ${msg.payload}`);\nif (msg.payload === \"hame\") {\n msg.payload = \"ack\";\n node.log(`Sent UDP response: ack`);\n return [msg, null];\n} else {\n node.warn(`Received unknown UDP message: ${msg.payload}`);\n return [null, null];\n}",
"outputs": 2,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 400,
"y": 160,
"wires": [
[
"udp-out"
],
[]
]
},
{
"id": "tcp-handler",
"type": "function",
"z": "subflow-powermeter",
"name": "Handle TCP",
"func": "node.log(`Received TCP message: ${msg.payload}`);\nif (msg.payload.trim() === \"hello\") {\n flow.set(\"tcp-addr\", msg._session);\n node.log(`Stored TCP session for future messages`);\n msg.payload = \"\"; // Clear payload to send later\n node.send([null, msg]);\n} else {\n node.warn(`Received unknown TCP message: ${msg.payload}`);\n return null;\n}",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 400,
"y": 240,
"wires": [
[]
]
},
{
"id": "send-powermeter-values",
"type": "function",
"z": "subflow-powermeter",
"name": "Send Powermeter Values",
"func": "var values = msg.payload;\nif (typeof values === 'string' || typeof values === 'number') {\n values = [Number(values)];\n} else if (Array.isArray(values)) {\n values = values.map(Number);\n} else {\n values = [0, 0, 0];\n}\n\nnode.log(`Received new powermeter values: ${values}`);\n\nvar disableSumPhases = flow.get(\"disableSumPhases\") || false;\nvar allowNegativeValues = flow.get(\"allowNegativeValues\") || false;\n\nvar value1 = values[0] || 0;\nvar value2 = values[1] || 0;\nvar value3 = values[2] || 0;\n\nif (!disableSumPhases) {\n value1 += value2 + value3;\n value2 = 0;\n value3 = 0;\n}\n\nif (!allowNegativeValues) {\n value1 = Math.abs(value1);\n value2 = Math.abs(value2);\n value3 = Math.abs(value3);\n}\n\nvalue1 = Math.round(value1);\nvalue2 = Math.round(value2);\nvalue3 = Math.round(value3);\n\nmsg.payload = `HM:${value1}|${value2}|${value3}`;\nmsg._session = flow.get(\"tcp-addr\");\nif (msg._session) {\n node.log(`Sent TCP message: ${msg.payload}`);\n return msg;\n} else {\n node.warn(`No TCP session found. Message not sent: ${msg.payload}`);\n return null;\n}",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 400,
"y": 320,
"wires": [
[
"tcp-out"
]
]
},
{
"id": "subflow-instance",
"type": "subflow:subflow-powermeter",
"z": "your-flow-id",
"name": "",
"env": [],
"x": 360,
"y": 80,
"wires": []
},
{
"id": "inject-powermeter-values",
"type": "inject",
"z": "your-flow-id",
"name": "Inject Powermeter Values",
"props": [
{
"p": "payload"
}
],
"repeat": "1",
"crontab": "",
"once": true,
"onceDelay": "1",
"topic": "",
"payload": "[100, 50, 25]",
"payloadType": "json",
"x": 160,
"y": 80,
"wires": [
[
"subflow-instance"
]
]
}
]