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
| [
{
"id": "891ae71fde4b071e",
"type": "inject",
"z": "back_to_basics_tab",
"name": "Poll 5s",
"props": [],
"repeat": "5",
"crontab": "",
"once": true,
"onceDelay": 0.1,
"topic": "",
"x": 140,
"y": 220,
"wires": [
[
"7e026a3184dc1331"
]
]
},
{
"id": "7e026a3184dc1331",
"type": "exec",
"z": "back_to_basics_tab",
"command": "vreg -c socketcan:vecan1 -n 0x41 -g 0xD08E",
"addpay": false,
"append": "",
"useSpawn": "false",
"name": "vreg Get",
"x": 310,
"y": 220,
"wires": [
[
"fb5caa1e8513f4c8"
],
[],
[]
]
},
{
"id": "fb5caa1e8513f4c8",
"type": "function",
"z": "back_to_basics_tab",
"name": "Decoder & Sync",
"func": "let input = msg.payload.toString().trim();\nlet lines = input.split('\\n');\nlet dataLine = lines[lines.length - 1];\nlet matches = dataLine.match(/0x([0-9A-Fa-f]{2})/g);\n\nif (matches && matches.length >= 4) {\n let b1 = parseInt(matches[0].replace('0x', ''), 16);\n let b2 = parseInt(matches[1].replace('0x', ''), 16);\n let b3 = parseInt(matches[2].replace('0x', ''), 16);\n let b4 = parseInt(matches[3].replace('0x', ''), 16);\n\n let watts = ( (b4 << 24) | (b3 << 16) | (b2 << 8) | b1 ) >>> 0;\n \n flow.set(\"lastKnownFeedIn\", watts);\n\n // Alleen doorsturen naar de switch als we niet net zelf iets verstuurd hebben\n let lastSent = flow.get(\"lastSentTime\") || 0;\n let now = Date.now();\n \n let msgStatus = { payload: watts };\n let msgSwitch = null;\n\n // Blokkeer status-update naar switch voor 6 seconden na een handmatige actie\n if (now - lastSent > 6000) {\n msgSwitch = { payload: (watts === 0) };\n }\n\n return [msgStatus, msgSwitch];\n}\nreturn null;",
"outputs": 2,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 510,
"y": 220,
"wires": [
[
"b7ce67da2a7d5fc6"
],
[]
]
},
{
"id": "7bbb55137e050ebb",
"type": "inject",
"z": "back_to_basics_tab",
"name": "set to zero",
"props": [
{
"p": "payload"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "vreg -c socketcan:vecan1 -n 0x41 -s 0xD08E 0x00 0x00 0x00 0x00",
"payloadType": "str",
"x": 140,
"y": 440,
"wires": [
[
"be162635f1ea4892"
]
]
},
{
"id": "65d5d85aa4cfce5e",
"type": "inject",
"z": "back_to_basics_tab",
"name": "set to 20000",
"props": [
{
"p": "payload"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "vreg -c socketcan:vecan1 -n 0x41 -s 0xD08E 0x20 0x4e 0x00 0x00",
"payloadType": "str",
"x": 150,
"y": 480,
"wires": [
[
"be162635f1ea4892"
]
]
},
{
"id": "be162635f1ea4892",
"type": "function",
"z": "back_to_basics_tab",
"name": "Schrijf-Beveiliging",
"func": "let lastKnown = flow.get(\"lastKnownFeedIn\");\nlet command = msg.payload;\n\n// We kijken welk commando er gestuurd wordt en vergelijken dat met de actuele status\nif (command.includes(\"0x00 0x00 0x00 0x00\") && lastKnown === 0) {\n node.status({fill:\"grey\", shape:\"ring\", text:\"Al op 0W - blokkeer schrijven\"});\n return null; // Stop de flow, niet schrijven\n}\n\nif (command.includes(\"0x20 0x4e 0x00 0x00\") && lastKnown === 20000) {\n node.status({fill:\"grey\", shape:\"ring\", text:\"Al op 20kW - blokkeer schrijven\"});\n return null; // Stop de flow, niet schrijven\n}\n\n// Als de waarde anders is, laten we het commando door en slaan we de tijd op\nlet nu = new Date();\nlet tijdstip = nu.toLocaleTimeString('nl-NL', { hour12: false });\n\nnode.status({\n fill: \"green\", \n shape: \"dot\", \n text: \"Verzonden om: \" + tijdstip\n});\n\nflow.set(\"lastSentTime\", nu.getTime());\nreturn msg;",
"outputs": 1,
"timeout": "",
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 390,
"y": 360,
"wires": [
[
"7793496b61e6f9be"
]
]
},
{
"id": "7793496b61e6f9be",
"type": "exec",
"z": "back_to_basics_tab",
"command": "",
"addpay": true,
"append": "",
"useSpawn": "false",
"name": "vreg EXEC",
"x": 610,
"y": 360,
"wires": [
[],
[],
[]
]
}
] |