diff -r e6e696add0b3 -r 98bd22f6629b bmsd/co2meters.c --- a/bmsd/co2meters.c Thu Mar 24 15:46:36 2022 +0100 +++ b/bmsd/co2meters.c Fri Jun 17 16:18:04 2022 +0200 @@ -3,7 +3,7 @@ * @brief Handle co2meters status * @author Michiel Broek * - * Copyright (C) 2019-2020 + * Copyright (C) 2019-2022 * * This file is part of the bms (Brewery Management System) * @@ -358,12 +358,13 @@ void co2meter_log(char *topic, char *payload) { - char *edge_node, *alias, *line, buf[128], *logfile; + char *edge_node, *alias, *line, buf[128], *logfile, *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 strtok(NULL, "/"); // group_id @@ -383,6 +384,8 @@ mytime = localtime(×tamp); snprintf(log->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); + if ((mytime->tm_min % 10) == 0) + trigger = true; if (json_object_object_get_ex(jobj, "metric", &metric)) { if (json_object_object_get_ex(metric, "uuid", &val)) { @@ -434,6 +437,17 @@ } /* + * Build the MySQL log + */ + if (trigger) { + snprintf(query, 511, "INSERT INTO log_co2pressure SET code='%s', datetime='%s', temperature='%.4f', " \ + "pressure='%.4f', uuid='%s'", + log->product_code, log->datetime, log->temperature, log->pressure, log->uuid); + //syslog(LOG_NOTICE, "%s", query); + bms_mysql_query(query); + } + + /* * Build csv log line */ line = xstrcpy(log->datetime);