Thu, 30 Jan 2020 15:29:43 +0100
Don't include carbonation sugars in the fermentables.
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 | */ | |
43
dcb9ff8846fa
Renamed monitor database tables
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
88 | if (mysql_query(con, "SELECT * FROM mon_nodes")) { |
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]); |
0 | 121 | |
122 | if (nodes == NULL) { | |
123 | nodes = node; | |
124 | } else { | |
125 | for (tmpp = nodes; tmpp; tmpp = tmpp->next) { | |
126 | if (tmpp->next == NULL) { | |
127 | tmpp->next = node; | |
128 | break; | |
129 | } | |
130 | } | |
131 | } | |
132 | ncnt++; | |
133 | } | |
134 | mysql_free_result(res_set); | |
135 | } | |
136 | } | |
137 | ||
43
dcb9ff8846fa
Renamed monitor database tables
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
138 | if (mysql_query(con, "SELECT * FROM mon_fermenters")) { |
dcb9ff8846fa
Renamed monitor database tables
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
139 | syslog(LOG_NOTICE, "MySQL: SELECT * FROM mon_fermenters error %u (%s))", mysql_errno(con), mysql_error(con)); |
0 | 140 | } else { |
141 | res_set = mysql_store_result(con); | |
142 | if (res_set == NULL) { | |
143 | syslog(LOG_NOTICE, "MySQL: mysq_store_result error %u (%s))", mysql_errno(con), mysql_error(con)); | |
144 | } else { | |
145 | while ((row = mysql_fetch_row(res_set)) != NULL) { | |
146 | fermenter = (sys_fermenter_list *)malloc(sizeof(sys_fermenter_list)); | |
147 | memset(fermenter, 0, sizeof(sys_fermenter_list)); | |
148 | fermenter->next = NULL; | |
149 | fermenter->uuid = xstrcpy(row[1]); | |
150 | fermenter->alias = xstrcpy(row[2]); | |
151 | 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
|
152 | fermenter->online = atoi(row[4]); |
0 | 153 | fermenter->beercode = xstrcpy(row[5]); |
154 | fermenter->beername = xstrcpy(row[6]); | |
192
7f69b43e6084
Implemented beer uuid product in monitor fermenters.
Michiel Broek <mbroek@mbse.eu>
parents:
76
diff
changeset
|
155 | fermenter->beeruuid = xstrcpy(row[44]); |
0 | 156 | if (strlen(row[7])) { |
157 | fermenter->air_address = xstrcpy(row[7]); | |
158 | fermenter->air_state = xstrcpy(row[8]); | |
159 | fermenter->air_temperature = atof(row[9]); | |
160 | } | |
161 | if (strlen(row[10])) { | |
162 | fermenter->beer_address = xstrcpy(row[10]); | |
163 | fermenter->beer_state = xstrcpy(row[11]); | |
164 | fermenter->beer_temperature = atof(row[12]); | |
165 | } | |
166 | if (strlen(row[13])) { | |
167 | fermenter->chiller_address = xstrcpy(row[13]); | |
168 | fermenter->chiller_state = xstrcpy(row[14]); | |
169 | fermenter->chiller_temperature = atof(row[15]); | |
170 | } | |
171 | if (strlen(row[16])) { | |
172 | fermenter->heater_address = xstrcpy(row[16]); | |
173 | fermenter->heater_state = atoi(row[17]); | |
174 | fermenter->heater_usage = atoi(row[18]); | |
175 | } | |
176 | if (strlen(row[19])) { | |
177 | fermenter->cooler_address = xstrcpy(row[19]); | |
178 | fermenter->cooler_state = atoi(row[20]); | |
179 | fermenter->cooler_usage = atoi(row[21]); | |
180 | } | |
181 | if (strlen(row[22])) { | |
182 | fermenter->fan_address = xstrcpy(row[22]); | |
183 | fermenter->fan_state = atoi(row[23]); | |
184 | fermenter->fan_usage = atoi(row[24]); | |
185 | } | |
186 | if (strlen(row[25])) { | |
187 | fermenter->light_address = xstrcpy(row[25]); | |
188 | fermenter->light_state = atoi(row[26]); | |
189 | fermenter->light_usage = atoi(row[27]); | |
190 | } | |
191 | if (strlen(row[28])) { | |
192 | fermenter->door_address = xstrcpy(row[28]); | |
193 | fermenter->door_state = atoi(row[29]); | |
194 | } | |
195 | if (strlen(row[30])) { | |
196 | fermenter->psu_address = xstrcpy(row[30]); | |
197 | fermenter->psu_state = atoi(row[31]); | |
198 | } | |
199 | fermenter->mode = xstrcpy(row[32]); | |
200 | fermenter->alarm = atoi(row[33]); | |
201 | fermenter->setpoint_high = atof(row[34]); | |
202 | fermenter->setpoint_low = atof(row[35]); | |
203 | if (strlen(row[36])) { | |
204 | fermenter->profile_uuid = xstrcpy(row[36]); | |
205 | fermenter->profile_name = xstrcpy(row[37]); | |
206 | fermenter->profile_state = xstrcpy(row[38]); | |
207 | fermenter->profile_percent = atoi(row[39]); | |
208 | fermenter->profile_inittemp_high = atof(row[40]); | |
209 | fermenter->profile_inittemp_low = atof(row[41]); | |
210 | fermenter->profile_steps = xstrcpy(row[42]); | |
211 | } | |
212 | 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
|
213 | 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
|
214 | 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
|
215 | 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
|
216 | fermenter->webcam_light = atoi(row[48]); |
0 | 217 | |
218 | if (fermenters == NULL) { | |
219 | fermenters = fermenter; | |
220 | } else { | |
221 | for (tmpf = fermenters; tmpf; tmpf = tmpf->next) { | |
222 | if (tmpf->next == NULL) { | |
223 | tmpf->next = fermenter; | |
224 | break; | |
225 | } | |
226 | } | |
227 | } | |
228 | fcnt++; | |
229 | } | |
230 | mysql_free_result(res_set); | |
231 | } | |
232 | } | |
233 | ||
502
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
234 | 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
|
235 | 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
|
236 | } else { |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
237 | res_set = mysql_store_result(con); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
238 | if (res_set == NULL) { |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
239 | 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
|
240 | } else { |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
241 | 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
|
242 | 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
|
243 | memset(co2meter, 0, sizeof(sys_co2meter_list)); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
244 | co2meter->next = NULL; |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
245 | co2meter->uuid = xstrcpy(row[1]); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
246 | co2meter->alias = xstrcpy(row[2]); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
247 | 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
|
248 | co2meter->online = atoi(row[4]); |
502
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
249 | co2meter->beercode = xstrcpy(row[5]); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
250 | co2meter->beername = xstrcpy(row[6]); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
251 | co2meter->beeruuid = xstrcpy(row[7]); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
252 | co2meter->mode = xstrcpy(row[8]); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
253 | co2meter->temperature_state = xstrcpy(row[9]); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
254 | co2meter->temperature_address = xstrcpy(row[10]); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
255 | co2meter->temperature = atof(row[11]); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
256 | co2meter->pressure_state = xstrcpy(row[12]); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
257 | co2meter->pressure_channel = atoi(row[13]); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
258 | co2meter->pressure_voltage = atof(row[14]); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
259 | co2meter->pressure_zero = atof(row[15]); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
260 | co2meter->pressure_bar = atof(row[16]); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
261 | |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
262 | if (co2meters == NULL) { |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
263 | co2meters = co2meter; |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
264 | } else { |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
265 | for (tmpc = co2meters; tmpc; tmpc = tmpc->next) { |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
266 | if (tmpc->next == NULL) { |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
267 | tmpc->next = co2meter; |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
268 | break; |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
269 | } |
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 | ccnt++; |
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 | mysql_free_result(res_set); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
275 | } |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
276 | } |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
277 | |
567
6bf0afc33e70
Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
558
diff
changeset
|
278 | if (mysql_query(con, "SELECT * FROM mon_ispindels")) { |
6bf0afc33e70
Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
558
diff
changeset
|
279 | 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
|
280 | } else { |
6bf0afc33e70
Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
558
diff
changeset
|
281 | res_set = mysql_store_result(con); |
6bf0afc33e70
Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
558
diff
changeset
|
282 | if (res_set == NULL) { |
6bf0afc33e70
Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
558
diff
changeset
|
283 | 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
|
284 | } else { |
6bf0afc33e70
Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
558
diff
changeset
|
285 | 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
|
286 | 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
|
287 | 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
|
288 | 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
|
289 | 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
|
290 | 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
|
291 | 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
|
292 | 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
|
293 | 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
|
294 | 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
|
295 | 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
|
296 | 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
|
297 | 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
|
298 | 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
|
299 | 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
|
300 | 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
|
301 | 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
|
302 | ispindel->mode = xstrcpy(row[14]); |
567
6bf0afc33e70
Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
558
diff
changeset
|
303 | |
6bf0afc33e70
Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
558
diff
changeset
|
304 | if (ispindels == NULL) { |
6bf0afc33e70
Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
558
diff
changeset
|
305 | ispindels = ispindel; |
6bf0afc33e70
Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
558
diff
changeset
|
306 | } else { |
6bf0afc33e70
Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
558
diff
changeset
|
307 | 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
|
308 | if (tmpi->next == NULL) { |
6bf0afc33e70
Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
558
diff
changeset
|
309 | tmpi->next = ispindel; |
6bf0afc33e70
Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
558
diff
changeset
|
310 | break; |
6bf0afc33e70
Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
558
diff
changeset
|
311 | } |
6bf0afc33e70
Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
558
diff
changeset
|
312 | } |
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 | icnt++; |
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 | mysql_free_result(res_set); |
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 | } |
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 | syslog(LOG_NOTICE, "MySQL: loaded %d nodes, %d fermenters, %d co2meters %d ispindels", ncnt, fcnt, ccnt, icnt); |
0 | 321 | return 0; |
322 | } | |
323 | ||
324 | ||
325 | ||
326 | void bms_mysql_end(void) | |
327 | { | |
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
|
328 | sys_ispindel_list *tmpi, *oldtmpi; |
502
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
329 | sys_co2meter_list *tmpp, *oldtmpp; |
0 | 330 | sys_fermenter_list *tmpf, *oldtmpf; |
331 | sys_node_list *tmpn, *oldtmpn; | |
332 | ||
333 | mysql_close(con); | |
334 | ||
335 | syslog(LOG_NOTICE, "MySQL: disconnected"); | |
336 | if (debug) | |
337 | fprintf(stdout, "MySQL: disconnected\n"); | |
338 | ||
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
|
339 | 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
|
340 | 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
|
341 | 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
|
342 | 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
|
343 | 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
|
344 | 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
|
345 | 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
|
346 | 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
|
347 | 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
|
348 | 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
|
349 | 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
|
350 | 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
|
351 | 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
|
352 | 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
|
353 | 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
|
354 | 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
|
355 | 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
|
356 | } |
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 | |
502
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
358 | for (tmpp = co2meters; tmpp; tmpp = oldtmpp) { |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
359 | oldtmpp = tmpp->next; |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
360 | if (tmpp->uuid) |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
361 | free(tmpp->uuid); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
362 | if (tmpp->alias) |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
363 | free(tmpp->alias); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
364 | if (tmpp->node) |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
365 | free(tmpp->node); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
366 | if (tmpp->beercode) |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
367 | free(tmpp->beercode); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
368 | if (tmpp->beername) |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
369 | free(tmpp->beername); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
370 | if (tmpp->beeruuid) |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
371 | free(tmpp->beeruuid); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
372 | if (tmpp->temperature_address) |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
373 | free(tmpp->temperature_address); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
374 | if (tmpp->temperature_state) |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
375 | free(tmpp->temperature_state); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
376 | if (tmpp->pressure_state) |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
377 | free(tmpp->pressure_state); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
378 | free(tmpp); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
379 | } |
0 | 380 | for (tmpf = fermenters; tmpf; tmpf = oldtmpf) { |
381 | oldtmpf = tmpf->next; | |
382 | if (tmpf->uuid) | |
383 | free(tmpf->uuid); | |
384 | if (tmpf->alias) | |
385 | free(tmpf->alias); | |
386 | if (tmpf->node) | |
387 | free(tmpf->node); | |
388 | if (tmpf->beercode) | |
389 | free(tmpf->beercode); | |
390 | if (tmpf->beername) | |
391 | free(tmpf->beername); | |
192
7f69b43e6084
Implemented beer uuid product in monitor fermenters.
Michiel Broek <mbroek@mbse.eu>
parents:
76
diff
changeset
|
392 | if (tmpf->beeruuid) |
7f69b43e6084
Implemented beer uuid product in monitor fermenters.
Michiel Broek <mbroek@mbse.eu>
parents:
76
diff
changeset
|
393 | free(tmpf->beeruuid); |
0 | 394 | if (tmpf->air_address) |
395 | free(tmpf->air_address); | |
396 | if (tmpf->air_state) | |
397 | free(tmpf->air_state); | |
398 | if (tmpf->beer_address) | |
399 | free(tmpf->beer_address); | |
400 | if (tmpf->beer_state) | |
401 | free(tmpf->beer_state); | |
402 | if (tmpf->chiller_address) | |
403 | free(tmpf->chiller_address); | |
404 | if (tmpf->chiller_state) | |
405 | free(tmpf->chiller_state); | |
406 | if (tmpf->heater_address) | |
407 | free(tmpf->heater_address); | |
408 | if (tmpf->cooler_address) | |
409 | free(tmpf->cooler_address); | |
410 | if (tmpf->fan_address) | |
411 | free(tmpf->fan_address); | |
412 | if (tmpf->light_address) | |
413 | free(tmpf->light_address); | |
414 | if (tmpf->door_address) | |
415 | free(tmpf->door_address); | |
416 | if (tmpf->psu_address) | |
417 | free(tmpf->psu_address); | |
418 | if (tmpf->mode) | |
419 | free(tmpf->mode); | |
420 | if (tmpf->stage) | |
421 | free(tmpf->stage); | |
422 | if (tmpf->profile_uuid) | |
423 | free(tmpf->profile_uuid); | |
424 | if (tmpf->profile_name) | |
425 | free(tmpf->profile_name); | |
426 | if (tmpf->profile_state) | |
427 | free(tmpf->profile_state); | |
428 | if (tmpf->profile_steps) | |
429 | 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
|
430 | 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
|
431 | free(tmpf->webcam_url); |
0 | 432 | free(tmpf); |
433 | } | |
434 | for (tmpn = nodes; tmpn; tmpn = oldtmpn) { | |
435 | oldtmpn = tmpn->next; | |
436 | if (tmpn->uuid) | |
437 | free(tmpn->uuid); | |
438 | if (tmpn->node) | |
439 | free(tmpn->node); | |
440 | if (tmpn->group_id) | |
441 | free(tmpn->group_id); | |
442 | if (tmpn->hardwaremake) | |
443 | free(tmpn->hardwaremake); | |
444 | if (tmpn->hardwaremodel) | |
445 | free(tmpn->hardwaremodel); | |
446 | if (tmpn->os) | |
447 | free(tmpn->os); | |
448 | if (tmpn->os_version) | |
449 | free(tmpn->os_version); | |
450 | if (tmpn->firmware) | |
451 | free(tmpn->firmware); | |
452 | if (tmpn->net_address) | |
453 | free(tmpn->net_address); | |
454 | if (tmpn->net_ifname) | |
455 | free(tmpn->net_ifname); | |
456 | free(tmpn); | |
457 | } | |
458 | } | |
459 | ||
460 | ||
461 | ||
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
|
462 | 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
|
463 | { |
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
|
464 | 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
|
465 | 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
|
466 | |
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 | 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
|
468 | 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
|
469 | 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
|
470 | } 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
|
471 | 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
|
472 | } |
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 | |
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 | /* 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
|
475 | 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
|
476 | 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
|
477 | |
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
|
478 | 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
|
479 | /* 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
|
480 | 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
|
481 | 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
|
482 | 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
|
483 | 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
|
484 | } |
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 | 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
|
486 | 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
|
487 | 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
|
488 | 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
|
489 | 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
|
490 | } |
ef3f0274a1ea
Added a private mysql_query function that does try to reconnect a lost MySQL connection.
Michiel Broek <mbroek@mbse.eu>
parents:
383
diff
changeset
|
491 | 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
|
492 | } |
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 | |
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 | |
0 | 496 | void bms_mysql_ping(void) |
497 | { | |
498 | } | |
499 | ||
500 | ||
501 | ||
502 | void node_mysql_insert(sys_node_list *node) | |
503 | { | |
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
|
504 | char *query = malloc(1024), first[73], last[73]; |
0 | 505 | struct tm *mytime; |
506 | ||
507 | 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
|
508 | snprintf(first, 72, "%04d-%02d-%02d %02d:%02d:%02d", |
0 | 509 | mytime->tm_year + 1900, mytime->tm_mon + 1, mytime->tm_mday, mytime->tm_hour, mytime->tm_min, mytime->tm_sec); |
510 | 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
|
511 | snprintf(last, 72, "%04d-%02d-%02d %02d:%02d:%02d", |
0 | 512 | mytime->tm_year + 1900, mytime->tm_mon + 1, mytime->tm_mday, mytime->tm_hour, mytime->tm_min, mytime->tm_sec); |
513 | ||
76
804d45bdaa86
Increased nenory for the nodes query strings.
Michiel Broek <mbroek@mbse.eu>
parents:
43
diff
changeset
|
514 | 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
|
515 | "INSERT INTO mon_nodes SET uuid='%s', node='%s', online='%d', group_id='%s', " \ |
0 | 516 | "hardwaremake='%s', hardwaremodel='%s', os='%s', os_version='%s', firmware='%s', firstseen='%s', lastseen='%s', " \ |
517 | "temperature='%.3f', humidity='%.3f', barometer='%.3f', gps_latitude='%.8f', gps_longitude='%.8f', gps_altitude='%.8f', " \ | |
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
|
518 | "net_address='%s', net_ifname='%s', net_rssi='%d', up_interval='%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
|
519 | node->uuid, node->node, node->online ?1:0, node->group_id, |
0 | 520 | node->hardwaremake, node->hardwaremodel, node->os, node->os_version, node->firmware, first, last, |
521 | node->temperature, node->humidity, node->barometer, node->gps_latitude, node->gps_longitude, node->gps_altitude, | |
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
|
522 | node->net_address, node->net_ifname, node->net_rssi, node->interval); |
0 | 523 | |
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
|
524 | if (bms_mysql_query(query) == 0) { |
0 | 525 | syslog(LOG_NOTICE, "MySQL: insert new node %s", node->node); |
526 | } | |
527 | ||
528 | free(query); | |
529 | } | |
530 | ||
531 | ||
532 | ||
533 | void node_mysql_update(sys_node_list *node) | |
534 | { | |
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
|
535 | char *query = malloc(1024), last[65]; |
0 | 536 | struct tm *mytime; |
537 | ||
538 | 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
|
539 | snprintf(last, 64, "%04d-%02d-%02d %02d:%02d:%02d", |
0 | 540 | mytime->tm_year + 1900, mytime->tm_mon + 1, mytime->tm_mday, mytime->tm_hour, mytime->tm_min, mytime->tm_sec); |
541 | ||
76
804d45bdaa86
Increased nenory for the nodes query strings.
Michiel Broek <mbroek@mbse.eu>
parents:
43
diff
changeset
|
542 | 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
|
543 | "UPDATE mon_nodes SET online='%d', hardwaremake='%s', hardwaremodel='%s', os='%s', os_version='%s', firmware='%s', lastseen='%s', " \ |
0 | 544 | "temperature='%.3f', humidity='%.3f', barometer='%.3f', gps_latitude='%.8f', gps_longitude='%.8f', gps_altitude='%.8f', " \ |
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
|
545 | "net_address='%s', net_ifname='%s', net_rssi='%d', up_interval='%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
|
546 | node->online ? 1:0, node->hardwaremake, node->hardwaremodel, node->os, node->os_version, node->firmware, last, |
0 | 547 | node->temperature, node->humidity, node->barometer, node->gps_latitude, node->gps_longitude, node->gps_altitude, |
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
|
548 | node->net_address, node->net_ifname, node->net_rssi, node->interval, node->uuid); |
0 | 549 | |
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
|
550 | bms_mysql_query(query); |
0 | 551 | free(query); |
552 | } | |
553 | ||
554 | ||
555 | ||
556 | void node_mysql_death(char *node) | |
557 | { | |
558 | char *query = malloc(512); | |
559 | ||
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
|
560 | 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
|
561 | bms_mysql_query(query); |
0 | 562 | free(query); |
563 | } | |
564 | ||
565 | ||
566 | ||
567 | void fermenter_mysql_insert(sys_fermenter_list *fermenter) | |
568 | { | |
569 | char *query = malloc(2560); | |
570 | ||
571 | 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
|
572 | "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
|
573 | "beercode='%s', beername='%s', beeruuid='%s', " \ |
0 | 574 | "air_address='%s', air_state='%s', air_temperature='%.3f', " \ |
575 | "beer_address='%s', beer_state='%s', beer_temperature='%.3f', " \ | |
576 | "chiller_address='%s', chiller_state='%s', chiller_temperature='%.3f', " \ | |
577 | "heater_address='%s', heater_state='%d', heater_usage='%lu', " \ | |
578 | "cooler_address='%s', cooler_state='%d', cooler_usage='%lu', " \ | |
579 | "fan_address='%s', fan_state='%d', fan_usage='%lu', " \ | |
580 | "light_address='%s', light_state='%d', light_usage='%lu', " \ | |
581 | "door_address='%s', door_state='%d', " \ | |
582 | "psu_address='%s', psu_state='%d', " \ | |
583 | "mode='%s', alarm='%d', setpoint_high='%.3f', setpoint_low='%.3f', " \ | |
584 | "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
|
585 | "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
|
586 | "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
|
587 | fermenter->uuid, fermenter->alias, fermenter->node, fermenter->online ? 1:0, |
0 | 588 | 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
|
589 | fermenter->beeruuid ? fermenter->beeruuid : "", |
0 | 590 | fermenter->air_address ? fermenter->air_address : "", fermenter->air_state ? fermenter->air_state : "", fermenter->air_temperature, |
591 | fermenter->beer_address ? fermenter->beer_address : "", fermenter->beer_state ? fermenter->beer_state : "", fermenter->beer_temperature, | |
592 | fermenter->chiller_address ? fermenter->chiller_address : "", fermenter->chiller_state ? fermenter->chiller_state : "", fermenter->chiller_temperature, | |
593 | fermenter->heater_address ? fermenter->heater_address : "", fermenter->heater_state, fermenter->heater_usage, | |
594 | fermenter->cooler_address ? fermenter->cooler_address : "", fermenter->cooler_state, fermenter->cooler_usage, | |
595 | fermenter->fan_address ? fermenter->fan_address : "", fermenter->fan_state, fermenter->fan_usage, | |
596 | fermenter->light_address ? fermenter->light_address : "", fermenter->light_state, fermenter->light_usage, | |
597 | fermenter->door_address ? fermenter->door_address : "", fermenter->door_state, | |
598 | fermenter->psu_address ? fermenter->psu_address : "", fermenter->psu_state, | |
599 | fermenter->mode, fermenter->alarm, fermenter->setpoint_high, fermenter->setpoint_low, | |
600 | fermenter->profile_uuid ? fermenter->profile_uuid : "", fermenter->profile_name ? fermenter->profile_name : "", | |
601 | fermenter->profile_state ? fermenter->profile_state : "", fermenter->profile_percent, | |
602 | 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
|
603 | 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
|
604 | fermenter->webcam_url ? fermenter->webcam_url : "", fermenter->webcam_light); |
0 | 605 | |
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
|
606 | if (bms_mysql_query(query) == 0) { |
0 | 607 | syslog(LOG_NOTICE, "MySQL: insert new fermenter %s/%s", fermenter->node, fermenter->alias); |
608 | } | |
609 | free(query); | |
610 | } | |
611 | ||
612 | ||
613 | void fermenter_mysql_update(sys_fermenter_list *fermenter) | |
614 | { | |
615 | char *query = malloc(2560); | |
616 | ||
617 | 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
|
618 | "UPDATE mon_fermenters SET online='%d', beercode='%s', beername='%s', beeruuid='%s', " \ |
0 | 619 | "air_address='%s', air_state='%s', air_temperature='%.3f', " \ |
620 | "beer_address='%s', beer_state='%s', beer_temperature='%.3f', " \ | |
621 | "chiller_address='%s', chiller_state='%s', chiller_temperature='%.3f', " \ | |
622 | "heater_address='%s', heater_state='%d', heater_usage='%lu', " \ | |
623 | "cooler_address='%s', cooler_state='%d', cooler_usage='%lu', " \ | |
624 | "fan_address='%s', fan_state='%d', fan_usage='%lu', " \ | |
625 | "light_address='%s', light_state='%d', light_usage='%lu', " \ | |
626 | "door_address='%s', door_state='%d', " \ | |
627 | "psu_address='%s', psu_state='%d', " \ | |
628 | "mode='%s', alarm='%d', setpoint_high='%.3f', setpoint_low='%.3f', " \ | |
629 | "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
|
630 | "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
|
631 | "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
|
632 | 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
|
633 | fermenter->beeruuid ? fermenter->beeruuid : "", |
0 | 634 | fermenter->air_address ? fermenter->air_address : "", fermenter->air_state ? fermenter->air_state : "", fermenter->air_temperature, |
635 | fermenter->beer_address ? fermenter->beer_address : "", fermenter->beer_state ? fermenter->beer_state : "", fermenter->beer_temperature, | |
636 | fermenter->chiller_address ? fermenter->chiller_address : "", fermenter->chiller_state ? fermenter->chiller_state : "", fermenter->chiller_temperature, | |
637 | fermenter->heater_address ? fermenter->heater_address : "", fermenter->heater_state, fermenter->heater_usage, | |
638 | fermenter->cooler_address ? fermenter->cooler_address : "", fermenter->cooler_state, fermenter->cooler_usage, | |
639 | fermenter->fan_address ? fermenter->fan_address : "", fermenter->fan_state, fermenter->fan_usage, | |
640 | fermenter->light_address ? fermenter->light_address : "", fermenter->light_state, fermenter->light_usage, | |
641 | fermenter->door_address ? fermenter->door_address : "", fermenter->door_state, | |
642 | fermenter->psu_address ? fermenter->psu_address : "", fermenter->psu_state, | |
643 | fermenter->mode, fermenter->alarm, fermenter->setpoint_high, fermenter->setpoint_low, | |
644 | fermenter->profile_uuid ? fermenter->profile_uuid : "", fermenter->profile_name ? fermenter->profile_name : "", | |
645 | fermenter->profile_state ? fermenter->profile_state : "", fermenter->profile_percent, | |
646 | 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
|
647 | 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
|
648 | fermenter->webcam_url ? fermenter->webcam_url : "", fermenter->webcam_light, fermenter->uuid); |
0 | 649 | |
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
|
650 | bms_mysql_query(query); |
0 | 651 | free(query); |
652 | } | |
653 | ||
654 | ||
655 | ||
656 | void fermenter_mysql_death(char *node, char *alias) | |
657 | { | |
658 | char *query = malloc(512); | |
659 | ||
660 | 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
|
661 | snprintf(query, 511, "UPDATE mon_fermenters SET online='0' WHERE node='%s' and alias='%s'", node, alias); |
0 | 662 | 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
|
663 | snprintf(query, 511, "UPDATE mon_fermenters SET online='0' WHERE node='%s'", node); |
0 | 664 | |
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
|
665 | bms_mysql_query(query); |
0 | 666 | free(query); |
667 | } | |
668 | ||
669 | ||
502
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
670 | |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
671 | 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
|
672 | { |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
673 | char *query = malloc(2560); |
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 | snprintf(query, 2559, |
505
c09b67fd8323
Added CO2 meter units alarm led.
Michiel Broek <mbroek@mbse.eu>
parents:
502
diff
changeset
|
676 | "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
|
677 | "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
|
678 | "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
|
679 | 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
|
680 | 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
|
681 | 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
|
682 | |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
683 | if (bms_mysql_query(query) == 0) { |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
684 | 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
|
685 | } |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
686 | free(query); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
687 | } |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
688 | |
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 | |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
691 | 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
|
692 | { |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
693 | char *query = malloc(2560); |
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 | snprintf(query, 2559, |
505
c09b67fd8323
Added CO2 meter units alarm led.
Michiel Broek <mbroek@mbse.eu>
parents:
502
diff
changeset
|
696 | "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
|
697 | "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
|
698 | "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
|
699 | "WHERE uuid='%s'", |
505
c09b67fd8323
Added CO2 meter units alarm led.
Michiel Broek <mbroek@mbse.eu>
parents:
502
diff
changeset
|
700 | 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
|
701 | 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
|
702 | 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
|
703 | co2meter->uuid); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
704 | |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
705 | bms_mysql_query(query); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
706 | free(query); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
707 | } |
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 | |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
710 | |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
711 | 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
|
712 | { |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
713 | char *query = malloc(512); |
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 | if (alias) |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
716 | 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
|
717 | else |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
718 | 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
|
719 | |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
720 | bms_mysql_query(query); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
721 | free(query); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
405
diff
changeset
|
722 | } |
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 | |
567
6bf0afc33e70
Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
558
diff
changeset
|
725 | |
6bf0afc33e70
Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
558
diff
changeset
|
726 | 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
|
727 | { |
6bf0afc33e70
Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
558
diff
changeset
|
728 | char *query = malloc(2560); |
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 | 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
|
731 | "INSERT INTO mon_ispindels SET uuid='%s', alias='%s', node='%s', online='%d', mode='%s', alarm='%d', " \ |
587
31caffee8c9c
Changed several float precision values. Changed some database fields to double. Everything has now the same precision as received values from the iSpindel.
Michiel Broek <mbroek@mbse.eu>
parents:
582
diff
changeset
|
732 | "angle='%.5f', temperature='%.4f', battery='%.6f', gravity='%.5f', up_interval='%d'", |
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
|
733 | 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
|
734 | 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
|
735 | |
6bf0afc33e70
Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
558
diff
changeset
|
736 | if (bms_mysql_query(query) == 0) { |
6bf0afc33e70
Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
558
diff
changeset
|
737 | 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
|
738 | } |
6bf0afc33e70
Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
558
diff
changeset
|
739 | free(query); |
6bf0afc33e70
Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
558
diff
changeset
|
740 | } |
6bf0afc33e70
Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
558
diff
changeset
|
741 | |
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 | |
6bf0afc33e70
Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
558
diff
changeset
|
744 | 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
|
745 | { |
6bf0afc33e70
Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
558
diff
changeset
|
746 | char *query = malloc(2560); |
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 | 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
|
749 | "UPDATE mon_ispindels SET online='%d', mode='%s', alarm='%d', " \ |
587
31caffee8c9c
Changed several float precision values. Changed some database fields to double. Everything has now the same precision as received values from the iSpindel.
Michiel Broek <mbroek@mbse.eu>
parents:
582
diff
changeset
|
750 | "angle='%.5f', temperature='%.4f', battery='%.6f', gravity='%.5f', up_interval='%d' WHERE uuid='%s'", |
578
e75ce5bbda73
Changed the interface from the iSpindels to be the same as other devices. A webpage converts each call to two standard MQTT messages. The nodes MQTT message extended with an interval parameter. iSpindels now have a generated uuid made up from the chipid.
Michiel Broek <mbroek@mbse.eu>
parents:
572
diff
changeset
|
751 | 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
|
752 | ispindel->angle, ispindel->temperature, ispindel->battery, ispindel->gravity, ispindel->interval, ispindel->uuid); |
567
6bf0afc33e70
Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
558
diff
changeset
|
753 | |
6bf0afc33e70
Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
558
diff
changeset
|
754 | bms_mysql_query(query); |
6bf0afc33e70
Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
558
diff
changeset
|
755 | free(query); |
6bf0afc33e70
Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
558
diff
changeset
|
756 | } |
6bf0afc33e70
Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
558
diff
changeset
|
757 | |
6bf0afc33e70
Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
558
diff
changeset
|
758 | |
6bf0afc33e70
Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
558
diff
changeset
|
759 | |
580
9cd6873bda75
Fixed ispindel_death. Added ispindel log graph.
Michiel Broek <mbroek@mbse.eu>
parents:
579
diff
changeset
|
760 | 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
|
761 | { |
6bf0afc33e70
Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
558
diff
changeset
|
762 | char *query = malloc(512); |
6bf0afc33e70
Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
558
diff
changeset
|
763 | |
580
9cd6873bda75
Fixed ispindel_death. Added ispindel log graph.
Michiel Broek <mbroek@mbse.eu>
parents:
579
diff
changeset
|
764 | 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
|
765 | bms_mysql_query(query); |
6bf0afc33e70
Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
558
diff
changeset
|
766 | free(query); |
6bf0afc33e70
Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
558
diff
changeset
|
767 | } |
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
|
768 | |
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
|
769 | |
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
|
770 | |
582
93848540442c
Try to solve the MySQL 2014 error.
Michiel Broek <mbroek@mbse.eu>
parents:
580
diff
changeset
|
771 | /* |
93848540442c
Try to solve the MySQL 2014 error.
Michiel Broek <mbroek@mbse.eu>
parents:
580
diff
changeset
|
772 | * Check using a new MySQL connection because we are running from another thread. |
93848540442c
Try to solve the MySQL 2014 error.
Michiel Broek <mbroek@mbse.eu>
parents:
580
diff
changeset
|
773 | */ |
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
|
774 | void ispindel_mysql_check(void) |
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
|
775 | { |
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
|
776 | sys_ispindel_list *tmpp; |
582
93848540442c
Try to solve the MySQL 2014 error.
Michiel Broek <mbroek@mbse.eu>
parents:
580
diff
changeset
|
777 | MYSQL *con2 = NULL; |
93848540442c
Try to solve the MySQL 2014 error.
Michiel Broek <mbroek@mbse.eu>
parents:
580
diff
changeset
|
778 | MYSQL_RES *res_set2; |
93848540442c
Try to solve the MySQL 2014 error.
Michiel Broek <mbroek@mbse.eu>
parents:
580
diff
changeset
|
779 | MYSQL_ROW row2; |
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
|
780 | |
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
|
781 | if (ispindels == NULL) |
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
|
782 | return; |
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
|
783 | |
582
93848540442c
Try to solve the MySQL 2014 error.
Michiel Broek <mbroek@mbse.eu>
parents:
580
diff
changeset
|
784 | con2 = mysql_init(NULL); |
93848540442c
Try to solve the MySQL 2014 error.
Michiel Broek <mbroek@mbse.eu>
parents:
580
diff
changeset
|
785 | if (con2 == NULL) { |
93848540442c
Try to solve the MySQL 2014 error.
Michiel Broek <mbroek@mbse.eu>
parents:
580
diff
changeset
|
786 | syslog(LOG_NOTICE, "MySQL: mysql_init() failed"); |
93848540442c
Try to solve the MySQL 2014 error.
Michiel Broek <mbroek@mbse.eu>
parents:
580
diff
changeset
|
787 | return; |
93848540442c
Try to solve the MySQL 2014 error.
Michiel Broek <mbroek@mbse.eu>
parents:
580
diff
changeset
|
788 | } |
93848540442c
Try to solve the MySQL 2014 error.
Michiel Broek <mbroek@mbse.eu>
parents:
580
diff
changeset
|
789 | |
93848540442c
Try to solve the MySQL 2014 error.
Michiel Broek <mbroek@mbse.eu>
parents:
580
diff
changeset
|
790 | if (mysql_real_connect(con2, Config.mysql_host, Config.mysql_user, Config.mysql_pass, Config.mysql_database, Config.mysql_port, NULL, 0) == NULL) { |
93848540442c
Try to solve the MySQL 2014 error.
Michiel Broek <mbroek@mbse.eu>
parents:
580
diff
changeset
|
791 | syslog(LOG_NOTICE, "MySQL: mysql_real_connect() %s", mysql_error(con2)); |
93848540442c
Try to solve the MySQL 2014 error.
Michiel Broek <mbroek@mbse.eu>
parents:
580
diff
changeset
|
792 | return; |
93848540442c
Try to solve the MySQL 2014 error.
Michiel Broek <mbroek@mbse.eu>
parents:
580
diff
changeset
|
793 | } |
93848540442c
Try to solve the MySQL 2014 error.
Michiel Broek <mbroek@mbse.eu>
parents:
580
diff
changeset
|
794 | |
93848540442c
Try to solve the MySQL 2014 error.
Michiel Broek <mbroek@mbse.eu>
parents:
580
diff
changeset
|
795 | if (mysql_query(con2, "SELECT uuid,alias,beercode,beername,beeruuid,mode FROM mon_ispindels;")) { |
93848540442c
Try to solve the MySQL 2014 error.
Michiel Broek <mbroek@mbse.eu>
parents:
580
diff
changeset
|
796 | syslog(LOG_NOTICE, "MySQL: SELECT uuid,alias,beercode,beername,beeruuid,mode FROM mon_ispindels error %u (%s))", mysql_errno(con2), mysql_error(con2)); |
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
|
797 | } else { |
582
93848540442c
Try to solve the MySQL 2014 error.
Michiel Broek <mbroek@mbse.eu>
parents:
580
diff
changeset
|
798 | res_set2 = mysql_store_result(con2); |
93848540442c
Try to solve the MySQL 2014 error.
Michiel Broek <mbroek@mbse.eu>
parents:
580
diff
changeset
|
799 | if (res_set2 == NULL) { |
93848540442c
Try to solve the MySQL 2014 error.
Michiel Broek <mbroek@mbse.eu>
parents:
580
diff
changeset
|
800 | syslog(LOG_NOTICE, "MySQL: mysq_store_result error %u (%s))", mysql_errno(con2), mysql_error(con2)); |
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
|
801 | } else { |
582
93848540442c
Try to solve the MySQL 2014 error.
Michiel Broek <mbroek@mbse.eu>
parents:
580
diff
changeset
|
802 | while ((row2 = mysql_fetch_row(res_set2)) != NULL) { |
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
|
803 | for (tmpp = ispindels; tmpp; tmpp = tmpp->next) { |
582
93848540442c
Try to solve the MySQL 2014 error.
Michiel Broek <mbroek@mbse.eu>
parents:
580
diff
changeset
|
804 | if (strcmp(tmpp->uuid, row2[0]) == 0) { |
93848540442c
Try to solve the MySQL 2014 error.
Michiel Broek <mbroek@mbse.eu>
parents:
580
diff
changeset
|
805 | if (strcmp(tmpp->beercode, row2[2]) || strcmp(tmpp->beername, row2[3]) || strcmp(tmpp->beeruuid, row2[4])) { |
93848540442c
Try to solve the MySQL 2014 error.
Michiel Broek <mbroek@mbse.eu>
parents:
580
diff
changeset
|
806 | syslog(LOG_NOTICE, "ispindel `%s` change beer to `%s %s`", row2[1], row2[2], row2[3]); |
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
|
807 | if (tmpp->beercode) |
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
|
808 | free(tmpp->beercode); |
582
93848540442c
Try to solve the MySQL 2014 error.
Michiel Broek <mbroek@mbse.eu>
parents:
580
diff
changeset
|
809 | tmpp->beercode = xstrcpy(row2[2]); |
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
|
810 | if (tmpp->beername) |
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
|
811 | free(tmpp->beername); |
582
93848540442c
Try to solve the MySQL 2014 error.
Michiel Broek <mbroek@mbse.eu>
parents:
580
diff
changeset
|
812 | tmpp->beername = xstrcpy(row2[3]); |
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
|
813 | if (tmpp->beeruuid) |
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
|
814 | free(tmpp->beeruuid); |
582
93848540442c
Try to solve the MySQL 2014 error.
Michiel Broek <mbroek@mbse.eu>
parents:
580
diff
changeset
|
815 | tmpp->beeruuid = xstrcpy(row2[4]); |
579
1253a237b620
Added check for database changes for iSpindels such as a new beer, or changing mode. Added denity in Plato and SG to the iSpindel web screen. The iSpindels must be calibrated in Plato! A bit of documentation updated.
Michiel Broek <mbroek@mbse.eu>
parents:
578
diff
changeset
|
816 | } |
582
93848540442c
Try to solve the MySQL 2014 error.
Michiel Broek <mbroek@mbse.eu>
parents:
580
diff
changeset
|
817 | if (strcmp(tmpp->mode, row2[5])) { |
93848540442c
Try to solve the MySQL 2014 error.
Michiel Broek <mbroek@mbse.eu>
parents:
580
diff
changeset
|
818 | syslog(LOG_NOTICE, "ispindel `%s` change mode `%s`", row2[1], row2[5]); |
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
|
819 | if (tmpp->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
|
820 | free(tmpp->mode); |
582
93848540442c
Try to solve the MySQL 2014 error.
Michiel Broek <mbroek@mbse.eu>
parents:
580
diff
changeset
|
821 | tmpp->mode = xstrcpy(row2[5]); |
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
|
822 | } |
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
|
823 | } |
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
|
824 | } |
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
|
825 | } |
582
93848540442c
Try to solve the MySQL 2014 error.
Michiel Broek <mbroek@mbse.eu>
parents:
580
diff
changeset
|
826 | mysql_free_result(res_set2); |
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
|
827 | } |
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
|
828 | } |
582
93848540442c
Try to solve the MySQL 2014 error.
Michiel Broek <mbroek@mbse.eu>
parents:
580
diff
changeset
|
829 | |
93848540442c
Try to solve the MySQL 2014 error.
Michiel Broek <mbroek@mbse.eu>
parents:
580
diff
changeset
|
830 | mysql_close(con2); |
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
|
831 | } |
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
|
832 |