bmsd/co2meters.c

changeset 852
71f0fa38b634
parent 799
cf145b35d65f
--- 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);
 }
 

mercurial