bmsd/mysql.c

Wed, 06 Dec 2023 20:26:00 +0100

author
Michiel Broek <mbroek@mbse.eu>
date
Wed, 06 Dec 2023 20:26:00 +0100
changeset 855
2d328a2a4025
parent 852
71f0fa38b634
permissions
-rw-r--r--

Fixed init scripts names in Makefile. Update crontasks to use the database to check the log entries for products.

0
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1 /**
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
2 * @file mysql.c
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
3 * @brief MySQL/MariaDB access.
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
4 * @author Michiel Broek <mbroek at mbse dot eu>
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
5 *
843
29e7223e37ae Version 0.3.42 added yeast_lo and yeast_hi fields to the iSpindel records and structures.
Michiel Broek <mbroek@mbse.eu>
parents: 799
diff changeset
6 * Copyright (C) 2018-2023
0
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
7 *
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
8 * This file is part of the bms (Brewery Management System)
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
9 *
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
10 * This is free software; you can redistribute it and/or modify it
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
11 * under the terms of the GNU General Public License as published by the
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
12 * Free Software Foundation; either version 2, or (at your option) any
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
13 * later version.
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
14 *
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
15 * bms is distributed in the hope that it will be useful, but
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
16 * WITHOUT ANY WARRANTY; without even the implied warranty of
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
18 * General Public License for more details.
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
19 *
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
20 * You should have received a copy of the GNU General Public License
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
21 * along with ThermFerm; see the file COPYING. If not, write to the Free
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
22 * Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
23 */
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
24
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
25 #include "bms.h"
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
26 #include "xutil.h"
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
27 #include "mysql.h"
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
28 #include "nodes.h"
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
29
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
30
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
31 MYSQL *con = NULL;
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
32 MYSQL_RES *res_set;
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
33 MYSQL_ROW row;
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
34
799
cf145b35d65f 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.
Michiel Broek <mbroek@mbse.eu>
parents: 747
diff changeset
35 my_bool reconnect = 1;
cf145b35d65f 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.
Michiel Broek <mbroek@mbse.eu>
parents: 747
diff changeset
36
0
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
37 extern sys_config Config;
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
38 extern sys_node_list *nodes;
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
39 extern sys_fermenter_list *fermenters;
502
a8a6901b5a99 Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents: 405
diff changeset
40 extern sys_co2meter_list *co2meters;
567
6bf0afc33e70 Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents: 558
diff changeset
41 extern sys_ispindel_list *ispindels;
0
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
42 extern int debug;
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
43
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
44
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
45 time_t datetime_to_time_t(char *dt_string)
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
46 {
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
47 struct tm tm;
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
48
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
49 memset(&tm, 0, sizeof(struct tm));
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
50 tm.tm_year = atoi(strtok(dt_string, "-")) - 1900;
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
51 tm.tm_mon = atoi(strtok(NULL, "-")) - 1;
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
52 tm.tm_mday = atoi(strtok(NULL, " "));
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
53 tm.tm_hour = atoi(strtok(NULL, ":"));
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
54 tm.tm_min = atoi(strtok(NULL, ":"));
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
55 tm.tm_sec = atoi(strtok(NULL, "\0"));
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
56 tm.tm_isdst = 1;
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
57
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
58 return mktime(&tm);
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
59 }
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
60
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
61
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
62
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
63 int bms_mysql_init(void)
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
64 {
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
65 sys_node_list *node, *tmpp;
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
66 sys_fermenter_list *fermenter, *tmpf;
502
a8a6901b5a99 Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents: 405
diff changeset
67 sys_co2meter_list *co2meter, *tmpc;
567
6bf0afc33e70 Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents: 558
diff changeset
68 sys_ispindel_list *ispindel, *tmpi;
6bf0afc33e70 Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents: 558
diff changeset
69 int icnt = 0, ccnt = 0, ncnt = 0, fcnt = 0;
0
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
70
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
71 con = mysql_init(NULL);
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
72 if (con == NULL) {
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
73 syslog(LOG_NOTICE, "MySQL: mysql_init() failed");
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
74 return 1;
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
75 }
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
76
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
77 if (mysql_real_connect(con, Config.mysql_host, Config.mysql_user, Config.mysql_pass, Config.mysql_database, Config.mysql_port, NULL, 0) == NULL) {
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
78 syslog(LOG_NOTICE, "MySQL: mysql_real_connect() %s", mysql_error(con));
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
79 return 2;
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
80 }
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
81
852
71f0fa38b634 Version 0.3.45. Removed all writing to ascii logfiles in the webserver environment, only log to MySQL.
Michiel Broek <mbroek@mbse.eu>
parents: 849
diff changeset
82 mysql_optionsv(con, MYSQL_OPT_RECONNECT, (void *)&reconnect);
71f0fa38b634 Version 0.3.45. Removed all writing to ascii logfiles in the webserver environment, only log to MySQL.
Michiel Broek <mbroek@mbse.eu>
parents: 849
diff changeset
83
0
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
84 syslog(LOG_NOTICE, "MySQL: connected to %s:%d database %s", Config.mysql_host, Config.mysql_port, Config.mysql_database);
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
85 syslog(LOG_NOTICE, "MySQL: %s server info: %s", mysql_get_host_info(con), mysql_get_server_info(con));
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
86 if (debug)
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
87 fprintf(stdout, "MySQL: connected\n");
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
88
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
89 /*
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
90 * Restore nodes from the database
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
91 */
684
ccb9f24d0fe9 Report any online status change via websocket broadcast. When starting, load all in memory tables sorted. The websocket status on the web pages has it's own panel. Prepared the menu system for dynamic updates.
Michiel Broek <mbroek@mbse.eu>
parents: 680
diff changeset
92 if (mysql_query(con, "SELECT * FROM mon_nodes ORDER BY node")) {
43
dcb9ff8846fa Renamed monitor database tables
Michiel Broek <mbroek@mbse.eu>
parents: 0
diff changeset
93 syslog(LOG_NOTICE, "MySQL: SELECT * FROM mon_nodes error %u (%s))", mysql_errno(con), mysql_error(con));
0
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
94 } else {
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
95 res_set = mysql_store_result(con);
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
96 if (res_set == NULL) {
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
97 syslog(LOG_NOTICE, "MySQL: mysq_store_result error %u (%s))", mysql_errno(con), mysql_error(con));
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
98 } else {
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
99 // Process results
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
100 while ((row = mysql_fetch_row(res_set)) != NULL) {
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
101 node = (sys_node_list *)malloc(sizeof(sys_node_list));
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
102 memset(node, 0, sizeof(sys_node_list));
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
103 node->next = NULL;
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
104 node->uuid = xstrcpy(row[1]);
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
105 node->node = xstrcpy(row[2]);
572
7a03181d29a3 Version 0.3.27 More code for iSpindels. All online/offline data in the database is now handles as integers. Nodes timeout use the configured interval time from the nodes.
Michiel Broek <mbroek@mbse.eu>
parents: 567
diff changeset
106 node->online = atoi(row[3]);
0
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
107 node->group_id = xstrcpy(row[4]);
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
108 node->hardwaremake = xstrcpy(row[5]);
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
109 node->hardwaremodel = xstrcpy(row[6]);
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
110 node->os = xstrcpy(row[7]);
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
111 node->os_version = xstrcpy(row[8]);
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
112 node->firmware = xstrcpy(row[9]);
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
113 node->firstseen = datetime_to_time_t(row[10]);
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
114 node->lastseen = datetime_to_time_t(row[11]);
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
115 node->temperature = atof(row[12]);
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
116 node->humidity = atof(row[13]);
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
117 node->barometer = atof(row[14]);
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
118 node->gps_latitude = atof(row[15]);
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
119 node->gps_longitude = atof(row[16]);
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
120 node->gps_altitude = atof(row[17]);
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
121 node->net_address = xstrcpy(row[18]);
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
122 node->net_ifname = xstrcpy(row[19]);
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
123 node->net_rssi = atoi(row[20]);
567
6bf0afc33e70 Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents: 558
diff changeset
124 node->interval = atoi(row[21]);
703
faeede125639 Version 0.3.35 Added nodes database net_ssid field.
Michiel Broek <mbroek@mbse.eu>
parents: 684
diff changeset
125 node->net_ssid = xstrcpy(row[22]);
0
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
126
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
127 if (nodes == NULL) {
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
128 nodes = node;
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
129 } else {
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
130 for (tmpp = nodes; tmpp; tmpp = tmpp->next) {
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
131 if (tmpp->next == NULL) {
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
132 tmpp->next = node;
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
133 break;
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
134 }
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
135 }
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
136 }
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
137 ncnt++;
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
138 }
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
139 mysql_free_result(res_set);
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
140 }
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
141 }
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
142
684
ccb9f24d0fe9 Report any online status change via websocket broadcast. When starting, load all in memory tables sorted. The websocket status on the web pages has it's own panel. Prepared the menu system for dynamic updates.
Michiel Broek <mbroek@mbse.eu>
parents: 680
diff changeset
143 if (mysql_query(con, "SELECT * FROM mon_fermenters ORDER BY node,alias")) {
43
dcb9ff8846fa Renamed monitor database tables
Michiel Broek <mbroek@mbse.eu>
parents: 0
diff changeset
144 syslog(LOG_NOTICE, "MySQL: SELECT * FROM mon_fermenters error %u (%s))", mysql_errno(con), mysql_error(con));
0
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
145 } else {
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
146 res_set = mysql_store_result(con);
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
147 if (res_set == NULL) {
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
148 syslog(LOG_NOTICE, "MySQL: mysq_store_result error %u (%s))", mysql_errno(con), mysql_error(con));
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
149 } else {
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
150 while ((row = mysql_fetch_row(res_set)) != NULL) {
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
151 fermenter = (sys_fermenter_list *)malloc(sizeof(sys_fermenter_list));
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
152 memset(fermenter, 0, sizeof(sys_fermenter_list));
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
153 fermenter->next = NULL;
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
154 fermenter->uuid = xstrcpy(row[1]);
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
155 fermenter->alias = xstrcpy(row[2]);
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
156 fermenter->node = xstrcpy(row[3]);
572
7a03181d29a3 Version 0.3.27 More code for iSpindels. All online/offline data in the database is now handles as integers. Nodes timeout use the configured interval time from the nodes.
Michiel Broek <mbroek@mbse.eu>
parents: 567
diff changeset
157 fermenter->online = atoi(row[4]);
0
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
158 fermenter->beercode = xstrcpy(row[5]);
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
159 fermenter->beername = xstrcpy(row[6]);
192
7f69b43e6084 Implemented beer uuid product in monitor fermenters.
Michiel Broek <mbroek@mbse.eu>
parents: 76
diff changeset
160 fermenter->beeruuid = xstrcpy(row[44]);
0
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
161 if (strlen(row[7])) {
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
162 fermenter->air_address = xstrcpy(row[7]);
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
163 fermenter->air_state = xstrcpy(row[8]);
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
164 fermenter->air_temperature = atof(row[9]);
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
165 }
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
166 if (strlen(row[10])) {
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
167 fermenter->beer_address = xstrcpy(row[10]);
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
168 fermenter->beer_state = xstrcpy(row[11]);
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
169 fermenter->beer_temperature = atof(row[12]);
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
170 }
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
171 if (strlen(row[13])) {
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
172 fermenter->chiller_address = xstrcpy(row[13]);
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
173 fermenter->chiller_state = xstrcpy(row[14]);
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
174 fermenter->chiller_temperature = atof(row[15]);
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
175 }
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
176 if (strlen(row[16])) {
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
177 fermenter->heater_address = xstrcpy(row[16]);
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
178 fermenter->heater_state = atoi(row[17]);
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
179 fermenter->heater_usage = atoi(row[18]);
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
180 }
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
181 if (strlen(row[19])) {
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
182 fermenter->cooler_address = xstrcpy(row[19]);
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
183 fermenter->cooler_state = atoi(row[20]);
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
184 fermenter->cooler_usage = atoi(row[21]);
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
185 }
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
186 if (strlen(row[22])) {
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
187 fermenter->fan_address = xstrcpy(row[22]);
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
188 fermenter->fan_state = atoi(row[23]);
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
189 fermenter->fan_usage = atoi(row[24]);
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
190 }
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
191 if (strlen(row[25])) {
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
192 fermenter->light_address = xstrcpy(row[25]);
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
193 fermenter->light_state = atoi(row[26]);
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
194 fermenter->light_usage = atoi(row[27]);
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
195 }
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
196 if (strlen(row[28])) {
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
197 fermenter->door_address = xstrcpy(row[28]);
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
198 fermenter->door_state = atoi(row[29]);
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
199 }
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
200 if (strlen(row[30])) {
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
201 fermenter->psu_address = xstrcpy(row[30]);
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
202 fermenter->psu_state = atoi(row[31]);
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
203 }
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
204 fermenter->mode = xstrcpy(row[32]);
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
205 fermenter->alarm = atoi(row[33]);
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
206 fermenter->setpoint_high = atof(row[34]);
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
207 fermenter->setpoint_low = atof(row[35]);
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
208 if (strlen(row[36])) {
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
209 fermenter->profile_uuid = xstrcpy(row[36]);
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
210 fermenter->profile_name = xstrcpy(row[37]);
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
211 fermenter->profile_state = xstrcpy(row[38]);
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
212 fermenter->profile_percent = atoi(row[39]);
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
213 fermenter->profile_inittemp_high = atof(row[40]);
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
214 fermenter->profile_inittemp_low = atof(row[41]);
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
215 fermenter->profile_steps = xstrcpy(row[42]);
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
216 }
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
217 fermenter->stage = xstrcpy(row[43]);
299
047ead629d4a Accept yeast temperature limits from thermferm via MQTT. Send yeat temperature ranges to thermferm together with the beer parameters. Store yeast temperature limits in the mon_fermenters database table. The monitor fermenters screen adjusts the temperature color ranges.
Michiel Broek <mbroek@mbse.eu>
parents: 194
diff changeset
218 fermenter->yeast_lo = atof(row[45]);
047ead629d4a Accept yeast temperature limits from thermferm via MQTT. Send yeat temperature ranges to thermferm together with the beer parameters. Store yeast temperature limits in the mon_fermenters database table. The monitor fermenters screen adjusts the temperature color ranges.
Michiel Broek <mbroek@mbse.eu>
parents: 194
diff changeset
219 fermenter->yeast_hi = atof(row[46]);
334
26c6f8e5d58e Added webcam_url and webcam_light fields to the mon_fermenters database table. Currently these fields need to be set using phpMyAdmin or another tool. If the webcam_url field is set, then on the mon_fermenter webpage a button is added to show a webcam page.
Michiel Broek <mbroek@mbse.eu>
parents: 299
diff changeset
220 fermenter->webcam_url = xstrcpy(row[47]);
26c6f8e5d58e Added webcam_url and webcam_light fields to the mon_fermenters database table. Currently these fields need to be set using phpMyAdmin or another tool. If the webcam_url field is set, then on the mon_fermenter webpage a button is added to show a webcam page.
Michiel Broek <mbroek@mbse.eu>
parents: 299
diff changeset
221 fermenter->webcam_light = atoi(row[48]);
0
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
222
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
223 if (fermenters == NULL) {
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
224 fermenters = fermenter;
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
225 } else {
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
226 for (tmpf = fermenters; tmpf; tmpf = tmpf->next) {
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
227 if (tmpf->next == NULL) {
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
228 tmpf->next = fermenter;
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
229 break;
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
230 }
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
231 }
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
232 }
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
233 fcnt++;
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
234 }
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
235 mysql_free_result(res_set);
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
236 }
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
237 }
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
238
684
ccb9f24d0fe9 Report any online status change via websocket broadcast. When starting, load all in memory tables sorted. The websocket status on the web pages has it's own panel. Prepared the menu system for dynamic updates.
Michiel Broek <mbroek@mbse.eu>
parents: 680
diff changeset
239 if (mysql_query(con, "SELECT * FROM mon_co2meters ORDER BY node,alias")) {
502
a8a6901b5a99 Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents: 405
diff changeset
240 syslog(LOG_NOTICE, "MySQL: SELECT * FROM mon_co2meters error %u (%s))", mysql_errno(con), mysql_error(con));
a8a6901b5a99 Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents: 405
diff changeset
241 } else {
a8a6901b5a99 Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents: 405
diff changeset
242 res_set = mysql_store_result(con);
a8a6901b5a99 Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents: 405
diff changeset
243 if (res_set == NULL) {
a8a6901b5a99 Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents: 405
diff changeset
244 syslog(LOG_NOTICE, "MySQL: mysq_store_result error %u (%s))", mysql_errno(con), mysql_error(con));
a8a6901b5a99 Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents: 405
diff changeset
245 } else {
a8a6901b5a99 Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents: 405
diff changeset
246 while ((row = mysql_fetch_row(res_set)) != NULL) {
a8a6901b5a99 Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents: 405
diff changeset
247 co2meter = (sys_co2meter_list *)malloc(sizeof(sys_co2meter_list));
a8a6901b5a99 Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents: 405
diff changeset
248 memset(co2meter, 0, sizeof(sys_co2meter_list));
a8a6901b5a99 Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents: 405
diff changeset
249 co2meter->next = NULL;
a8a6901b5a99 Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents: 405
diff changeset
250 co2meter->uuid = xstrcpy(row[1]);
a8a6901b5a99 Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents: 405
diff changeset
251 co2meter->alias = xstrcpy(row[2]);
a8a6901b5a99 Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents: 405
diff changeset
252 co2meter->node = xstrcpy(row[3]);
572
7a03181d29a3 Version 0.3.27 More code for iSpindels. All online/offline data in the database is now handles as integers. Nodes timeout use the configured interval time from the nodes.
Michiel Broek <mbroek@mbse.eu>
parents: 567
diff changeset
253 co2meter->online = atoi(row[4]);
502
a8a6901b5a99 Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents: 405
diff changeset
254 co2meter->beercode = xstrcpy(row[5]);
a8a6901b5a99 Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents: 405
diff changeset
255 co2meter->beername = xstrcpy(row[6]);
a8a6901b5a99 Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents: 405
diff changeset
256 co2meter->beeruuid = xstrcpy(row[7]);
a8a6901b5a99 Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents: 405
diff changeset
257 co2meter->mode = xstrcpy(row[8]);
a8a6901b5a99 Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents: 405
diff changeset
258 co2meter->temperature_state = xstrcpy(row[9]);
a8a6901b5a99 Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents: 405
diff changeset
259 co2meter->temperature_address = xstrcpy(row[10]);
a8a6901b5a99 Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents: 405
diff changeset
260 co2meter->temperature = atof(row[11]);
a8a6901b5a99 Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents: 405
diff changeset
261 co2meter->pressure_state = xstrcpy(row[12]);
a8a6901b5a99 Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents: 405
diff changeset
262 co2meter->pressure_channel = atoi(row[13]);
a8a6901b5a99 Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents: 405
diff changeset
263 co2meter->pressure_voltage = atof(row[14]);
a8a6901b5a99 Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents: 405
diff changeset
264 co2meter->pressure_zero = atof(row[15]);
a8a6901b5a99 Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents: 405
diff changeset
265 co2meter->pressure_bar = atof(row[16]);
a8a6901b5a99 Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents: 405
diff changeset
266
a8a6901b5a99 Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents: 405
diff changeset
267 if (co2meters == NULL) {
a8a6901b5a99 Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents: 405
diff changeset
268 co2meters = co2meter;
a8a6901b5a99 Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents: 405
diff changeset
269 } else {
a8a6901b5a99 Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents: 405
diff changeset
270 for (tmpc = co2meters; tmpc; tmpc = tmpc->next) {
a8a6901b5a99 Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents: 405
diff changeset
271 if (tmpc->next == NULL) {
a8a6901b5a99 Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents: 405
diff changeset
272 tmpc->next = co2meter;
a8a6901b5a99 Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents: 405
diff changeset
273 break;
a8a6901b5a99 Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents: 405
diff changeset
274 }
a8a6901b5a99 Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents: 405
diff changeset
275 }
a8a6901b5a99 Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents: 405
diff changeset
276 }
a8a6901b5a99 Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents: 405
diff changeset
277 ccnt++;
a8a6901b5a99 Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents: 405
diff changeset
278 }
a8a6901b5a99 Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents: 405
diff changeset
279 mysql_free_result(res_set);
a8a6901b5a99 Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents: 405
diff changeset
280 }
a8a6901b5a99 Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents: 405
diff changeset
281 }
a8a6901b5a99 Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents: 405
diff changeset
282
684
ccb9f24d0fe9 Report any online status change via websocket broadcast. When starting, load all in memory tables sorted. The websocket status on the web pages has it's own panel. Prepared the menu system for dynamic updates.
Michiel Broek <mbroek@mbse.eu>
parents: 680
diff changeset
283 if (mysql_query(con, "SELECT * FROM mon_ispindels ORDER BY node,alias")) {
567
6bf0afc33e70 Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents: 558
diff changeset
284 syslog(LOG_NOTICE, "MySQL: SELECT * FROM mon_ispindels error %u (%s))", mysql_errno(con), mysql_error(con));
6bf0afc33e70 Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents: 558
diff changeset
285 } else {
6bf0afc33e70 Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents: 558
diff changeset
286 res_set = mysql_store_result(con);
6bf0afc33e70 Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents: 558
diff changeset
287 if (res_set == NULL) {
6bf0afc33e70 Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents: 558
diff changeset
288 syslog(LOG_NOTICE, "MySQL: mysq_store_result error %u (%s))", mysql_errno(con), mysql_error(con));
6bf0afc33e70 Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents: 558
diff changeset
289 } else {
6bf0afc33e70 Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents: 558
diff changeset
290 while ((row = mysql_fetch_row(res_set)) != NULL) {
6bf0afc33e70 Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents: 558
diff changeset
291 ispindel = (sys_ispindel_list *)malloc(sizeof(sys_ispindel_list));
6bf0afc33e70 Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents: 558
diff changeset
292 memset(ispindel, 0, sizeof(sys_ispindel_list));
6bf0afc33e70 Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents: 558
diff changeset
293 ispindel->next = NULL;
578
e75ce5bbda73 Changed the interface from the iSpindels to be the same as other devices. A webpage converts each call to two standard MQTT messages. The nodes MQTT message extended with an interval parameter. iSpindels now have a generated uuid made up from the chipid.
Michiel Broek <mbroek@mbse.eu>
parents: 572
diff changeset
294 ispindel->uuid = xstrcpy(row[1]);
e75ce5bbda73 Changed the interface from the iSpindels to be the same as other devices. A webpage converts each call to two standard MQTT messages. The nodes MQTT message extended with an interval parameter. iSpindels now have a generated uuid made up from the chipid.
Michiel Broek <mbroek@mbse.eu>
parents: 572
diff changeset
295 ispindel->alias = xstrcpy(row[2]);
e75ce5bbda73 Changed the interface from the iSpindels to be the same as other devices. A webpage converts each call to two standard MQTT messages. The nodes MQTT message extended with an interval parameter. iSpindels now have a generated uuid made up from the chipid.
Michiel Broek <mbroek@mbse.eu>
parents: 572
diff changeset
296 ispindel->node = xstrcpy(row[3]);
e75ce5bbda73 Changed the interface from the iSpindels to be the same as other devices. A webpage converts each call to two standard MQTT messages. The nodes MQTT message extended with an interval parameter. iSpindels now have a generated uuid made up from the chipid.
Michiel Broek <mbroek@mbse.eu>
parents: 572
diff changeset
297 ispindel->online = atoi(row[4]);
e75ce5bbda73 Changed the interface from the iSpindels to be the same as other devices. A webpage converts each call to two standard MQTT messages. The nodes MQTT message extended with an interval parameter. iSpindels now have a generated uuid made up from the chipid.
Michiel Broek <mbroek@mbse.eu>
parents: 572
diff changeset
298 ispindel->alarm = atoi(row[5]);
e75ce5bbda73 Changed the interface from the iSpindels to be the same as other devices. A webpage converts each call to two standard MQTT messages. The nodes MQTT message extended with an interval parameter. iSpindels now have a generated uuid made up from the chipid.
Michiel Broek <mbroek@mbse.eu>
parents: 572
diff changeset
299 ispindel->beercode = xstrcpy(row[6]);
e75ce5bbda73 Changed the interface from the iSpindels to be the same as other devices. A webpage converts each call to two standard MQTT messages. The nodes MQTT message extended with an interval parameter. iSpindels now have a generated uuid made up from the chipid.
Michiel Broek <mbroek@mbse.eu>
parents: 572
diff changeset
300 ispindel->beername = xstrcpy(row[7]);
e75ce5bbda73 Changed the interface from the iSpindels to be the same as other devices. A webpage converts each call to two standard MQTT messages. The nodes MQTT message extended with an interval parameter. iSpindels now have a generated uuid made up from the chipid.
Michiel Broek <mbroek@mbse.eu>
parents: 572
diff changeset
301 ispindel->beeruuid = xstrcpy(row[8]);
e75ce5bbda73 Changed the interface from the iSpindels to be the same as other devices. A webpage converts each call to two standard MQTT messages. The nodes MQTT message extended with an interval parameter. iSpindels now have a generated uuid made up from the chipid.
Michiel Broek <mbroek@mbse.eu>
parents: 572
diff changeset
302 ispindel->angle = atof(row[9]);
e75ce5bbda73 Changed the interface from the iSpindels to be the same as other devices. A webpage converts each call to two standard MQTT messages. The nodes MQTT message extended with an interval parameter. iSpindels now have a generated uuid made up from the chipid.
Michiel Broek <mbroek@mbse.eu>
parents: 572
diff changeset
303 ispindel->temperature = atof(row[10]);
e75ce5bbda73 Changed the interface from the iSpindels to be the same as other devices. A webpage converts each call to two standard MQTT messages. The nodes MQTT message extended with an interval parameter. iSpindels now have a generated uuid made up from the chipid.
Michiel Broek <mbroek@mbse.eu>
parents: 572
diff changeset
304 ispindel->battery = atof(row[11]);
e75ce5bbda73 Changed the interface from the iSpindels to be the same as other devices. A webpage converts each call to two standard MQTT messages. The nodes MQTT message extended with an interval parameter. iSpindels now have a generated uuid made up from the chipid.
Michiel Broek <mbroek@mbse.eu>
parents: 572
diff changeset
305 ispindel->gravity = atof(row[12]);
e75ce5bbda73 Changed the interface from the iSpindels to be the same as other devices. A webpage converts each call to two standard MQTT messages. The nodes MQTT message extended with an interval parameter. iSpindels now have a generated uuid made up from the chipid.
Michiel Broek <mbroek@mbse.eu>
parents: 572
diff changeset
306 ispindel->interval = atoi(row[13]);
e75ce5bbda73 Changed the interface from the iSpindels to be the same as other devices. A webpage converts each call to two standard MQTT messages. The nodes MQTT message extended with an interval parameter. iSpindels now have a generated uuid made up from the chipid.
Michiel Broek <mbroek@mbse.eu>
parents: 572
diff changeset
307 ispindel->mode = xstrcpy(row[14]);
680
0bb48333d133 Fixed missing co2meters websocket data. Added websockets and removed polling for the mon-ispindel screen. The iSpindel SG gauge adjusts the resolution to the highest detected OG.
Michiel Broek <mbroek@mbse.eu>
parents: 628
diff changeset
308 ispindel->og_gravity = atof(row[15]);
843
29e7223e37ae Version 0.3.42 added yeast_lo and yeast_hi fields to the iSpindel records and structures.
Michiel Broek <mbroek@mbse.eu>
parents: 799
diff changeset
309 ispindel->yeast_lo = atof(row[16]);
29e7223e37ae Version 0.3.42 added yeast_lo and yeast_hi fields to the iSpindel records and structures.
Michiel Broek <mbroek@mbse.eu>
parents: 799
diff changeset
310 ispindel->yeast_hi = atof(row[17]);
849
16079aef4c4c Version 0.3.44. Moved iSpindel Plato calculation from the php script to bmsd. This uses calibration data in the mon_ispindels table. Setup of this data will be done by the bmsapp applications. Default settings are stored in MySQL. From now on you don't need to store calibration data in the iSpindel.
Michiel Broek <mbroek@mbse.eu>
parents: 844
diff changeset
311 ispindel->calibrate = xstrcpy(row[18]);
16079aef4c4c Version 0.3.44. Moved iSpindel Plato calculation from the php script to bmsd. This uses calibration data in the mon_ispindels table. Setup of this data will be done by the bmsapp applications. Default settings are stored in MySQL. From now on you don't need to store calibration data in the iSpindel.
Michiel Broek <mbroek@mbse.eu>
parents: 844
diff changeset
312 ispindel->lastseen = datetime_to_time_t(row[19]);
567
6bf0afc33e70 Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents: 558
diff changeset
313
6bf0afc33e70 Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents: 558
diff changeset
314 if (ispindels == NULL) {
6bf0afc33e70 Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents: 558
diff changeset
315 ispindels = ispindel;
6bf0afc33e70 Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents: 558
diff changeset
316 } else {
6bf0afc33e70 Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents: 558
diff changeset
317 for (tmpi = ispindels; tmpi; tmpi = tmpi->next) {
6bf0afc33e70 Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents: 558
diff changeset
318 if (tmpi->next == NULL) {
6bf0afc33e70 Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents: 558
diff changeset
319 tmpi->next = ispindel;
6bf0afc33e70 Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents: 558
diff changeset
320 break;
6bf0afc33e70 Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents: 558
diff changeset
321 }
6bf0afc33e70 Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents: 558
diff changeset
322 }
6bf0afc33e70 Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents: 558
diff changeset
323 }
6bf0afc33e70 Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents: 558
diff changeset
324 icnt++;
6bf0afc33e70 Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents: 558
diff changeset
325 }
6bf0afc33e70 Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents: 558
diff changeset
326 mysql_free_result(res_set);
6bf0afc33e70 Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents: 558
diff changeset
327 }
6bf0afc33e70 Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents: 558
diff changeset
328 }
6bf0afc33e70 Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents: 558
diff changeset
329
680
0bb48333d133 Fixed missing co2meters websocket data. Added websockets and removed polling for the mon-ispindel screen. The iSpindel SG gauge adjusts the resolution to the highest detected OG.
Michiel Broek <mbroek@mbse.eu>
parents: 628
diff changeset
330 syslog(LOG_NOTICE, "MySQL: loaded %d nodes, %d fermenters, %d co2meters, %d ispindels", ncnt, fcnt, ccnt, icnt);
0
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
331 return 0;
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
332 }
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
333
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
334
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
335
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
336 void bms_mysql_end(void)
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
337 {
572
7a03181d29a3 Version 0.3.27 More code for iSpindels. All online/offline data in the database is now handles as integers. Nodes timeout use the configured interval time from the nodes.
Michiel Broek <mbroek@mbse.eu>
parents: 567
diff changeset
338 sys_ispindel_list *tmpi, *oldtmpi;
502
a8a6901b5a99 Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents: 405
diff changeset
339 sys_co2meter_list *tmpp, *oldtmpp;
0
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
340 sys_fermenter_list *tmpf, *oldtmpf;
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
341 sys_node_list *tmpn, *oldtmpn;
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
342
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
343 mysql_close(con);
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
344
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
345 syslog(LOG_NOTICE, "MySQL: disconnected");
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
346 if (debug)
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
347 fprintf(stdout, "MySQL: disconnected\n");
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
348
572
7a03181d29a3 Version 0.3.27 More code for iSpindels. All online/offline data in the database is now handles as integers. Nodes timeout use the configured interval time from the nodes.
Michiel Broek <mbroek@mbse.eu>
parents: 567
diff changeset
349 for (tmpi = ispindels; tmpi; tmpi = oldtmpi) {
7a03181d29a3 Version 0.3.27 More code for iSpindels. All online/offline data in the database is now handles as integers. Nodes timeout use the configured interval time from the nodes.
Michiel Broek <mbroek@mbse.eu>
parents: 567
diff changeset
350 oldtmpi = tmpi->next;
579
1253a237b620 Added check for database changes for iSpindels such as a new beer, or changing mode. Added denity in Plato and SG to the iSpindel web screen. The iSpindels must be calibrated in Plato! A bit of documentation updated.
Michiel Broek <mbroek@mbse.eu>
parents: 578
diff changeset
351 if (tmpi->uuid)
1253a237b620 Added check for database changes for iSpindels such as a new beer, or changing mode. Added denity in Plato and SG to the iSpindel web screen. The iSpindels must be calibrated in Plato! A bit of documentation updated.
Michiel Broek <mbroek@mbse.eu>
parents: 578
diff changeset
352 free(tmpi->uuid);
1253a237b620 Added check for database changes for iSpindels such as a new beer, or changing mode. Added denity in Plato and SG to the iSpindel web screen. The iSpindels must be calibrated in Plato! A bit of documentation updated.
Michiel Broek <mbroek@mbse.eu>
parents: 578
diff changeset
353 if (tmpi->alias)
1253a237b620 Added check for database changes for iSpindels such as a new beer, or changing mode. Added denity in Plato and SG to the iSpindel web screen. The iSpindels must be calibrated in Plato! A bit of documentation updated.
Michiel Broek <mbroek@mbse.eu>
parents: 578
diff changeset
354 free(tmpi->alias);
572
7a03181d29a3 Version 0.3.27 More code for iSpindels. All online/offline data in the database is now handles as integers. Nodes timeout use the configured interval time from the nodes.
Michiel Broek <mbroek@mbse.eu>
parents: 567
diff changeset
355 if (tmpi->node)
7a03181d29a3 Version 0.3.27 More code for iSpindels. All online/offline data in the database is now handles as integers. Nodes timeout use the configured interval time from the nodes.
Michiel Broek <mbroek@mbse.eu>
parents: 567
diff changeset
356 free(tmpi->node);
7a03181d29a3 Version 0.3.27 More code for iSpindels. All online/offline data in the database is now handles as integers. Nodes timeout use the configured interval time from the nodes.
Michiel Broek <mbroek@mbse.eu>
parents: 567
diff changeset
357 if (tmpi->beercode)
7a03181d29a3 Version 0.3.27 More code for iSpindels. All online/offline data in the database is now handles as integers. Nodes timeout use the configured interval time from the nodes.
Michiel Broek <mbroek@mbse.eu>
parents: 567
diff changeset
358 free(tmpi->beercode);
7a03181d29a3 Version 0.3.27 More code for iSpindels. All online/offline data in the database is now handles as integers. Nodes timeout use the configured interval time from the nodes.
Michiel Broek <mbroek@mbse.eu>
parents: 567
diff changeset
359 if (tmpi->beername)
7a03181d29a3 Version 0.3.27 More code for iSpindels. All online/offline data in the database is now handles as integers. Nodes timeout use the configured interval time from the nodes.
Michiel Broek <mbroek@mbse.eu>
parents: 567
diff changeset
360 free(tmpi->beername);
7a03181d29a3 Version 0.3.27 More code for iSpindels. All online/offline data in the database is now handles as integers. Nodes timeout use the configured interval time from the nodes.
Michiel Broek <mbroek@mbse.eu>
parents: 567
diff changeset
361 if (tmpi->beeruuid)
7a03181d29a3 Version 0.3.27 More code for iSpindels. All online/offline data in the database is now handles as integers. Nodes timeout use the configured interval time from the nodes.
Michiel Broek <mbroek@mbse.eu>
parents: 567
diff changeset
362 free(tmpi->beeruuid);
579
1253a237b620 Added check for database changes for iSpindels such as a new beer, or changing mode. Added denity in Plato and SG to the iSpindel web screen. The iSpindels must be calibrated in Plato! A bit of documentation updated.
Michiel Broek <mbroek@mbse.eu>
parents: 578
diff changeset
363 if (tmpi->mode)
1253a237b620 Added check for database changes for iSpindels such as a new beer, or changing mode. Added denity in Plato and SG to the iSpindel web screen. The iSpindels must be calibrated in Plato! A bit of documentation updated.
Michiel Broek <mbroek@mbse.eu>
parents: 578
diff changeset
364 free(tmpi->mode);
849
16079aef4c4c Version 0.3.44. Moved iSpindel Plato calculation from the php script to bmsd. This uses calibration data in the mon_ispindels table. Setup of this data will be done by the bmsapp applications. Default settings are stored in MySQL. From now on you don't need to store calibration data in the iSpindel.
Michiel Broek <mbroek@mbse.eu>
parents: 844
diff changeset
365 if (tmpi->calibrate)
16079aef4c4c Version 0.3.44. Moved iSpindel Plato calculation from the php script to bmsd. This uses calibration data in the mon_ispindels table. Setup of this data will be done by the bmsapp applications. Default settings are stored in MySQL. From now on you don't need to store calibration data in the iSpindel.
Michiel Broek <mbroek@mbse.eu>
parents: 844
diff changeset
366 free(tmpi->calibrate);
572
7a03181d29a3 Version 0.3.27 More code for iSpindels. All online/offline data in the database is now handles as integers. Nodes timeout use the configured interval time from the nodes.
Michiel Broek <mbroek@mbse.eu>
parents: 567
diff changeset
367 free(tmpi);
7a03181d29a3 Version 0.3.27 More code for iSpindels. All online/offline data in the database is now handles as integers. Nodes timeout use the configured interval time from the nodes.
Michiel Broek <mbroek@mbse.eu>
parents: 567
diff changeset
368 }
7a03181d29a3 Version 0.3.27 More code for iSpindels. All online/offline data in the database is now handles as integers. Nodes timeout use the configured interval time from the nodes.
Michiel Broek <mbroek@mbse.eu>
parents: 567
diff changeset
369
502
a8a6901b5a99 Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents: 405
diff changeset
370 for (tmpp = co2meters; tmpp; tmpp = oldtmpp) {
a8a6901b5a99 Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents: 405
diff changeset
371 oldtmpp = tmpp->next;
a8a6901b5a99 Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents: 405
diff changeset
372 if (tmpp->uuid)
a8a6901b5a99 Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents: 405
diff changeset
373 free(tmpp->uuid);
a8a6901b5a99 Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents: 405
diff changeset
374 if (tmpp->alias)
a8a6901b5a99 Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents: 405
diff changeset
375 free(tmpp->alias);
a8a6901b5a99 Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents: 405
diff changeset
376 if (tmpp->node)
a8a6901b5a99 Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents: 405
diff changeset
377 free(tmpp->node);
a8a6901b5a99 Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents: 405
diff changeset
378 if (tmpp->beercode)
a8a6901b5a99 Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents: 405
diff changeset
379 free(tmpp->beercode);
a8a6901b5a99 Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents: 405
diff changeset
380 if (tmpp->beername)
a8a6901b5a99 Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents: 405
diff changeset
381 free(tmpp->beername);
a8a6901b5a99 Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents: 405
diff changeset
382 if (tmpp->beeruuid)
a8a6901b5a99 Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents: 405
diff changeset
383 free(tmpp->beeruuid);
a8a6901b5a99 Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents: 405
diff changeset
384 if (tmpp->temperature_address)
a8a6901b5a99 Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents: 405
diff changeset
385 free(tmpp->temperature_address);
a8a6901b5a99 Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents: 405
diff changeset
386 if (tmpp->temperature_state)
a8a6901b5a99 Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents: 405
diff changeset
387 free(tmpp->temperature_state);
a8a6901b5a99 Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents: 405
diff changeset
388 if (tmpp->pressure_state)
a8a6901b5a99 Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents: 405
diff changeset
389 free(tmpp->pressure_state);
a8a6901b5a99 Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents: 405
diff changeset
390 free(tmpp);
a8a6901b5a99 Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents: 405
diff changeset
391 }
0
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
392 for (tmpf = fermenters; tmpf; tmpf = oldtmpf) {
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
393 oldtmpf = tmpf->next;
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
394 if (tmpf->uuid)
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
395 free(tmpf->uuid);
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
396 if (tmpf->alias)
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
397 free(tmpf->alias);
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
398 if (tmpf->node)
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
399 free(tmpf->node);
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
400 if (tmpf->beercode)
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
401 free(tmpf->beercode);
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
402 if (tmpf->beername)
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
403 free(tmpf->beername);
192
7f69b43e6084 Implemented beer uuid product in monitor fermenters.
Michiel Broek <mbroek@mbse.eu>
parents: 76
diff changeset
404 if (tmpf->beeruuid)
7f69b43e6084 Implemented beer uuid product in monitor fermenters.
Michiel Broek <mbroek@mbse.eu>
parents: 76
diff changeset
405 free(tmpf->beeruuid);
0
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
406 if (tmpf->air_address)
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
407 free(tmpf->air_address);
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
408 if (tmpf->air_state)
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
409 free(tmpf->air_state);
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
410 if (tmpf->beer_address)
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
411 free(tmpf->beer_address);
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
412 if (tmpf->beer_state)
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
413 free(tmpf->beer_state);
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
414 if (tmpf->chiller_address)
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
415 free(tmpf->chiller_address);
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
416 if (tmpf->chiller_state)
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
417 free(tmpf->chiller_state);
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
418 if (tmpf->heater_address)
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
419 free(tmpf->heater_address);
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
420 if (tmpf->cooler_address)
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
421 free(tmpf->cooler_address);
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
422 if (tmpf->fan_address)
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
423 free(tmpf->fan_address);
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
424 if (tmpf->light_address)
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
425 free(tmpf->light_address);
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
426 if (tmpf->door_address)
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
427 free(tmpf->door_address);
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
428 if (tmpf->psu_address)
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
429 free(tmpf->psu_address);
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
430 if (tmpf->mode)
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
431 free(tmpf->mode);
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
432 if (tmpf->stage)
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
433 free(tmpf->stage);
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
434 if (tmpf->profile_uuid)
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
435 free(tmpf->profile_uuid);
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
436 if (tmpf->profile_name)
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
437 free(tmpf->profile_name);
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
438 if (tmpf->profile_state)
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
439 free(tmpf->profile_state);
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
440 if (tmpf->profile_steps)
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
441 free(tmpf->profile_steps);
334
26c6f8e5d58e Added webcam_url and webcam_light fields to the mon_fermenters database table. Currently these fields need to be set using phpMyAdmin or another tool. If the webcam_url field is set, then on the mon_fermenter webpage a button is added to show a webcam page.
Michiel Broek <mbroek@mbse.eu>
parents: 299
diff changeset
442 if (tmpf->webcam_url)
26c6f8e5d58e Added webcam_url and webcam_light fields to the mon_fermenters database table. Currently these fields need to be set using phpMyAdmin or another tool. If the webcam_url field is set, then on the mon_fermenter webpage a button is added to show a webcam page.
Michiel Broek <mbroek@mbse.eu>
parents: 299
diff changeset
443 free(tmpf->webcam_url);
0
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
444 free(tmpf);
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
445 }
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
446 for (tmpn = nodes; tmpn; tmpn = oldtmpn) {
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
447 oldtmpn = tmpn->next;
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
448 if (tmpn->uuid)
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
449 free(tmpn->uuid);
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
450 if (tmpn->node)
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
451 free(tmpn->node);
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
452 if (tmpn->group_id)
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
453 free(tmpn->group_id);
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
454 if (tmpn->hardwaremake)
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
455 free(tmpn->hardwaremake);
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
456 if (tmpn->hardwaremodel)
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
457 free(tmpn->hardwaremodel);
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
458 if (tmpn->os)
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
459 free(tmpn->os);
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
460 if (tmpn->os_version)
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
461 free(tmpn->os_version);
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
462 if (tmpn->firmware)
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
463 free(tmpn->firmware);
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
464 if (tmpn->net_address)
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
465 free(tmpn->net_address);
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
466 if (tmpn->net_ifname)
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
467 free(tmpn->net_ifname);
703
faeede125639 Version 0.3.35 Added nodes database net_ssid field.
Michiel Broek <mbroek@mbse.eu>
parents: 684
diff changeset
468 if (tmpn->net_ssid)
faeede125639 Version 0.3.35 Added nodes database net_ssid field.
Michiel Broek <mbroek@mbse.eu>
parents: 684
diff changeset
469 free(tmpn->net_ssid);
0
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
470 free(tmpn);
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
471 }
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
472 }
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
473
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
474
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
475
405
ef3f0274a1ea Added a private mysql_query function that does try to reconnect a lost MySQL connection.
Michiel Broek <mbroek@mbse.eu>
parents: 383
diff changeset
476 int bms_mysql_query(const char *query)
ef3f0274a1ea Added a private mysql_query function that does try to reconnect a lost MySQL connection.
Michiel Broek <mbroek@mbse.eu>
parents: 383
diff changeset
477 {
ef3f0274a1ea Added a private mysql_query function that does try to reconnect a lost MySQL connection.
Michiel Broek <mbroek@mbse.eu>
parents: 383
diff changeset
478 int rc = mysql_query(con, query);
558
a8e065a9f851 Another attempt to fix the MySQL server has gone away error. Fixed gcc 7.1+ compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents: 505
diff changeset
479 int err = mysql_errno(con);
405
ef3f0274a1ea Added a private mysql_query function that does try to reconnect a lost MySQL connection.
Michiel Broek <mbroek@mbse.eu>
parents: 383
diff changeset
480
ef3f0274a1ea Added a private mysql_query function that does try to reconnect a lost MySQL connection.
Michiel Broek <mbroek@mbse.eu>
parents: 383
diff changeset
481 if (rc) {
558
a8e065a9f851 Another attempt to fix the MySQL server has gone away error. Fixed gcc 7.1+ compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents: 505
diff changeset
482 syslog(LOG_NOTICE, "MySQL: error %u (%s)", err, mysql_error(con));
405
ef3f0274a1ea Added a private mysql_query function that does try to reconnect a lost MySQL connection.
Michiel Broek <mbroek@mbse.eu>
parents: 383
diff changeset
483 syslog(LOG_NOTICE, query);
ef3f0274a1ea Added a private mysql_query function that does try to reconnect a lost MySQL connection.
Michiel Broek <mbroek@mbse.eu>
parents: 383
diff changeset
484 } else {
ef3f0274a1ea Added a private mysql_query function that does try to reconnect a lost MySQL connection.
Michiel Broek <mbroek@mbse.eu>
parents: 383
diff changeset
485 return 0;
ef3f0274a1ea Added a private mysql_query function that does try to reconnect a lost MySQL connection.
Michiel Broek <mbroek@mbse.eu>
parents: 383
diff changeset
486 }
ef3f0274a1ea Added a private mysql_query function that does try to reconnect a lost MySQL connection.
Michiel Broek <mbroek@mbse.eu>
parents: 383
diff changeset
487
ef3f0274a1ea Added a private mysql_query function that does try to reconnect a lost MySQL connection.
Michiel Broek <mbroek@mbse.eu>
parents: 383
diff changeset
488 return rc;
ef3f0274a1ea Added a private mysql_query function that does try to reconnect a lost MySQL connection.
Michiel Broek <mbroek@mbse.eu>
parents: 383
diff changeset
489 }
ef3f0274a1ea Added a private mysql_query function that does try to reconnect a lost MySQL connection.
Michiel Broek <mbroek@mbse.eu>
parents: 383
diff changeset
490
ef3f0274a1ea Added a private mysql_query function that does try to reconnect a lost MySQL connection.
Michiel Broek <mbroek@mbse.eu>
parents: 383
diff changeset
491
ef3f0274a1ea Added a private mysql_query function that does try to reconnect a lost MySQL connection.
Michiel Broek <mbroek@mbse.eu>
parents: 383
diff changeset
492
0
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
493 void node_mysql_insert(sys_node_list *node)
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
494 {
558
a8e065a9f851 Another attempt to fix the MySQL server has gone away error. Fixed gcc 7.1+ compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents: 505
diff changeset
495 char *query = malloc(1024), first[73], last[73];
0
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
496 struct tm *mytime;
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
497
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
498 mytime = localtime(&node->firstseen);
558
a8e065a9f851 Another attempt to fix the MySQL server has gone away error. Fixed gcc 7.1+ compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents: 505
diff changeset
499 snprintf(first, 72, "%04d-%02d-%02d %02d:%02d:%02d",
0
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
500 mytime->tm_year + 1900, mytime->tm_mon + 1, mytime->tm_mday, mytime->tm_hour, mytime->tm_min, mytime->tm_sec);
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
501 mytime = localtime(&node->lastseen);
558
a8e065a9f851 Another attempt to fix the MySQL server has gone away error. Fixed gcc 7.1+ compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents: 505
diff changeset
502 snprintf(last, 72, "%04d-%02d-%02d %02d:%02d:%02d",
0
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
503 mytime->tm_year + 1900, mytime->tm_mon + 1, mytime->tm_mday, mytime->tm_hour, mytime->tm_min, mytime->tm_sec);
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
504
76
804d45bdaa86 Increased nenory for the nodes query strings.
Michiel Broek <mbroek@mbse.eu>
parents: 43
diff changeset
505 snprintf(query, 1023,
572
7a03181d29a3 Version 0.3.27 More code for iSpindels. All online/offline data in the database is now handles as integers. Nodes timeout use the configured interval time from the nodes.
Michiel Broek <mbroek@mbse.eu>
parents: 567
diff changeset
506 "INSERT INTO mon_nodes SET uuid='%s', node='%s', online='%d', group_id='%s', " \
0
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
507 "hardwaremake='%s', hardwaremodel='%s', os='%s', os_version='%s', firmware='%s', firstseen='%s', lastseen='%s', " \
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
508 "temperature='%.3f', humidity='%.3f', barometer='%.3f', gps_latitude='%.8f', gps_longitude='%.8f', gps_altitude='%.8f', " \
703
faeede125639 Version 0.3.35 Added nodes database net_ssid field.
Michiel Broek <mbroek@mbse.eu>
parents: 684
diff changeset
509 "net_address='%s', net_ifname='%s', net_rssi='%d', up_interval='%d', net_ssid='%s'",
572
7a03181d29a3 Version 0.3.27 More code for iSpindels. All online/offline data in the database is now handles as integers. Nodes timeout use the configured interval time from the nodes.
Michiel Broek <mbroek@mbse.eu>
parents: 567
diff changeset
510 node->uuid, node->node, node->online ?1:0, node->group_id,
0
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
511 node->hardwaremake, node->hardwaremodel, node->os, node->os_version, node->firmware, first, last,
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
512 node->temperature, node->humidity, node->barometer, node->gps_latitude, node->gps_longitude, node->gps_altitude,
844
a6ee7b5b036b Version 0.3.43 bmsd if there is no ssid received from a node message then send '' to the mon_nodes table in the database instead of (null).
Michiel Broek <mbroek@mbse.eu>
parents: 843
diff changeset
513 node->net_address, node->net_ifname, node->net_rssi, node->interval, (node->net_ssid) ? node->net_ssid:"");
0
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
514
405
ef3f0274a1ea Added a private mysql_query function that does try to reconnect a lost MySQL connection.
Michiel Broek <mbroek@mbse.eu>
parents: 383
diff changeset
515 if (bms_mysql_query(query) == 0) {
0
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
516 syslog(LOG_NOTICE, "MySQL: insert new node %s", node->node);
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
517 }
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
518
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
519 free(query);
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
520 }
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
521
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
522
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
523
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
524 void node_mysql_update(sys_node_list *node)
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
525 {
558
a8e065a9f851 Another attempt to fix the MySQL server has gone away error. Fixed gcc 7.1+ compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents: 505
diff changeset
526 char *query = malloc(1024), last[65];
0
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
527 struct tm *mytime;
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
528
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
529 mytime = localtime(&node->lastseen);
558
a8e065a9f851 Another attempt to fix the MySQL server has gone away error. Fixed gcc 7.1+ compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents: 505
diff changeset
530 snprintf(last, 64, "%04d-%02d-%02d %02d:%02d:%02d",
0
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
531 mytime->tm_year + 1900, mytime->tm_mon + 1, mytime->tm_mday, mytime->tm_hour, mytime->tm_min, mytime->tm_sec);
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
532
76
804d45bdaa86 Increased nenory for the nodes query strings.
Michiel Broek <mbroek@mbse.eu>
parents: 43
diff changeset
533 snprintf(query, 1023,
572
7a03181d29a3 Version 0.3.27 More code for iSpindels. All online/offline data in the database is now handles as integers. Nodes timeout use the configured interval time from the nodes.
Michiel Broek <mbroek@mbse.eu>
parents: 567
diff changeset
534 "UPDATE mon_nodes SET online='%d', hardwaremake='%s', hardwaremodel='%s', os='%s', os_version='%s', firmware='%s', lastseen='%s', " \
0
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
535 "temperature='%.3f', humidity='%.3f', barometer='%.3f', gps_latitude='%.8f', gps_longitude='%.8f', gps_altitude='%.8f', " \
703
faeede125639 Version 0.3.35 Added nodes database net_ssid field.
Michiel Broek <mbroek@mbse.eu>
parents: 684
diff changeset
536 "net_address='%s', net_ifname='%s', net_rssi='%d', up_interval='%d', net_ssid='%s' WHERE uuid='%s'",
572
7a03181d29a3 Version 0.3.27 More code for iSpindels. All online/offline data in the database is now handles as integers. Nodes timeout use the configured interval time from the nodes.
Michiel Broek <mbroek@mbse.eu>
parents: 567
diff changeset
537 node->online ? 1:0, node->hardwaremake, node->hardwaremodel, node->os, node->os_version, node->firmware, last,
0
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
538 node->temperature, node->humidity, node->barometer, node->gps_latitude, node->gps_longitude, node->gps_altitude,
844
a6ee7b5b036b Version 0.3.43 bmsd if there is no ssid received from a node message then send '' to the mon_nodes table in the database instead of (null).
Michiel Broek <mbroek@mbse.eu>
parents: 843
diff changeset
539 node->net_address, node->net_ifname, node->net_rssi, node->interval, (node->net_ssid) ? node->net_ssid:"", node->uuid);
0
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
540
405
ef3f0274a1ea Added a private mysql_query function that does try to reconnect a lost MySQL connection.
Michiel Broek <mbroek@mbse.eu>
parents: 383
diff changeset
541 bms_mysql_query(query);
0
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
542 free(query);
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
543 }
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
544
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
545
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
546
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
547 void node_mysql_death(char *node)
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
548 {
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
549 char *query = malloc(512);
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
550
572
7a03181d29a3 Version 0.3.27 More code for iSpindels. All online/offline data in the database is now handles as integers. Nodes timeout use the configured interval time from the nodes.
Michiel Broek <mbroek@mbse.eu>
parents: 567
diff changeset
551 snprintf(query, 511, "UPDATE mon_nodes SET online='0' WHERE node='%s'", node);
405
ef3f0274a1ea Added a private mysql_query function that does try to reconnect a lost MySQL connection.
Michiel Broek <mbroek@mbse.eu>
parents: 383
diff changeset
552 bms_mysql_query(query);
0
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
553 free(query);
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
554 }
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
555
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
556
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
557
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
558 void fermenter_mysql_insert(sys_fermenter_list *fermenter)
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
559 {
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
560 char *query = malloc(2560);
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
561
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
562 snprintf(query, 2559,
572
7a03181d29a3 Version 0.3.27 More code for iSpindels. All online/offline data in the database is now handles as integers. Nodes timeout use the configured interval time from the nodes.
Michiel Broek <mbroek@mbse.eu>
parents: 567
diff changeset
563 "INSERT INTO mon_fermenters SET uuid='%s', alias='%s', node='%s', online='%d', " \
192
7f69b43e6084 Implemented beer uuid product in monitor fermenters.
Michiel Broek <mbroek@mbse.eu>
parents: 76
diff changeset
564 "beercode='%s', beername='%s', beeruuid='%s', " \
0
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
565 "air_address='%s', air_state='%s', air_temperature='%.3f', " \
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
566 "beer_address='%s', beer_state='%s', beer_temperature='%.3f', " \
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
567 "chiller_address='%s', chiller_state='%s', chiller_temperature='%.3f', " \
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
568 "heater_address='%s', heater_state='%d', heater_usage='%lu', " \
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
569 "cooler_address='%s', cooler_state='%d', cooler_usage='%lu', " \
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
570 "fan_address='%s', fan_state='%d', fan_usage='%lu', " \
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
571 "light_address='%s', light_state='%d', light_usage='%lu', " \
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
572 "door_address='%s', door_state='%d', " \
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
573 "psu_address='%s', psu_state='%d', " \
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
574 "mode='%s', alarm='%d', setpoint_high='%.3f', setpoint_low='%.3f', " \
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
575 "profile_uuid='%s', profile_name='%s', profile_state='%s', profile_percent='%d', " \
299
047ead629d4a Accept yeast temperature limits from thermferm via MQTT. Send yeat temperature ranges to thermferm together with the beer parameters. Store yeast temperature limits in the mon_fermenters database table. The monitor fermenters screen adjusts the temperature color ranges.
Michiel Broek <mbroek@mbse.eu>
parents: 194
diff changeset
576 "profile_inittemp_high='%.3f', profile_inittemp_low='%.3f', profile_steps='%s', stage='%s', " \
334
26c6f8e5d58e Added webcam_url and webcam_light fields to the mon_fermenters database table. Currently these fields need to be set using phpMyAdmin or another tool. If the webcam_url field is set, then on the mon_fermenter webpage a button is added to show a webcam page.
Michiel Broek <mbroek@mbse.eu>
parents: 299
diff changeset
577 "yeast_lo='%.1f', yeast_hi='%.1f', webcam_url='%s', webcam_light='%d'",
572
7a03181d29a3 Version 0.3.27 More code for iSpindels. All online/offline data in the database is now handles as integers. Nodes timeout use the configured interval time from the nodes.
Michiel Broek <mbroek@mbse.eu>
parents: 567
diff changeset
578 fermenter->uuid, fermenter->alias, fermenter->node, fermenter->online ? 1:0,
0
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
579 fermenter->beercode ? fermenter->beercode : "", fermenter->beername ? fermenter->beername : "",
192
7f69b43e6084 Implemented beer uuid product in monitor fermenters.
Michiel Broek <mbroek@mbse.eu>
parents: 76
diff changeset
580 fermenter->beeruuid ? fermenter->beeruuid : "",
718
59b02b64131b Version 0.3.36. Removed debug logs for websocket received messages. Fixed some default enum values send to the MySQL server.
Michiel Broek <mbroek@mbse.eu>
parents: 705
diff changeset
581 fermenter->air_address ? fermenter->air_address : "", fermenter->air_state ? fermenter->air_state : "MISSING", fermenter->air_temperature,
59b02b64131b Version 0.3.36. Removed debug logs for websocket received messages. Fixed some default enum values send to the MySQL server.
Michiel Broek <mbroek@mbse.eu>
parents: 705
diff changeset
582 fermenter->beer_address ? fermenter->beer_address : "", fermenter->beer_state ? fermenter->beer_state : "MISSING", fermenter->beer_temperature,
59b02b64131b Version 0.3.36. Removed debug logs for websocket received messages. Fixed some default enum values send to the MySQL server.
Michiel Broek <mbroek@mbse.eu>
parents: 705
diff changeset
583 fermenter->chiller_address ? fermenter->chiller_address : "", fermenter->chiller_state ? fermenter->chiller_state : "MISSING", fermenter->chiller_temperature,
0
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
584 fermenter->heater_address ? fermenter->heater_address : "", fermenter->heater_state, fermenter->heater_usage,
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
585 fermenter->cooler_address ? fermenter->cooler_address : "", fermenter->cooler_state, fermenter->cooler_usage,
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
586 fermenter->fan_address ? fermenter->fan_address : "", fermenter->fan_state, fermenter->fan_usage,
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
587 fermenter->light_address ? fermenter->light_address : "", fermenter->light_state, fermenter->light_usage,
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
588 fermenter->door_address ? fermenter->door_address : "", fermenter->door_state,
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
589 fermenter->psu_address ? fermenter->psu_address : "", fermenter->psu_state,
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
590 fermenter->mode, fermenter->alarm, fermenter->setpoint_high, fermenter->setpoint_low,
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
591 fermenter->profile_uuid ? fermenter->profile_uuid : "", fermenter->profile_name ? fermenter->profile_name : "",
718
59b02b64131b Version 0.3.36. Removed debug logs for websocket received messages. Fixed some default enum values send to the MySQL server.
Michiel Broek <mbroek@mbse.eu>
parents: 705
diff changeset
592 fermenter->profile_state ? fermenter->profile_state : "OFF", fermenter->profile_percent,
0
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
593 fermenter->profile_inittemp_high, fermenter->profile_inittemp_low,
334
26c6f8e5d58e Added webcam_url and webcam_light fields to the mon_fermenters database table. Currently these fields need to be set using phpMyAdmin or another tool. If the webcam_url field is set, then on the mon_fermenter webpage a button is added to show a webcam page.
Michiel Broek <mbroek@mbse.eu>
parents: 299
diff changeset
594 fermenter->profile_steps ? fermenter->profile_steps : "", fermenter->stage, fermenter->yeast_lo, fermenter->yeast_hi,
26c6f8e5d58e Added webcam_url and webcam_light fields to the mon_fermenters database table. Currently these fields need to be set using phpMyAdmin or another tool. If the webcam_url field is set, then on the mon_fermenter webpage a button is added to show a webcam page.
Michiel Broek <mbroek@mbse.eu>
parents: 299
diff changeset
595 fermenter->webcam_url ? fermenter->webcam_url : "", fermenter->webcam_light);
0
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
596
405
ef3f0274a1ea Added a private mysql_query function that does try to reconnect a lost MySQL connection.
Michiel Broek <mbroek@mbse.eu>
parents: 383
diff changeset
597 if (bms_mysql_query(query) == 0) {
0
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
598 syslog(LOG_NOTICE, "MySQL: insert new fermenter %s/%s", fermenter->node, fermenter->alias);
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
599 }
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
600 free(query);
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
601 }
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
602
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
603
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
604 void fermenter_mysql_update(sys_fermenter_list *fermenter)
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
605 {
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
606 char *query = malloc(2560);
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
607
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
608 snprintf(query, 2559,
572
7a03181d29a3 Version 0.3.27 More code for iSpindels. All online/offline data in the database is now handles as integers. Nodes timeout use the configured interval time from the nodes.
Michiel Broek <mbroek@mbse.eu>
parents: 567
diff changeset
609 "UPDATE mon_fermenters SET online='%d', beercode='%s', beername='%s', beeruuid='%s', " \
0
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
610 "air_address='%s', air_state='%s', air_temperature='%.3f', " \
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
611 "beer_address='%s', beer_state='%s', beer_temperature='%.3f', " \
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
612 "chiller_address='%s', chiller_state='%s', chiller_temperature='%.3f', " \
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
613 "heater_address='%s', heater_state='%d', heater_usage='%lu', " \
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
614 "cooler_address='%s', cooler_state='%d', cooler_usage='%lu', " \
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
615 "fan_address='%s', fan_state='%d', fan_usage='%lu', " \
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
616 "light_address='%s', light_state='%d', light_usage='%lu', " \
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
617 "door_address='%s', door_state='%d', " \
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
618 "psu_address='%s', psu_state='%d', " \
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
619 "mode='%s', alarm='%d', setpoint_high='%.3f', setpoint_low='%.3f', " \
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
620 "profile_uuid='%s', profile_name='%s', profile_state='%s', profile_percent='%d', " \
299
047ead629d4a Accept yeast temperature limits from thermferm via MQTT. Send yeat temperature ranges to thermferm together with the beer parameters. Store yeast temperature limits in the mon_fermenters database table. The monitor fermenters screen adjusts the temperature color ranges.
Michiel Broek <mbroek@mbse.eu>
parents: 194
diff changeset
621 "profile_inittemp_high='%.3f', profile_inittemp_low='%.3f', profile_steps='%s', stage='%s', " \
334
26c6f8e5d58e Added webcam_url and webcam_light fields to the mon_fermenters database table. Currently these fields need to be set using phpMyAdmin or another tool. If the webcam_url field is set, then on the mon_fermenter webpage a button is added to show a webcam page.
Michiel Broek <mbroek@mbse.eu>
parents: 299
diff changeset
622 "yeast_lo='%.1f', yeast_hi='%.1f', webcam_url='%s', webcam_light='%d' WHERE uuid='%s'",
572
7a03181d29a3 Version 0.3.27 More code for iSpindels. All online/offline data in the database is now handles as integers. Nodes timeout use the configured interval time from the nodes.
Michiel Broek <mbroek@mbse.eu>
parents: 567
diff changeset
623 fermenter->online ? 1:0, fermenter->beercode ? fermenter->beercode : "", fermenter->beername ? fermenter->beername : "",
192
7f69b43e6084 Implemented beer uuid product in monitor fermenters.
Michiel Broek <mbroek@mbse.eu>
parents: 76
diff changeset
624 fermenter->beeruuid ? fermenter->beeruuid : "",
705
d77b723f7b35 Make sure enumerated values are not empty in database updates. On several data queries set the database connection to UTF-8.
Michiel Broek <mbroek@mbse.eu>
parents: 703
diff changeset
625 fermenter->air_address ? fermenter->air_address : "", fermenter->air_state ? fermenter->air_state : "MISSING", fermenter->air_temperature,
d77b723f7b35 Make sure enumerated values are not empty in database updates. On several data queries set the database connection to UTF-8.
Michiel Broek <mbroek@mbse.eu>
parents: 703
diff changeset
626 fermenter->beer_address ? fermenter->beer_address : "", fermenter->beer_state ? fermenter->beer_state : "MISSING", fermenter->beer_temperature,
d77b723f7b35 Make sure enumerated values are not empty in database updates. On several data queries set the database connection to UTF-8.
Michiel Broek <mbroek@mbse.eu>
parents: 703
diff changeset
627 fermenter->chiller_address ? fermenter->chiller_address : "", fermenter->chiller_state ? fermenter->chiller_state : "MISSING", fermenter->chiller_temperature,
0
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
628 fermenter->heater_address ? fermenter->heater_address : "", fermenter->heater_state, fermenter->heater_usage,
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
629 fermenter->cooler_address ? fermenter->cooler_address : "", fermenter->cooler_state, fermenter->cooler_usage,
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
630 fermenter->fan_address ? fermenter->fan_address : "", fermenter->fan_state, fermenter->fan_usage,
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
631 fermenter->light_address ? fermenter->light_address : "", fermenter->light_state, fermenter->light_usage,
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
632 fermenter->door_address ? fermenter->door_address : "", fermenter->door_state,
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
633 fermenter->psu_address ? fermenter->psu_address : "", fermenter->psu_state,
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
634 fermenter->mode, fermenter->alarm, fermenter->setpoint_high, fermenter->setpoint_low,
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
635 fermenter->profile_uuid ? fermenter->profile_uuid : "", fermenter->profile_name ? fermenter->profile_name : "",
718
59b02b64131b Version 0.3.36. Removed debug logs for websocket received messages. Fixed some default enum values send to the MySQL server.
Michiel Broek <mbroek@mbse.eu>
parents: 705
diff changeset
636 fermenter->profile_state ? fermenter->profile_state : "OFF", fermenter->profile_percent,
0
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
637 fermenter->profile_inittemp_high, fermenter->profile_inittemp_low,
334
26c6f8e5d58e Added webcam_url and webcam_light fields to the mon_fermenters database table. Currently these fields need to be set using phpMyAdmin or another tool. If the webcam_url field is set, then on the mon_fermenter webpage a button is added to show a webcam page.
Michiel Broek <mbroek@mbse.eu>
parents: 299
diff changeset
638 fermenter->profile_steps ? fermenter->profile_steps : "", fermenter->stage, fermenter->yeast_lo, fermenter->yeast_hi,
26c6f8e5d58e Added webcam_url and webcam_light fields to the mon_fermenters database table. Currently these fields need to be set using phpMyAdmin or another tool. If the webcam_url field is set, then on the mon_fermenter webpage a button is added to show a webcam page.
Michiel Broek <mbroek@mbse.eu>
parents: 299
diff changeset
639 fermenter->webcam_url ? fermenter->webcam_url : "", fermenter->webcam_light, fermenter->uuid);
0
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
640
405
ef3f0274a1ea Added a private mysql_query function that does try to reconnect a lost MySQL connection.
Michiel Broek <mbroek@mbse.eu>
parents: 383
diff changeset
641 bms_mysql_query(query);
0
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
642 free(query);
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
643 }
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
644
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
645
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
646
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
647 void fermenter_mysql_death(char *node, char *alias)
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
648 {
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
649 char *query = malloc(512);
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
650
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
651 if (alias)
572
7a03181d29a3 Version 0.3.27 More code for iSpindels. All online/offline data in the database is now handles as integers. Nodes timeout use the configured interval time from the nodes.
Michiel Broek <mbroek@mbse.eu>
parents: 567
diff changeset
652 snprintf(query, 511, "UPDATE mon_fermenters SET online='0' WHERE node='%s' and alias='%s'", node, alias);
0
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
653 else
572
7a03181d29a3 Version 0.3.27 More code for iSpindels. All online/offline data in the database is now handles as integers. Nodes timeout use the configured interval time from the nodes.
Michiel Broek <mbroek@mbse.eu>
parents: 567
diff changeset
654 snprintf(query, 511, "UPDATE mon_fermenters SET online='0' WHERE node='%s'", node);
0
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
655
405
ef3f0274a1ea Added a private mysql_query function that does try to reconnect a lost MySQL connection.
Michiel Broek <mbroek@mbse.eu>
parents: 383
diff changeset
656 bms_mysql_query(query);
0
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
657 free(query);
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
658 }
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
659
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
660
502
a8a6901b5a99 Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents: 405
diff changeset
661
a8a6901b5a99 Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents: 405
diff changeset
662 void co2meter_mysql_insert(sys_co2meter_list *co2meter)
a8a6901b5a99 Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents: 405
diff changeset
663 {
a8a6901b5a99 Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents: 405
diff changeset
664 char *query = malloc(2560);
a8a6901b5a99 Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents: 405
diff changeset
665
a8a6901b5a99 Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents: 405
diff changeset
666 snprintf(query, 2559,
505
c09b67fd8323 Added CO2 meter units alarm led.
Michiel Broek <mbroek@mbse.eu>
parents: 502
diff changeset
667 "INSERT INTO mon_co2meters SET uuid='%s', alias='%s', node='%s', online='%d', mode='%s', alarm='%d', " \
502
a8a6901b5a99 Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents: 405
diff changeset
668 "temperature_address='%s', temperature_state='%s', temperature='%.3f', " \
a8a6901b5a99 Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents: 405
diff changeset
669 "pressure_state='%s', pressure_channel='%d', pressure_voltage='%.3f', pressure_zero='%.3f', pressure_bar='%.3f'",
505
c09b67fd8323 Added CO2 meter units alarm led.
Michiel Broek <mbroek@mbse.eu>
parents: 502
diff changeset
670 co2meter->uuid, co2meter->alias, co2meter->node, co2meter->online ? 1:0, co2meter->mode, co2meter->alarm,
502
a8a6901b5a99 Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents: 405
diff changeset
671 co2meter->temperature_address, co2meter->temperature_state, co2meter->temperature,
a8a6901b5a99 Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents: 405
diff changeset
672 co2meter->pressure_state, co2meter->pressure_channel, co2meter->pressure_voltage, co2meter->pressure_zero, co2meter->pressure_bar);
a8a6901b5a99 Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents: 405
diff changeset
673
a8a6901b5a99 Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents: 405
diff changeset
674 if (bms_mysql_query(query) == 0) {
a8a6901b5a99 Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents: 405
diff changeset
675 syslog(LOG_NOTICE, "MySQL: insert new co2meter %s/%s", co2meter->node, co2meter->alias);
a8a6901b5a99 Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents: 405
diff changeset
676 }
a8a6901b5a99 Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents: 405
diff changeset
677 free(query);
a8a6901b5a99 Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents: 405
diff changeset
678 }
a8a6901b5a99 Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents: 405
diff changeset
679
a8a6901b5a99 Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents: 405
diff changeset
680
a8a6901b5a99 Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents: 405
diff changeset
681
a8a6901b5a99 Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents: 405
diff changeset
682 void co2meter_mysql_update(sys_co2meter_list *co2meter)
a8a6901b5a99 Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents: 405
diff changeset
683 {
a8a6901b5a99 Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents: 405
diff changeset
684 char *query = malloc(2560);
a8a6901b5a99 Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents: 405
diff changeset
685
a8a6901b5a99 Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents: 405
diff changeset
686 snprintf(query, 2559,
505
c09b67fd8323 Added CO2 meter units alarm led.
Michiel Broek <mbroek@mbse.eu>
parents: 502
diff changeset
687 "UPDATE mon_co2meters SET online='%d', mode='%s', alarm='%d', " \
502
a8a6901b5a99 Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents: 405
diff changeset
688 "temperature_address='%s', temperature_state='%s', temperature='%.3f', " \
a8a6901b5a99 Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents: 405
diff changeset
689 "pressure_state='%s', pressure_channel='%d', pressure_voltage='%.3f', pressure_zero='%.3f', pressure_bar='%.3f' " \
a8a6901b5a99 Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents: 405
diff changeset
690 "WHERE uuid='%s'",
505
c09b67fd8323 Added CO2 meter units alarm led.
Michiel Broek <mbroek@mbse.eu>
parents: 502
diff changeset
691 co2meter->online ? 1:0, co2meter->mode, co2meter->alarm,
502
a8a6901b5a99 Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents: 405
diff changeset
692 co2meter->temperature_address, co2meter->temperature_state, co2meter->temperature,
a8a6901b5a99 Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents: 405
diff changeset
693 co2meter->pressure_state, co2meter->pressure_channel, co2meter->pressure_voltage, co2meter->pressure_zero, co2meter->pressure_bar,
a8a6901b5a99 Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents: 405
diff changeset
694 co2meter->uuid);
a8a6901b5a99 Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents: 405
diff changeset
695
a8a6901b5a99 Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents: 405
diff changeset
696 bms_mysql_query(query);
a8a6901b5a99 Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents: 405
diff changeset
697 free(query);
a8a6901b5a99 Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents: 405
diff changeset
698 }
a8a6901b5a99 Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents: 405
diff changeset
699
a8a6901b5a99 Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents: 405
diff changeset
700
a8a6901b5a99 Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents: 405
diff changeset
701
a8a6901b5a99 Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents: 405
diff changeset
702 void co2meter_mysql_death(char *node, char *alias)
a8a6901b5a99 Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents: 405
diff changeset
703 {
a8a6901b5a99 Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents: 405
diff changeset
704 char *query = malloc(512);
a8a6901b5a99 Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents: 405
diff changeset
705
a8a6901b5a99 Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents: 405
diff changeset
706 if (alias)
a8a6901b5a99 Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents: 405
diff changeset
707 snprintf(query, 511, "UPDATE mon_co2meters SET online='0' WHERE node='%s' and alias='%s'", node, alias);
a8a6901b5a99 Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents: 405
diff changeset
708 else
a8a6901b5a99 Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents: 405
diff changeset
709 snprintf(query, 511, "UPDATE mon_co2meters SET online='0' WHERE node='%s'", node);
a8a6901b5a99 Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents: 405
diff changeset
710
a8a6901b5a99 Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents: 405
diff changeset
711 bms_mysql_query(query);
a8a6901b5a99 Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents: 405
diff changeset
712 free(query);
a8a6901b5a99 Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents: 405
diff changeset
713 }
a8a6901b5a99 Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents: 405
diff changeset
714
a8a6901b5a99 Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents: 405
diff changeset
715
567
6bf0afc33e70 Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents: 558
diff changeset
716
849
16079aef4c4c Version 0.3.44. Moved iSpindel Plato calculation from the php script to bmsd. This uses calibration data in the mon_ispindels table. Setup of this data will be done by the bmsapp applications. Default settings are stored in MySQL. From now on you don't need to store calibration data in the iSpindel.
Michiel Broek <mbroek@mbse.eu>
parents: 844
diff changeset
717 /*
16079aef4c4c Version 0.3.44. Moved iSpindel Plato calculation from the php script to bmsd. This uses calibration data in the mon_ispindels table. Setup of this data will be done by the bmsapp applications. Default settings are stored in MySQL. From now on you don't need to store calibration data in the iSpindel.
Michiel Broek <mbroek@mbse.eu>
parents: 844
diff changeset
718 * Update the gravity calculated from the calibrate data.
16079aef4c4c Version 0.3.44. Moved iSpindel Plato calculation from the php script to bmsd. This uses calibration data in the mon_ispindels table. Setup of this data will be done by the bmsapp applications. Default settings are stored in MySQL. From now on you don't need to store calibration data in the iSpindel.
Michiel Broek <mbroek@mbse.eu>
parents: 844
diff changeset
719 */
16079aef4c4c Version 0.3.44. Moved iSpindel Plato calculation from the php script to bmsd. This uses calibration data in the mon_ispindels table. Setup of this data will be done by the bmsapp applications. Default settings are stored in MySQL. From now on you don't need to store calibration data in the iSpindel.
Michiel Broek <mbroek@mbse.eu>
parents: 844
diff changeset
720 double ispindel_mysql_plato(char *uuid, double angle)
16079aef4c4c Version 0.3.44. Moved iSpindel Plato calculation from the php script to bmsd. This uses calibration data in the mon_ispindels table. Setup of this data will be done by the bmsapp applications. Default settings are stored in MySQL. From now on you don't need to store calibration data in the iSpindel.
Michiel Broek <mbroek@mbse.eu>
parents: 844
diff changeset
721 {
16079aef4c4c Version 0.3.44. Moved iSpindel Plato calculation from the php script to bmsd. This uses calibration data in the mon_ispindels table. Setup of this data will be done by the bmsapp applications. Default settings are stored in MySQL. From now on you don't need to store calibration data in the iSpindel.
Michiel Broek <mbroek@mbse.eu>
parents: 844
diff changeset
722 char *query = malloc(1024), *cal;
16079aef4c4c Version 0.3.44. Moved iSpindel Plato calculation from the php script to bmsd. This uses calibration data in the mon_ispindels table. Setup of this data will be done by the bmsapp applications. Default settings are stored in MySQL. From now on you don't need to store calibration data in the iSpindel.
Michiel Broek <mbroek@mbse.eu>
parents: 844
diff changeset
723 struct json_object *jobj, *metric, *val;
16079aef4c4c Version 0.3.44. Moved iSpindel Plato calculation from the php script to bmsd. This uses calibration data in the mon_ispindels table. Setup of this data will be done by the bmsapp applications. Default settings are stored in MySQL. From now on you don't need to store calibration data in the iSpindel.
Michiel Broek <mbroek@mbse.eu>
parents: 844
diff changeset
724 double poly[4], plato = 0;
16079aef4c4c Version 0.3.44. Moved iSpindel Plato calculation from the php script to bmsd. This uses calibration data in the mon_ispindels table. Setup of this data will be done by the bmsapp applications. Default settings are stored in MySQL. From now on you don't need to store calibration data in the iSpindel.
Michiel Broek <mbroek@mbse.eu>
parents: 844
diff changeset
725
16079aef4c4c Version 0.3.44. Moved iSpindel Plato calculation from the php script to bmsd. This uses calibration data in the mon_ispindels table. Setup of this data will be done by the bmsapp applications. Default settings are stored in MySQL. From now on you don't need to store calibration data in the iSpindel.
Michiel Broek <mbroek@mbse.eu>
parents: 844
diff changeset
726 snprintf(query, 1023, "SELECT uuid,calibrate FROM mon_ispindels WHERE uuid='%s'", uuid);
16079aef4c4c Version 0.3.44. Moved iSpindel Plato calculation from the php script to bmsd. This uses calibration data in the mon_ispindels table. Setup of this data will be done by the bmsapp applications. Default settings are stored in MySQL. From now on you don't need to store calibration data in the iSpindel.
Michiel Broek <mbroek@mbse.eu>
parents: 844
diff changeset
727 if (mysql_query(con, query)) {
16079aef4c4c Version 0.3.44. Moved iSpindel Plato calculation from the php script to bmsd. This uses calibration data in the mon_ispindels table. Setup of this data will be done by the bmsapp applications. Default settings are stored in MySQL. From now on you don't need to store calibration data in the iSpindel.
Michiel Broek <mbroek@mbse.eu>
parents: 844
diff changeset
728 syslog(LOG_NOTICE, "MySQL: %s error %u (%s))", query, mysql_errno(con), mysql_error(con));
16079aef4c4c Version 0.3.44. Moved iSpindel Plato calculation from the php script to bmsd. This uses calibration data in the mon_ispindels table. Setup of this data will be done by the bmsapp applications. Default settings are stored in MySQL. From now on you don't need to store calibration data in the iSpindel.
Michiel Broek <mbroek@mbse.eu>
parents: 844
diff changeset
729 free(query);
16079aef4c4c Version 0.3.44. Moved iSpindel Plato calculation from the php script to bmsd. This uses calibration data in the mon_ispindels table. Setup of this data will be done by the bmsapp applications. Default settings are stored in MySQL. From now on you don't need to store calibration data in the iSpindel.
Michiel Broek <mbroek@mbse.eu>
parents: 844
diff changeset
730 return 0.0;
16079aef4c4c Version 0.3.44. Moved iSpindel Plato calculation from the php script to bmsd. This uses calibration data in the mon_ispindels table. Setup of this data will be done by the bmsapp applications. Default settings are stored in MySQL. From now on you don't need to store calibration data in the iSpindel.
Michiel Broek <mbroek@mbse.eu>
parents: 844
diff changeset
731 }
16079aef4c4c Version 0.3.44. Moved iSpindel Plato calculation from the php script to bmsd. This uses calibration data in the mon_ispindels table. Setup of this data will be done by the bmsapp applications. Default settings are stored in MySQL. From now on you don't need to store calibration data in the iSpindel.
Michiel Broek <mbroek@mbse.eu>
parents: 844
diff changeset
732
16079aef4c4c Version 0.3.44. Moved iSpindel Plato calculation from the php script to bmsd. This uses calibration data in the mon_ispindels table. Setup of this data will be done by the bmsapp applications. Default settings are stored in MySQL. From now on you don't need to store calibration data in the iSpindel.
Michiel Broek <mbroek@mbse.eu>
parents: 844
diff changeset
733 res_set = mysql_store_result(con);
16079aef4c4c Version 0.3.44. Moved iSpindel Plato calculation from the php script to bmsd. This uses calibration data in the mon_ispindels table. Setup of this data will be done by the bmsapp applications. Default settings are stored in MySQL. From now on you don't need to store calibration data in the iSpindel.
Michiel Broek <mbroek@mbse.eu>
parents: 844
diff changeset
734 if (res_set == NULL) {
16079aef4c4c Version 0.3.44. Moved iSpindel Plato calculation from the php script to bmsd. This uses calibration data in the mon_ispindels table. Setup of this data will be done by the bmsapp applications. Default settings are stored in MySQL. From now on you don't need to store calibration data in the iSpindel.
Michiel Broek <mbroek@mbse.eu>
parents: 844
diff changeset
735 syslog(LOG_NOTICE, "MySQL: mysq_store_result error %u (%s))", mysql_errno(con), mysql_error(con));
16079aef4c4c Version 0.3.44. Moved iSpindel Plato calculation from the php script to bmsd. This uses calibration data in the mon_ispindels table. Setup of this data will be done by the bmsapp applications. Default settings are stored in MySQL. From now on you don't need to store calibration data in the iSpindel.
Michiel Broek <mbroek@mbse.eu>
parents: 844
diff changeset
736 free(query);
16079aef4c4c Version 0.3.44. Moved iSpindel Plato calculation from the php script to bmsd. This uses calibration data in the mon_ispindels table. Setup of this data will be done by the bmsapp applications. Default settings are stored in MySQL. From now on you don't need to store calibration data in the iSpindel.
Michiel Broek <mbroek@mbse.eu>
parents: 844
diff changeset
737 return 0.0;
16079aef4c4c Version 0.3.44. Moved iSpindel Plato calculation from the php script to bmsd. This uses calibration data in the mon_ispindels table. Setup of this data will be done by the bmsapp applications. Default settings are stored in MySQL. From now on you don't need to store calibration data in the iSpindel.
Michiel Broek <mbroek@mbse.eu>
parents: 844
diff changeset
738 }
16079aef4c4c Version 0.3.44. Moved iSpindel Plato calculation from the php script to bmsd. This uses calibration data in the mon_ispindels table. Setup of this data will be done by the bmsapp applications. Default settings are stored in MySQL. From now on you don't need to store calibration data in the iSpindel.
Michiel Broek <mbroek@mbse.eu>
parents: 844
diff changeset
739 free(query);
16079aef4c4c Version 0.3.44. Moved iSpindel Plato calculation from the php script to bmsd. This uses calibration data in the mon_ispindels table. Setup of this data will be done by the bmsapp applications. Default settings are stored in MySQL. From now on you don't need to store calibration data in the iSpindel.
Michiel Broek <mbroek@mbse.eu>
parents: 844
diff changeset
740
16079aef4c4c Version 0.3.44. Moved iSpindel Plato calculation from the php script to bmsd. This uses calibration data in the mon_ispindels table. Setup of this data will be done by the bmsapp applications. Default settings are stored in MySQL. From now on you don't need to store calibration data in the iSpindel.
Michiel Broek <mbroek@mbse.eu>
parents: 844
diff changeset
741 if ((row = mysql_fetch_row(res_set)) != NULL) {
16079aef4c4c Version 0.3.44. Moved iSpindel Plato calculation from the php script to bmsd. This uses calibration data in the mon_ispindels table. Setup of this data will be done by the bmsapp applications. Default settings are stored in MySQL. From now on you don't need to store calibration data in the iSpindel.
Michiel Broek <mbroek@mbse.eu>
parents: 844
diff changeset
742 cal = xstrcpy(row[1]);
16079aef4c4c Version 0.3.44. Moved iSpindel Plato calculation from the php script to bmsd. This uses calibration data in the mon_ispindels table. Setup of this data will be done by the bmsapp applications. Default settings are stored in MySQL. From now on you don't need to store calibration data in the iSpindel.
Michiel Broek <mbroek@mbse.eu>
parents: 844
diff changeset
743 jobj = json_tokener_parse(cal);
16079aef4c4c Version 0.3.44. Moved iSpindel Plato calculation from the php script to bmsd. This uses calibration data in the mon_ispindels table. Setup of this data will be done by the bmsapp applications. Default settings are stored in MySQL. From now on you don't need to store calibration data in the iSpindel.
Michiel Broek <mbroek@mbse.eu>
parents: 844
diff changeset
744 if (json_object_object_get_ex(jobj, "polyData", &metric)) {
16079aef4c4c Version 0.3.44. Moved iSpindel Plato calculation from the php script to bmsd. This uses calibration data in the mon_ispindels table. Setup of this data will be done by the bmsapp applications. Default settings are stored in MySQL. From now on you don't need to store calibration data in the iSpindel.
Michiel Broek <mbroek@mbse.eu>
parents: 844
diff changeset
745 int arraylen = json_object_array_length(metric);
16079aef4c4c Version 0.3.44. Moved iSpindel Plato calculation from the php script to bmsd. This uses calibration data in the mon_ispindels table. Setup of this data will be done by the bmsapp applications. Default settings are stored in MySQL. From now on you don't need to store calibration data in the iSpindel.
Michiel Broek <mbroek@mbse.eu>
parents: 844
diff changeset
746 for (int i = 0; i < arraylen; i++) {
16079aef4c4c Version 0.3.44. Moved iSpindel Plato calculation from the php script to bmsd. This uses calibration data in the mon_ispindels table. Setup of this data will be done by the bmsapp applications. Default settings are stored in MySQL. From now on you don't need to store calibration data in the iSpindel.
Michiel Broek <mbroek@mbse.eu>
parents: 844
diff changeset
747 val = json_object_array_get_idx(metric, i);
16079aef4c4c Version 0.3.44. Moved iSpindel Plato calculation from the php script to bmsd. This uses calibration data in the mon_ispindels table. Setup of this data will be done by the bmsapp applications. Default settings are stored in MySQL. From now on you don't need to store calibration data in the iSpindel.
Michiel Broek <mbroek@mbse.eu>
parents: 844
diff changeset
748 poly[i] = json_object_get_double(val);
16079aef4c4c Version 0.3.44. Moved iSpindel Plato calculation from the php script to bmsd. This uses calibration data in the mon_ispindels table. Setup of this data will be done by the bmsapp applications. Default settings are stored in MySQL. From now on you don't need to store calibration data in the iSpindel.
Michiel Broek <mbroek@mbse.eu>
parents: 844
diff changeset
749 }
16079aef4c4c Version 0.3.44. Moved iSpindel Plato calculation from the php script to bmsd. This uses calibration data in the mon_ispindels table. Setup of this data will be done by the bmsapp applications. Default settings are stored in MySQL. From now on you don't need to store calibration data in the iSpindel.
Michiel Broek <mbroek@mbse.eu>
parents: 844
diff changeset
750 plato = (poly[0] * pow(angle, 3)) + (poly[1] * pow(angle, 2)) + (poly[2] * angle) + poly[3];
16079aef4c4c Version 0.3.44. Moved iSpindel Plato calculation from the php script to bmsd. This uses calibration data in the mon_ispindels table. Setup of this data will be done by the bmsapp applications. Default settings are stored in MySQL. From now on you don't need to store calibration data in the iSpindel.
Michiel Broek <mbroek@mbse.eu>
parents: 844
diff changeset
751 }
16079aef4c4c Version 0.3.44. Moved iSpindel Plato calculation from the php script to bmsd. This uses calibration data in the mon_ispindels table. Setup of this data will be done by the bmsapp applications. Default settings are stored in MySQL. From now on you don't need to store calibration data in the iSpindel.
Michiel Broek <mbroek@mbse.eu>
parents: 844
diff changeset
752 free(cal);
16079aef4c4c Version 0.3.44. Moved iSpindel Plato calculation from the php script to bmsd. This uses calibration data in the mon_ispindels table. Setup of this data will be done by the bmsapp applications. Default settings are stored in MySQL. From now on you don't need to store calibration data in the iSpindel.
Michiel Broek <mbroek@mbse.eu>
parents: 844
diff changeset
753 }
16079aef4c4c Version 0.3.44. Moved iSpindel Plato calculation from the php script to bmsd. This uses calibration data in the mon_ispindels table. Setup of this data will be done by the bmsapp applications. Default settings are stored in MySQL. From now on you don't need to store calibration data in the iSpindel.
Michiel Broek <mbroek@mbse.eu>
parents: 844
diff changeset
754 return plato;
16079aef4c4c Version 0.3.44. Moved iSpindel Plato calculation from the php script to bmsd. This uses calibration data in the mon_ispindels table. Setup of this data will be done by the bmsapp applications. Default settings are stored in MySQL. From now on you don't need to store calibration data in the iSpindel.
Michiel Broek <mbroek@mbse.eu>
parents: 844
diff changeset
755 }
16079aef4c4c Version 0.3.44. Moved iSpindel Plato calculation from the php script to bmsd. This uses calibration data in the mon_ispindels table. Setup of this data will be done by the bmsapp applications. Default settings are stored in MySQL. From now on you don't need to store calibration data in the iSpindel.
Michiel Broek <mbroek@mbse.eu>
parents: 844
diff changeset
756
16079aef4c4c Version 0.3.44. Moved iSpindel Plato calculation from the php script to bmsd. This uses calibration data in the mon_ispindels table. Setup of this data will be done by the bmsapp applications. Default settings are stored in MySQL. From now on you don't need to store calibration data in the iSpindel.
Michiel Broek <mbroek@mbse.eu>
parents: 844
diff changeset
757
567
6bf0afc33e70 Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents: 558
diff changeset
758 void ispindel_mysql_insert(sys_ispindel_list *ispindel)
6bf0afc33e70 Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents: 558
diff changeset
759 {
849
16079aef4c4c Version 0.3.44. Moved iSpindel Plato calculation from the php script to bmsd. This uses calibration data in the mon_ispindels table. Setup of this data will be done by the bmsapp applications. Default settings are stored in MySQL. From now on you don't need to store calibration data in the iSpindel.
Michiel Broek <mbroek@mbse.eu>
parents: 844
diff changeset
760 char *query = malloc(2560), last[73];
16079aef4c4c Version 0.3.44. Moved iSpindel Plato calculation from the php script to bmsd. This uses calibration data in the mon_ispindels table. Setup of this data will be done by the bmsapp applications. Default settings are stored in MySQL. From now on you don't need to store calibration data in the iSpindel.
Michiel Broek <mbroek@mbse.eu>
parents: 844
diff changeset
761 struct tm *mytime;
16079aef4c4c Version 0.3.44. Moved iSpindel Plato calculation from the php script to bmsd. This uses calibration data in the mon_ispindels table. Setup of this data will be done by the bmsapp applications. Default settings are stored in MySQL. From now on you don't need to store calibration data in the iSpindel.
Michiel Broek <mbroek@mbse.eu>
parents: 844
diff changeset
762
16079aef4c4c Version 0.3.44. Moved iSpindel Plato calculation from the php script to bmsd. This uses calibration data in the mon_ispindels table. Setup of this data will be done by the bmsapp applications. Default settings are stored in MySQL. From now on you don't need to store calibration data in the iSpindel.
Michiel Broek <mbroek@mbse.eu>
parents: 844
diff changeset
763 mytime = localtime(&ispindel->lastseen);
16079aef4c4c Version 0.3.44. Moved iSpindel Plato calculation from the php script to bmsd. This uses calibration data in the mon_ispindels table. Setup of this data will be done by the bmsapp applications. Default settings are stored in MySQL. From now on you don't need to store calibration data in the iSpindel.
Michiel Broek <mbroek@mbse.eu>
parents: 844
diff changeset
764 snprintf(last, 64, "%04d-%02d-%02d %02d:%02d:%02d",
16079aef4c4c Version 0.3.44. Moved iSpindel Plato calculation from the php script to bmsd. This uses calibration data in the mon_ispindels table. Setup of this data will be done by the bmsapp applications. Default settings are stored in MySQL. From now on you don't need to store calibration data in the iSpindel.
Michiel Broek <mbroek@mbse.eu>
parents: 844
diff changeset
765 mytime->tm_year + 1900, mytime->tm_mon + 1, mytime->tm_mday, mytime->tm_hour, mytime->tm_min, mytime->tm_sec);
567
6bf0afc33e70 Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents: 558
diff changeset
766
6bf0afc33e70 Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents: 558
diff changeset
767 snprintf(query, 2559,
578
e75ce5bbda73 Changed the interface from the iSpindels to be the same as other devices. A webpage converts each call to two standard MQTT messages. The nodes MQTT message extended with an interval parameter. iSpindels now have a generated uuid made up from the chipid.
Michiel Broek <mbroek@mbse.eu>
parents: 572
diff changeset
768 "INSERT INTO mon_ispindels SET uuid='%s', alias='%s', node='%s', online='%d', mode='%s', alarm='%d', " \
843
29e7223e37ae Version 0.3.42 added yeast_lo and yeast_hi fields to the iSpindel records and structures.
Michiel Broek <mbroek@mbse.eu>
parents: 799
diff changeset
769 "angle='%.6f', temperature='%.4f', battery='%.6f', gravity='%.6f', up_interval='%d', og_gravity='0.0', " \
849
16079aef4c4c Version 0.3.44. Moved iSpindel Plato calculation from the php script to bmsd. This uses calibration data in the mon_ispindels table. Setup of this data will be done by the bmsapp applications. Default settings are stored in MySQL. From now on you don't need to store calibration data in the iSpindel.
Michiel Broek <mbroek@mbse.eu>
parents: 844
diff changeset
770 "yeast_lo='%.1f', yeast_hi='%.1f', lastseen='%s'",
578
e75ce5bbda73 Changed the interface from the iSpindels to be the same as other devices. A webpage converts each call to two standard MQTT messages. The nodes MQTT message extended with an interval parameter. iSpindels now have a generated uuid made up from the chipid.
Michiel Broek <mbroek@mbse.eu>
parents: 572
diff changeset
771 ispindel->uuid, ispindel->alias, ispindel->node, ispindel->online ? 1:0, ispindel->mode, ispindel->alarm,
843
29e7223e37ae Version 0.3.42 added yeast_lo and yeast_hi fields to the iSpindel records and structures.
Michiel Broek <mbroek@mbse.eu>
parents: 799
diff changeset
772 ispindel->angle, ispindel->temperature, ispindel->battery, ispindel->gravity, ispindel->interval,
849
16079aef4c4c Version 0.3.44. Moved iSpindel Plato calculation from the php script to bmsd. This uses calibration data in the mon_ispindels table. Setup of this data will be done by the bmsapp applications. Default settings are stored in MySQL. From now on you don't need to store calibration data in the iSpindel.
Michiel Broek <mbroek@mbse.eu>
parents: 844
diff changeset
773 ispindel->yeast_lo, ispindel->yeast_hi, last);
567
6bf0afc33e70 Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents: 558
diff changeset
774
6bf0afc33e70 Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents: 558
diff changeset
775 if (bms_mysql_query(query) == 0) {
6bf0afc33e70 Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents: 558
diff changeset
776 syslog(LOG_NOTICE, "MySQL: insert new ispindel %s", ispindel->node);
6bf0afc33e70 Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents: 558
diff changeset
777 }
6bf0afc33e70 Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents: 558
diff changeset
778 free(query);
6bf0afc33e70 Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents: 558
diff changeset
779 }
6bf0afc33e70 Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents: 558
diff changeset
780
6bf0afc33e70 Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents: 558
diff changeset
781
6bf0afc33e70 Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents: 558
diff changeset
782
6bf0afc33e70 Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents: 558
diff changeset
783 void ispindel_mysql_update(sys_ispindel_list *ispindel)
6bf0afc33e70 Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents: 558
diff changeset
784 {
849
16079aef4c4c Version 0.3.44. Moved iSpindel Plato calculation from the php script to bmsd. This uses calibration data in the mon_ispindels table. Setup of this data will be done by the bmsapp applications. Default settings are stored in MySQL. From now on you don't need to store calibration data in the iSpindel.
Michiel Broek <mbroek@mbse.eu>
parents: 844
diff changeset
785 char *query = malloc(2560), last[73];
16079aef4c4c Version 0.3.44. Moved iSpindel Plato calculation from the php script to bmsd. This uses calibration data in the mon_ispindels table. Setup of this data will be done by the bmsapp applications. Default settings are stored in MySQL. From now on you don't need to store calibration data in the iSpindel.
Michiel Broek <mbroek@mbse.eu>
parents: 844
diff changeset
786 struct tm *mytime;
567
6bf0afc33e70 Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents: 558
diff changeset
787
849
16079aef4c4c Version 0.3.44. Moved iSpindel Plato calculation from the php script to bmsd. This uses calibration data in the mon_ispindels table. Setup of this data will be done by the bmsapp applications. Default settings are stored in MySQL. From now on you don't need to store calibration data in the iSpindel.
Michiel Broek <mbroek@mbse.eu>
parents: 844
diff changeset
788 mytime = localtime(&ispindel->lastseen);
16079aef4c4c Version 0.3.44. Moved iSpindel Plato calculation from the php script to bmsd. This uses calibration data in the mon_ispindels table. Setup of this data will be done by the bmsapp applications. Default settings are stored in MySQL. From now on you don't need to store calibration data in the iSpindel.
Michiel Broek <mbroek@mbse.eu>
parents: 844
diff changeset
789 snprintf(last, 64, "%04d-%02d-%02d %02d:%02d:%02d",
16079aef4c4c Version 0.3.44. Moved iSpindel Plato calculation from the php script to bmsd. This uses calibration data in the mon_ispindels table. Setup of this data will be done by the bmsapp applications. Default settings are stored in MySQL. From now on you don't need to store calibration data in the iSpindel.
Michiel Broek <mbroek@mbse.eu>
parents: 844
diff changeset
790 mytime->tm_year + 1900, mytime->tm_mon + 1, mytime->tm_mday, mytime->tm_hour, mytime->tm_min, mytime->tm_sec);
16079aef4c4c Version 0.3.44. Moved iSpindel Plato calculation from the php script to bmsd. This uses calibration data in the mon_ispindels table. Setup of this data will be done by the bmsapp applications. Default settings are stored in MySQL. From now on you don't need to store calibration data in the iSpindel.
Michiel Broek <mbroek@mbse.eu>
parents: 844
diff changeset
791
16079aef4c4c Version 0.3.44. Moved iSpindel Plato calculation from the php script to bmsd. This uses calibration data in the mon_ispindels table. Setup of this data will be done by the bmsapp applications. Default settings are stored in MySQL. From now on you don't need to store calibration data in the iSpindel.
Michiel Broek <mbroek@mbse.eu>
parents: 844
diff changeset
792 /*
16079aef4c4c Version 0.3.44. Moved iSpindel Plato calculation from the php script to bmsd. This uses calibration data in the mon_ispindels table. Setup of this data will be done by the bmsapp applications. Default settings are stored in MySQL. From now on you don't need to store calibration data in the iSpindel.
Michiel Broek <mbroek@mbse.eu>
parents: 844
diff changeset
793 * Do not update the calibrate field with regular updates.
16079aef4c4c Version 0.3.44. Moved iSpindel Plato calculation from the php script to bmsd. This uses calibration data in the mon_ispindels table. Setup of this data will be done by the bmsapp applications. Default settings are stored in MySQL. From now on you don't need to store calibration data in the iSpindel.
Michiel Broek <mbroek@mbse.eu>
parents: 844
diff changeset
794 */
567
6bf0afc33e70 Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents: 558
diff changeset
795 snprintf(query, 2559,
680
0bb48333d133 Fixed missing co2meters websocket data. Added websockets and removed polling for the mon-ispindel screen. The iSpindel SG gauge adjusts the resolution to the highest detected OG.
Michiel Broek <mbroek@mbse.eu>
parents: 628
diff changeset
796 "UPDATE mon_ispindels SET online='%d', mode='%s', alias='%s', alarm='%d', " \
843
29e7223e37ae Version 0.3.42 added yeast_lo and yeast_hi fields to the iSpindel records and structures.
Michiel Broek <mbroek@mbse.eu>
parents: 799
diff changeset
797 "angle='%.6f', temperature='%.4f', battery='%.6f', gravity='%.6f', up_interval='%d', og_gravity=GREATEST(og_gravity, '%.6f'), " \
849
16079aef4c4c Version 0.3.44. Moved iSpindel Plato calculation from the php script to bmsd. This uses calibration data in the mon_ispindels table. Setup of this data will be done by the bmsapp applications. Default settings are stored in MySQL. From now on you don't need to store calibration data in the iSpindel.
Michiel Broek <mbroek@mbse.eu>
parents: 844
diff changeset
798 "yeast_lo='%.1f', yeast_hi='%.1f', lastseen='%s' WHERE uuid='%s'",
680
0bb48333d133 Fixed missing co2meters websocket data. Added websockets and removed polling for the mon-ispindel screen. The iSpindel SG gauge adjusts the resolution to the highest detected OG.
Michiel Broek <mbroek@mbse.eu>
parents: 628
diff changeset
799 ispindel->online ? 1:0, ispindel->mode, ispindel->alias, ispindel->alarm,
843
29e7223e37ae Version 0.3.42 added yeast_lo and yeast_hi fields to the iSpindel records and structures.
Michiel Broek <mbroek@mbse.eu>
parents: 799
diff changeset
800 ispindel->angle, ispindel->temperature, ispindel->battery, ispindel->gravity, ispindel->interval, ispindel->gravity,
849
16079aef4c4c Version 0.3.44. Moved iSpindel Plato calculation from the php script to bmsd. This uses calibration data in the mon_ispindels table. Setup of this data will be done by the bmsapp applications. Default settings are stored in MySQL. From now on you don't need to store calibration data in the iSpindel.
Michiel Broek <mbroek@mbse.eu>
parents: 844
diff changeset
801 ispindel->yeast_lo, ispindel->yeast_hi, last, ispindel->uuid);
567
6bf0afc33e70 Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents: 558
diff changeset
802 bms_mysql_query(query);
6bf0afc33e70 Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents: 558
diff changeset
803 free(query);
6bf0afc33e70 Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents: 558
diff changeset
804 }
6bf0afc33e70 Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents: 558
diff changeset
805
6bf0afc33e70 Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents: 558
diff changeset
806
6bf0afc33e70 Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents: 558
diff changeset
807
580
9cd6873bda75 Fixed ispindel_death. Added ispindel log graph.
Michiel Broek <mbroek@mbse.eu>
parents: 579
diff changeset
808 void ispindel_mysql_death(char *node)
567
6bf0afc33e70 Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents: 558
diff changeset
809 {
6bf0afc33e70 Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents: 558
diff changeset
810 char *query = malloc(512);
6bf0afc33e70 Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents: 558
diff changeset
811
580
9cd6873bda75 Fixed ispindel_death. Added ispindel log graph.
Michiel Broek <mbroek@mbse.eu>
parents: 579
diff changeset
812 snprintf(query, 511, "UPDATE mon_ispindels SET online='0' WHERE node='%s'", node);
567
6bf0afc33e70 Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents: 558
diff changeset
813 bms_mysql_query(query);
6bf0afc33e70 Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents: 558
diff changeset
814 free(query);
6bf0afc33e70 Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents: 558
diff changeset
815 }
579
1253a237b620 Added check for database changes for iSpindels such as a new beer, or changing mode. Added denity in Plato and SG to the iSpindel web screen. The iSpindels must be calibrated in Plato! A bit of documentation updated.
Michiel Broek <mbroek@mbse.eu>
parents: 578
diff changeset
816

mercurial