Tue, 12 May 2020 15:13:06 +0200
Added iSpindel to the websockets. Better offline detection for websockets.
0 | 1 | /** |
2 | * @file nodes.c | |
3 | * @brief Handle nodes status | |
4 | * @author Michiel Broek <mbroek at mbse dot eu> | |
5 | * | |
578
e75ce5bbda73
Changed the interface from the iSpindels to be the same as other devices. A webpage converts each call to two standard MQTT messages. The nodes MQTT message extended with an interval parameter. iSpindels now have a generated uuid made up from the chipid.
Michiel Broek <mbroek@mbse.eu>
parents:
572
diff
changeset
|
6 | * Copyright (C) 2018-2020 |
0 | 7 | * |
8 | * This file is part of the bms (Brewery Management System) | |
9 | * | |
10 | * This is free software; you can redistribute it and/or modify it | |
11 | * under the terms of the GNU General Public License as published by the | |
12 | * Free Software Foundation; either version 2, or (at your option) any | |
13 | * later version. | |
14 | * | |
15 | * bms is distributed in the hope that it will be useful, but | |
16 | * WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
18 | * General Public License for more details. | |
19 | * | |
20 | * You should have received a copy of the GNU General Public License | |
21 | * along with ThermFerm; see the file COPYING. If not, write to the Free | |
22 | * Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. | |
23 | */ | |
24 | ||
25 | ||
26 | #include "bms.h" | |
27 | #include "xutil.h" | |
28 | #include "nodes.h" | |
29 | #include "mysql.h" | |
672
23f959713fcb
Added websockets for node status changes.
Michiel Broek <mbroek@mbse.eu>
parents:
578
diff
changeset
|
30 | #include "websocket.h" |
0 | 31 | |
32 | ||
384
442d23455ae4
The bms daemon now checks if a node went away of no data is received for 10 minutes.
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
33 | sys_node_list *nodes = NULL; |
0 | 34 | |
384
442d23455ae4
The bms daemon now checks if a node went away of no data is received for 10 minutes.
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
35 | extern int debug; |
442d23455ae4
The bms daemon now checks if a node went away of no data is received for 10 minutes.
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
36 | extern sys_fermenter_list *fermenters; |
502
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
384
diff
changeset
|
37 | extern sys_co2meter_list *co2meters; |
572
7a03181d29a3
Version 0.3.27 More code for iSpindels. All online/offline data in the database is now handles as integers. Nodes timeout use the configured interval time from the nodes.
Michiel Broek <mbroek@mbse.eu>
parents:
502
diff
changeset
|
38 | extern sys_ispindel_list *ispindels; |
0 | 39 | |
40 | ||
41 | void node_birth_data(char *topic, char *payload) | |
42 | { | |
43 | struct json_object *jobj, *val, *metric, *metric2; | |
44 | sys_node_list *node, *tmpp; | |
672
23f959713fcb
Added websockets for node status changes.
Michiel Broek <mbroek@mbse.eu>
parents:
578
diff
changeset
|
45 | struct tm *mytime; |
23f959713fcb
Added websockets for node status changes.
Michiel Broek <mbroek@mbse.eu>
parents:
578
diff
changeset
|
46 | char *group_id, *message_type, *edge_node, *msg = NULL, buf[74]; |
0 | 47 | bool new_node = true; |
48 | ||
49 | // fprintf(stdout, "node_birth: %s %s\n", topic, payload); | |
50 | ||
51 | strtok(topic, "/"); // ignore namespace | |
52 | group_id = strtok(NULL, "/"); | |
53 | message_type = strtok(NULL, "/"); | |
54 | edge_node = strtok(NULL, "/\0"); | |
55 | ||
56 | /* | |
57 | * Search node record in the memory array and use it if found. | |
58 | */ | |
59 | if (nodes) { | |
60 | for (tmpp = nodes; tmpp; tmpp = tmpp->next) { | |
61 | if ((strcmp(tmpp->group_id, group_id) == 0) && (strcmp(tmpp->node, edge_node) == 0)) { | |
62 | new_node = false; | |
63 | node = tmpp; | |
64 | node->lastseen = time(NULL); | |
65 | node->online = true; | |
66 | break; | |
67 | } | |
68 | } | |
69 | } | |
70 | ||
71 | /* | |
72 | * Allocate new node if not yet known. | |
73 | */ | |
74 | if (new_node) { | |
75 | node = (sys_node_list *)malloc(sizeof(sys_node_list)); | |
76 | node->uuid = NULL; | |
77 | node->next = NULL; | |
78 | node->group_id = xstrcpy(group_id); | |
79 | node->node = xstrcpy(edge_node); | |
80 | node->online = true; | |
81 | node->hardwaremake = node->hardwaremodel = node->os = node->os_version = node->firmware = NULL; | |
82 | node->firstseen = node->lastseen = time(NULL); | |
83 | node->temperature = node->humidity = node->barometer = 0.0; | |
84 | node->gps_latitude = node->gps_longitude = node->gps_altitude = 0.0; | |
85 | node->net_address = node->net_ifname = NULL; | |
86 | node->net_rssi = 0; | |
578
e75ce5bbda73
Changed the interface from the iSpindels to be the same as other devices. A webpage converts each call to two standard MQTT messages. The nodes MQTT message extended with an interval parameter. iSpindels now have a generated uuid made up from the chipid.
Michiel Broek <mbroek@mbse.eu>
parents:
572
diff
changeset
|
87 | node->interval = 300; |
0 | 88 | } |
89 | ||
90 | /* | |
91 | * Process the JSON formatted payload. | |
92 | * Update only the fields that are found in the payload. | |
93 | */ | |
94 | jobj = json_tokener_parse(payload); | |
95 | ||
96 | if (json_object_object_get_ex(jobj, "timestamp", &val)) { | |
97 | if (strcmp((char *)"NDATA", message_type)) { | |
98 | node->firstseen = json_object_get_int(val); | |
99 | syslog(LOG_NOTICE, "Online node `%s/%s'", node->group_id, node->node); | |
100 | } else { | |
101 | node->lastseen = json_object_get_int(val); | |
102 | } | |
103 | } | |
104 | ||
105 | if (json_object_object_get_ex(jobj, "metric", &metric)) { | |
106 | if (json_object_object_get_ex(metric, "uuid", &val)) { | |
107 | if (node->uuid) | |
108 | free(node->uuid); | |
109 | node->uuid = xstrcpy((char *)json_object_get_string(val)); | |
110 | } | |
578
e75ce5bbda73
Changed the interface from the iSpindels to be the same as other devices. A webpage converts each call to two standard MQTT messages. The nodes MQTT message extended with an interval parameter. iSpindels now have a generated uuid made up from the chipid.
Michiel Broek <mbroek@mbse.eu>
parents:
572
diff
changeset
|
111 | if (json_object_object_get_ex(metric, "interval", &val)) { |
e75ce5bbda73
Changed the interface from the iSpindels to be the same as other devices. A webpage converts each call to two standard MQTT messages. The nodes MQTT message extended with an interval parameter. iSpindels now have a generated uuid made up from the chipid.
Michiel Broek <mbroek@mbse.eu>
parents:
572
diff
changeset
|
112 | node->interval = json_object_get_int(val); |
e75ce5bbda73
Changed the interface from the iSpindels to be the same as other devices. A webpage converts each call to two standard MQTT messages. The nodes MQTT message extended with an interval parameter. iSpindels now have a generated uuid made up from the chipid.
Michiel Broek <mbroek@mbse.eu>
parents:
572
diff
changeset
|
113 | } |
0 | 114 | if (json_object_object_get_ex(metric, "properties", &metric2)) { |
115 | if (json_object_object_get_ex(metric2, "hardwaremake", &val)) { | |
116 | if (node->hardwaremake) | |
117 | free(node->hardwaremake); | |
118 | node->hardwaremake = xstrcpy((char *)json_object_get_string(val)); | |
119 | } | |
120 | if (json_object_object_get_ex(metric2, "hardwaremodel", &val)) { | |
121 | if (node->hardwaremodel) | |
122 | free(node->hardwaremodel); | |
123 | node->hardwaremodel = xstrcpy((char *)json_object_get_string(val)); | |
124 | } | |
125 | if (json_object_object_get_ex(metric2, "os", &val)) { | |
126 | if (node->os) | |
127 | free(node->os); | |
128 | node->os = xstrcpy((char *)json_object_get_string(val)); | |
129 | } | |
130 | if (json_object_object_get_ex(metric2, "os_version", &val)) { | |
131 | if (node->os_version) | |
132 | free(node->os_version); | |
133 | node->os_version = xstrcpy((char *)json_object_get_string(val)); | |
134 | } | |
135 | if (json_object_object_get_ex(metric2, "FW", &val)) { | |
136 | if (node->firmware) | |
137 | free(node->firmware); | |
138 | node->firmware = xstrcpy((char *)json_object_get_string(val)); | |
139 | } | |
140 | } | |
141 | if (json_object_object_get_ex(metric, "THB", &metric2)) { | |
142 | if (json_object_object_get_ex(metric2, "temperature", &val)) { | |
143 | node->temperature = json_object_get_double(val); | |
144 | } | |
145 | if (json_object_object_get_ex(metric2, "humidity", &val)) { | |
146 | node->humidity= json_object_get_double(val); | |
147 | } | |
148 | if (json_object_object_get_ex(metric2, "barometer", &val)) { | |
149 | node->barometer = json_object_get_double(val); | |
150 | } | |
151 | } | |
152 | if (json_object_object_get_ex(metric, "GPS", &metric2)) { | |
153 | if (json_object_object_get_ex(metric2, "latitude", &val)) { | |
154 | node->gps_latitude = json_object_get_double(val); | |
155 | } | |
156 | if (json_object_object_get_ex(metric2, "longitude", &val)) { | |
157 | node->gps_longitude = json_object_get_double(val); | |
158 | } | |
159 | if (json_object_object_get_ex(metric2, "altitude", &val)) { | |
160 | node->gps_altitude = json_object_get_double(val); | |
161 | } | |
162 | } | |
163 | if (json_object_object_get_ex(metric, "net", &metric2)) { | |
164 | if (json_object_object_get_ex(metric2, "address", &val)) { | |
165 | if (node->net_address) | |
166 | free(node->net_address); | |
167 | node->net_address = xstrcpy((char *)json_object_get_string(val)); | |
168 | } | |
169 | if (json_object_object_get_ex(metric2, "ifname", &val)) { | |
170 | if (node->net_ifname) | |
171 | free(node->net_ifname); | |
172 | node->net_ifname = xstrcpy((char *)json_object_get_string(val)); | |
173 | } | |
174 | if (json_object_object_get_ex(metric2, "rssi", &val)) { | |
175 | node->net_rssi = json_object_get_int(val); | |
176 | } | |
177 | } | |
178 | } | |
179 | json_object_put(jobj); | |
180 | ||
672
23f959713fcb
Added websockets for node status changes.
Michiel Broek <mbroek@mbse.eu>
parents:
578
diff
changeset
|
181 | msg = xstrcpy((char *)"{\"node\":\""); |
23f959713fcb
Added websockets for node status changes.
Michiel Broek <mbroek@mbse.eu>
parents:
578
diff
changeset
|
182 | msg = xstrcat(msg, edge_node); |
23f959713fcb
Added websockets for node status changes.
Michiel Broek <mbroek@mbse.eu>
parents:
578
diff
changeset
|
183 | msg = xstrcat(msg, (char *)"\",\"group\":\""); |
23f959713fcb
Added websockets for node status changes.
Michiel Broek <mbroek@mbse.eu>
parents:
578
diff
changeset
|
184 | msg = xstrcat(msg, group_id); |
23f959713fcb
Added websockets for node status changes.
Michiel Broek <mbroek@mbse.eu>
parents:
578
diff
changeset
|
185 | msg = xstrcat(msg, (char *)"\",\"online\":"); |
23f959713fcb
Added websockets for node status changes.
Michiel Broek <mbroek@mbse.eu>
parents:
578
diff
changeset
|
186 | msg = xstrcat(msg, node->online ? (char *)"1":(char *)"0"); |
23f959713fcb
Added websockets for node status changes.
Michiel Broek <mbroek@mbse.eu>
parents:
578
diff
changeset
|
187 | msg = xstrcat(msg, (char *)",\"lastseen\":\""); |
23f959713fcb
Added websockets for node status changes.
Michiel Broek <mbroek@mbse.eu>
parents:
578
diff
changeset
|
188 | mytime = localtime(&node->lastseen); |
23f959713fcb
Added websockets for node status changes.
Michiel Broek <mbroek@mbse.eu>
parents:
578
diff
changeset
|
189 | snprintf(buf, 73, "%04d-%02d-%02d %02d:%02d:%02d", |
23f959713fcb
Added websockets for node status changes.
Michiel Broek <mbroek@mbse.eu>
parents:
578
diff
changeset
|
190 | mytime->tm_year + 1900, mytime->tm_mon + 1, mytime->tm_mday, mytime->tm_hour, mytime->tm_min, mytime->tm_sec); |
23f959713fcb
Added websockets for node status changes.
Michiel Broek <mbroek@mbse.eu>
parents:
578
diff
changeset
|
191 | msg = xstrcat(msg, buf); |
23f959713fcb
Added websockets for node status changes.
Michiel Broek <mbroek@mbse.eu>
parents:
578
diff
changeset
|
192 | msg = xstrcat(msg, (char *)"\""); |
23f959713fcb
Added websockets for node status changes.
Michiel Broek <mbroek@mbse.eu>
parents:
578
diff
changeset
|
193 | if (node->temperature) { |
23f959713fcb
Added websockets for node status changes.
Michiel Broek <mbroek@mbse.eu>
parents:
578
diff
changeset
|
194 | msg = xstrcat(msg, (char *)",\"temperature\":"); |
23f959713fcb
Added websockets for node status changes.
Michiel Broek <mbroek@mbse.eu>
parents:
578
diff
changeset
|
195 | snprintf(buf, 64, "%.1f", node->temperature); |
23f959713fcb
Added websockets for node status changes.
Michiel Broek <mbroek@mbse.eu>
parents:
578
diff
changeset
|
196 | msg = xstrcat(msg, buf); |
23f959713fcb
Added websockets for node status changes.
Michiel Broek <mbroek@mbse.eu>
parents:
578
diff
changeset
|
197 | } |
23f959713fcb
Added websockets for node status changes.
Michiel Broek <mbroek@mbse.eu>
parents:
578
diff
changeset
|
198 | if (node->humidity) { |
23f959713fcb
Added websockets for node status changes.
Michiel Broek <mbroek@mbse.eu>
parents:
578
diff
changeset
|
199 | msg = xstrcat(msg, (char *)",\"humidity\":"); |
23f959713fcb
Added websockets for node status changes.
Michiel Broek <mbroek@mbse.eu>
parents:
578
diff
changeset
|
200 | snprintf(buf, 64, "%.1f", node->humidity); |
23f959713fcb
Added websockets for node status changes.
Michiel Broek <mbroek@mbse.eu>
parents:
578
diff
changeset
|
201 | msg = xstrcat(msg, buf); |
23f959713fcb
Added websockets for node status changes.
Michiel Broek <mbroek@mbse.eu>
parents:
578
diff
changeset
|
202 | } |
23f959713fcb
Added websockets for node status changes.
Michiel Broek <mbroek@mbse.eu>
parents:
578
diff
changeset
|
203 | msg = xstrcat(msg, (char *)",\"ip\":\""); |
23f959713fcb
Added websockets for node status changes.
Michiel Broek <mbroek@mbse.eu>
parents:
578
diff
changeset
|
204 | msg = xstrcat(msg, node->net_address); |
23f959713fcb
Added websockets for node status changes.
Michiel Broek <mbroek@mbse.eu>
parents:
578
diff
changeset
|
205 | msg = xstrcat(msg, (char *)"\""); |
23f959713fcb
Added websockets for node status changes.
Michiel Broek <mbroek@mbse.eu>
parents:
578
diff
changeset
|
206 | if (node->net_rssi != 0) { |
23f959713fcb
Added websockets for node status changes.
Michiel Broek <mbroek@mbse.eu>
parents:
578
diff
changeset
|
207 | msg = xstrcat(msg, (char *)",\"rssi\":"); |
23f959713fcb
Added websockets for node status changes.
Michiel Broek <mbroek@mbse.eu>
parents:
578
diff
changeset
|
208 | snprintf(buf, 64, "%d", node->net_rssi); |
23f959713fcb
Added websockets for node status changes.
Michiel Broek <mbroek@mbse.eu>
parents:
578
diff
changeset
|
209 | msg = xstrcat(msg, buf); |
23f959713fcb
Added websockets for node status changes.
Michiel Broek <mbroek@mbse.eu>
parents:
578
diff
changeset
|
210 | } |
23f959713fcb
Added websockets for node status changes.
Michiel Broek <mbroek@mbse.eu>
parents:
578
diff
changeset
|
211 | msg = xstrcat(msg, (char *)"}"); |
23f959713fcb
Added websockets for node status changes.
Michiel Broek <mbroek@mbse.eu>
parents:
578
diff
changeset
|
212 | ws_broadcast(msg); |
23f959713fcb
Added websockets for node status changes.
Michiel Broek <mbroek@mbse.eu>
parents:
578
diff
changeset
|
213 | free(msg); |
23f959713fcb
Added websockets for node status changes.
Michiel Broek <mbroek@mbse.eu>
parents:
578
diff
changeset
|
214 | msg = NULL; |
23f959713fcb
Added websockets for node status changes.
Michiel Broek <mbroek@mbse.eu>
parents:
578
diff
changeset
|
215 | |
0 | 216 | // node_dump(node); |
217 | ||
218 | if (new_node) { | |
219 | if (nodes == NULL) { | |
220 | nodes = node; | |
221 | } else { | |
222 | for (tmpp = nodes; tmpp; tmpp = tmpp->next) { | |
223 | if (tmpp->next == NULL) { | |
224 | tmpp->next = node; | |
225 | break; | |
226 | } | |
227 | } | |
228 | } | |
229 | node_mysql_insert(node); | |
230 | } else { | |
231 | node_mysql_update(node); | |
232 | } | |
233 | } | |
234 | ||
235 | ||
236 | ||
237 | void node_dump(sys_node_list *node) | |
238 | { | |
239 | if (debug) { | |
240 | printf("online %s\n", node->online ? "yes":"no"); | |
241 | printf("uuid %s\n", node->uuid); | |
242 | printf("node %s\n", node->node); | |
243 | printf("group %s\n", node->group_id); | |
244 | printf("hw make %s model %s\n", node->hardwaremake, node->hardwaremodel); | |
245 | printf("os %s version %s\n", node->os, node->os_version); | |
246 | printf("firmware %s\n", node->firmware); | |
247 | printf("first %ld last %ld\n", node->firstseen, node->lastseen); | |
248 | printf("THB %.2f %.2f %.2f\n", node->temperature, node->humidity, node->barometer); | |
249 | printf("GPS %.5f %.5f %.5f\n", node->gps_latitude, node->gps_longitude, node->gps_altitude); | |
250 | printf("net %s:%s\n", node->net_ifname, node->net_address); | |
251 | printf("rssi %d\n", node->net_rssi); | |
578
e75ce5bbda73
Changed the interface from the iSpindels to be the same as other devices. A webpage converts each call to two standard MQTT messages. The nodes MQTT message extended with an interval parameter. iSpindels now have a generated uuid made up from the chipid.
Michiel Broek <mbroek@mbse.eu>
parents:
572
diff
changeset
|
252 | printf("interval %d\n", node->interval); |
0 | 253 | } |
254 | } | |
255 | ||
256 | ||
257 | ||
258 | void node_death(char *topic) | |
259 | { | |
672
23f959713fcb
Added websockets for node status changes.
Michiel Broek <mbroek@mbse.eu>
parents:
578
diff
changeset
|
260 | char *group_id, *edge_node, *msg; |
0 | 261 | sys_node_list *tmpp; |
262 | ||
263 | strtok(topic, "/"); // ignore namespace | |
264 | group_id = strtok(NULL, "/"); | |
265 | strtok(NULL, "/"); // ignore message_type | |
266 | edge_node = strtok(NULL, "/\0"); | |
267 | ||
268 | syslog(LOG_NOTICE, "Offline node `%s/%s'", group_id, edge_node); | |
269 | node_mysql_death(edge_node); | |
270 | ||
271 | for (tmpp = nodes; tmpp; tmpp = tmpp->next) { | |
272 | if (strcmp(tmpp->node, edge_node) == 0) { | |
273 | tmpp->online = false; | |
672
23f959713fcb
Added websockets for node status changes.
Michiel Broek <mbroek@mbse.eu>
parents:
578
diff
changeset
|
274 | msg = xstrcpy((char *)"{\"node\":\""); |
23f959713fcb
Added websockets for node status changes.
Michiel Broek <mbroek@mbse.eu>
parents:
578
diff
changeset
|
275 | msg = xstrcat(msg, edge_node); |
23f959713fcb
Added websockets for node status changes.
Michiel Broek <mbroek@mbse.eu>
parents:
578
diff
changeset
|
276 | msg = xstrcat(msg, (char *)"\",\"group\":\""); |
23f959713fcb
Added websockets for node status changes.
Michiel Broek <mbroek@mbse.eu>
parents:
578
diff
changeset
|
277 | msg = xstrcat(msg, group_id); |
23f959713fcb
Added websockets for node status changes.
Michiel Broek <mbroek@mbse.eu>
parents:
578
diff
changeset
|
278 | msg = xstrcat(msg, (char *)"\",\"online\":0}"); |
23f959713fcb
Added websockets for node status changes.
Michiel Broek <mbroek@mbse.eu>
parents:
578
diff
changeset
|
279 | ws_broadcast(msg); |
23f959713fcb
Added websockets for node status changes.
Michiel Broek <mbroek@mbse.eu>
parents:
578
diff
changeset
|
280 | free(msg); |
23f959713fcb
Added websockets for node status changes.
Michiel Broek <mbroek@mbse.eu>
parents:
578
diff
changeset
|
281 | msg = NULL; |
0 | 282 | break; |
283 | } | |
284 | } | |
285 | } | |
286 | ||
287 | ||
384
442d23455ae4
The bms daemon now checks if a node went away of no data is received for 10 minutes.
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
288 | |
442d23455ae4
The bms daemon now checks if a node went away of no data is received for 10 minutes.
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
289 | void nodes_check_online() |
442d23455ae4
The bms daemon now checks if a node went away of no data is received for 10 minutes.
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
290 | { |
442d23455ae4
The bms daemon now checks if a node went away of no data is received for 10 minutes.
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
291 | sys_node_list *tmpn; |
442d23455ae4
The bms daemon now checks if a node went away of no data is received for 10 minutes.
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
292 | sys_fermenter_list *tmpf; |
502
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
384
diff
changeset
|
293 | sys_co2meter_list *tmpc; |
572
7a03181d29a3
Version 0.3.27 More code for iSpindels. All online/offline data in the database is now handles as integers. Nodes timeout use the configured interval time from the nodes.
Michiel Broek <mbroek@mbse.eu>
parents:
502
diff
changeset
|
294 | sys_ispindel_list *tmpi; |
384
442d23455ae4
The bms daemon now checks if a node went away of no data is received for 10 minutes.
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
295 | time_t now = time(NULL); |
672
23f959713fcb
Added websockets for node status changes.
Michiel Broek <mbroek@mbse.eu>
parents:
578
diff
changeset
|
296 | char *msg = NULL; |
384
442d23455ae4
The bms daemon now checks if a node went away of no data is received for 10 minutes.
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
297 | |
442d23455ae4
The bms daemon now checks if a node went away of no data is received for 10 minutes.
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
298 | for (tmpn = nodes; tmpn; tmpn = tmpn->next) { |
578
e75ce5bbda73
Changed the interface from the iSpindels to be the same as other devices. A webpage converts each call to two standard MQTT messages. The nodes MQTT message extended with an interval parameter. iSpindels now have a generated uuid made up from the chipid.
Michiel Broek <mbroek@mbse.eu>
parents:
572
diff
changeset
|
299 | // if (debug) |
e75ce5bbda73
Changed the interface from the iSpindels to be the same as other devices. A webpage converts each call to two standard MQTT messages. The nodes MQTT message extended with an interval parameter. iSpindels now have a generated uuid made up from the chipid.
Michiel Broek <mbroek@mbse.eu>
parents:
572
diff
changeset
|
300 | // printf("%-20s online %s %ld %d\n", tmpn->node, tmpn->online ? "yes":"no ", tmpn->lastseen, tmpn->interval); |
572
7a03181d29a3
Version 0.3.27 More code for iSpindels. All online/offline data in the database is now handles as integers. Nodes timeout use the configured interval time from the nodes.
Michiel Broek <mbroek@mbse.eu>
parents:
502
diff
changeset
|
301 | if (tmpn->online && ((now - tmpn->lastseen) > (tmpn->interval * 2 + 5))) { // 2 times interval + 5 seconds |
7a03181d29a3
Version 0.3.27 More code for iSpindels. All online/offline data in the database is now handles as integers. Nodes timeout use the configured interval time from the nodes.
Michiel Broek <mbroek@mbse.eu>
parents:
502
diff
changeset
|
302 | syslog(LOG_NOTICE, "Timeout node `%s/%s' after %ld seconds", tmpn->group_id, tmpn->node, (now - tmpn->lastseen)); |
384
442d23455ae4
The bms daemon now checks if a node went away of no data is received for 10 minutes.
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
303 | tmpn->online = false; |
442d23455ae4
The bms daemon now checks if a node went away of no data is received for 10 minutes.
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
304 | node_mysql_death(tmpn->node); |
672
23f959713fcb
Added websockets for node status changes.
Michiel Broek <mbroek@mbse.eu>
parents:
578
diff
changeset
|
305 | msg = xstrcpy((char *)"{\"node\":\""); |
23f959713fcb
Added websockets for node status changes.
Michiel Broek <mbroek@mbse.eu>
parents:
578
diff
changeset
|
306 | msg = xstrcat(msg, tmpn->node); |
23f959713fcb
Added websockets for node status changes.
Michiel Broek <mbroek@mbse.eu>
parents:
578
diff
changeset
|
307 | msg = xstrcat(msg, (char *)"\",\"group\":\""); |
23f959713fcb
Added websockets for node status changes.
Michiel Broek <mbroek@mbse.eu>
parents:
578
diff
changeset
|
308 | msg = xstrcat(msg, tmpn->group_id); |
23f959713fcb
Added websockets for node status changes.
Michiel Broek <mbroek@mbse.eu>
parents:
578
diff
changeset
|
309 | msg = xstrcat(msg, (char *)"\",\"online\":0}"); |
23f959713fcb
Added websockets for node status changes.
Michiel Broek <mbroek@mbse.eu>
parents:
578
diff
changeset
|
310 | ws_broadcast(msg); |
675
a27af02ab16a
Added iSpindel to the websockets. Better offline detection for websockets.
Michiel Broek <mbroek@mbse.eu>
parents:
673
diff
changeset
|
311 | syslog(LOG_NOTICE, msg); |
672
23f959713fcb
Added websockets for node status changes.
Michiel Broek <mbroek@mbse.eu>
parents:
578
diff
changeset
|
312 | free(msg); |
23f959713fcb
Added websockets for node status changes.
Michiel Broek <mbroek@mbse.eu>
parents:
578
diff
changeset
|
313 | msg = NULL; |
384
442d23455ae4
The bms daemon now checks if a node went away of no data is received for 10 minutes.
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
314 | |
442d23455ae4
The bms daemon now checks if a node went away of no data is received for 10 minutes.
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
315 | for (tmpf = fermenters; tmpf; tmpf = tmpf->next) { |
442d23455ae4
The bms daemon now checks if a node went away of no data is received for 10 minutes.
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
316 | if (strcmp(tmpf->node, tmpn->node) == 0) { |
442d23455ae4
The bms daemon now checks if a node went away of no data is received for 10 minutes.
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
317 | if (tmpf->online) { |
442d23455ae4
The bms daemon now checks if a node went away of no data is received for 10 minutes.
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
318 | syslog(LOG_NOTICE, "Timeout fermenter %s/%s", tmpf->node, tmpf->alias); |
442d23455ae4
The bms daemon now checks if a node went away of no data is received for 10 minutes.
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
319 | tmpf->online = false; |
442d23455ae4
The bms daemon now checks if a node went away of no data is received for 10 minutes.
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
320 | fermenter_mysql_death(tmpf->node, tmpf->alias); |
673
9924b1218d39
Added co2meters to the websockets. Added node and units offline messages to the websockets.
Michiel Broek <mbroek@mbse.eu>
parents:
672
diff
changeset
|
321 | msg = xstrcpy((char *)"{\"device\":\"fermenter\",\"node\":\""); |
9924b1218d39
Added co2meters to the websockets. Added node and units offline messages to the websockets.
Michiel Broek <mbroek@mbse.eu>
parents:
672
diff
changeset
|
322 | msg = xstrcat(msg, tmpf->node); |
9924b1218d39
Added co2meters to the websockets. Added node and units offline messages to the websockets.
Michiel Broek <mbroek@mbse.eu>
parents:
672
diff
changeset
|
323 | msg = xstrcat(msg, (char *)"\",\"unit\":\""); |
9924b1218d39
Added co2meters to the websockets. Added node and units offline messages to the websockets.
Michiel Broek <mbroek@mbse.eu>
parents:
672
diff
changeset
|
324 | msg = xstrcat(msg, tmpf->alias); |
9924b1218d39
Added co2meters to the websockets. Added node and units offline messages to the websockets.
Michiel Broek <mbroek@mbse.eu>
parents:
672
diff
changeset
|
325 | msg = xstrcat(msg, (char *)"\",\"online\":0}"); |
9924b1218d39
Added co2meters to the websockets. Added node and units offline messages to the websockets.
Michiel Broek <mbroek@mbse.eu>
parents:
672
diff
changeset
|
326 | ws_broadcast(msg); |
675
a27af02ab16a
Added iSpindel to the websockets. Better offline detection for websockets.
Michiel Broek <mbroek@mbse.eu>
parents:
673
diff
changeset
|
327 | syslog(LOG_NOTICE, msg); |
673
9924b1218d39
Added co2meters to the websockets. Added node and units offline messages to the websockets.
Michiel Broek <mbroek@mbse.eu>
parents:
672
diff
changeset
|
328 | free(msg); |
9924b1218d39
Added co2meters to the websockets. Added node and units offline messages to the websockets.
Michiel Broek <mbroek@mbse.eu>
parents:
672
diff
changeset
|
329 | msg = NULL; |
384
442d23455ae4
The bms daemon now checks if a node went away of no data is received for 10 minutes.
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
330 | } |
442d23455ae4
The bms daemon now checks if a node went away of no data is received for 10 minutes.
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
331 | } |
442d23455ae4
The bms daemon now checks if a node went away of no data is received for 10 minutes.
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
332 | } |
502
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
384
diff
changeset
|
333 | |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
384
diff
changeset
|
334 | for (tmpc = co2meters; tmpc; tmpc = tmpc->next) { |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
384
diff
changeset
|
335 | if (strcmp(tmpc->node, tmpn->node) == 0) { |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
384
diff
changeset
|
336 | if (tmpc->online) { |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
384
diff
changeset
|
337 | syslog(LOG_NOTICE, "Timeout co2meter %s/%s", tmpc->node, tmpc->alias); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
384
diff
changeset
|
338 | tmpc->online = false; |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
384
diff
changeset
|
339 | co2meter_mysql_death(tmpc->node, tmpc->alias); |
673
9924b1218d39
Added co2meters to the websockets. Added node and units offline messages to the websockets.
Michiel Broek <mbroek@mbse.eu>
parents:
672
diff
changeset
|
340 | msg = xstrcpy((char *)"{\"device\":\"co2meter\",\"node\":\""); |
9924b1218d39
Added co2meters to the websockets. Added node and units offline messages to the websockets.
Michiel Broek <mbroek@mbse.eu>
parents:
672
diff
changeset
|
341 | msg = xstrcat(msg, tmpc->node); |
9924b1218d39
Added co2meters to the websockets. Added node and units offline messages to the websockets.
Michiel Broek <mbroek@mbse.eu>
parents:
672
diff
changeset
|
342 | msg = xstrcat(msg, (char *)"\",\"unit\":\""); |
9924b1218d39
Added co2meters to the websockets. Added node and units offline messages to the websockets.
Michiel Broek <mbroek@mbse.eu>
parents:
672
diff
changeset
|
343 | msg = xstrcat(msg, tmpc->alias); |
9924b1218d39
Added co2meters to the websockets. Added node and units offline messages to the websockets.
Michiel Broek <mbroek@mbse.eu>
parents:
672
diff
changeset
|
344 | msg = xstrcat(msg, (char *)"\",\"online\":0}"); |
9924b1218d39
Added co2meters to the websockets. Added node and units offline messages to the websockets.
Michiel Broek <mbroek@mbse.eu>
parents:
672
diff
changeset
|
345 | ws_broadcast(msg); |
675
a27af02ab16a
Added iSpindel to the websockets. Better offline detection for websockets.
Michiel Broek <mbroek@mbse.eu>
parents:
673
diff
changeset
|
346 | syslog(LOG_NOTICE, msg); |
673
9924b1218d39
Added co2meters to the websockets. Added node and units offline messages to the websockets.
Michiel Broek <mbroek@mbse.eu>
parents:
672
diff
changeset
|
347 | free(msg); |
9924b1218d39
Added co2meters to the websockets. Added node and units offline messages to the websockets.
Michiel Broek <mbroek@mbse.eu>
parents:
672
diff
changeset
|
348 | msg = NULL; |
502
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
384
diff
changeset
|
349 | } |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
384
diff
changeset
|
350 | } |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
384
diff
changeset
|
351 | } |
572
7a03181d29a3
Version 0.3.27 More code for iSpindels. All online/offline data in the database is now handles as integers. Nodes timeout use the configured interval time from the nodes.
Michiel Broek <mbroek@mbse.eu>
parents:
502
diff
changeset
|
352 | |
7a03181d29a3
Version 0.3.27 More code for iSpindels. All online/offline data in the database is now handles as integers. Nodes timeout use the configured interval time from the nodes.
Michiel Broek <mbroek@mbse.eu>
parents:
502
diff
changeset
|
353 | for (tmpi = ispindels; tmpi; tmpi = tmpi->next) { |
7a03181d29a3
Version 0.3.27 More code for iSpindels. All online/offline data in the database is now handles as integers. Nodes timeout use the configured interval time from the nodes.
Michiel Broek <mbroek@mbse.eu>
parents:
502
diff
changeset
|
354 | if (strcmp(tmpi->node, tmpn->node) == 0) { |
7a03181d29a3
Version 0.3.27 More code for iSpindels. All online/offline data in the database is now handles as integers. Nodes timeout use the configured interval time from the nodes.
Michiel Broek <mbroek@mbse.eu>
parents:
502
diff
changeset
|
355 | if (tmpi->online) { |
7a03181d29a3
Version 0.3.27 More code for iSpindels. All online/offline data in the database is now handles as integers. Nodes timeout use the configured interval time from the nodes.
Michiel Broek <mbroek@mbse.eu>
parents:
502
diff
changeset
|
356 | syslog(LOG_NOTICE, "Timeout ispindel %s", tmpi->node); |
7a03181d29a3
Version 0.3.27 More code for iSpindels. All online/offline data in the database is now handles as integers. Nodes timeout use the configured interval time from the nodes.
Michiel Broek <mbroek@mbse.eu>
parents:
502
diff
changeset
|
357 | tmpi->online = false; |
7a03181d29a3
Version 0.3.27 More code for iSpindels. All online/offline data in the database is now handles as integers. Nodes timeout use the configured interval time from the nodes.
Michiel Broek <mbroek@mbse.eu>
parents:
502
diff
changeset
|
358 | ispindel_mysql_death(tmpi->node); |
673
9924b1218d39
Added co2meters to the websockets. Added node and units offline messages to the websockets.
Michiel Broek <mbroek@mbse.eu>
parents:
672
diff
changeset
|
359 | msg = xstrcpy((char *)"{\"device\":\"ispindel\",\"node\":\""); |
9924b1218d39
Added co2meters to the websockets. Added node and units offline messages to the websockets.
Michiel Broek <mbroek@mbse.eu>
parents:
672
diff
changeset
|
360 | msg = xstrcat(msg, tmpi->node); |
9924b1218d39
Added co2meters to the websockets. Added node and units offline messages to the websockets.
Michiel Broek <mbroek@mbse.eu>
parents:
672
diff
changeset
|
361 | msg = xstrcat(msg, (char *)"\",\"unit\":\""); |
9924b1218d39
Added co2meters to the websockets. Added node and units offline messages to the websockets.
Michiel Broek <mbroek@mbse.eu>
parents:
672
diff
changeset
|
362 | msg = xstrcat(msg, tmpi->alias); |
9924b1218d39
Added co2meters to the websockets. Added node and units offline messages to the websockets.
Michiel Broek <mbroek@mbse.eu>
parents:
672
diff
changeset
|
363 | msg = xstrcat(msg, (char *)"\",\"online\":0}"); |
9924b1218d39
Added co2meters to the websockets. Added node and units offline messages to the websockets.
Michiel Broek <mbroek@mbse.eu>
parents:
672
diff
changeset
|
364 | ws_broadcast(msg); |
675
a27af02ab16a
Added iSpindel to the websockets. Better offline detection for websockets.
Michiel Broek <mbroek@mbse.eu>
parents:
673
diff
changeset
|
365 | syslog(LOG_NOTICE, msg); |
673
9924b1218d39
Added co2meters to the websockets. Added node and units offline messages to the websockets.
Michiel Broek <mbroek@mbse.eu>
parents:
672
diff
changeset
|
366 | free(msg); |
9924b1218d39
Added co2meters to the websockets. Added node and units offline messages to the websockets.
Michiel Broek <mbroek@mbse.eu>
parents:
672
diff
changeset
|
367 | msg = NULL; |
572
7a03181d29a3
Version 0.3.27 More code for iSpindels. All online/offline data in the database is now handles as integers. Nodes timeout use the configured interval time from the nodes.
Michiel Broek <mbroek@mbse.eu>
parents:
502
diff
changeset
|
368 | } |
7a03181d29a3
Version 0.3.27 More code for iSpindels. All online/offline data in the database is now handles as integers. Nodes timeout use the configured interval time from the nodes.
Michiel Broek <mbroek@mbse.eu>
parents:
502
diff
changeset
|
369 | } |
7a03181d29a3
Version 0.3.27 More code for iSpindels. All online/offline data in the database is now handles as integers. Nodes timeout use the configured interval time from the nodes.
Michiel Broek <mbroek@mbse.eu>
parents:
502
diff
changeset
|
370 | } |
384
442d23455ae4
The bms daemon now checks if a node went away of no data is received for 10 minutes.
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
371 | } |
442d23455ae4
The bms daemon now checks if a node went away of no data is received for 10 minutes.
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
372 | } |
442d23455ae4
The bms daemon now checks if a node went away of no data is received for 10 minutes.
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
373 | } |
442d23455ae4
The bms daemon now checks if a node went away of no data is received for 10 minutes.
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
374 | |
442d23455ae4
The bms daemon now checks if a node went away of no data is received for 10 minutes.
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
375 |