Wed, 23 Oct 2019 14:20:50 +0200
Added the product divide scripts. All parts have all the volumes and weights divided, including the master record. Splitted batches have their own records with the product code formatted as code-n. From this design, we can rebuild the print and checklist.
0 | 1 | /** |
2 | * @file mysql.c | |
3 | * @brief MySQL/MariaDB access. | |
4 | * @author Michiel Broek <mbroek at mbse dot eu> | |
5 | * | |
192
7f69b43e6084
Implemented beer uuid product in monitor fermenters.
Michiel Broek <mbroek@mbse.eu>
parents:
76
diff
changeset
|
6 | * Copyright (C) 2018-2019 |
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; |
0 | 39 | extern int debug; |
40 | ||
41 | ||
42 | time_t datetime_to_time_t(char *dt_string) | |
43 | { | |
44 | struct tm tm; | |
45 | ||
46 | memset(&tm, 0, sizeof(struct tm)); | |
47 | tm.tm_year = atoi(strtok(dt_string, "-")) - 1900; | |
48 | tm.tm_mon = atoi(strtok(NULL, "-")) - 1; | |
49 | tm.tm_mday = atoi(strtok(NULL, " ")); | |
50 | tm.tm_hour = atoi(strtok(NULL, ":")); | |
51 | tm.tm_min = atoi(strtok(NULL, ":")); | |
52 | tm.tm_sec = atoi(strtok(NULL, "\0")); | |
53 | tm.tm_isdst = 1; | |
54 | ||
55 | return mktime(&tm); | |
56 | } | |
57 | ||
58 | ||
59 | ||
60 | int bms_mysql_init(void) | |
61 | { | |
62 | sys_node_list *node, *tmpp; | |
63 | sys_fermenter_list *fermenter, *tmpf; | |
502
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
64 | sys_co2meter_list *co2meter, *tmpc; |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
65 | int ccnt = 0, ncnt = 0, fcnt = 0; |
0 | 66 | |
67 | con = mysql_init(NULL); | |
68 | if (con == NULL) { | |
69 | syslog(LOG_NOTICE, "MySQL: mysql_init() failed"); | |
70 | return 1; | |
71 | } | |
72 | ||
73 | if (mysql_real_connect(con, Config.mysql_host, Config.mysql_user, Config.mysql_pass, Config.mysql_database, Config.mysql_port, NULL, 0) == NULL) { | |
74 | syslog(LOG_NOTICE, "MySQL: mysql_real_connect() %s", mysql_error(con)); | |
75 | return 2; | |
76 | } | |
77 | ||
78 | syslog(LOG_NOTICE, "MySQL: connected to %s:%d database %s", Config.mysql_host, Config.mysql_port, Config.mysql_database); | |
79 | syslog(LOG_NOTICE, "MySQL: %s server info: %s", mysql_get_host_info(con), mysql_get_server_info(con)); | |
80 | if (debug) | |
81 | fprintf(stdout, "MySQL: connected\n"); | |
82 | ||
83 | /* | |
84 | * Restore nodes from the database | |
85 | */ | |
43
dcb9ff8846fa
Renamed monitor database tables
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
86 | if (mysql_query(con, "SELECT * FROM mon_nodes")) { |
dcb9ff8846fa
Renamed monitor database tables
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
87 | syslog(LOG_NOTICE, "MySQL: SELECT * FROM mon_nodes error %u (%s))", mysql_errno(con), mysql_error(con)); |
0 | 88 | } else { |
89 | res_set = mysql_store_result(con); | |
90 | if (res_set == NULL) { | |
91 | syslog(LOG_NOTICE, "MySQL: mysq_store_result error %u (%s))", mysql_errno(con), mysql_error(con)); | |
92 | } else { | |
93 | // Process results | |
94 | while ((row = mysql_fetch_row(res_set)) != NULL) { | |
95 | node = (sys_node_list *)malloc(sizeof(sys_node_list)); | |
96 | memset(node, 0, sizeof(sys_node_list)); | |
97 | node->next = NULL; | |
98 | node->uuid = xstrcpy(row[1]); | |
99 | node->node = xstrcpy(row[2]); | |
100 | node->online = false; // Will be set using MQTT | |
101 | node->group_id = xstrcpy(row[4]); | |
102 | node->hardwaremake = xstrcpy(row[5]); | |
103 | node->hardwaremodel = xstrcpy(row[6]); | |
104 | node->os = xstrcpy(row[7]); | |
105 | node->os_version = xstrcpy(row[8]); | |
106 | node->firmware = xstrcpy(row[9]); | |
107 | node->firstseen = datetime_to_time_t(row[10]); | |
108 | node->lastseen = datetime_to_time_t(row[11]); | |
109 | node->temperature = atof(row[12]); | |
110 | node->humidity = atof(row[13]); | |
111 | node->barometer = atof(row[14]); | |
112 | node->gps_latitude = atof(row[15]); | |
113 | node->gps_longitude = atof(row[16]); | |
114 | node->gps_altitude = atof(row[17]); | |
115 | node->net_address = xstrcpy(row[18]); | |
116 | node->net_ifname = xstrcpy(row[19]); | |
117 | node->net_rssi = atoi(row[20]); | |
118 | ||
119 | if (nodes == NULL) { | |
120 | nodes = node; | |
121 | } else { | |
122 | for (tmpp = nodes; tmpp; tmpp = tmpp->next) { | |
123 | if (tmpp->next == NULL) { | |
124 | tmpp->next = node; | |
125 | break; | |
126 | } | |
127 | } | |
128 | } | |
129 | ncnt++; | |
130 | } | |
131 | mysql_free_result(res_set); | |
132 | } | |
133 | } | |
134 | ||
43
dcb9ff8846fa
Renamed monitor database tables
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
135 | if (mysql_query(con, "SELECT * FROM mon_fermenters")) { |
dcb9ff8846fa
Renamed monitor database tables
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
136 | syslog(LOG_NOTICE, "MySQL: SELECT * FROM mon_fermenters error %u (%s))", mysql_errno(con), mysql_error(con)); |
0 | 137 | } else { |
138 | res_set = mysql_store_result(con); | |
139 | if (res_set == NULL) { | |
140 | syslog(LOG_NOTICE, "MySQL: mysq_store_result error %u (%s))", mysql_errno(con), mysql_error(con)); | |
141 | } else { | |
142 | while ((row = mysql_fetch_row(res_set)) != NULL) { | |
143 | fermenter = (sys_fermenter_list *)malloc(sizeof(sys_fermenter_list)); | |
144 | memset(fermenter, 0, sizeof(sys_fermenter_list)); | |
145 | fermenter->next = NULL; | |
146 | fermenter->uuid = xstrcpy(row[1]); | |
147 | fermenter->alias = xstrcpy(row[2]); | |
148 | fermenter->node = xstrcpy(row[3]); | |
149 | fermenter->online = false; // Will be set later | |
150 | fermenter->beercode = xstrcpy(row[5]); | |
151 | fermenter->beername = xstrcpy(row[6]); | |
192
7f69b43e6084
Implemented beer uuid product in monitor fermenters.
Michiel Broek <mbroek@mbse.eu>
parents:
76
diff
changeset
|
152 | fermenter->beeruuid = xstrcpy(row[44]); |
0 | 153 | if (strlen(row[7])) { |
154 | fermenter->air_address = xstrcpy(row[7]); | |
155 | fermenter->air_state = xstrcpy(row[8]); | |
156 | fermenter->air_temperature = atof(row[9]); | |
157 | } | |
158 | if (strlen(row[10])) { | |
159 | fermenter->beer_address = xstrcpy(row[10]); | |
160 | fermenter->beer_state = xstrcpy(row[11]); | |
161 | fermenter->beer_temperature = atof(row[12]); | |
162 | } | |
163 | if (strlen(row[13])) { | |
164 | fermenter->chiller_address = xstrcpy(row[13]); | |
165 | fermenter->chiller_state = xstrcpy(row[14]); | |
166 | fermenter->chiller_temperature = atof(row[15]); | |
167 | } | |
168 | if (strlen(row[16])) { | |
169 | fermenter->heater_address = xstrcpy(row[16]); | |
170 | fermenter->heater_state = atoi(row[17]); | |
171 | fermenter->heater_usage = atoi(row[18]); | |
172 | } | |
173 | if (strlen(row[19])) { | |
174 | fermenter->cooler_address = xstrcpy(row[19]); | |
175 | fermenter->cooler_state = atoi(row[20]); | |
176 | fermenter->cooler_usage = atoi(row[21]); | |
177 | } | |
178 | if (strlen(row[22])) { | |
179 | fermenter->fan_address = xstrcpy(row[22]); | |
180 | fermenter->fan_state = atoi(row[23]); | |
181 | fermenter->fan_usage = atoi(row[24]); | |
182 | } | |
183 | if (strlen(row[25])) { | |
184 | fermenter->light_address = xstrcpy(row[25]); | |
185 | fermenter->light_state = atoi(row[26]); | |
186 | fermenter->light_usage = atoi(row[27]); | |
187 | } | |
188 | if (strlen(row[28])) { | |
189 | fermenter->door_address = xstrcpy(row[28]); | |
190 | fermenter->door_state = atoi(row[29]); | |
191 | } | |
192 | if (strlen(row[30])) { | |
193 | fermenter->psu_address = xstrcpy(row[30]); | |
194 | fermenter->psu_state = atoi(row[31]); | |
195 | } | |
196 | fermenter->mode = xstrcpy(row[32]); | |
197 | fermenter->alarm = atoi(row[33]); | |
198 | fermenter->setpoint_high = atof(row[34]); | |
199 | fermenter->setpoint_low = atof(row[35]); | |
200 | if (strlen(row[36])) { | |
201 | fermenter->profile_uuid = xstrcpy(row[36]); | |
202 | fermenter->profile_name = xstrcpy(row[37]); | |
203 | fermenter->profile_state = xstrcpy(row[38]); | |
204 | fermenter->profile_percent = atoi(row[39]); | |
205 | fermenter->profile_inittemp_high = atof(row[40]); | |
206 | fermenter->profile_inittemp_low = atof(row[41]); | |
207 | fermenter->profile_steps = xstrcpy(row[42]); | |
208 | } | |
209 | 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
|
210 | 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
|
211 | 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
|
212 | 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
|
213 | fermenter->webcam_light = atoi(row[48]); |
0 | 214 | |
215 | if (fermenters == NULL) { | |
216 | fermenters = fermenter; | |
217 | } else { | |
218 | for (tmpf = fermenters; tmpf; tmpf = tmpf->next) { | |
219 | if (tmpf->next == NULL) { | |
220 | tmpf->next = fermenter; | |
221 | break; | |
222 | } | |
223 | } | |
224 | } | |
225 | fcnt++; | |
226 | } | |
227 | mysql_free_result(res_set); | |
228 | } | |
229 | } | |
230 | ||
502
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
231 | if (mysql_query(con, "SELECT * FROM mon_co2meters")) { |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
232 | 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
|
233 | } else { |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
234 | res_set = mysql_store_result(con); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
235 | if (res_set == NULL) { |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
236 | 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
|
237 | } else { |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
238 | 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
|
239 | 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
|
240 | memset(co2meter, 0, sizeof(sys_co2meter_list)); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
241 | co2meter->next = NULL; |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
242 | co2meter->uuid = xstrcpy(row[1]); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
243 | co2meter->alias = xstrcpy(row[2]); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
244 | co2meter->node = xstrcpy(row[3]); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
245 | co2meter->online = 0; // Will be set later |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
246 | co2meter->beercode = xstrcpy(row[5]); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
247 | co2meter->beername = xstrcpy(row[6]); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
248 | co2meter->beeruuid = xstrcpy(row[7]); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
249 | co2meter->mode = xstrcpy(row[8]); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
250 | co2meter->temperature_state = xstrcpy(row[9]); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
251 | co2meter->temperature_address = xstrcpy(row[10]); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
252 | co2meter->temperature = atof(row[11]); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
253 | co2meter->pressure_state = xstrcpy(row[12]); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
254 | co2meter->pressure_channel = atoi(row[13]); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
255 | co2meter->pressure_voltage = atof(row[14]); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
256 | co2meter->pressure_zero = atof(row[15]); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
257 | co2meter->pressure_bar = atof(row[16]); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
258 | |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
259 | if (co2meters == NULL) { |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
260 | co2meters = co2meter; |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
261 | } else { |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
262 | for (tmpc = co2meters; tmpc; tmpc = tmpc->next) { |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
263 | if (tmpc->next == NULL) { |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
264 | tmpc->next = co2meter; |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
265 | break; |
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 | } |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
268 | } |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
269 | ccnt++; |
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 | mysql_free_result(res_set); |
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 | } |
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 | syslog(LOG_NOTICE, "MySQL: loaded %d nodes, %d fermenters, %d co2meters", ncnt, fcnt, ccnt); |
0 | 276 | return 0; |
277 | } | |
278 | ||
279 | ||
280 | ||
281 | void bms_mysql_end(void) | |
282 | { | |
502
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
283 | sys_co2meter_list *tmpp, *oldtmpp; |
0 | 284 | sys_fermenter_list *tmpf, *oldtmpf; |
285 | sys_node_list *tmpn, *oldtmpn; | |
286 | ||
287 | mysql_close(con); | |
288 | ||
289 | syslog(LOG_NOTICE, "MySQL: disconnected"); | |
290 | if (debug) | |
291 | fprintf(stdout, "MySQL: disconnected\n"); | |
292 | ||
502
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
293 | for (tmpp = co2meters; tmpp; tmpp = oldtmpp) { |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
294 | oldtmpp = tmpp->next; |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
295 | if (tmpp->uuid) |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
296 | free(tmpp->uuid); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
297 | if (tmpp->alias) |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
298 | free(tmpp->alias); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
299 | if (tmpp->node) |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
300 | free(tmpp->node); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
301 | if (tmpp->beercode) |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
302 | free(tmpp->beercode); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
303 | if (tmpp->beername) |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
304 | free(tmpp->beername); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
305 | if (tmpp->beeruuid) |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
306 | free(tmpp->beeruuid); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
307 | if (tmpp->temperature_address) |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
308 | free(tmpp->temperature_address); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
309 | if (tmpp->temperature_state) |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
310 | free(tmpp->temperature_state); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
311 | if (tmpp->pressure_state) |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
312 | free(tmpp->pressure_state); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
313 | free(tmpp); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
314 | } |
0 | 315 | for (tmpf = fermenters; tmpf; tmpf = oldtmpf) { |
316 | oldtmpf = tmpf->next; | |
317 | if (tmpf->uuid) | |
318 | free(tmpf->uuid); | |
319 | if (tmpf->alias) | |
320 | free(tmpf->alias); | |
321 | if (tmpf->node) | |
322 | free(tmpf->node); | |
323 | if (tmpf->beercode) | |
324 | free(tmpf->beercode); | |
325 | if (tmpf->beername) | |
326 | free(tmpf->beername); | |
192
7f69b43e6084
Implemented beer uuid product in monitor fermenters.
Michiel Broek <mbroek@mbse.eu>
parents:
76
diff
changeset
|
327 | if (tmpf->beeruuid) |
7f69b43e6084
Implemented beer uuid product in monitor fermenters.
Michiel Broek <mbroek@mbse.eu>
parents:
76
diff
changeset
|
328 | free(tmpf->beeruuid); |
0 | 329 | if (tmpf->air_address) |
330 | free(tmpf->air_address); | |
331 | if (tmpf->air_state) | |
332 | free(tmpf->air_state); | |
333 | if (tmpf->beer_address) | |
334 | free(tmpf->beer_address); | |
335 | if (tmpf->beer_state) | |
336 | free(tmpf->beer_state); | |
337 | if (tmpf->chiller_address) | |
338 | free(tmpf->chiller_address); | |
339 | if (tmpf->chiller_state) | |
340 | free(tmpf->chiller_state); | |
341 | if (tmpf->heater_address) | |
342 | free(tmpf->heater_address); | |
343 | if (tmpf->cooler_address) | |
344 | free(tmpf->cooler_address); | |
345 | if (tmpf->fan_address) | |
346 | free(tmpf->fan_address); | |
347 | if (tmpf->light_address) | |
348 | free(tmpf->light_address); | |
349 | if (tmpf->door_address) | |
350 | free(tmpf->door_address); | |
351 | if (tmpf->psu_address) | |
352 | free(tmpf->psu_address); | |
353 | if (tmpf->mode) | |
354 | free(tmpf->mode); | |
355 | if (tmpf->stage) | |
356 | free(tmpf->stage); | |
357 | if (tmpf->profile_uuid) | |
358 | free(tmpf->profile_uuid); | |
359 | if (tmpf->profile_name) | |
360 | free(tmpf->profile_name); | |
361 | if (tmpf->profile_state) | |
362 | free(tmpf->profile_state); | |
363 | if (tmpf->profile_steps) | |
364 | 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
|
365 | 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
|
366 | free(tmpf->webcam_url); |
0 | 367 | free(tmpf); |
368 | } | |
369 | for (tmpn = nodes; tmpn; tmpn = oldtmpn) { | |
370 | oldtmpn = tmpn->next; | |
371 | if (tmpn->uuid) | |
372 | free(tmpn->uuid); | |
373 | if (tmpn->node) | |
374 | free(tmpn->node); | |
375 | if (tmpn->group_id) | |
376 | free(tmpn->group_id); | |
377 | if (tmpn->hardwaremake) | |
378 | free(tmpn->hardwaremake); | |
379 | if (tmpn->hardwaremodel) | |
380 | free(tmpn->hardwaremodel); | |
381 | if (tmpn->os) | |
382 | free(tmpn->os); | |
383 | if (tmpn->os_version) | |
384 | free(tmpn->os_version); | |
385 | if (tmpn->firmware) | |
386 | free(tmpn->firmware); | |
387 | if (tmpn->net_address) | |
388 | free(tmpn->net_address); | |
389 | if (tmpn->net_ifname) | |
390 | free(tmpn->net_ifname); | |
391 | free(tmpn); | |
392 | } | |
393 | } | |
394 | ||
395 | ||
396 | ||
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
|
397 | 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
|
398 | { |
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
|
399 | int 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
|
400 | |
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
|
401 | 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
|
402 | 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
|
403 | 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
|
404 | } 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
|
405 | 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
|
406 | } |
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
|
407 | |
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
|
408 | /* Any error execpt server gone away */ |
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
|
409 | if (rc != 2006) |
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
|
410 | 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
|
411 | |
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
|
412 | /* 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
|
413 | 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
|
414 | 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
|
415 | 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
|
416 | 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
|
417 | } |
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
|
418 | 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
|
419 | 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
|
420 | 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
|
421 | 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
|
422 | 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
|
423 | } |
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
|
424 | 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
|
425 | } |
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
|
426 | |
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
|
427 | |
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
|
428 | |
0 | 429 | void bms_mysql_ping(void) |
430 | { | |
431 | } | |
432 | ||
433 | ||
434 | ||
435 | void node_mysql_insert(sys_node_list *node) | |
436 | { | |
76
804d45bdaa86
Increased nenory for the nodes query strings.
Michiel Broek <mbroek@mbse.eu>
parents:
43
diff
changeset
|
437 | char *query = malloc(1024), first[21], last[21]; |
0 | 438 | struct tm *mytime; |
439 | ||
440 | mytime = localtime(&node->firstseen); | |
441 | snprintf(first, 20, "%04d-%02d-%02d %02d:%02d:%02d", | |
442 | mytime->tm_year + 1900, mytime->tm_mon + 1, mytime->tm_mday, mytime->tm_hour, mytime->tm_min, mytime->tm_sec); | |
443 | mytime = localtime(&node->lastseen); | |
444 | snprintf(last, 20, "%04d-%02d-%02d %02d:%02d:%02d", | |
445 | mytime->tm_year + 1900, mytime->tm_mon + 1, mytime->tm_mday, mytime->tm_hour, mytime->tm_min, mytime->tm_sec); | |
446 | ||
76
804d45bdaa86
Increased nenory for the nodes query strings.
Michiel Broek <mbroek@mbse.eu>
parents:
43
diff
changeset
|
447 | snprintf(query, 1023, |
43
dcb9ff8846fa
Renamed monitor database tables
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
448 | "INSERT INTO mon_nodes SET uuid='%s', node='%s', online='%s', group_id='%s', " \ |
0 | 449 | "hardwaremake='%s', hardwaremodel='%s', os='%s', os_version='%s', firmware='%s', firstseen='%s', lastseen='%s', " \ |
450 | "temperature='%.3f', humidity='%.3f', barometer='%.3f', gps_latitude='%.8f', gps_longitude='%.8f', gps_altitude='%.8f', " \ | |
451 | "net_address='%s', net_ifname='%s', net_rssi='%d'", | |
452 | node->uuid, node->node, node->online ?"Y":"N", node->group_id, | |
453 | node->hardwaremake, node->hardwaremodel, node->os, node->os_version, node->firmware, first, last, | |
454 | node->temperature, node->humidity, node->barometer, node->gps_latitude, node->gps_longitude, node->gps_altitude, | |
455 | node->net_address, node->net_ifname, node->net_rssi); | |
456 | ||
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
|
457 | if (bms_mysql_query(query) == 0) { |
0 | 458 | syslog(LOG_NOTICE, "MySQL: insert new node %s", node->node); |
459 | } | |
460 | ||
461 | free(query); | |
462 | } | |
463 | ||
464 | ||
465 | ||
466 | void node_mysql_update(sys_node_list *node) | |
467 | { | |
76
804d45bdaa86
Increased nenory for the nodes query strings.
Michiel Broek <mbroek@mbse.eu>
parents:
43
diff
changeset
|
468 | char *query = malloc(1024), last[21]; |
0 | 469 | struct tm *mytime; |
470 | ||
471 | mytime = localtime(&node->lastseen); | |
472 | snprintf(last, 20, "%04d-%02d-%02d %02d:%02d:%02d", | |
473 | mytime->tm_year + 1900, mytime->tm_mon + 1, mytime->tm_mday, mytime->tm_hour, mytime->tm_min, mytime->tm_sec); | |
474 | ||
76
804d45bdaa86
Increased nenory for the nodes query strings.
Michiel Broek <mbroek@mbse.eu>
parents:
43
diff
changeset
|
475 | snprintf(query, 1023, |
43
dcb9ff8846fa
Renamed monitor database tables
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
476 | "UPDATE mon_nodes SET online='%s', hardwaremake='%s', hardwaremodel='%s', os='%s', os_version='%s', firmware='%s', lastseen='%s', " \ |
0 | 477 | "temperature='%.3f', humidity='%.3f', barometer='%.3f', gps_latitude='%.8f', gps_longitude='%.8f', gps_altitude='%.8f', " \ |
478 | "net_address='%s', net_ifname='%s', net_rssi='%d' WHERE uuid='%s'", | |
479 | node->online ?"Y":"N", node->hardwaremake, node->hardwaremodel, node->os, node->os_version, node->firmware, last, | |
480 | node->temperature, node->humidity, node->barometer, node->gps_latitude, node->gps_longitude, node->gps_altitude, | |
481 | node->net_address, node->net_ifname, node->net_rssi, node->uuid); | |
482 | ||
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 | bms_mysql_query(query); |
0 | 484 | free(query); |
485 | } | |
486 | ||
487 | ||
488 | ||
489 | void node_mysql_death(char *node) | |
490 | { | |
491 | char *query = malloc(512); | |
492 | ||
43
dcb9ff8846fa
Renamed monitor database tables
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
493 | snprintf(query, 511, "UPDATE mon_nodes SET online='N' 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
|
494 | bms_mysql_query(query); |
0 | 495 | free(query); |
496 | } | |
497 | ||
498 | ||
499 | ||
500 | void fermenter_mysql_insert(sys_fermenter_list *fermenter) | |
501 | { | |
502 | char *query = malloc(2560); | |
503 | ||
504 | snprintf(query, 2559, | |
43
dcb9ff8846fa
Renamed monitor database tables
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
505 | "INSERT INTO mon_fermenters SET uuid='%s', alias='%s', node='%s', online='%s', " \ |
192
7f69b43e6084
Implemented beer uuid product in monitor fermenters.
Michiel Broek <mbroek@mbse.eu>
parents:
76
diff
changeset
|
506 | "beercode='%s', beername='%s', beeruuid='%s', " \ |
0 | 507 | "air_address='%s', air_state='%s', air_temperature='%.3f', " \ |
508 | "beer_address='%s', beer_state='%s', beer_temperature='%.3f', " \ | |
509 | "chiller_address='%s', chiller_state='%s', chiller_temperature='%.3f', " \ | |
510 | "heater_address='%s', heater_state='%d', heater_usage='%lu', " \ | |
511 | "cooler_address='%s', cooler_state='%d', cooler_usage='%lu', " \ | |
512 | "fan_address='%s', fan_state='%d', fan_usage='%lu', " \ | |
513 | "light_address='%s', light_state='%d', light_usage='%lu', " \ | |
514 | "door_address='%s', door_state='%d', " \ | |
515 | "psu_address='%s', psu_state='%d', " \ | |
516 | "mode='%s', alarm='%d', setpoint_high='%.3f', setpoint_low='%.3f', " \ | |
517 | "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
|
518 | "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
|
519 | "yeast_lo='%.1f', yeast_hi='%.1f', webcam_url='%s', webcam_light='%d'", |
0 | 520 | fermenter->uuid, fermenter->alias, fermenter->node, fermenter->online ? "Y":"N", |
521 | 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
|
522 | fermenter->beeruuid ? fermenter->beeruuid : "", |
0 | 523 | fermenter->air_address ? fermenter->air_address : "", fermenter->air_state ? fermenter->air_state : "", fermenter->air_temperature, |
524 | fermenter->beer_address ? fermenter->beer_address : "", fermenter->beer_state ? fermenter->beer_state : "", fermenter->beer_temperature, | |
525 | fermenter->chiller_address ? fermenter->chiller_address : "", fermenter->chiller_state ? fermenter->chiller_state : "", fermenter->chiller_temperature, | |
526 | fermenter->heater_address ? fermenter->heater_address : "", fermenter->heater_state, fermenter->heater_usage, | |
527 | fermenter->cooler_address ? fermenter->cooler_address : "", fermenter->cooler_state, fermenter->cooler_usage, | |
528 | fermenter->fan_address ? fermenter->fan_address : "", fermenter->fan_state, fermenter->fan_usage, | |
529 | fermenter->light_address ? fermenter->light_address : "", fermenter->light_state, fermenter->light_usage, | |
530 | fermenter->door_address ? fermenter->door_address : "", fermenter->door_state, | |
531 | fermenter->psu_address ? fermenter->psu_address : "", fermenter->psu_state, | |
532 | fermenter->mode, fermenter->alarm, fermenter->setpoint_high, fermenter->setpoint_low, | |
533 | fermenter->profile_uuid ? fermenter->profile_uuid : "", fermenter->profile_name ? fermenter->profile_name : "", | |
534 | fermenter->profile_state ? fermenter->profile_state : "", fermenter->profile_percent, | |
535 | 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
|
536 | 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
|
537 | fermenter->webcam_url ? fermenter->webcam_url : "", fermenter->webcam_light); |
0 | 538 | |
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
|
539 | if (bms_mysql_query(query) == 0) { |
0 | 540 | syslog(LOG_NOTICE, "MySQL: insert new fermenter %s/%s", fermenter->node, fermenter->alias); |
541 | } | |
542 | free(query); | |
543 | } | |
544 | ||
545 | ||
546 | void fermenter_mysql_update(sys_fermenter_list *fermenter) | |
547 | { | |
548 | char *query = malloc(2560); | |
549 | ||
550 | snprintf(query, 2559, | |
192
7f69b43e6084
Implemented beer uuid product in monitor fermenters.
Michiel Broek <mbroek@mbse.eu>
parents:
76
diff
changeset
|
551 | "UPDATE mon_fermenters SET online='%s', beercode='%s', beername='%s', beeruuid='%s', " \ |
0 | 552 | "air_address='%s', air_state='%s', air_temperature='%.3f', " \ |
553 | "beer_address='%s', beer_state='%s', beer_temperature='%.3f', " \ | |
554 | "chiller_address='%s', chiller_state='%s', chiller_temperature='%.3f', " \ | |
555 | "heater_address='%s', heater_state='%d', heater_usage='%lu', " \ | |
556 | "cooler_address='%s', cooler_state='%d', cooler_usage='%lu', " \ | |
557 | "fan_address='%s', fan_state='%d', fan_usage='%lu', " \ | |
558 | "light_address='%s', light_state='%d', light_usage='%lu', " \ | |
559 | "door_address='%s', door_state='%d', " \ | |
560 | "psu_address='%s', psu_state='%d', " \ | |
561 | "mode='%s', alarm='%d', setpoint_high='%.3f', setpoint_low='%.3f', " \ | |
562 | "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
|
563 | "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
|
564 | "yeast_lo='%.1f', yeast_hi='%.1f', webcam_url='%s', webcam_light='%d' WHERE uuid='%s'", |
0 | 565 | fermenter->online ? "Y":"N", 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
|
566 | fermenter->beeruuid ? fermenter->beeruuid : "", |
0 | 567 | fermenter->air_address ? fermenter->air_address : "", fermenter->air_state ? fermenter->air_state : "", fermenter->air_temperature, |
568 | fermenter->beer_address ? fermenter->beer_address : "", fermenter->beer_state ? fermenter->beer_state : "", fermenter->beer_temperature, | |
569 | fermenter->chiller_address ? fermenter->chiller_address : "", fermenter->chiller_state ? fermenter->chiller_state : "", fermenter->chiller_temperature, | |
570 | fermenter->heater_address ? fermenter->heater_address : "", fermenter->heater_state, fermenter->heater_usage, | |
571 | fermenter->cooler_address ? fermenter->cooler_address : "", fermenter->cooler_state, fermenter->cooler_usage, | |
572 | fermenter->fan_address ? fermenter->fan_address : "", fermenter->fan_state, fermenter->fan_usage, | |
573 | fermenter->light_address ? fermenter->light_address : "", fermenter->light_state, fermenter->light_usage, | |
574 | fermenter->door_address ? fermenter->door_address : "", fermenter->door_state, | |
575 | fermenter->psu_address ? fermenter->psu_address : "", fermenter->psu_state, | |
576 | fermenter->mode, fermenter->alarm, fermenter->setpoint_high, fermenter->setpoint_low, | |
577 | fermenter->profile_uuid ? fermenter->profile_uuid : "", fermenter->profile_name ? fermenter->profile_name : "", | |
578 | fermenter->profile_state ? fermenter->profile_state : "", fermenter->profile_percent, | |
579 | 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
|
580 | 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
|
581 | fermenter->webcam_url ? fermenter->webcam_url : "", fermenter->webcam_light, fermenter->uuid); |
0 | 582 | |
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
|
583 | bms_mysql_query(query); |
0 | 584 | free(query); |
585 | } | |
586 | ||
587 | ||
588 | ||
589 | void fermenter_mysql_death(char *node, char *alias) | |
590 | { | |
591 | char *query = malloc(512); | |
592 | ||
593 | if (alias) | |
43
dcb9ff8846fa
Renamed monitor database tables
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
594 | snprintf(query, 511, "UPDATE mon_fermenters SET online='N' WHERE node='%s' and alias='%s'", node, alias); |
0 | 595 | else |
43
dcb9ff8846fa
Renamed monitor database tables
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
596 | snprintf(query, 511, "UPDATE mon_fermenters SET online='N' WHERE node='%s'", node); |
0 | 597 | |
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
|
598 | bms_mysql_query(query); |
0 | 599 | free(query); |
600 | } | |
601 | ||
602 | ||
502
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
603 | |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
604 | 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
|
605 | { |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
606 | char *query = malloc(2560); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
607 | |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
608 | snprintf(query, 2559, |
505
c09b67fd8323
Added CO2 meter units alarm led.
Michiel Broek <mbroek@mbse.eu>
parents:
502
diff
changeset
|
609 | "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
|
610 | "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
|
611 | "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
|
612 | 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
|
613 | 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
|
614 | 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
|
615 | |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
616 | if (bms_mysql_query(query) == 0) { |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
617 | 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
|
618 | } |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
619 | free(query); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
620 | } |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
621 | |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
622 | |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
623 | |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
624 | 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
|
625 | { |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
626 | char *query = malloc(2560); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
627 | |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
628 | snprintf(query, 2559, |
505
c09b67fd8323
Added CO2 meter units alarm led.
Michiel Broek <mbroek@mbse.eu>
parents:
502
diff
changeset
|
629 | "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
|
630 | "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
|
631 | "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
|
632 | "WHERE uuid='%s'", |
505
c09b67fd8323
Added CO2 meter units alarm led.
Michiel Broek <mbroek@mbse.eu>
parents:
502
diff
changeset
|
633 | 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
|
634 | 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
|
635 | 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
|
636 | co2meter->uuid); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
637 | |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
638 | bms_mysql_query(query); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
639 | free(query); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
640 | } |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
641 | |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
642 | |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
643 | |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
644 | 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
|
645 | { |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
646 | char *query = malloc(512); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
647 | |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
648 | if (alias) |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
649 | 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
|
650 | else |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
651 | 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
|
652 | |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
653 | bms_mysql_query(query); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
654 | free(query); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
655 | } |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
656 | |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
657 |