1 /** |
1 /** |
2 * @file mysql.c |
2 * @file mysql.c |
3 * @brief MySQL/MariaDB access. |
3 * @brief MySQL/MariaDB access. |
4 * @author Michiel Broek <mbroek at mbse dot eu> |
4 * @author Michiel Broek <mbroek at mbse dot eu> |
5 * |
5 * |
6 * Copyright (C) 2018-2022 |
6 * Copyright (C) 2018-2023 |
7 * |
7 * |
8 * This file is part of the bms (Brewery Management System) |
8 * This file is part of the bms (Brewery Management System) |
9 * |
9 * |
10 * This is free software; you can redistribute it and/or modify it |
10 * This is free software; you can redistribute it and/or modify it |
11 * under the terms of the GNU General Public License as published by the |
11 * under the terms of the GNU General Public License as published by the |
304 ispindel->battery = atof(row[11]); |
304 ispindel->battery = atof(row[11]); |
305 ispindel->gravity = atof(row[12]); |
305 ispindel->gravity = atof(row[12]); |
306 ispindel->interval = atoi(row[13]); |
306 ispindel->interval = atoi(row[13]); |
307 ispindel->mode = xstrcpy(row[14]); |
307 ispindel->mode = xstrcpy(row[14]); |
308 ispindel->og_gravity = atof(row[15]); |
308 ispindel->og_gravity = atof(row[15]); |
|
309 ispindel->yeast_lo = atof(row[16]); |
|
310 ispindel->yeast_hi = atof(row[17]); |
309 |
311 |
310 if (ispindels == NULL) { |
312 if (ispindels == NULL) { |
311 ispindels = ispindel; |
313 ispindels = ispindel; |
312 } else { |
314 } else { |
313 for (tmpi = ispindels; tmpi; tmpi = tmpi->next) { |
315 for (tmpi = ispindels; tmpi; tmpi = tmpi->next) { |
712 { |
714 { |
713 char *query = malloc(2560); |
715 char *query = malloc(2560); |
714 |
716 |
715 snprintf(query, 2559, |
717 snprintf(query, 2559, |
716 "INSERT INTO mon_ispindels SET uuid='%s', alias='%s', node='%s', online='%d', mode='%s', alarm='%d', " \ |
718 "INSERT INTO mon_ispindels SET uuid='%s', alias='%s', node='%s', online='%d', mode='%s', alarm='%d', " \ |
717 "angle='%.6f', temperature='%.4f', battery='%.6f', gravity='%.6f', up_interval='%d', og_gravity='0.0'", |
719 "angle='%.6f', temperature='%.4f', battery='%.6f', gravity='%.6f', up_interval='%d', og_gravity='0.0', " \ |
|
720 "yeast_lo='%.1f', yeast_hi='%.1f'", |
718 ispindel->uuid, ispindel->alias, ispindel->node, ispindel->online ? 1:0, ispindel->mode, ispindel->alarm, |
721 ispindel->uuid, ispindel->alias, ispindel->node, ispindel->online ? 1:0, ispindel->mode, ispindel->alarm, |
719 ispindel->angle, ispindel->temperature, ispindel->battery, ispindel->gravity, ispindel->interval); |
722 ispindel->angle, ispindel->temperature, ispindel->battery, ispindel->gravity, ispindel->interval, |
|
723 ispindel->yeast_lo, ispindel->yeast_hi); |
720 |
724 |
721 if (bms_mysql_query(query) == 0) { |
725 if (bms_mysql_query(query) == 0) { |
722 syslog(LOG_NOTICE, "MySQL: insert new ispindel %s", ispindel->node); |
726 syslog(LOG_NOTICE, "MySQL: insert new ispindel %s", ispindel->node); |
723 } |
727 } |
724 free(query); |
728 free(query); |
730 { |
734 { |
731 char *query = malloc(2560); |
735 char *query = malloc(2560); |
732 |
736 |
733 snprintf(query, 2559, |
737 snprintf(query, 2559, |
734 "UPDATE mon_ispindels SET online='%d', mode='%s', alias='%s', alarm='%d', " \ |
738 "UPDATE mon_ispindels SET online='%d', mode='%s', alias='%s', alarm='%d', " \ |
735 "angle='%.6f', temperature='%.4f', battery='%.6f', gravity='%.6f', up_interval='%d', og_gravity=GREATEST(og_gravity, '%.6f') WHERE uuid='%s'", |
739 "angle='%.6f', temperature='%.4f', battery='%.6f', gravity='%.6f', up_interval='%d', og_gravity=GREATEST(og_gravity, '%.6f'), " \ |
|
740 "yeast_lo='%.1f', yeast_hi='%.1f' WHERE uuid='%s'", |
736 ispindel->online ? 1:0, ispindel->mode, ispindel->alias, ispindel->alarm, |
741 ispindel->online ? 1:0, ispindel->mode, ispindel->alias, ispindel->alarm, |
737 ispindel->angle, ispindel->temperature, ispindel->battery, ispindel->gravity, ispindel->interval, ispindel->gravity, ispindel->uuid); |
742 ispindel->angle, ispindel->temperature, ispindel->battery, ispindel->gravity, ispindel->interval, ispindel->gravity, |
|
743 ispindel->yeast_lo, ispindel->yeast_hi, ispindel->uuid); |
738 bms_mysql_query(query); |
744 bms_mysql_query(query); |
739 free(query); |
745 free(query); |
740 } |
746 } |
741 |
747 |
742 |
748 |