bmsd/mysql.c

changeset 680
0bb48333d133
parent 628
a42166cbb19a
child 684
ccb9f24d0fe9
--- a/bmsd/mysql.c	Mon May 18 11:00:59 2020 +0200
+++ b/bmsd/mysql.c	Tue May 19 13:50:14 2020 +0200
@@ -300,6 +300,7 @@
 		ispindel->gravity             = atof(row[12]);
 		ispindel->interval            = atoi(row[13]);
 		ispindel->mode		      = xstrcpy(row[14]);
+		ispindel->og_gravity	      = atof(row[15]);
 
                 if (ispindels == NULL) {
                     ispindels = ispindel;
@@ -317,7 +318,7 @@
         }
     }
 
-    syslog(LOG_NOTICE, "MySQL: loaded %d nodes, %d fermenters, %d co2meters %d ispindels", ncnt, fcnt, ccnt, icnt);
+    syslog(LOG_NOTICE, "MySQL: loaded %d nodes, %d fermenters, %d co2meters, %d ispindels", ncnt, fcnt, ccnt, icnt);
     return 0;
 }
 
@@ -729,7 +730,7 @@
 
     snprintf(query, 2559,
         "INSERT INTO mon_ispindels SET uuid='%s', alias='%s', node='%s', online='%d', mode='%s', alarm='%d', " \
-        "angle='%.5f', temperature='%.4f', battery='%.6f', gravity='%.5f', up_interval='%d', og_gravity='0.0'",
+        "angle='%.6f', temperature='%.4f', battery='%.6f', gravity='%.6f', up_interval='%d', og_gravity='0.0'",
         ispindel->uuid, ispindel->alias, ispindel->node, ispindel->online ? 1:0, ispindel->mode, ispindel->alarm,
         ispindel->angle, ispindel->temperature, ispindel->battery, ispindel->gravity, ispindel->interval);
 
@@ -746,11 +747,10 @@
     char        *query = malloc(2560);
 
     snprintf(query, 2559,
-        "UPDATE mon_ispindels SET online='%d', mode='%s', alarm='%d', " \
-	"angle='%.5f', temperature='%.4f', battery='%.6f', gravity='%.5f', up_interval='%d', og_gravity=GREATEST(og_gravity, '%.5f') WHERE uuid='%s'",
-        ispindel->online ? 1:0, ispindel->mode, ispindel->alarm,
+        "UPDATE mon_ispindels SET online='%d', mode='%s', alias='%s', alarm='%d', " \
+	"angle='%.6f', temperature='%.4f', battery='%.6f', gravity='%.6f', up_interval='%d', og_gravity=GREATEST(og_gravity, '%.6f') WHERE uuid='%s'",
+        ispindel->online ? 1:0, ispindel->mode, ispindel->alias, ispindel->alarm,
 	ispindel->angle, ispindel->temperature, ispindel->battery, ispindel->gravity, ispindel->interval, ispindel->gravity, ispindel->uuid);
-
     bms_mysql_query(query);
     free(query);
 }
@@ -766,67 +766,3 @@
     free(query);
 }
 
-
-
-/*
- * Check using a new MySQL connection because we are running from another thread.
- */
-void ispindel_mysql_check(void)
-{
-    sys_ispindel_list	*tmpp;
-    MYSQL		*con2 = NULL;
-    MYSQL_RES		*res_set2;
-    MYSQL_ROW		row2;
-
-    if (ispindels == NULL)
-	return;
-
-    con2 = mysql_init(NULL);
-    if (con2 == NULL) {
-        syslog(LOG_NOTICE, "MySQL: mysql_init() failed");
-        return;
-    }
-
-    if (mysql_real_connect(con2, Config.mysql_host, Config.mysql_user, Config.mysql_pass, Config.mysql_database, Config.mysql_port, NULL, 0) == NULL) {
-        syslog(LOG_NOTICE, "MySQL: mysql_real_connect() %s", mysql_error(con2));
-        return;
-    }
-
-    if (mysql_query(con2, "SELECT uuid,alias,beercode,beername,beeruuid,mode FROM mon_ispindels;")) {
-        syslog(LOG_NOTICE, "MySQL: SELECT uuid,alias,beercode,beername,beeruuid,mode FROM mon_ispindels error %u (%s))", mysql_errno(con2), mysql_error(con2));
-    } else {
-        res_set2 = mysql_store_result(con2);
-        if (res_set2 == NULL) {
-            syslog(LOG_NOTICE, "MySQL: mysq_store_result error %u (%s))", mysql_errno(con2), mysql_error(con2));
-        } else {
-            while ((row2 = mysql_fetch_row(res_set2)) != NULL) {
-		for (tmpp = ispindels; tmpp; tmpp = tmpp->next) {
-		    if (strcmp(tmpp->uuid, row2[0]) == 0) {
-			if (strcmp(tmpp->beercode, row2[2]) || strcmp(tmpp->beername, row2[3]) || strcmp(tmpp->beeruuid, row2[4])) {
-			    syslog(LOG_NOTICE, "ispindel `%s` change beer to `%s %s`", row2[1], row2[2], row2[3]);
-			    if (tmpp->beercode)
-				free(tmpp->beercode);
-			    tmpp->beercode = xstrcpy(row2[2]);
-			    if (tmpp->beername)
-				free(tmpp->beername);
-			    tmpp->beername = xstrcpy(row2[3]);
-			    if (tmpp->beeruuid)
-				free(tmpp->beeruuid);
-			    tmpp->beeruuid = xstrcpy(row2[4]);
-			}
-			if (strcmp(tmpp->mode, row2[5])) {
-			    syslog(LOG_NOTICE, "ispindel `%s` change mode `%s`", row2[1], row2[5]);
-			    if (tmpp->mode)
-				free(tmpp->mode);
-			    tmpp->mode = xstrcpy(row2[5]);
-			}
-		    }
-		}
-	    }
-	    mysql_free_result(res_set2);
-	}
-    }
-
-    mysql_close(con2);
-}
-

mercurial