# HG changeset patch # User Michiel Broek # Date 1559250020 -7200 # Node ID 442d23455ae4840a2c396d1e4dfbb7ac5d5306b5 # Parent 2395bdfac38774ee376f42ae290ed10cf9cc0002 The bms daemon now checks if a node went away of no data is received for 10 minutes. diff -r 2395bdfac387 -r 442d23455ae4 bmsd/Makefile --- a/bmsd/Makefile Thu May 30 21:19:43 2019 +0200 +++ b/bmsd/Makefile Thu May 30 23:00:20 2019 +0200 @@ -60,7 +60,7 @@ nodes.o: bms.h xutil.h nodes.h mysql.h futil.o: bms.h futil.h fermenters.o: bms.h xutil.h fermenters.h mysql.h -bms.o: bms.h xutil.h futil.h rdconfig.h lock.h mqtt.h mysql.h +bms.o: bms.h xutil.h futil.h rdconfig.h lock.h mqtt.h mysql.h nodes.h xutil.o: bms.h xutil.h rdconfig.o: bms.h xutil.h futil.h rdconfig.h mysql.o: bms.h xutil.h mysql.h nodes.h diff -r 2395bdfac387 -r 442d23455ae4 bmsd/bms.c --- a/bmsd/bms.c Thu May 30 21:19:43 2019 +0200 +++ b/bmsd/bms.c Thu May 30 23:00:20 2019 +0200 @@ -27,6 +27,7 @@ #include "lock.h" #include "mqtt.h" #include "mysql.h" +#include "nodes.h" int my_shutdown = FALSE; @@ -133,6 +134,7 @@ while (my_shutdown == FALSE) { usleep(100000); + nodes_check_online(); } if (debug) fprintf(stdout, "[main] Exit from main loop\n"); diff -r 2395bdfac387 -r 442d23455ae4 bmsd/nodes.c --- a/bmsd/nodes.c Thu May 30 21:19:43 2019 +0200 +++ b/bmsd/nodes.c Thu May 30 23:00:20 2019 +0200 @@ -29,10 +29,10 @@ #include "mysql.h" -sys_node_list *nodes = NULL; +sys_node_list *nodes = NULL; -extern int debug; - +extern int debug; +extern sys_fermenter_list *fermenters; void node_birth_data(char *topic, char *payload) @@ -239,3 +239,30 @@ } + +void nodes_check_online() +{ + sys_node_list *tmpn; + sys_fermenter_list *tmpf; + time_t now = time(NULL); + + for (tmpn = nodes; tmpn; tmpn = tmpn->next) { + if (tmpn->online && ((now - tmpn->lastseen) > 600)) { + syslog(LOG_NOTICE, "Timeout node `%s/%s'", tmpn->group_id, tmpn->node); + tmpn->online = false; + node_mysql_death(tmpn->node); + + for (tmpf = fermenters; tmpf; tmpf = tmpf->next) { + if (strcmp(tmpf->node, tmpn->node) == 0) { + if (tmpf->online) { + syslog(LOG_NOTICE, "Timeout fermenter %s/%s", tmpf->node, tmpf->alias); + tmpf->online = false; + fermenter_mysql_death(tmpf->node, tmpf->alias); + } + } + } + } + } +} + + diff -r 2395bdfac387 -r 442d23455ae4 bmsd/nodes.h --- a/bmsd/nodes.h Thu May 30 21:19:43 2019 +0200 +++ b/bmsd/nodes.h Thu May 30 23:00:20 2019 +0200 @@ -21,4 +21,10 @@ */ void node_death(char *topic); +/** + * @brief Check if nodes are still online and mark them offline if not + * been seen for 10 minutes. + */ +void nodes_check_online(void); + #endif