1 /** |
1 /** |
2 * @file nodes.c |
2 * @file nodes.c |
3 * @brief Handle nodes status |
3 * @brief Handle nodes status |
4 * @author Michiel Broek <mbroek at mbse dot eu> |
4 * @author Michiel Broek <mbroek at mbse dot eu> |
5 * |
5 * |
6 * Copyright (C) 2018 |
6 * Copyright (C) 2018-2019 |
7 * |
7 * |
8 * This file is part of the bms (Brewery Management System) |
8 * This file is part of the bms (Brewery Management System) |
9 * |
9 * |
10 * This is free software; you can redistribute it and/or modify it |
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 |
11 * under the terms of the GNU General Public License as published by the |
31 |
31 |
32 sys_node_list *nodes = NULL; |
32 sys_node_list *nodes = NULL; |
33 |
33 |
34 extern int debug; |
34 extern int debug; |
35 extern sys_fermenter_list *fermenters; |
35 extern sys_fermenter_list *fermenters; |
|
36 extern sys_co2meter_list *co2meters; |
|
37 |
36 |
38 |
37 |
39 |
38 void node_birth_data(char *topic, char *payload) |
40 void node_birth_data(char *topic, char *payload) |
39 { |
41 { |
40 struct json_object *jobj, *val, *metric, *metric2; |
42 struct json_object *jobj, *val, *metric, *metric2; |
242 |
244 |
243 void nodes_check_online() |
245 void nodes_check_online() |
244 { |
246 { |
245 sys_node_list *tmpn; |
247 sys_node_list *tmpn; |
246 sys_fermenter_list *tmpf; |
248 sys_fermenter_list *tmpf; |
|
249 sys_co2meter_list *tmpc; |
247 time_t now = time(NULL); |
250 time_t now = time(NULL); |
248 |
251 |
249 for (tmpn = nodes; tmpn; tmpn = tmpn->next) { |
252 for (tmpn = nodes; tmpn; tmpn = tmpn->next) { |
250 if (tmpn->online && ((now - tmpn->lastseen) > 600)) { |
253 if (tmpn->online && ((now - tmpn->lastseen) > 600)) { |
251 syslog(LOG_NOTICE, "Timeout node `%s/%s'", tmpn->group_id, tmpn->node); |
254 syslog(LOG_NOTICE, "Timeout node `%s/%s'", tmpn->group_id, tmpn->node); |
259 tmpf->online = false; |
262 tmpf->online = false; |
260 fermenter_mysql_death(tmpf->node, tmpf->alias); |
263 fermenter_mysql_death(tmpf->node, tmpf->alias); |
261 } |
264 } |
262 } |
265 } |
263 } |
266 } |
264 } |
267 |
265 } |
268 for (tmpc = co2meters; tmpc; tmpc = tmpc->next) { |
266 } |
269 if (strcmp(tmpc->node, tmpn->node) == 0) { |
267 |
270 if (tmpc->online) { |
268 |
271 syslog(LOG_NOTICE, "Timeout co2meter %s/%s", tmpc->node, tmpc->alias); |
|
272 tmpc->online = false; |
|
273 co2meter_mysql_death(tmpc->node, tmpc->alias); |
|
274 } |
|
275 } |
|
276 } |
|
277 } |
|
278 } |
|
279 } |
|
280 |
|
281 |