Fri, 22 Jul 2022 12:15:05 +0200
Version 0.3.41. Use INSERT IGNORE .. for insert log messages from fermenters, co2meters and ispindels. Connect to MySQL servers with MYSQL_OPT_RECONNECT instead of manual working around the connection lost problem if a mysql server is restarted. Removed unused bms_mysql_ping function.
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 | |
bmsd/mysql.h | file | annotate | diff | comparison | revisions | |
configure | file | annotate | diff | comparison | revisions | |
configure.ac | file | annotate | diff | comparison | revisions |
--- a/bmsd/co2meters.c Tue Jul 19 13:55:53 2022 +0200 +++ b/bmsd/co2meters.c Fri Jul 22 12:15:05 2022 +0200 @@ -440,7 +440,7 @@ * Build the MySQL log */ if (trigger) { - snprintf(query, 511, "INSERT INTO log_co2pressure SET code='%s', datetime='%s', temperature='%.4f', " \ + snprintf(query, 511, "INSERT IGNORE 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);
--- a/bmsd/fermenters.c Tue Jul 19 13:55:53 2022 +0200 +++ b/bmsd/fermenters.c Fri Jul 22 12:15:05 2022 +0200 @@ -936,7 +936,7 @@ trigger = true; if (trigger) { snprintf(query, 511, - "INSERT INTO log_fermenter SET code='%s', datetime='%s', mode='%s', stage='%s', " \ + "INSERT IGNORE INTO log_fermenter SET code='%s', datetime='%s', mode='%s', stage='%s', " \ "temp_air='%.4f', temp_beer='%.4f', temp_chiller='%.4f', temp_room='%.3f', " \ "sp_low='%.3f', sp_high='%.3f', heater_power='%d', cooler_power='%d', " \ "event='%s', fermenter_uuid='%s'",
--- a/bmsd/ispindels.c Tue Jul 19 13:55:53 2022 +0200 +++ b/bmsd/ispindels.c Fri Jul 22 12:15:05 2022 +0200 @@ -327,7 +327,7 @@ line = xstrcat(line, (char *)","); line = xstrcat(line, ispindel->uuid); - snprintf(query, 511, "INSERT INTO log_ispindel SET code='%s', datetime='%s', " \ + 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,
--- a/bmsd/mysql.c Tue Jul 19 13:55:53 2022 +0200 +++ b/bmsd/mysql.c Fri Jul 22 12:15:05 2022 +0200 @@ -3,7 +3,7 @@ * @brief MySQL/MariaDB access. * @author Michiel Broek <mbroek at mbse dot eu> * - * Copyright (C) 2018-2021 + * Copyright (C) 2018-2022 * * This file is part of the bms (Brewery Management System) * @@ -32,6 +32,8 @@ MYSQL_RES *res_set; MYSQL_ROW row; +my_bool reconnect = 1; + extern sys_config Config; extern sys_node_list *nodes; extern sys_fermenter_list *fermenters; @@ -72,6 +74,8 @@ 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; @@ -475,34 +479,11 @@ return 0; } - /* Any error execpt server gone away */ - if (err != 2006) - return rc; - - syslog(LOG_NOTICE, "Trying to reconnect"); - /* Try to reconnect and do the query again */ - mysql_close(con); - 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; - } - syslog(LOG_NOTICE, "MySQL: reconnected."); - rc = mysql_query(con, query); - if (rc) { - syslog(LOG_NOTICE, "MySQL: error %u (%s)", mysql_errno(con), mysql_error(con)); - syslog(LOG_NOTICE, query); - } return rc; } -void bms_mysql_ping(void) -{ -} - - - void node_mysql_insert(sys_node_list *node) { char *query = malloc(1024), first[73], last[73];
--- a/bmsd/mysql.h Tue Jul 19 13:55:53 2022 +0200 +++ b/bmsd/mysql.h Fri Jul 22 12:15:05 2022 +0200 @@ -24,11 +24,6 @@ */ int bms_mysql_query(const char *query); -/** - * @brief Ping MySQL connection and try to reconnect if the connection is broken. - */ -void bms_mysql_ping(void); - void node_mysql_insert(sys_node_list *node); void node_mysql_update(sys_node_list *node); void node_mysql_death(char *node);
--- a/configure Tue Jul 19 13:55:53 2022 +0200 +++ b/configure Fri Jul 22 12:15:05 2022 +0200 @@ -2031,7 +2031,7 @@ PACKAGE="bms" -VERSION="0.3.40" +VERSION="0.3.41" COPYRIGHT="Copyright (C) 2016-2022 Michiel Broek, All Rights Reserved" CYEARS="2016-2022"
--- a/configure.ac Tue Jul 19 13:55:53 2022 +0200 +++ b/configure.ac Fri Jul 22 12:15:05 2022 +0200 @@ -8,7 +8,7 @@ dnl General settings dnl After changeing the version number, run autoconf! PACKAGE="bms" -VERSION="0.3.40" +VERSION="0.3.41" COPYRIGHT="Copyright (C) 2016-2022 Michiel Broek, All Rights Reserved" CYEARS="2016-2022" AC_SUBST(PACKAGE)