bmsd/mysql.c

changeset 578
e75ce5bbda73
parent 572
7a03181d29a3
child 579
1253a237b620
--- a/bmsd/mysql.c	Fri Jan 03 15:21:22 2020 +0100
+++ b/bmsd/mysql.c	Sun Jan 05 11:42:02 2020 +0100
@@ -3,7 +3,7 @@
  * @brief MySQL/MariaDB access.
  * @author Michiel Broek <mbroek at mbse dot eu>
  *
- * Copyright (C) 2018-2019
+ * Copyright (C) 2018-2020
  *
  * This file is part of the bms (Brewery Management System)
  *
@@ -286,18 +286,20 @@
                 ispindel = (sys_ispindel_list *)malloc(sizeof(sys_ispindel_list));
                 memset(ispindel, 0, sizeof(sys_ispindel_list));
                 ispindel->next                = NULL;
-		ispindel->node                = xstrcpy(row[1]);
-		ispindel->online              = atoi(row[2]);
-		ispindel->alarm               = atoi(row[3]);
-		ispindel->beercode            = xstrcpy(row[4]);
-                ispindel->beername            = xstrcpy(row[5]);
-                ispindel->beeruuid            = xstrcpy(row[6]);
-		ispindel->tilt                = atof(row[7]);
-		ispindel->temperature         = atof(row[8]);
-                ispindel->battery             = atof(row[9]);
-		ispindel->gravity             = atof(row[10]);
-		ispindel->interval            = atoi(row[11]);
-		ispindel->rssi                = atoi(row[12]);
+		ispindel->uuid		      = xstrcpy(row[1]);
+		ispindel->alias		      = xstrcpy(row[2]);
+		ispindel->node                = xstrcpy(row[3]);
+		ispindel->online              = atoi(row[4]);
+		ispindel->alarm               = atoi(row[5]);
+		ispindel->beercode            = xstrcpy(row[6]);
+                ispindel->beername            = xstrcpy(row[7]);
+                ispindel->beeruuid            = xstrcpy(row[8]);
+		ispindel->angle               = atof(row[9]);
+		ispindel->temperature         = atof(row[10]);
+                ispindel->battery             = atof(row[11]);
+		ispindel->gravity             = atof(row[12]);
+		ispindel->interval            = atoi(row[13]);
+		ispindel->mode		      = xstrcpy(row[14]);
 
                 if (ispindels == NULL) {
                     ispindels = ispindel;
@@ -507,11 +509,11 @@
 	"INSERT INTO  mon_nodes SET uuid='%s', node='%s', online='%d', group_id='%s', " \
         "hardwaremake='%s', hardwaremodel='%s', os='%s', os_version='%s', firmware='%s', firstseen='%s', lastseen='%s', " \
 	"temperature='%.3f', humidity='%.3f', barometer='%.3f', gps_latitude='%.8f', gps_longitude='%.8f', gps_altitude='%.8f', " \
-	"net_address='%s', net_ifname='%s', net_rssi='%d'",
+	"net_address='%s', net_ifname='%s', net_rssi='%d', up_interval='%d'",
 	node->uuid, node->node, node->online ?1:0, node->group_id, 
 	node->hardwaremake, node->hardwaremodel, node->os, node->os_version, node->firmware, first, last,
 	node->temperature, node->humidity, node->barometer, node->gps_latitude, node->gps_longitude, node->gps_altitude,
-	node->net_address, node->net_ifname, node->net_rssi);
+	node->net_address, node->net_ifname, node->net_rssi, node->interval);
 
     if (bms_mysql_query(query) == 0) {
 	syslog(LOG_NOTICE,  "MySQL: insert new node %s", node->node);
@@ -534,10 +536,10 @@
     snprintf(query, 1023,
 	"UPDATE mon_nodes SET online='%d', hardwaremake='%s', hardwaremodel='%s', os='%s', os_version='%s', firmware='%s', lastseen='%s', " \
 	"temperature='%.3f', humidity='%.3f', barometer='%.3f', gps_latitude='%.8f', gps_longitude='%.8f', gps_altitude='%.8f', " \
-	"net_address='%s', net_ifname='%s', net_rssi='%d' WHERE uuid='%s'",
+	"net_address='%s', net_ifname='%s', net_rssi='%d', up_interval='%d' WHERE uuid='%s'",
 	node->online ? 1:0, node->hardwaremake, node->hardwaremodel, node->os, node->os_version, node->firmware, last,
 	node->temperature, node->humidity, node->barometer, node->gps_latitude, node->gps_longitude, node->gps_altitude, 
-	node->net_address, node->net_ifname, node->net_rssi, node->uuid);
+	node->net_address, node->net_ifname, node->net_rssi, node->interval, node->uuid);
 
     bms_mysql_query(query);
     free(query);
@@ -720,10 +722,10 @@
     char        *query = malloc(2560);
 
     snprintf(query, 2559,
-        "INSERT INTO mon_ispindels SET node='%s', online='%d', alarm='%d', " \
-        "tilt='%.6f', temperature='%.4f', battery='%.4f', gravity='%.6f', interval='%d', rssi='%d'",
-        ispindel->node, ispindel->online ? 1:0, ispindel->alarm,
-        ispindel->tilt, ispindel->temperature, ispindel->battery, ispindel->gravity, ispindel->interval, ispindel->rssi);
+        "INSERT INTO mon_ispindels SET uuid='%s', alias='%s', node='%s', online='%d', mode='%s', alarm='%d', " \
+        "angle='%.6f', temperature='%.4f', battery='%.4f', gravity='%.6f', up_interval='%d'",
+        ispindel->uuid, ispindel->alias, ispindel->node, ispindel->online ? 1:0, ispindel->mode, ispindel->alarm,
+        ispindel->angle, ispindel->temperature, ispindel->battery, ispindel->gravity, ispindel->interval);
 
     if (bms_mysql_query(query) == 0) {
         syslog(LOG_NOTICE,  "MySQL: insert new ispindel %s", ispindel->node);
@@ -738,10 +740,10 @@
     char        *query = malloc(2560);
 
     snprintf(query, 2559,
-        "UPDATE mon_ispindels SET online='%d', alarm='%d', " \
-	"tilt='%.3f', temperature='%.3f', battery='%.3f', gravity='%.3f', interval='%d', rssi='%d' WHERE node='%s'",
-        ispindel->online ? 1:0, ispindel->alarm,
-	ispindel->tilt, ispindel->temperature, ispindel->battery, ispindel->gravity, ispindel->interval, ispindel->rssi, ispindel->node);
+        "UPDATE mon_ispindels SET online='%d', mode='%s', alarm='%d', " \
+	"angle='%.3f', temperature='%.3f', battery='%.3f', gravity='%.3f', up_interval='%d' WHERE uuid='%s'",
+        ispindel->online ? 1:0, ispindel->mode, ispindel->alarm,
+	ispindel->angle, ispindel->temperature, ispindel->battery, ispindel->gravity, ispindel->interval, ispindel->uuid);
 
     bms_mysql_query(query);
     free(query);
@@ -749,11 +751,11 @@
 
 
 
-void ispindel_mysql_death(char *node)
+void ispindel_mysql_death(char *uuid)
 {
     char        *query = malloc(512);
 
-    snprintf(query, 511, "UPDATE mon_ispindels SET online='0' WHERE node='%s'", node);
+    snprintf(query, 511, "UPDATE mon_ispindels SET online='0' WHERE uuid='%s'", uuid);
     bms_mysql_query(query);
     free(query);
 }

mercurial