Fri, 21 Aug 2020 10:55:36 +0200
Removed some debug messages in products and recipes
0 | 1 | /** |
2 | * @file mysql.c | |
3 | * @brief MySQL/MariaDB access. | |
4 | * @author Michiel Broek <mbroek at mbse dot eu> | |
5 | * | |
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
|
6 | * Copyright (C) 2018-2020 |
0 | 7 | * |
8 | * This file is part of the bms (Brewery Management System) | |
9 | * | |
10 | * This is free software; you can redistribute it and/or modify it | |
11 | * under the terms of the GNU General Public License as published by the | |
12 | * Free Software Foundation; either version 2, or (at your option) any | |
13 | * later version. | |
14 | * | |
15 | * bms is distributed in the hope that it will be useful, but | |
16 | * WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
18 | * General Public License for more details. | |
19 | * | |
20 | * You should have received a copy of the GNU General Public License | |
21 | * along with ThermFerm; see the file COPYING. If not, write to the Free | |
22 | * Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. | |
23 | */ | |
24 | ||
25 | #include "bms.h" | |
26 | #include "xutil.h" | |
27 | #include "mysql.h" | |
28 | #include "nodes.h" | |
29 | ||
30 | ||
31 | MYSQL *con = NULL; | |
32 | MYSQL_RES *res_set; | |
33 | MYSQL_ROW row; | |
34 | ||
35 | extern sys_config Config; | |
36 | extern sys_node_list *nodes; | |
37 | extern sys_fermenter_list *fermenters; | |
502
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
38 | extern sys_co2meter_list *co2meters; |
567
6bf0afc33e70
Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
558
diff
changeset
|
39 | extern sys_ispindel_list *ispindels; |
0 | 40 | extern int debug; |
41 | ||
42 | ||
43 | time_t datetime_to_time_t(char *dt_string) | |
44 | { | |
45 | struct tm tm; | |
46 | ||
47 | memset(&tm, 0, sizeof(struct tm)); | |
48 | tm.tm_year = atoi(strtok(dt_string, "-")) - 1900; | |
49 | tm.tm_mon = atoi(strtok(NULL, "-")) - 1; | |
50 | tm.tm_mday = atoi(strtok(NULL, " ")); | |
51 | tm.tm_hour = atoi(strtok(NULL, ":")); | |
52 | tm.tm_min = atoi(strtok(NULL, ":")); | |
53 | tm.tm_sec = atoi(strtok(NULL, "\0")); | |
54 | tm.tm_isdst = 1; | |
55 | ||
56 | return mktime(&tm); | |
57 | } | |
58 | ||
59 | ||
60 | ||
61 | int bms_mysql_init(void) | |
62 | { | |
63 | sys_node_list *node, *tmpp; | |
64 | sys_fermenter_list *fermenter, *tmpf; | |
502
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
65 | sys_co2meter_list *co2meter, *tmpc; |
567
6bf0afc33e70
Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
558
diff
changeset
|
66 | sys_ispindel_list *ispindel, *tmpi; |
6bf0afc33e70
Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
558
diff
changeset
|
67 | int icnt = 0, ccnt = 0, ncnt = 0, fcnt = 0; |
0 | 68 | |
69 | con = mysql_init(NULL); | |
70 | if (con == NULL) { | |
71 | syslog(LOG_NOTICE, "MySQL: mysql_init() failed"); | |
72 | return 1; | |
73 | } | |
74 | ||
75 | if (mysql_real_connect(con, Config.mysql_host, Config.mysql_user, Config.mysql_pass, Config.mysql_database, Config.mysql_port, NULL, 0) == NULL) { | |
76 | syslog(LOG_NOTICE, "MySQL: mysql_real_connect() %s", mysql_error(con)); | |
77 | return 2; | |
78 | } | |
79 | ||
80 | syslog(LOG_NOTICE, "MySQL: connected to %s:%d database %s", Config.mysql_host, Config.mysql_port, Config.mysql_database); | |
81 | syslog(LOG_NOTICE, "MySQL: %s server info: %s", mysql_get_host_info(con), mysql_get_server_info(con)); | |
82 | if (debug) | |
83 | fprintf(stdout, "MySQL: connected\n"); | |
84 | ||
85 | /* | |
86 | * Restore nodes from the database | |
87 | */ | |
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
|
88 | 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
|
89 | syslog(LOG_NOTICE, "MySQL: SELECT * FROM mon_nodes error %u (%s))", mysql_errno(con), mysql_error(con)); |
0 | 90 | } else { |
91 | res_set = mysql_store_result(con); | |
92 | if (res_set == NULL) { | |
93 | syslog(LOG_NOTICE, "MySQL: mysq_store_result error %u (%s))", mysql_errno(con), mysql_error(con)); | |
94 | } else { | |
95 | // Process results | |
96 | while ((row = mysql_fetch_row(res_set)) != NULL) { | |
97 | node = (sys_node_list *)malloc(sizeof(sys_node_list)); | |
98 | memset(node, 0, sizeof(sys_node_list)); | |
99 | node->next = NULL; | |
100 | node->uuid = xstrcpy(row[1]); | |
101 | 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
|
102 | node->online = atoi(row[3]); |
0 | 103 | node->group_id = xstrcpy(row[4]); |
104 | node->hardwaremake = xstrcpy(row[5]); | |
105 | node->hardwaremodel = xstrcpy(row[6]); | |
106 | node->os = xstrcpy(row[7]); | |
107 | node->os_version = xstrcpy(row[8]); | |
108 | node->firmware = xstrcpy(row[9]); | |
109 | node->firstseen = datetime_to_time_t(row[10]); | |
110 | node->lastseen = datetime_to_time_t(row[11]); | |
111 | node->temperature = atof(row[12]); | |
112 | node->humidity = atof(row[13]); | |
113 | node->barometer = atof(row[14]); | |
114 | node->gps_latitude = atof(row[15]); | |
115 | node->gps_longitude = atof(row[16]); | |
116 | node->gps_altitude = atof(row[17]); | |
117 | node->net_address = xstrcpy(row[18]); | |
118 | node->net_ifname = xstrcpy(row[19]); | |
119 | 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
|
120 | 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
|
121 | node->net_ssid = xstrcpy(row[22]); |
0 | 122 | |
123 | if (nodes == NULL) { | |
124 | nodes = node; | |
125 | } else { | |
126 | for (tmpp = nodes; tmpp; tmpp = tmpp->next) { | |
127 | if (tmpp->next == NULL) { | |
128 | tmpp->next = node; | |
129 | break; | |
130 | } | |
131 | } | |
132 | } | |
133 | ncnt++; | |
134 | } | |
135 | mysql_free_result(res_set); | |
136 | } | |
137 | } | |
138 | ||
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
|
139 | 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
|
140 | syslog(LOG_NOTICE, "MySQL: SELECT * FROM mon_fermenters error %u (%s))", mysql_errno(con), mysql_error(con)); |
0 | 141 | } else { |
142 | res_set = mysql_store_result(con); | |
143 | if (res_set == NULL) { | |
144 | syslog(LOG_NOTICE, "MySQL: mysq_store_result error %u (%s))", mysql_errno(con), mysql_error(con)); | |
145 | } else { | |
146 | while ((row = mysql_fetch_row(res_set)) != NULL) { | |
147 | fermenter = (sys_fermenter_list *)malloc(sizeof(sys_fermenter_list)); | |
148 | memset(fermenter, 0, sizeof(sys_fermenter_list)); | |
149 | fermenter->next = NULL; | |
150 | fermenter->uuid = xstrcpy(row[1]); | |
151 | fermenter->alias = xstrcpy(row[2]); | |
152 | 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
|
153 | fermenter->online = atoi(row[4]); |
0 | 154 | fermenter->beercode = xstrcpy(row[5]); |
155 | fermenter->beername = xstrcpy(row[6]); | |
192
7f69b43e6084
Implemented beer uuid product in monitor fermenters.
Michiel Broek <mbroek@mbse.eu>
parents:
76
diff
changeset
|
156 | fermenter->beeruuid = xstrcpy(row[44]); |
0 | 157 | if (strlen(row[7])) { |
158 | fermenter->air_address = xstrcpy(row[7]); | |
159 | fermenter->air_state = xstrcpy(row[8]); | |
160 | fermenter->air_temperature = atof(row[9]); | |
161 | } | |
162 | if (strlen(row[10])) { | |
163 | fermenter->beer_address = xstrcpy(row[10]); | |
164 | fermenter->beer_state = xstrcpy(row[11]); | |
165 | fermenter->beer_temperature = atof(row[12]); | |
166 | } | |
167 | if (strlen(row[13])) { | |
168 | fermenter->chiller_address = xstrcpy(row[13]); | |
169 | fermenter->chiller_state = xstrcpy(row[14]); | |
170 | fermenter->chiller_temperature = atof(row[15]); | |
171 | } | |
172 | if (strlen(row[16])) { | |
173 | fermenter->heater_address = xstrcpy(row[16]); | |
174 | fermenter->heater_state = atoi(row[17]); | |
175 | fermenter->heater_usage = atoi(row[18]); | |
176 | } | |
177 | if (strlen(row[19])) { | |
178 | fermenter->cooler_address = xstrcpy(row[19]); | |
179 | fermenter->cooler_state = atoi(row[20]); | |
180 | fermenter->cooler_usage = atoi(row[21]); | |
181 | } | |
182 | if (strlen(row[22])) { | |
183 | fermenter->fan_address = xstrcpy(row[22]); | |
184 | fermenter->fan_state = atoi(row[23]); | |
185 | fermenter->fan_usage = atoi(row[24]); | |
186 | } | |
187 | if (strlen(row[25])) { | |
188 | fermenter->light_address = xstrcpy(row[25]); | |
189 | fermenter->light_state = atoi(row[26]); | |
190 | fermenter->light_usage = atoi(row[27]); | |
191 | } | |
192 | if (strlen(row[28])) { | |
193 | fermenter->door_address = xstrcpy(row[28]); | |
194 | fermenter->door_state = atoi(row[29]); | |
195 | } | |
196 | if (strlen(row[30])) { | |
197 | fermenter->psu_address = xstrcpy(row[30]); | |
198 | fermenter->psu_state = atoi(row[31]); | |
199 | } | |
200 | fermenter->mode = xstrcpy(row[32]); | |
201 | fermenter->alarm = atoi(row[33]); | |
202 | fermenter->setpoint_high = atof(row[34]); | |
203 | fermenter->setpoint_low = atof(row[35]); | |
204 | if (strlen(row[36])) { | |
205 | fermenter->profile_uuid = xstrcpy(row[36]); | |
206 | fermenter->profile_name = xstrcpy(row[37]); | |
207 | fermenter->profile_state = xstrcpy(row[38]); | |
208 | fermenter->profile_percent = atoi(row[39]); | |
209 | fermenter->profile_inittemp_high = atof(row[40]); | |
210 | fermenter->profile_inittemp_low = atof(row[41]); | |
211 | fermenter->profile_steps = xstrcpy(row[42]); | |
212 | } | |
213 | 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
|
214 | 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
|
215 | 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
|
216 | 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
|
217 | fermenter->webcam_light = atoi(row[48]); |
0 | 218 | |
219 | if (fermenters == NULL) { | |
220 | fermenters = fermenter; | |
221 | } else { | |
222 | for (tmpf = fermenters; tmpf; tmpf = tmpf->next) { | |
223 | if (tmpf->next == NULL) { | |
224 | tmpf->next = fermenter; | |
225 | break; | |
226 | } | |
227 | } | |
228 | } | |
229 | fcnt++; | |
230 | } | |
231 | mysql_free_result(res_set); | |
232 | } | |
233 | } | |
234 | ||
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
|
235 | 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
|
236 | 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
|
237 | } else { |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
238 | res_set = mysql_store_result(con); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
239 | if (res_set == NULL) { |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
240 | 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
|
241 | } else { |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
242 | 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
|
243 | 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
|
244 | memset(co2meter, 0, sizeof(sys_co2meter_list)); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
245 | co2meter->next = NULL; |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
246 | co2meter->uuid = xstrcpy(row[1]); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
247 | co2meter->alias = xstrcpy(row[2]); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
248 | 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
|
249 | co2meter->online = atoi(row[4]); |
502
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
250 | co2meter->beercode = xstrcpy(row[5]); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
251 | co2meter->beername = xstrcpy(row[6]); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
252 | co2meter->beeruuid = xstrcpy(row[7]); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
253 | co2meter->mode = xstrcpy(row[8]); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
254 | co2meter->temperature_state = xstrcpy(row[9]); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
255 | co2meter->temperature_address = xstrcpy(row[10]); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
256 | co2meter->temperature = atof(row[11]); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
257 | co2meter->pressure_state = xstrcpy(row[12]); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
258 | co2meter->pressure_channel = atoi(row[13]); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
259 | co2meter->pressure_voltage = atof(row[14]); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
260 | co2meter->pressure_zero = atof(row[15]); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
261 | co2meter->pressure_bar = atof(row[16]); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
262 | |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
263 | if (co2meters == NULL) { |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
264 | co2meters = co2meter; |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
265 | } else { |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
266 | for (tmpc = co2meters; tmpc; tmpc = tmpc->next) { |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
267 | if (tmpc->next == NULL) { |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
268 | tmpc->next = co2meter; |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
269 | break; |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
270 | } |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
271 | } |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
272 | } |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
273 | ccnt++; |
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 | mysql_free_result(res_set); |
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 | } |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
278 | |
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
|
279 | 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
|
280 | 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
|
281 | } else { |
6bf0afc33e70
Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
558
diff
changeset
|
282 | res_set = mysql_store_result(con); |
6bf0afc33e70
Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
558
diff
changeset
|
283 | if (res_set == NULL) { |
6bf0afc33e70
Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
558
diff
changeset
|
284 | 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
|
285 | } else { |
6bf0afc33e70
Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
558
diff
changeset
|
286 | 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
|
287 | 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
|
288 | 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
|
289 | 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
|
290 | 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
|
291 | 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
|
292 | 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
|
293 | 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
|
294 | 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
|
295 | 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
|
296 | 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
|
297 | 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
|
298 | 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
|
299 | 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
|
300 | 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
|
301 | 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
|
302 | 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
|
303 | 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
|
304 | ispindel->og_gravity = atof(row[15]); |
567
6bf0afc33e70
Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
558
diff
changeset
|
305 | |
6bf0afc33e70
Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
558
diff
changeset
|
306 | if (ispindels == NULL) { |
6bf0afc33e70
Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
558
diff
changeset
|
307 | ispindels = ispindel; |
6bf0afc33e70
Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
558
diff
changeset
|
308 | } else { |
6bf0afc33e70
Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
558
diff
changeset
|
309 | 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
|
310 | if (tmpi->next == NULL) { |
6bf0afc33e70
Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
558
diff
changeset
|
311 | tmpi->next = ispindel; |
6bf0afc33e70
Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
558
diff
changeset
|
312 | break; |
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 | } |
6bf0afc33e70
Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
558
diff
changeset
|
315 | } |
6bf0afc33e70
Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
558
diff
changeset
|
316 | icnt++; |
6bf0afc33e70
Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
558
diff
changeset
|
317 | } |
6bf0afc33e70
Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
558
diff
changeset
|
318 | mysql_free_result(res_set); |
6bf0afc33e70
Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
558
diff
changeset
|
319 | } |
6bf0afc33e70
Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
558
diff
changeset
|
320 | } |
6bf0afc33e70
Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
558
diff
changeset
|
321 | |
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
|
322 | syslog(LOG_NOTICE, "MySQL: loaded %d nodes, %d fermenters, %d co2meters, %d ispindels", ncnt, fcnt, ccnt, icnt); |
0 | 323 | return 0; |
324 | } | |
325 | ||
326 | ||
327 | ||
328 | void bms_mysql_end(void) | |
329 | { | |
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
|
330 | sys_ispindel_list *tmpi, *oldtmpi; |
502
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
331 | sys_co2meter_list *tmpp, *oldtmpp; |
0 | 332 | sys_fermenter_list *tmpf, *oldtmpf; |
333 | sys_node_list *tmpn, *oldtmpn; | |
334 | ||
335 | mysql_close(con); | |
336 | ||
337 | syslog(LOG_NOTICE, "MySQL: disconnected"); | |
338 | if (debug) | |
339 | fprintf(stdout, "MySQL: disconnected\n"); | |
340 | ||
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
|
341 | 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
|
342 | 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
|
343 | 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
|
344 | 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
|
345 | 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
|
346 | 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
|
347 | 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
|
348 | 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
|
349 | 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
|
350 | 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
|
351 | 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
|
352 | 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
|
353 | 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
|
354 | 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
|
355 | 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
|
356 | free(tmpi->mode); |
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
|
357 | 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
|
358 | } |
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 | |
502
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
360 | for (tmpp = co2meters; tmpp; tmpp = oldtmpp) { |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
361 | oldtmpp = tmpp->next; |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
362 | if (tmpp->uuid) |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
363 | free(tmpp->uuid); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
364 | if (tmpp->alias) |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
365 | free(tmpp->alias); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
366 | if (tmpp->node) |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
367 | free(tmpp->node); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
368 | if (tmpp->beercode) |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
369 | free(tmpp->beercode); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
370 | if (tmpp->beername) |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
371 | free(tmpp->beername); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
372 | if (tmpp->beeruuid) |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
373 | free(tmpp->beeruuid); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
374 | if (tmpp->temperature_address) |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
375 | free(tmpp->temperature_address); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
376 | if (tmpp->temperature_state) |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
377 | free(tmpp->temperature_state); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
378 | if (tmpp->pressure_state) |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
379 | free(tmpp->pressure_state); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
380 | free(tmpp); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
381 | } |
0 | 382 | for (tmpf = fermenters; tmpf; tmpf = oldtmpf) { |
383 | oldtmpf = tmpf->next; | |
384 | if (tmpf->uuid) | |
385 | free(tmpf->uuid); | |
386 | if (tmpf->alias) | |
387 | free(tmpf->alias); | |
388 | if (tmpf->node) | |
389 | free(tmpf->node); | |
390 | if (tmpf->beercode) | |
391 | free(tmpf->beercode); | |
392 | if (tmpf->beername) | |
393 | free(tmpf->beername); | |
192
7f69b43e6084
Implemented beer uuid product in monitor fermenters.
Michiel Broek <mbroek@mbse.eu>
parents:
76
diff
changeset
|
394 | if (tmpf->beeruuid) |
7f69b43e6084
Implemented beer uuid product in monitor fermenters.
Michiel Broek <mbroek@mbse.eu>
parents:
76
diff
changeset
|
395 | free(tmpf->beeruuid); |
0 | 396 | if (tmpf->air_address) |
397 | free(tmpf->air_address); | |
398 | if (tmpf->air_state) | |
399 | free(tmpf->air_state); | |
400 | if (tmpf->beer_address) | |
401 | free(tmpf->beer_address); | |
402 | if (tmpf->beer_state) | |
403 | free(tmpf->beer_state); | |
404 | if (tmpf->chiller_address) | |
405 | free(tmpf->chiller_address); | |
406 | if (tmpf->chiller_state) | |
407 | free(tmpf->chiller_state); | |
408 | if (tmpf->heater_address) | |
409 | free(tmpf->heater_address); | |
410 | if (tmpf->cooler_address) | |
411 | free(tmpf->cooler_address); | |
412 | if (tmpf->fan_address) | |
413 | free(tmpf->fan_address); | |
414 | if (tmpf->light_address) | |
415 | free(tmpf->light_address); | |
416 | if (tmpf->door_address) | |
417 | free(tmpf->door_address); | |
418 | if (tmpf->psu_address) | |
419 | free(tmpf->psu_address); | |
420 | if (tmpf->mode) | |
421 | free(tmpf->mode); | |
422 | if (tmpf->stage) | |
423 | free(tmpf->stage); | |
424 | if (tmpf->profile_uuid) | |
425 | free(tmpf->profile_uuid); | |
426 | if (tmpf->profile_name) | |
427 | free(tmpf->profile_name); | |
428 | if (tmpf->profile_state) | |
429 | free(tmpf->profile_state); | |
430 | if (tmpf->profile_steps) | |
431 | 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
|
432 | 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
|
433 | free(tmpf->webcam_url); |
0 | 434 | free(tmpf); |
435 | } | |
436 | for (tmpn = nodes; tmpn; tmpn = oldtmpn) { | |
437 | oldtmpn = tmpn->next; | |
438 | if (tmpn->uuid) | |
439 | free(tmpn->uuid); | |
440 | if (tmpn->node) | |
441 | free(tmpn->node); | |
442 | if (tmpn->group_id) | |
443 | free(tmpn->group_id); | |
444 | if (tmpn->hardwaremake) | |
445 | free(tmpn->hardwaremake); | |
446 | if (tmpn->hardwaremodel) | |
447 | free(tmpn->hardwaremodel); | |
448 | if (tmpn->os) | |
449 | free(tmpn->os); | |
450 | if (tmpn->os_version) | |
451 | free(tmpn->os_version); | |
452 | if (tmpn->firmware) | |
453 | free(tmpn->firmware); | |
454 | if (tmpn->net_address) | |
455 | free(tmpn->net_address); | |
456 | if (tmpn->net_ifname) | |
457 | 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
|
458 | if (tmpn->net_ssid) |
faeede125639
Version 0.3.35 Added nodes database net_ssid field.
Michiel Broek <mbroek@mbse.eu>
parents:
684
diff
changeset
|
459 | free(tmpn->net_ssid); |
0 | 460 | free(tmpn); |
461 | } | |
462 | } | |
463 | ||
464 | ||
465 | ||
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
|
466 | 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
|
467 | { |
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
|
468 | 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
|
469 | 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
|
470 | |
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
|
471 | 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
|
472 | 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
|
473 | 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
|
474 | } 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
|
475 | 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
|
476 | } |
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 | /* Any error execpt server gone away */ |
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 | if (err != 2006) |
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 | 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
|
481 | |
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, "Trying to reconnect"); |
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 | /* Try to reconnect and do the query again */ |
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 | mysql_close(con); |
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 | if (mysql_real_connect(con, Config.mysql_host, Config.mysql_user, Config.mysql_pass, Config.mysql_database, Config.mysql_port, NULL, 0) == NULL) { |
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 | syslog(LOG_NOTICE, "MySQL: mysql_real_connect() %s", mysql_error(con)); |
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 | return 2; |
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 | } |
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 | syslog(LOG_NOTICE, "MySQL: reconnected."); |
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 | rc = mysql_query(con, 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
|
491 | if (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
|
492 | syslog(LOG_NOTICE, "MySQL: error %u (%s)", mysql_errno(con), mysql_error(con)); |
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
|
493 | 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
|
494 | } |
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
|
495 | 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
|
496 | } |
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
|
497 | |
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
|
498 | |
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
|
499 | |
0 | 500 | void bms_mysql_ping(void) |
501 | { | |
502 | } | |
503 | ||
504 | ||
505 | ||
506 | void node_mysql_insert(sys_node_list *node) | |
507 | { | |
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
|
508 | char *query = malloc(1024), first[73], last[73]; |
0 | 509 | struct tm *mytime; |
510 | ||
511 | 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
|
512 | snprintf(first, 72, "%04d-%02d-%02d %02d:%02d:%02d", |
0 | 513 | mytime->tm_year + 1900, mytime->tm_mon + 1, mytime->tm_mday, mytime->tm_hour, mytime->tm_min, mytime->tm_sec); |
514 | 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
|
515 | snprintf(last, 72, "%04d-%02d-%02d %02d:%02d:%02d", |
0 | 516 | mytime->tm_year + 1900, mytime->tm_mon + 1, mytime->tm_mday, mytime->tm_hour, mytime->tm_min, mytime->tm_sec); |
517 | ||
76
804d45bdaa86
Increased nenory for the nodes query strings.
Michiel Broek <mbroek@mbse.eu>
parents:
43
diff
changeset
|
518 | 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
|
519 | "INSERT INTO mon_nodes SET uuid='%s', node='%s', online='%d', group_id='%s', " \ |
0 | 520 | "hardwaremake='%s', hardwaremodel='%s', os='%s', os_version='%s', firmware='%s', firstseen='%s', lastseen='%s', " \ |
521 | "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
|
522 | "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
|
523 | node->uuid, node->node, node->online ?1:0, node->group_id, |
0 | 524 | node->hardwaremake, node->hardwaremodel, node->os, node->os_version, node->firmware, first, last, |
525 | node->temperature, node->humidity, node->barometer, node->gps_latitude, node->gps_longitude, node->gps_altitude, | |
703
faeede125639
Version 0.3.35 Added nodes database net_ssid field.
Michiel Broek <mbroek@mbse.eu>
parents:
684
diff
changeset
|
526 | node->net_address, node->net_ifname, node->net_rssi, node->interval, node->net_ssid); |
0 | 527 | |
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
|
528 | if (bms_mysql_query(query) == 0) { |
0 | 529 | syslog(LOG_NOTICE, "MySQL: insert new node %s", node->node); |
530 | } | |
531 | ||
532 | free(query); | |
533 | } | |
534 | ||
535 | ||
536 | ||
537 | void node_mysql_update(sys_node_list *node) | |
538 | { | |
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
|
539 | char *query = malloc(1024), last[65]; |
0 | 540 | struct tm *mytime; |
541 | ||
542 | 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
|
543 | snprintf(last, 64, "%04d-%02d-%02d %02d:%02d:%02d", |
0 | 544 | mytime->tm_year + 1900, mytime->tm_mon + 1, mytime->tm_mday, mytime->tm_hour, mytime->tm_min, mytime->tm_sec); |
545 | ||
76
804d45bdaa86
Increased nenory for the nodes query strings.
Michiel Broek <mbroek@mbse.eu>
parents:
43
diff
changeset
|
546 | 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
|
547 | "UPDATE mon_nodes SET online='%d', hardwaremake='%s', hardwaremodel='%s', os='%s', os_version='%s', firmware='%s', lastseen='%s', " \ |
0 | 548 | "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
|
549 | "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
|
550 | node->online ? 1:0, node->hardwaremake, node->hardwaremodel, node->os, node->os_version, node->firmware, last, |
0 | 551 | node->temperature, node->humidity, node->barometer, node->gps_latitude, node->gps_longitude, node->gps_altitude, |
703
faeede125639
Version 0.3.35 Added nodes database net_ssid field.
Michiel Broek <mbroek@mbse.eu>
parents:
684
diff
changeset
|
552 | node->net_address, node->net_ifname, node->net_rssi, node->interval, node->net_ssid, node->uuid); |
0 | 553 | |
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
|
554 | bms_mysql_query(query); |
0 | 555 | free(query); |
556 | } | |
557 | ||
558 | ||
559 | ||
560 | void node_mysql_death(char *node) | |
561 | { | |
562 | char *query = malloc(512); | |
563 | ||
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
|
564 | 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
|
565 | bms_mysql_query(query); |
0 | 566 | free(query); |
567 | } | |
568 | ||
569 | ||
570 | ||
571 | void fermenter_mysql_insert(sys_fermenter_list *fermenter) | |
572 | { | |
573 | char *query = malloc(2560); | |
574 | ||
575 | 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
|
576 | "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
|
577 | "beercode='%s', beername='%s', beeruuid='%s', " \ |
0 | 578 | "air_address='%s', air_state='%s', air_temperature='%.3f', " \ |
579 | "beer_address='%s', beer_state='%s', beer_temperature='%.3f', " \ | |
580 | "chiller_address='%s', chiller_state='%s', chiller_temperature='%.3f', " \ | |
581 | "heater_address='%s', heater_state='%d', heater_usage='%lu', " \ | |
582 | "cooler_address='%s', cooler_state='%d', cooler_usage='%lu', " \ | |
583 | "fan_address='%s', fan_state='%d', fan_usage='%lu', " \ | |
584 | "light_address='%s', light_state='%d', light_usage='%lu', " \ | |
585 | "door_address='%s', door_state='%d', " \ | |
586 | "psu_address='%s', psu_state='%d', " \ | |
587 | "mode='%s', alarm='%d', setpoint_high='%.3f', setpoint_low='%.3f', " \ | |
588 | "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
|
589 | "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
|
590 | "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
|
591 | fermenter->uuid, fermenter->alias, fermenter->node, fermenter->online ? 1:0, |
0 | 592 | 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
|
593 | fermenter->beeruuid ? fermenter->beeruuid : "", |
0 | 594 | fermenter->air_address ? fermenter->air_address : "", fermenter->air_state ? fermenter->air_state : "", fermenter->air_temperature, |
595 | fermenter->beer_address ? fermenter->beer_address : "", fermenter->beer_state ? fermenter->beer_state : "", fermenter->beer_temperature, | |
596 | fermenter->chiller_address ? fermenter->chiller_address : "", fermenter->chiller_state ? fermenter->chiller_state : "", fermenter->chiller_temperature, | |
597 | fermenter->heater_address ? fermenter->heater_address : "", fermenter->heater_state, fermenter->heater_usage, | |
598 | fermenter->cooler_address ? fermenter->cooler_address : "", fermenter->cooler_state, fermenter->cooler_usage, | |
599 | fermenter->fan_address ? fermenter->fan_address : "", fermenter->fan_state, fermenter->fan_usage, | |
600 | fermenter->light_address ? fermenter->light_address : "", fermenter->light_state, fermenter->light_usage, | |
601 | fermenter->door_address ? fermenter->door_address : "", fermenter->door_state, | |
602 | fermenter->psu_address ? fermenter->psu_address : "", fermenter->psu_state, | |
603 | fermenter->mode, fermenter->alarm, fermenter->setpoint_high, fermenter->setpoint_low, | |
604 | fermenter->profile_uuid ? fermenter->profile_uuid : "", fermenter->profile_name ? fermenter->profile_name : "", | |
605 | fermenter->profile_state ? fermenter->profile_state : "", fermenter->profile_percent, | |
606 | 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
|
607 | 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
|
608 | fermenter->webcam_url ? fermenter->webcam_url : "", fermenter->webcam_light); |
0 | 609 | |
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
|
610 | if (bms_mysql_query(query) == 0) { |
0 | 611 | syslog(LOG_NOTICE, "MySQL: insert new fermenter %s/%s", fermenter->node, fermenter->alias); |
612 | } | |
613 | free(query); | |
614 | } | |
615 | ||
616 | ||
617 | void fermenter_mysql_update(sys_fermenter_list *fermenter) | |
618 | { | |
619 | char *query = malloc(2560); | |
620 | ||
621 | 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
|
622 | "UPDATE mon_fermenters SET online='%d', beercode='%s', beername='%s', beeruuid='%s', " \ |
0 | 623 | "air_address='%s', air_state='%s', air_temperature='%.3f', " \ |
624 | "beer_address='%s', beer_state='%s', beer_temperature='%.3f', " \ | |
625 | "chiller_address='%s', chiller_state='%s', chiller_temperature='%.3f', " \ | |
626 | "heater_address='%s', heater_state='%d', heater_usage='%lu', " \ | |
627 | "cooler_address='%s', cooler_state='%d', cooler_usage='%lu', " \ | |
628 | "fan_address='%s', fan_state='%d', fan_usage='%lu', " \ | |
629 | "light_address='%s', light_state='%d', light_usage='%lu', " \ | |
630 | "door_address='%s', door_state='%d', " \ | |
631 | "psu_address='%s', psu_state='%d', " \ | |
632 | "mode='%s', alarm='%d', setpoint_high='%.3f', setpoint_low='%.3f', " \ | |
633 | "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
|
634 | "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
|
635 | "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
|
636 | 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
|
637 | 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
|
638 | 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
|
639 | 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
|
640 | fermenter->chiller_address ? fermenter->chiller_address : "", fermenter->chiller_state ? fermenter->chiller_state : "MISSING", fermenter->chiller_temperature, |
0 | 641 | fermenter->heater_address ? fermenter->heater_address : "", fermenter->heater_state, fermenter->heater_usage, |
642 | fermenter->cooler_address ? fermenter->cooler_address : "", fermenter->cooler_state, fermenter->cooler_usage, | |
643 | fermenter->fan_address ? fermenter->fan_address : "", fermenter->fan_state, fermenter->fan_usage, | |
644 | fermenter->light_address ? fermenter->light_address : "", fermenter->light_state, fermenter->light_usage, | |
645 | fermenter->door_address ? fermenter->door_address : "", fermenter->door_state, | |
646 | fermenter->psu_address ? fermenter->psu_address : "", fermenter->psu_state, | |
647 | fermenter->mode, fermenter->alarm, fermenter->setpoint_high, fermenter->setpoint_low, | |
648 | fermenter->profile_uuid ? fermenter->profile_uuid : "", fermenter->profile_name ? fermenter->profile_name : "", | |
649 | fermenter->profile_state ? fermenter->profile_state : "", fermenter->profile_percent, | |
650 | 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
|
651 | 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
|
652 | fermenter->webcam_url ? fermenter->webcam_url : "", fermenter->webcam_light, fermenter->uuid); |
0 | 653 | |
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
|
654 | bms_mysql_query(query); |
0 | 655 | free(query); |
656 | } | |
657 | ||
658 | ||
659 | ||
660 | void fermenter_mysql_death(char *node, char *alias) | |
661 | { | |
662 | char *query = malloc(512); | |
663 | ||
664 | 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
|
665 | snprintf(query, 511, "UPDATE mon_fermenters SET online='0' WHERE node='%s' and alias='%s'", node, alias); |
0 | 666 | 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
|
667 | snprintf(query, 511, "UPDATE mon_fermenters SET online='0' WHERE node='%s'", node); |
0 | 668 | |
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
|
669 | bms_mysql_query(query); |
0 | 670 | free(query); |
671 | } | |
672 | ||
673 | ||
502
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
674 | |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
675 | 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
|
676 | { |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
677 | char *query = malloc(2560); |
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 | snprintf(query, 2559, |
505
c09b67fd8323
Added CO2 meter units alarm led.
Michiel Broek <mbroek@mbse.eu>
parents:
502
diff
changeset
|
680 | "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
|
681 | "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
|
682 | "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
|
683 | 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
|
684 | 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
|
685 | 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
|
686 | |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
687 | if (bms_mysql_query(query) == 0) { |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
688 | 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
|
689 | } |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
690 | free(query); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
691 | } |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
692 | |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
693 | |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
694 | |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
695 | 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
|
696 | { |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
697 | char *query = malloc(2560); |
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 | snprintf(query, 2559, |
505
c09b67fd8323
Added CO2 meter units alarm led.
Michiel Broek <mbroek@mbse.eu>
parents:
502
diff
changeset
|
700 | "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
|
701 | "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
|
702 | "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
|
703 | "WHERE uuid='%s'", |
505
c09b67fd8323
Added CO2 meter units alarm led.
Michiel Broek <mbroek@mbse.eu>
parents:
502
diff
changeset
|
704 | 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
|
705 | 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
|
706 | 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
|
707 | co2meter->uuid); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
708 | |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
709 | bms_mysql_query(query); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
710 | free(query); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
711 | } |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
712 | |
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 | 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
|
716 | { |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
717 | char *query = malloc(512); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
718 | |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
719 | if (alias) |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
720 | 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
|
721 | else |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
722 | 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
|
723 | |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
724 | bms_mysql_query(query); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
725 | free(query); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
726 | } |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
727 | |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
728 | |
567
6bf0afc33e70
Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
558
diff
changeset
|
729 | |
6bf0afc33e70
Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
558
diff
changeset
|
730 | 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
|
731 | { |
6bf0afc33e70
Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
558
diff
changeset
|
732 | char *query = malloc(2560); |
6bf0afc33e70
Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
558
diff
changeset
|
733 | |
6bf0afc33e70
Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
558
diff
changeset
|
734 | 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
|
735 | "INSERT INTO mon_ispindels SET uuid='%s', alias='%s', node='%s', online='%d', mode='%s', alarm='%d', " \ |
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
|
736 | "angle='%.6f', temperature='%.4f', battery='%.6f', gravity='%.6f', up_interval='%d', og_gravity='0.0'", |
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
|
737 | ispindel->uuid, ispindel->alias, ispindel->node, ispindel->online ? 1:0, ispindel->mode, ispindel->alarm, |
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
|
738 | ispindel->angle, ispindel->temperature, ispindel->battery, ispindel->gravity, ispindel->interval); |
567
6bf0afc33e70
Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
558
diff
changeset
|
739 | |
6bf0afc33e70
Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
558
diff
changeset
|
740 | if (bms_mysql_query(query) == 0) { |
6bf0afc33e70
Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
558
diff
changeset
|
741 | 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
|
742 | } |
6bf0afc33e70
Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
558
diff
changeset
|
743 | free(query); |
6bf0afc33e70
Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
558
diff
changeset
|
744 | } |
6bf0afc33e70
Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
558
diff
changeset
|
745 | |
6bf0afc33e70
Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
558
diff
changeset
|
746 | |
6bf0afc33e70
Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
558
diff
changeset
|
747 | |
6bf0afc33e70
Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
558
diff
changeset
|
748 | 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
|
749 | { |
6bf0afc33e70
Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
558
diff
changeset
|
750 | char *query = malloc(2560); |
6bf0afc33e70
Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
558
diff
changeset
|
751 | |
6bf0afc33e70
Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
558
diff
changeset
|
752 | 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
|
753 | "UPDATE mon_ispindels SET online='%d', mode='%s', alias='%s', alarm='%d', " \ |
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
|
754 | "angle='%.6f', temperature='%.4f', battery='%.6f', gravity='%.6f', up_interval='%d', og_gravity=GREATEST(og_gravity, '%.6f') WHERE uuid='%s'", |
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
|
755 | ispindel->online ? 1:0, ispindel->mode, ispindel->alias, ispindel->alarm, |
628
a42166cbb19a
Record iSpindel original plato by updating to the highest measured value. Reset this value when a new beer is set. Added current status to the monitor screen.
Michiel Broek <mbroek@mbse.eu>
parents:
587
diff
changeset
|
756 | ispindel->angle, ispindel->temperature, ispindel->battery, ispindel->gravity, ispindel->interval, ispindel->gravity, ispindel->uuid); |
567
6bf0afc33e70
Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
558
diff
changeset
|
757 | bms_mysql_query(query); |
6bf0afc33e70
Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
558
diff
changeset
|
758 | free(query); |
6bf0afc33e70
Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
558
diff
changeset
|
759 | } |
6bf0afc33e70
Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
558
diff
changeset
|
760 | |
6bf0afc33e70
Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
558
diff
changeset
|
761 | |
6bf0afc33e70
Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
558
diff
changeset
|
762 | |
580
9cd6873bda75
Fixed ispindel_death. Added ispindel log graph.
Michiel Broek <mbroek@mbse.eu>
parents:
579
diff
changeset
|
763 | 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
|
764 | { |
6bf0afc33e70
Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
558
diff
changeset
|
765 | char *query = malloc(512); |
6bf0afc33e70
Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
558
diff
changeset
|
766 | |
580
9cd6873bda75
Fixed ispindel_death. Added ispindel log graph.
Michiel Broek <mbroek@mbse.eu>
parents:
579
diff
changeset
|
767 | 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
|
768 | bms_mysql_query(query); |
6bf0afc33e70
Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
558
diff
changeset
|
769 | free(query); |
6bf0afc33e70
Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
558
diff
changeset
|
770 | } |
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
|
771 |