Version 0.3.45. Removed all writing to ascii logfiles in the webserver environment, only log to MySQL.

Wed, 18 Oct 2023 10:06:11 +0200

author
Michiel Broek <mbroek@mbse.eu>
date
Wed, 18 Oct 2023 10:06:11 +0200
changeset 852
71f0fa38b634
parent 851
b15fa90a9af5
child 853
f54decd31acb

Version 0.3.45. Removed all writing to ascii logfiles in the webserver environment, only log to MySQL.

bmsd/co2meters.c file | annotate | diff | comparison | revisions
bmsd/fermenters.c file | annotate | diff | comparison | revisions
bmsd/ispindels.c file | annotate | diff | comparison | revisions
bmsd/mysql.c file | annotate | diff | comparison | revisions
config.status file | annotate | diff | comparison | revisions
configure file | annotate | diff | comparison | revisions
configure.ac file | annotate | diff | comparison | revisions
doc/bms-ch8.sgml file | annotate | diff | comparison | revisions
www/getco2pressurelog.php file | annotate | diff | comparison | revisions
--- a/bmsd/co2meters.c	Tue Oct 17 11:54:38 2023 +0200
+++ b/bmsd/co2meters.c	Wed Oct 18 10:06:11 2023 +0200
@@ -3,7 +3,7 @@
  * @brief Handle co2meters status
  * @author Michiel Broek <mbroek at mbse dot eu>
  *
- * Copyright (C) 2019-2022
+ * Copyright (C) 2019-2023
  *
  * This file is part of the bms (Brewery Management System)
  *
@@ -358,12 +358,11 @@
 
 void co2meter_log(char *topic, char *payload)
 {
-    char                *edge_node, *alias, *line, buf[128], *logfile, *query = malloc(512);
+    char                *edge_node, *alias, buf[128], *query = malloc(512);
     struct json_object  *jobj, *val, *metric;
     co2pressure_log	*log;
     struct tm		*mytime;
     time_t		timestamp;
-    FILE		*fp;
     bool		trigger = false;
 
     strtok(topic, "/"); // ignore namespace
@@ -437,7 +436,7 @@
     }
 
     /*
-     * Build the MySQL log
+     * Build the MySQL log and insert if trigger is set.
      */
     if (trigger) {
 	snprintf(query, 511, "INSERT IGNORE INTO log_co2pressure SET code='%s', datetime='%s', temperature='%.4f', " \
@@ -447,59 +446,20 @@
 	bms_mysql_query(query);
     }
 
-    /*
-     * Build csv log line
-     */
-    line = xstrcpy(log->datetime);
-    line = xstrcat(line, (char *)",");
-    snprintf(buf, 64, "%.3f", log->temperature);
-    line = xstrcat(line, buf);
-    line = xstrcat(line, (char *)",");
-    snprintf(buf, 64, "%.3f", log->pressure);
-    line = xstrcat(line, buf);
-    line = xstrcat(line, (char *)",");
-    line = xstrcat(line, log->uuid);
-
-    /*
-     * Build logfile name
-     */
-    logfile = xstrcpy(Config.web_root);
-    logfile = xstrcat(logfile, (char *)"/log/co2pressure/");
-    logfile = xstrcat(logfile, log->product_code);
-    logfile = xstrcat(logfile, (char *)" ");
-    logfile = xstrcat(logfile, log->product_name);
-    logfile = xstrcat(logfile, (char *)".log");
-
-    if (debug)
-	fprintf(stdout, "%s %s\n", logfile, line);
-
-    fp = fopen(logfile, "a");
-    if (fp) {
-	fprintf(fp, "%s\n", line);
-	fclose(fp);
-    } else {
-	syslog(LOG_NOTICE, "cannot append to `%s'", logfile);
-    }
-
-    free(logfile);
-    logfile = NULL;
-    free(line);
-    line = NULL;
-
     if (log->datetime)
-    	free(log->datetime);
+       free(log->datetime);
     if (log->product_uuid )
-	free(log->product_uuid );
+       free(log->product_uuid );
     if (log->product_code )
-	free(log->product_code );
+       free(log->product_code );
     if (log->product_name )
-	free(log->product_name );
+       free(log->product_name );
     if (log->uuid)
-	free(log->uuid);
+       free(log->uuid);
     if (log->node)
-	free(log->node);
+       free(log->node);
     if (log->alias)
-	free(log->alias);
+       free(log->alias);
     free(log);
 }
 
--- a/bmsd/fermenters.c	Tue Oct 17 11:54:38 2023 +0200
+++ b/bmsd/fermenters.c	Wed Oct 18 10:06:11 2023 +0200
@@ -3,7 +3,7 @@
  * @brief Handle fermenters status
  * @author Michiel Broek <mbroek at mbse dot eu>
  *
- * Copyright (C) 2018-2022
+ * Copyright (C) 2018-2023
  *
  * This file is part of the bms (Brewery Management System)
  *
@@ -818,13 +818,12 @@
 
 void fermenter_log(char *topic, char *payload)
 {
-    char                *edge_node, *alias, *line, buf[65], *logfile, *query = malloc(512);
+    char                *edge_node, *alias, *query = malloc(512);
     struct json_object  *jobj, *val, *metric, *metric2;
     fermentation_log	*log;
     bool		trigger = false;
     struct tm		*mytime;
     time_t		timestamp;
-    FILE		*fp;
 
     strtok(topic, "/"); // ignore namespace
     strtok(NULL, "/");	// group_id
@@ -948,77 +947,6 @@
     }
     free(query);
 
-    /*
-     * Build csv log line. Used by the web client.
-     */
-    line = xstrcpy(log->datetime);
-    line = xstrcat(line, (char *)",");
-    line = xstrcat(line, log->mode);
-    line = xstrcat(line, (char *)",");
-    line = xstrcat(line, log->stage);
-    line = xstrcat(line, (char *)",");
-    snprintf(buf, 64, "%.3f", log->temperature_air);
-    line = xstrcat(line, buf);
-    line = xstrcat(line, (char *)",");
-    snprintf(buf, 64, "%.3f", log->temperature_beer);
-    line = xstrcat(line, buf);
-    line = xstrcat(line, (char *)",");
-    snprintf(buf, 64, "%.3f", log->temperature_chiller);
-    line = xstrcat(line, buf);
-    line = xstrcat(line, (char *)",");
-    snprintf(buf, 64, "%.3f", log->temperature_room);
-    line = xstrcat(line, buf);
-    line = xstrcat(line, (char *)",");
-    snprintf(buf, 64, "%.1f", log->setpoint_low);
-    line = xstrcat(line, buf);
-    line = xstrcat(line, (char *)",");
-    snprintf(buf, 64, "%.1f", log->setpoint_high);
-    line = xstrcat(line, buf);
-    line = xstrcat(line, (char *)",");
-    snprintf(buf, 64, "%d", log->heater_power);
-    line = xstrcat(line, buf);
-    line = xstrcat(line, (char *)",");
-    snprintf(buf, 64, "%ld", log->heater_usage);
-    line = xstrcat(line, buf);
-    line = xstrcat(line, (char *)",");
-    snprintf(buf, 64, "%d", log->cooler_power);
-    line = xstrcat(line, buf);
-    line = xstrcat(line, (char *)",");
-    snprintf(buf, 64, "%ld", log->cooler_usage);
-    line = xstrcat(line, buf);
-    line = xstrcat(line, (char *)",");
-    if (log->event)
-	line = xstrcat(line, log->event);
-    line = xstrcat(line, (char *)",");
-    if (log->fermenter_uuid)
-	line = xstrcat(line, log->fermenter_uuid);
-
-    /*
-     * Build logfile name
-     */
-    logfile = xstrcpy(Config.web_root);
-    logfile = xstrcat(logfile, (char *)"/log/fermentation/");
-    logfile = xstrcat(logfile, log->product_code);
-    logfile = xstrcat(logfile, (char *)" ");
-    logfile = xstrcat(logfile, log->product_name);
-    logfile = xstrcat(logfile, (char *)".log");
-
-    if (debug)
-	fprintf(stdout, "%s %s\n", logfile, line);
-
-    fp = fopen(logfile, "a");
-    if (fp) {
-	fprintf(fp, "%s\n", line);
-	fclose(fp);
-    } else {
-	syslog(LOG_NOTICE, "cannot append to `%s'", logfile);
-    }
-
-    free(logfile);
-    logfile = NULL;
-    free(line);
-    line = NULL;
-
     if (log->datetime)
     	free(log->datetime);
     if (log->product_uuid )
--- a/bmsd/ispindels.c	Tue Oct 17 11:54:38 2023 +0200
+++ b/bmsd/ispindels.c	Wed Oct 18 10:06:11 2023 +0200
@@ -231,10 +231,9 @@
     sys_ispindel_list	*ispindel, *tmpp;
     struct json_object  *jobj, *metric, *val;
     bool		new_ispindel = true;
-    char		*datetime, buf[65], *line, *logfile, *query = malloc(512);
+    char		*datetime, *query = malloc(512);
     struct tm           *mytime;
     time_t              timestamp;
-    FILE		*fp;
 
     //syslog(LOG_NOTICE, "ispindel_set: %s %s", node, payload);
 
@@ -341,58 +340,14 @@
     	snprintf(datetime, 72, "%04d-%02d-%02d %02d:%02d:%02d",
         	mytime->tm_year + 1900, mytime->tm_mon + 1, mytime->tm_mday, mytime->tm_hour, mytime->tm_min, mytime->tm_sec);
 
-	line = xstrcpy(datetime);
-    	line = xstrcat(line, (char *)",");
-	snprintf(buf, 64, "%.4f", ispindel->temperature);
-        line = xstrcat(line, buf);
-        line = xstrcat(line, (char *)",");
-	snprintf(buf, 64, "%.5f", ispindel->gravity);
-        line = xstrcat(line, buf);
-        line = xstrcat(line, (char *)",");
-	snprintf(buf, 64, "%.5f", plato_to_sg(ispindel->gravity));
-	line = xstrcat(line, buf);
-        line = xstrcat(line, (char *)",");
-        snprintf(buf, 64, "%.6f", ispindel->battery);
-        line = xstrcat(line, buf);
-        line = xstrcat(line, (char *)",");
-        snprintf(buf, 64, "%.5f", ispindel->angle);
-        line = xstrcat(line, buf);
-        line = xstrcat(line, (char *)",");
-	snprintf(buf, 64, "%d", ispindel->interval);
-        line = xstrcat(line, buf);
-        line = xstrcat(line, (char *)",");
-	line = xstrcat(line, ispindel->uuid);
-
 	snprintf(query, 511, "INSERT IGNORE INTO log_ispindel SET code='%s', datetime='%s', " \
 			"temperature='%.4f', plato='%.5f', sg='%.5f', battery='%.6f', " \
 			"angle='%.5f', refresh='%d', uuid='%s'",
 			ispindel->beercode, datetime, ispindel->temperature, ispindel->gravity, plato_to_sg(ispindel->gravity),
 			ispindel->battery, ispindel->angle, ispindel->interval, ispindel->uuid);
-	//syslog(LOG_NOTICE, "%s", query);
+	syslog(LOG_NOTICE, "%s", query);
 	bms_mysql_query(query);
 
-	/*
-	 * Build logfile name
-	 */
-	logfile = xstrcpy(Config.web_root);
-	logfile = xstrcat(logfile, (char *)"/log/ispindel/");
-	logfile = xstrcat(logfile, ispindel->beercode);
-	logfile = xstrcat(logfile, (char *)" ");
-	logfile = xstrcat(logfile, ispindel->beername);
-	logfile = xstrcat(logfile, (char *)".log");
-
-	fp = fopen(logfile, "a");
-	if (fp) {
-	    fprintf(fp, "%s\n", line);
-	    fclose(fp);
-	} else {
-	    syslog(LOG_NOTICE, "cannot append to `%s'", logfile);
-	}
-
-	free(logfile);
-	logfile = NULL;
-	free(line);
-	line = NULL;
 	free(datetime);
 	datetime = NULL;
     }
--- a/bmsd/mysql.c	Tue Oct 17 11:54:38 2023 +0200
+++ b/bmsd/mysql.c	Wed Oct 18 10:06:11 2023 +0200
@@ -74,13 +74,13 @@
 	return 1;
     }
 
-    mysql_options(con, MYSQL_OPT_RECONNECT, &reconnect);
-
     if (mysql_real_connect(con, 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(con));
 	return 2;
     }
 
+    mysql_optionsv(con, MYSQL_OPT_RECONNECT, (void *)&reconnect);
+
     syslog(LOG_NOTICE, "MySQL: connected to %s:%d database %s", Config.mysql_host, Config.mysql_port, Config.mysql_database);
     syslog(LOG_NOTICE, "MySQL: %s server info: %s", mysql_get_host_info(con), mysql_get_server_info(con));
     if (debug)
--- a/config.status	Tue Oct 17 11:54:38 2023 +0200
+++ b/config.status	Wed Oct 18 10:06:11 2023 +0200
@@ -621,7 +621,7 @@
 S["CC"]="gcc"
 S["CYEARS"]="2016-2023"
 S["COPYRIGHT"]="Copyright (C) 2016-2023 Michiel Broek, All Rights Reserved"
-S["VERSION"]="0.3.44"
+S["VERSION"]="0.3.45"
 S["PACKAGE"]="bms"
 S["SUBDIRS"]="bmsd doc script tools www"
 S["target_alias"]=""
@@ -709,7 +709,7 @@
 D["PACKAGE_STRING"]=" \"\""
 D["PACKAGE_BUGREPORT"]=" \"\""
 D["PACKAGE_URL"]=" \"\""
-D["VERSION"]=" \"0.3.44\""
+D["VERSION"]=" \"0.3.45\""
 D["COPYRIGHT"]=" \"Copyright (C) 2016-2023 Michiel Broek, All Rights Reserved\""
 D["STDC_HEADERS"]=" 1"
 D["HAVE_SYS_TYPES_H"]=" 1"
--- a/configure	Tue Oct 17 11:54:38 2023 +0200
+++ b/configure	Wed Oct 18 10:06:11 2023 +0200
@@ -2031,7 +2031,7 @@
 
 
 PACKAGE="bms"
-VERSION="0.3.44"
+VERSION="0.3.45"
 COPYRIGHT="Copyright (C) 2016-2023 Michiel Broek, All Rights Reserved"
 CYEARS="2016-2023"
 
--- a/configure.ac	Tue Oct 17 11:54:38 2023 +0200
+++ b/configure.ac	Wed Oct 18 10:06:11 2023 +0200
@@ -8,7 +8,7 @@
 dnl General settings
 dnl After changeing the version number, run autoconf!
 PACKAGE="bms"
-VERSION="0.3.44"
+VERSION="0.3.45"
 COPYRIGHT="Copyright (C) 2016-2023 Michiel Broek, All Rights Reserved"
 CYEARS="2016-2023"
 AC_SUBST(PACKAGE)
--- a/doc/bms-ch8.sgml	Tue Oct 17 11:54:38 2023 +0200
+++ b/doc/bms-ch8.sgml	Wed Oct 18 10:06:11 2023 +0200
@@ -509,9 +509,10 @@
 </programlisting>
 
 <para>
-De densiteit wordt door de iSpindel in graden Plato gegeven en zo worden
-de gegevens ook verwerkt. 
-Zorg er dus voor dat de iSpindel gecalibreerd wordt in Plato.
+De densiteit wordt door de iSpindel in graden Plato gegeven maar wordt sinds server versie 0.3.44 niet
+meer gebruikt. De server heeft nu zelf per iSpindel een calibratie tabel en gebruikt die om graden Plato
+te berekenen. Hiervoor wordt alleen de 'angle' gebruikt om de gravity in Plato te berekenen.
+Hierdoor is het dus zelfs mogelijk online de calibratie aan te passen.
 Het script <code>/ispindel/index.php</code> verzorgd de omzetting van de iSpindel POST data naar MQTT
 data.
 Eerst wordt het node bericht gemaakt:</para>
@@ -556,7 +557,7 @@
 <para>
 De iSpindel stuurt geen aparte log informatie, alle informatie voor de logfile
 wordt uit het standaard unit data bericht gehaald.
-Ook wordt het SG door <code>bmsd</code> berekend uit de ontvangen Plato waarde.
+Ook wordt het Plato en SG door <code>bmsd</code> berekend uit de ontvangen <code>angle</code> waarde.
 De log gegevens worden niet opgeslagen in de SQL database
 maar weggeschreven in platte tekst bestanden. Hierdoor is de gelogde informatie sneller toegankelijk.
 Ieder brouw product heeft zijn eigen bestand.
@@ -575,6 +576,10 @@
  6 update interval ----------------------------------------------+                 |
  7 ispindel uuid ------------------------------------------------------------------+
 </programlisting>
+<para>
+De data staat tegenwoordig ook in de database in de tabel <code>log_ispindel</code>. Door
+verbeteringen in de MySQL database is dit nu voldoende snel.
+</para>
 </sect1>
 
 
--- a/www/getco2pressurelog.php	Tue Oct 17 11:54:38 2023 +0200
+++ b/www/getco2pressurelog.php	Wed Oct 18 10:06:11 2023 +0200
@@ -8,15 +8,6 @@
 	$code = "CB0080";
 
 
-/*
- * 2014-11-15 18:39:12,TEMPERATURE,PRESSURE,UUID
- *          |              |          |      |
- * datetime +              |          |      |
- * temperature ------------+          |      |
- * pressure --------------------------+      |
- * unit uuid --------------------------------+
- */
-
 $connect = mysqli_connect(DBASE_HOST, DBASE_USER, DBASE_PASS, DBASE_NAME);
 if (! $connect) {
         die('Connect Error (' . mysqli_connect_errno() . ') ' . mysqli_connect_error());

mercurial