The bms daemon now checks if a node went away of no data is received for 10 minutes.

Thu, 30 May 2019 23:00:20 +0200

author
Michiel Broek <mbroek@mbse.eu>
date
Thu, 30 May 2019 23:00:20 +0200
changeset 384
442d23455ae4
parent 383
2395bdfac387
child 385
95276520a11c

The bms daemon now checks if a node went away of no data is received for 10 minutes.

bmsd/Makefile file | annotate | diff | comparison | revisions
bmsd/bms.c file | annotate | diff | comparison | revisions
bmsd/nodes.c file | annotate | diff | comparison | revisions
bmsd/nodes.h file | annotate | diff | comparison | revisions
--- 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
--- 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");
--- 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);
+		    }
+            	}
+            }
+	}
+    }
+}
+
+
--- 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

mercurial