Sun, 03 Feb 2019 21:26:23 +0100
Added calcStage function that will be used to increase the brew process stage.
0 | 1 | /** |
2 | * @file fermenters.c | |
3 | * @brief Handle fermenters status | |
4 | * @author Michiel Broek <mbroek at mbse dot eu> | |
5 | * | |
189
6470e5c6a001
In bmsd added missing json percent. The Makefile didn't install the fpdf library. Added profile commands. Small changes to the monitor fermenters screen. The monitor fermenters scheduler is now more responsive. Profiles selection and commands in the remote thermferm.
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
6 | * Copyright (C) 2018-2019 |
0 | 7 | * |
8 | * This file is part of the bms (Brewery Management System) | |
9 | * | |
10 | * This is free software; you can redistribute it and/or modify it | |
11 | * under the terms of the GNU General Public License as published by the | |
12 | * Free Software Foundation; either version 2, or (at your option) any | |
13 | * later version. | |
14 | * | |
15 | * bms is distributed in the hope that it will be useful, but | |
16 | * WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
18 | * General Public License for more details. | |
19 | * | |
20 | * You should have received a copy of the GNU General Public License | |
21 | * along with ThermFerm; see the file COPYING. If not, write to the Free | |
22 | * Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. | |
23 | */ | |
24 | ||
25 | ||
26 | #include "bms.h" | |
27 | #include "xutil.h" | |
28 | #include "fermenters.h" | |
29 | #include "mysql.h" | |
30 | ||
31 | ||
32 | sys_fermenter_list *fermenters = NULL; | |
33 | ||
34 | extern int debug; | |
194
d202777ebae5
Added design notes for the csv log format from fermenters. In bmsd configuration added the web_root entry. Switched fermenter DLOG messages to store the log in flat csv files instead of the database. This is much faster and the graphs look better.
Michiel Broek <mbroek@mbse.eu>
parents:
192
diff
changeset
|
35 | extern sys_config Config; |
0 | 36 | |
37 | ||
38 | ||
39 | void fermenter_set(char *edge_node, char *alias, bool birth, char *payload) | |
40 | { | |
41 | struct json_object *jobj, *val, *sensor, *temp; | |
42 | sys_fermenter_list *fermenter, *tmpp; | |
43 | bool new_fermenter = true; | |
44 | ||
45 | // fprintf(stdout, "fermenter_set: %s/%s %s %s\n", edge_node, alias, birth ? "BIRTH":"DATA", payload); | |
46 | ||
47 | /* | |
48 | * Search fermenter record in the memory array and use it if found. | |
49 | */ | |
50 | if (fermenters) { | |
51 | for (tmpp = fermenters; tmpp; tmpp = tmpp->next) { | |
52 | if ((strcmp(tmpp->alias, alias) == 0) && (strcmp(tmpp->node, edge_node) == 0)) { | |
53 | new_fermenter = false; | |
54 | fermenter = tmpp; | |
55 | break; | |
56 | } | |
57 | } | |
58 | } | |
59 | ||
60 | if (! birth && new_fermenter) { | |
61 | printf("ERROR got DDATA and fermenter %s/%s doesn't exist\n", edge_node, alias); | |
62 | return; | |
63 | } | |
64 | //printf("new_fermenter %s\n", new_fermenter ? "true":"false"); | |
65 | ||
66 | /* | |
67 | * Allocate new fermenter if not yet known. | |
68 | */ | |
69 | if (new_fermenter) { | |
70 | fermenter = (sys_fermenter_list *)malloc(sizeof(sys_fermenter_list)); | |
71 | memset(fermenter, 0, sizeof(sys_fermenter_list)); | |
72 | fermenter->alias = xstrcpy(alias); | |
73 | fermenter->node = xstrcpy(edge_node); | |
74 | fermenter->mode = xstrcpy((char *)"OFF"); | |
75 | fermenter->stage = xstrcpy((char *)"PRIMARY"); | |
76 | } | |
77 | ||
78 | fermenter->online = true; | |
79 | if (birth) { | |
80 | syslog(LOG_NOTICE, "Online fermenter %s/%s mode %s", edge_node, alias, fermenter->mode); | |
81 | } | |
82 | ||
83 | /* | |
84 | * Process the JSON formatted payload. | |
85 | * Update only the fields that are found in the payload. | |
86 | */ | |
87 | jobj = json_tokener_parse(payload); | |
88 | ||
89 | if (json_object_object_get_ex(jobj, "uuid", &val)) { | |
90 | if (fermenter->uuid) | |
91 | free(fermenter->uuid); | |
92 | fermenter->uuid = xstrcpy((char *)json_object_get_string(val)); | |
93 | } | |
94 | if (json_object_object_get_ex(jobj, "mode", &val)) { | |
95 | if (fermenter->mode) { | |
96 | if (strcmp(fermenter->mode, (char *)json_object_get_string(val))) { | |
97 | syslog(LOG_NOTICE, "Change mode fermenter %s/%s: %s to %s", edge_node, alias, fermenter->mode, (char *)json_object_get_string(val)); | |
98 | } | |
99 | free(fermenter->mode); | |
100 | } | |
101 | fermenter->mode = xstrcpy((char *)json_object_get_string(val)); | |
102 | } | |
103 | if (json_object_object_get_ex(jobj, "stage", &val)) { | |
104 | if (fermenter->stage) { | |
105 | if (strcmp(fermenter->stage, (char *)json_object_get_string(val))) { | |
106 | syslog(LOG_NOTICE, "Change stage fermenter %s/%s: %s to %s", edge_node, alias, fermenter->stage, (char *)json_object_get_string(val)); | |
107 | } | |
108 | free(fermenter->stage); | |
109 | } | |
110 | fermenter->stage = xstrcpy((char *)json_object_get_string(val)); | |
111 | } | |
112 | if (json_object_object_get_ex(jobj, "alarm", &val)) { | |
113 | if (fermenter->alarm != json_object_get_int(val)) { | |
114 | syslog(LOG_NOTICE, "Change alarm fermenter %s/%s: %d to %d", edge_node, alias, fermenter->alarm, json_object_get_int(val)); | |
115 | } | |
116 | fermenter->alarm = json_object_get_int(val); | |
117 | } | |
118 | if (json_object_object_get_ex(jobj, "product", &sensor)) { | |
119 | if (json_object_object_get_ex(sensor, "code", &val)) { | |
120 | if (fermenter->beercode) | |
121 | free(fermenter->beercode); | |
122 | fermenter->beercode = xstrcpy((char *)json_object_get_string(val)); | |
123 | } | |
124 | if (json_object_object_get_ex(sensor, "name", &val)) { | |
125 | if (fermenter->beername) | |
126 | free(fermenter->beername); | |
127 | fermenter->beername = xstrcpy((char *)json_object_get_string(val)); | |
128 | } | |
192
7f69b43e6084
Implemented beer uuid product in monitor fermenters.
Michiel Broek <mbroek@mbse.eu>
parents:
189
diff
changeset
|
129 | if (json_object_object_get_ex(sensor, "uuid", &val)) { |
7f69b43e6084
Implemented beer uuid product in monitor fermenters.
Michiel Broek <mbroek@mbse.eu>
parents:
189
diff
changeset
|
130 | if (fermenter->beeruuid) |
7f69b43e6084
Implemented beer uuid product in monitor fermenters.
Michiel Broek <mbroek@mbse.eu>
parents:
189
diff
changeset
|
131 | free(fermenter->beeruuid); |
7f69b43e6084
Implemented beer uuid product in monitor fermenters.
Michiel Broek <mbroek@mbse.eu>
parents:
189
diff
changeset
|
132 | fermenter->beeruuid = xstrcpy((char *)json_object_get_string(val)); |
7f69b43e6084
Implemented beer uuid product in monitor fermenters.
Michiel Broek <mbroek@mbse.eu>
parents:
189
diff
changeset
|
133 | } |
0 | 134 | } |
135 | if (json_object_object_get_ex(jobj, "air", &sensor)) { | |
136 | if (json_object_object_get_ex(sensor, "address", &val)) { | |
137 | if (fermenter->air_address) | |
138 | free(fermenter->air_address); | |
139 | fermenter->air_address= xstrcpy((char *)json_object_get_string(val)); | |
140 | } | |
141 | if (json_object_object_get_ex(sensor, "state", &val)) { | |
142 | if (fermenter->air_state) | |
143 | free(fermenter->air_state); | |
144 | fermenter->air_state= xstrcpy((char *)json_object_get_string(val)); | |
145 | } | |
146 | if (json_object_object_get_ex(sensor, "temperature", &val)) { | |
147 | fermenter->air_temperature = json_object_get_double(val); | |
148 | } | |
149 | } | |
150 | if (json_object_object_get_ex(jobj, "beer", &sensor)) { | |
151 | if (json_object_object_get_ex(sensor, "address", &val)) { | |
152 | if (fermenter->beer_address) | |
153 | free(fermenter->beer_address); | |
154 | fermenter->beer_address= xstrcpy((char *)json_object_get_string(val)); | |
155 | } | |
156 | if (json_object_object_get_ex(sensor, "state", &val)) { | |
157 | if (fermenter->beer_state) | |
158 | free(fermenter->beer_state); | |
159 | fermenter->beer_state= xstrcpy((char *)json_object_get_string(val)); | |
160 | } | |
161 | if (json_object_object_get_ex(sensor, "temperature", &val)) { | |
162 | fermenter->beer_temperature = json_object_get_double(val); | |
163 | } | |
164 | } | |
165 | if (json_object_object_get_ex(jobj, "chiller", &sensor)) { | |
166 | if (json_object_object_get_ex(sensor, "address", &val)) { | |
167 | if (fermenter->chiller_address) | |
168 | free(fermenter->chiller_address); | |
169 | fermenter->chiller_address= xstrcpy((char *)json_object_get_string(val)); | |
170 | } | |
171 | if (json_object_object_get_ex(sensor, "state", &val)) { | |
172 | if (fermenter->chiller_state) | |
173 | free(fermenter->chiller_state); | |
174 | fermenter->chiller_state= xstrcpy((char *)json_object_get_string(val)); | |
175 | } | |
176 | if (json_object_object_get_ex(sensor, "temperature", &val)) { | |
177 | fermenter->chiller_temperature = json_object_get_double(val); | |
178 | } | |
179 | } | |
180 | if (json_object_object_get_ex(jobj, "heater", &sensor)) { | |
181 | if (json_object_object_get_ex(sensor, "address", &val)) { | |
182 | if (fermenter->heater_address) | |
183 | free(fermenter->heater_address); | |
184 | fermenter->heater_address= xstrcpy((char *)json_object_get_string(val)); | |
185 | } | |
186 | if (json_object_object_get_ex(sensor, "state", &val)) { | |
187 | fermenter->heater_state = json_object_get_int(val); | |
188 | } | |
189 | if (json_object_object_get_ex(sensor, "usage", &val)) { | |
190 | fermenter->heater_usage = json_object_get_int(val); | |
191 | } | |
192 | } | |
193 | if (json_object_object_get_ex(jobj, "cooler", &sensor)) { | |
194 | if (json_object_object_get_ex(sensor, "address", &val)) { | |
195 | if (fermenter->cooler_address) | |
196 | free(fermenter->cooler_address); | |
197 | fermenter->cooler_address= xstrcpy((char *)json_object_get_string(val)); | |
198 | } | |
199 | if (json_object_object_get_ex(sensor, "state", &val)) { | |
200 | fermenter->cooler_state = json_object_get_int(val); | |
201 | } | |
202 | if (json_object_object_get_ex(sensor, "usage", &val)) { | |
203 | fermenter->cooler_usage = json_object_get_int(val); | |
204 | } | |
205 | } | |
206 | if (json_object_object_get_ex(jobj, "fan", &sensor)) { | |
207 | if (json_object_object_get_ex(sensor, "address", &val)) { | |
208 | if (fermenter->fan_address) | |
209 | free(fermenter->fan_address); | |
210 | fermenter->fan_address= xstrcpy((char *)json_object_get_string(val)); | |
211 | } | |
212 | if (json_object_object_get_ex(sensor, "state", &val)) { | |
213 | fermenter->fan_state = json_object_get_int(val); | |
214 | } | |
215 | if (json_object_object_get_ex(sensor, "usage", &val)) { | |
216 | fermenter->fan_usage = json_object_get_int(val); | |
217 | } | |
218 | } | |
219 | if (json_object_object_get_ex(jobj, "light", &sensor)) { | |
220 | if (json_object_object_get_ex(sensor, "address", &val)) { | |
221 | if (fermenter->light_address) | |
222 | free(fermenter->light_address); | |
223 | fermenter->light_address= xstrcpy((char *)json_object_get_string(val)); | |
224 | } | |
225 | if (json_object_object_get_ex(sensor, "state", &val)) { | |
226 | fermenter->light_state = json_object_get_int(val); | |
227 | } | |
228 | if (json_object_object_get_ex(sensor, "usage", &val)) { | |
229 | fermenter->light_usage = json_object_get_int(val); | |
230 | } | |
231 | } | |
232 | if (json_object_object_get_ex(jobj, "door", &sensor)) { | |
233 | if (json_object_object_get_ex(sensor, "address", &val)) { | |
234 | if (fermenter->door_address) | |
235 | free(fermenter->door_address); | |
236 | fermenter->door_address= xstrcpy((char *)json_object_get_string(val)); | |
237 | } | |
238 | if (json_object_object_get_ex(sensor, "state", &val)) { | |
239 | fermenter->door_state = json_object_get_int(val); | |
240 | } | |
241 | } | |
242 | if (json_object_object_get_ex(jobj, "psu", &sensor)) { | |
243 | if (json_object_object_get_ex(sensor, "address", &val)) { | |
244 | if (fermenter->psu_address) | |
245 | free(fermenter->psu_address); | |
246 | fermenter->psu_address= xstrcpy((char *)json_object_get_string(val)); | |
247 | } | |
248 | if (json_object_object_get_ex(sensor, "state", &val)) { | |
249 | fermenter->psu_state = json_object_get_int(val); | |
250 | } | |
251 | } | |
252 | if (json_object_object_get_ex(jobj, "setpoint", &sensor)) { | |
253 | if (json_object_object_get_ex(sensor, "low", &val)) { | |
254 | fermenter->setpoint_low = json_object_get_double(val); | |
255 | } | |
256 | if (json_object_object_get_ex(sensor, "high", &val)) { | |
257 | fermenter->setpoint_high = json_object_get_double(val); | |
258 | } | |
259 | } | |
260 | if (json_object_object_get_ex(jobj, "profile", &sensor)) { | |
261 | if (strcmp(json_object_to_json_string_ext(sensor, 0), "null")) { | |
262 | // printf("profile: %s\n", json_object_to_json_string_ext(sensor, 0)); | |
263 | ||
264 | if (json_object_object_get_ex(sensor, "uuid", &val)) { | |
265 | if (fermenter->profile_uuid) | |
266 | free(fermenter->profile_uuid); | |
267 | fermenter->profile_uuid = xstrcpy((char *)json_object_get_string(val)); | |
268 | } | |
269 | if (json_object_object_get_ex(sensor, "name", &val)) { | |
270 | if (fermenter->profile_name) | |
271 | free(fermenter->profile_name); | |
272 | fermenter->profile_name = xstrcpy((char *)json_object_get_string(val)); | |
273 | } | |
274 | if (json_object_object_get_ex(sensor, "state", &val)) { | |
275 | if (fermenter->profile_state) | |
276 | free(fermenter->profile_state); | |
277 | fermenter->profile_state = xstrcpy((char *)json_object_get_string(val)); | |
278 | } | |
189
6470e5c6a001
In bmsd added missing json percent. The Makefile didn't install the fpdf library. Added profile commands. Small changes to the monitor fermenters screen. The monitor fermenters scheduler is now more responsive. Profiles selection and commands in the remote thermferm.
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
279 | if (json_object_object_get_ex(sensor, "percent", &val)) { |
6470e5c6a001
In bmsd added missing json percent. The Makefile didn't install the fpdf library. Added profile commands. Small changes to the monitor fermenters screen. The monitor fermenters scheduler is now more responsive. Profiles selection and commands in the remote thermferm.
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
280 | fermenter->profile_percent = json_object_get_int(val); |
6470e5c6a001
In bmsd added missing json percent. The Makefile didn't install the fpdf library. Added profile commands. Small changes to the monitor fermenters screen. The monitor fermenters scheduler is now more responsive. Profiles selection and commands in the remote thermferm.
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
281 | } |
0 | 282 | if (json_object_object_get_ex(sensor, "inittemp", &temp)) { |
283 | if (json_object_object_get_ex(temp, "low", &val)) { | |
284 | fermenter->profile_inittemp_low = json_object_get_double(val); | |
285 | } | |
286 | if (json_object_object_get_ex(temp, "high", &val)) { | |
287 | fermenter->profile_inittemp_high = json_object_get_double(val); | |
288 | } | |
289 | } | |
290 | if (json_object_object_get_ex(sensor, "steps", &val)) { | |
291 | if (fermenter->profile_steps) | |
292 | free(fermenter->profile_steps); | |
293 | fermenter->profile_steps = xstrcpy((char *)json_object_to_json_string_ext(val, 0)); | |
294 | } | |
295 | ||
296 | ||
297 | } else { | |
298 | if (fermenter->profile_uuid) | |
299 | free(fermenter->profile_uuid); | |
300 | if (fermenter->profile_name) | |
301 | free(fermenter->profile_name); | |
302 | if (fermenter->profile_state) | |
303 | free(fermenter->profile_state); | |
304 | if (fermenter->profile_steps) | |
305 | free(fermenter->profile_steps); | |
306 | fermenter->profile_uuid = fermenter->profile_name = fermenter->profile_state = fermenter->profile_steps = NULL; | |
307 | fermenter->profile_percent = 0; | |
308 | fermenter->profile_inittemp_high = fermenter->profile_inittemp_low = 0.0; | |
309 | } | |
310 | } | |
311 | json_object_put(jobj); | |
312 | ||
313 | // fermenter_dump(fermenter); | |
314 | ||
315 | if (new_fermenter) { | |
316 | if (fermenters == NULL) { | |
317 | fermenters = fermenter; | |
318 | } else { | |
319 | for (tmpp = fermenters; tmpp; tmpp = tmpp->next) { | |
320 | if (tmpp->next == NULL) { | |
321 | tmpp->next = fermenter; | |
322 | break; | |
323 | } | |
324 | } | |
325 | } | |
326 | fermenter_mysql_insert(fermenter); | |
327 | } else { | |
328 | fermenter_mysql_update(fermenter); | |
329 | } | |
330 | ||
331 | } | |
332 | ||
333 | ||
334 | ||
335 | /* | |
336 | * With DBIRTH all active fermenters are publishd in an array. | |
337 | * With DDATA only one fermenter is published in the payload. | |
338 | */ | |
339 | void fermenter_birth_data(char *topic, char *payload) | |
340 | { | |
341 | char *message_type, *edge_node, *alias; | |
342 | struct json_object *jobj, *val, *metric, *units, *unit; | |
343 | int arraylen; | |
344 | ||
345 | strtok(topic, "/"); // ignore namespace | |
346 | strtok(NULL, "/"); | |
347 | message_type = strtok(NULL, "/"); | |
348 | edge_node = strtok(NULL, "/\0"); | |
349 | alias = strtok(NULL, "/\0"); | |
350 | ||
351 | if ((alias == NULL) && (strcmp("DBIRTH", message_type) == 0)) { | |
352 | /* | |
353 | * Global initial DBIRTH message with array of fermenters. | |
354 | */ | |
355 | jobj = json_tokener_parse(payload); | |
356 | ||
357 | if (json_object_object_get_ex(jobj, "metric", &metric)) { | |
358 | if (json_object_object_get_ex(metric, "units", &units)) { | |
359 | arraylen = json_object_array_length(units); | |
360 | for (int i = 0; i < arraylen; i++) { | |
361 | /* | |
362 | * Parse the array of units | |
363 | */ | |
364 | unit = json_object_array_get_idx(units, i); | |
365 | ||
366 | if (json_object_object_get_ex(unit, "alias", &val)) { | |
367 | if (alias) | |
368 | free(alias); | |
369 | alias = xstrcpy((char *)json_object_get_string(val)); | |
370 | fermenter_set(edge_node, alias, true, (char *)json_object_to_json_string_ext(unit, 0)); | |
371 | free(alias); | |
372 | alias = NULL; | |
373 | } | |
374 | } | |
375 | } | |
376 | } | |
377 | json_object_put(jobj); | |
378 | return; | |
379 | } | |
380 | ||
381 | if (strcmp("DBIRTH", message_type) == 0) { | |
382 | /* | |
383 | * DBIRTH for just one fermenter. | |
384 | */ | |
385 | jobj = json_tokener_parse(payload); | |
386 | ||
387 | if (json_object_object_get_ex(jobj, "metric", &metric)) { | |
388 | fermenter_set(edge_node, alias, true, (char *)json_object_to_json_string_ext(metric, 0)); | |
389 | } | |
390 | json_object_put(jobj); | |
391 | return; | |
392 | } | |
393 | ||
394 | if (strcmp("DDATA", message_type) == 0) { | |
395 | /* | |
396 | * DDATA update messages for each fermenter. | |
397 | */ | |
398 | jobj = json_tokener_parse(payload); | |
399 | ||
400 | if (json_object_object_get_ex(jobj, "metric", &metric)) { | |
401 | fermenter_set(edge_node, alias, false, (char *)json_object_to_json_string_ext(metric, 0)); | |
402 | } | |
403 | json_object_put(jobj); | |
404 | return; | |
405 | } | |
406 | ||
407 | /* | |
408 | * The rest are errors. | |
409 | */ | |
410 | printf("ERROR fermenter_birth_data: %s %s %s\n", message_type, edge_node, alias); | |
411 | } | |
412 | ||
413 | ||
414 | ||
415 | void fermenter_log(char *topic, char *payload) | |
416 | { | |
194
d202777ebae5
Added design notes for the csv log format from fermenters. In bmsd configuration added the web_root entry. Switched fermenter DLOG messages to store the log in flat csv files instead of the database. This is much faster and the graphs look better.
Michiel Broek <mbroek@mbse.eu>
parents:
192
diff
changeset
|
417 | char *edge_node, *alias, *line, buf[65], *logfile; |
0 | 418 | struct json_object *jobj, *val, *metric, *metric2; |
419 | fermentation_log *log; | |
420 | struct tm *mytime; | |
421 | time_t timestamp; | |
194
d202777ebae5
Added design notes for the csv log format from fermenters. In bmsd configuration added the web_root entry. Switched fermenter DLOG messages to store the log in flat csv files instead of the database. This is much faster and the graphs look better.
Michiel Broek <mbroek@mbse.eu>
parents:
192
diff
changeset
|
422 | FILE *fp; |
0 | 423 | |
424 | strtok(topic, "/"); // ignore namespace | |
425 | strtok(NULL, "/"); // group_id | |
426 | strtok(NULL, "/"); // message_type | |
427 | edge_node = strtok(NULL, "/\0"); | |
428 | alias = strtok(NULL, "/\0"); | |
429 | ||
430 | log = (fermentation_log *)malloc(sizeof(fermentation_log)); | |
431 | memset(log, 0, sizeof(fermentation_log)); | |
432 | ||
433 | log->fermenter_node = xstrcpy(edge_node); | |
434 | log->fermenter_alias = xstrcpy(alias); | |
435 | jobj = json_tokener_parse(payload); | |
436 | ||
437 | if (json_object_object_get_ex(jobj, "timestamp", &val)) { | |
438 | timestamp = json_object_get_int(val); | |
439 | log->datetime = malloc(21); | |
440 | mytime = localtime(×tamp); | |
441 | snprintf(log->datetime, 20, "%04d-%02d-%02d %02d:%02d:%02d", | |
442 | mytime->tm_year + 1900, mytime->tm_mon + 1, mytime->tm_mday, mytime->tm_hour, mytime->tm_min, mytime->tm_sec); | |
443 | } | |
444 | ||
445 | if (json_object_object_get_ex(jobj, "metric", &metric)) { | |
446 | ||
447 | if (json_object_object_get_ex(metric, "product", &metric2)) { | |
448 | if (json_object_object_get_ex(metric2, "uuid", &val)) { | |
449 | if (strcmp((char *)"(null)", json_object_get_string(val))) | |
450 | log->product_uuid = xstrcpy((char *)json_object_get_string(val)); | |
451 | } | |
452 | if (json_object_object_get_ex(metric2, "code", &val)) { | |
453 | if (strcmp((char *)"(null)", json_object_get_string(val))) | |
454 | log->product_code = xstrcpy((char *)json_object_get_string(val)); | |
455 | } | |
456 | if (json_object_object_get_ex(metric2, "name", &val)) { | |
457 | if (strcmp((char *)"(null)", json_object_get_string(val))) | |
458 | log->product_name = xstrcpy((char *)json_object_get_string(val)); | |
459 | } | |
460 | } | |
461 | if (json_object_object_get_ex(metric, "stage", &val)) { | |
462 | log->stage = xstrcpy((char *)json_object_get_string(val)); | |
463 | } | |
464 | if (json_object_object_get_ex(metric, "mode", &val)) { | |
465 | log->mode = xstrcpy((char *)json_object_get_string(val)); | |
466 | } | |
467 | if (json_object_object_get_ex(metric, "event", &val)) { | |
468 | if (strcmp((char *)"(null)", json_object_get_string(val))) | |
469 | log->event = xstrcpy((char *)json_object_get_string(val)); | |
470 | } | |
471 | if (json_object_object_get_ex(metric, "fermenter_uuid", &val)) { | |
472 | if (strcmp((char *)"(null)", json_object_get_string(val))) | |
473 | log->fermenter_uuid = xstrcpy((char *)json_object_get_string(val)); | |
474 | } | |
475 | if (json_object_object_get_ex(metric, "temperature", &metric2)) { | |
476 | if (json_object_object_get_ex(metric2, "air", &val)) { | |
477 | log->temperature_air = json_object_get_double(val); | |
478 | } | |
479 | if (json_object_object_get_ex(metric2, "beer", &val)) { | |
480 | log->temperature_beer = json_object_get_double(val); | |
481 | } | |
482 | if (json_object_object_get_ex(metric2, "chiller", &val)) { | |
483 | log->temperature_chiller = json_object_get_double(val); | |
484 | } | |
485 | if (json_object_object_get_ex(metric2, "room", &val)) { | |
486 | log->temperature_room = json_object_get_double(val); | |
487 | } | |
488 | } | |
489 | if (json_object_object_get_ex(metric, "setpoint", &metric2)) { | |
490 | if (json_object_object_get_ex(metric2, "low", &val)) { | |
491 | log->setpoint_low = json_object_get_double(val); | |
492 | } | |
493 | if (json_object_object_get_ex(metric2, "high", &val)) { | |
494 | log->setpoint_high = json_object_get_double(val); | |
495 | } | |
496 | } | |
497 | if (json_object_object_get_ex(metric, "heater", &metric2)) { | |
498 | if (json_object_object_get_ex(metric2, "power", &val)) { | |
499 | log->heater_power = json_object_get_int(val); | |
500 | } | |
501 | if (json_object_object_get_ex(metric2, "usage", &val)) { | |
502 | log->heater_usage = json_object_get_int(val); | |
503 | } | |
504 | } | |
505 | if (json_object_object_get_ex(metric, "cooler", &metric2)) { | |
506 | if (json_object_object_get_ex(metric2, "power", &val)) { | |
507 | log->cooler_power = json_object_get_int(val); | |
508 | } | |
509 | if (json_object_object_get_ex(metric2, "usage", &val)) { | |
510 | log->cooler_usage = json_object_get_int(val); | |
511 | } | |
512 | } | |
513 | if (json_object_object_get_ex(metric, "fan", &metric2)) { | |
514 | if (json_object_object_get_ex(metric2, "power", &val)) { | |
515 | log->fan_power = json_object_get_int(val); | |
516 | } | |
517 | if (json_object_object_get_ex(metric2, "usage", &val)) { | |
518 | log->fan_usage = json_object_get_int(val); | |
519 | } | |
520 | } | |
521 | } | |
522 | json_object_put(jobj); | |
523 | ||
194
d202777ebae5
Added design notes for the csv log format from fermenters. In bmsd configuration added the web_root entry. Switched fermenter DLOG messages to store the log in flat csv files instead of the database. This is much faster and the graphs look better.
Michiel Broek <mbroek@mbse.eu>
parents:
192
diff
changeset
|
524 | /* |
d202777ebae5
Added design notes for the csv log format from fermenters. In bmsd configuration added the web_root entry. Switched fermenter DLOG messages to store the log in flat csv files instead of the database. This is much faster and the graphs look better.
Michiel Broek <mbroek@mbse.eu>
parents:
192
diff
changeset
|
525 | * Build csv log line |
d202777ebae5
Added design notes for the csv log format from fermenters. In bmsd configuration added the web_root entry. Switched fermenter DLOG messages to store the log in flat csv files instead of the database. This is much faster and the graphs look better.
Michiel Broek <mbroek@mbse.eu>
parents:
192
diff
changeset
|
526 | */ |
d202777ebae5
Added design notes for the csv log format from fermenters. In bmsd configuration added the web_root entry. Switched fermenter DLOG messages to store the log in flat csv files instead of the database. This is much faster and the graphs look better.
Michiel Broek <mbroek@mbse.eu>
parents:
192
diff
changeset
|
527 | line = xstrcpy(log->datetime); |
d202777ebae5
Added design notes for the csv log format from fermenters. In bmsd configuration added the web_root entry. Switched fermenter DLOG messages to store the log in flat csv files instead of the database. This is much faster and the graphs look better.
Michiel Broek <mbroek@mbse.eu>
parents:
192
diff
changeset
|
528 | line = xstrcat(line, (char *)","); |
d202777ebae5
Added design notes for the csv log format from fermenters. In bmsd configuration added the web_root entry. Switched fermenter DLOG messages to store the log in flat csv files instead of the database. This is much faster and the graphs look better.
Michiel Broek <mbroek@mbse.eu>
parents:
192
diff
changeset
|
529 | line = xstrcat(line, log->mode); |
d202777ebae5
Added design notes for the csv log format from fermenters. In bmsd configuration added the web_root entry. Switched fermenter DLOG messages to store the log in flat csv files instead of the database. This is much faster and the graphs look better.
Michiel Broek <mbroek@mbse.eu>
parents:
192
diff
changeset
|
530 | line = xstrcat(line, (char *)","); |
d202777ebae5
Added design notes for the csv log format from fermenters. In bmsd configuration added the web_root entry. Switched fermenter DLOG messages to store the log in flat csv files instead of the database. This is much faster and the graphs look better.
Michiel Broek <mbroek@mbse.eu>
parents:
192
diff
changeset
|
531 | line = xstrcat(line, log->stage); |
d202777ebae5
Added design notes for the csv log format from fermenters. In bmsd configuration added the web_root entry. Switched fermenter DLOG messages to store the log in flat csv files instead of the database. This is much faster and the graphs look better.
Michiel Broek <mbroek@mbse.eu>
parents:
192
diff
changeset
|
532 | line = xstrcat(line, (char *)","); |
d202777ebae5
Added design notes for the csv log format from fermenters. In bmsd configuration added the web_root entry. Switched fermenter DLOG messages to store the log in flat csv files instead of the database. This is much faster and the graphs look better.
Michiel Broek <mbroek@mbse.eu>
parents:
192
diff
changeset
|
533 | snprintf(buf, 64, "%.3f", log->temperature_air); |
d202777ebae5
Added design notes for the csv log format from fermenters. In bmsd configuration added the web_root entry. Switched fermenter DLOG messages to store the log in flat csv files instead of the database. This is much faster and the graphs look better.
Michiel Broek <mbroek@mbse.eu>
parents:
192
diff
changeset
|
534 | line = xstrcat(line, buf); |
d202777ebae5
Added design notes for the csv log format from fermenters. In bmsd configuration added the web_root entry. Switched fermenter DLOG messages to store the log in flat csv files instead of the database. This is much faster and the graphs look better.
Michiel Broek <mbroek@mbse.eu>
parents:
192
diff
changeset
|
535 | line = xstrcat(line, (char *)","); |
d202777ebae5
Added design notes for the csv log format from fermenters. In bmsd configuration added the web_root entry. Switched fermenter DLOG messages to store the log in flat csv files instead of the database. This is much faster and the graphs look better.
Michiel Broek <mbroek@mbse.eu>
parents:
192
diff
changeset
|
536 | snprintf(buf, 64, "%.3f", log->temperature_beer); |
d202777ebae5
Added design notes for the csv log format from fermenters. In bmsd configuration added the web_root entry. Switched fermenter DLOG messages to store the log in flat csv files instead of the database. This is much faster and the graphs look better.
Michiel Broek <mbroek@mbse.eu>
parents:
192
diff
changeset
|
537 | line = xstrcat(line, buf); |
d202777ebae5
Added design notes for the csv log format from fermenters. In bmsd configuration added the web_root entry. Switched fermenter DLOG messages to store the log in flat csv files instead of the database. This is much faster and the graphs look better.
Michiel Broek <mbroek@mbse.eu>
parents:
192
diff
changeset
|
538 | line = xstrcat(line, (char *)","); |
d202777ebae5
Added design notes for the csv log format from fermenters. In bmsd configuration added the web_root entry. Switched fermenter DLOG messages to store the log in flat csv files instead of the database. This is much faster and the graphs look better.
Michiel Broek <mbroek@mbse.eu>
parents:
192
diff
changeset
|
539 | snprintf(buf, 64, "%.3f", log->temperature_chiller); |
d202777ebae5
Added design notes for the csv log format from fermenters. In bmsd configuration added the web_root entry. Switched fermenter DLOG messages to store the log in flat csv files instead of the database. This is much faster and the graphs look better.
Michiel Broek <mbroek@mbse.eu>
parents:
192
diff
changeset
|
540 | line = xstrcat(line, buf); |
d202777ebae5
Added design notes for the csv log format from fermenters. In bmsd configuration added the web_root entry. Switched fermenter DLOG messages to store the log in flat csv files instead of the database. This is much faster and the graphs look better.
Michiel Broek <mbroek@mbse.eu>
parents:
192
diff
changeset
|
541 | line = xstrcat(line, (char *)","); |
d202777ebae5
Added design notes for the csv log format from fermenters. In bmsd configuration added the web_root entry. Switched fermenter DLOG messages to store the log in flat csv files instead of the database. This is much faster and the graphs look better.
Michiel Broek <mbroek@mbse.eu>
parents:
192
diff
changeset
|
542 | snprintf(buf, 64, "%.3f", log->temperature_room); |
d202777ebae5
Added design notes for the csv log format from fermenters. In bmsd configuration added the web_root entry. Switched fermenter DLOG messages to store the log in flat csv files instead of the database. This is much faster and the graphs look better.
Michiel Broek <mbroek@mbse.eu>
parents:
192
diff
changeset
|
543 | line = xstrcat(line, buf); |
d202777ebae5
Added design notes for the csv log format from fermenters. In bmsd configuration added the web_root entry. Switched fermenter DLOG messages to store the log in flat csv files instead of the database. This is much faster and the graphs look better.
Michiel Broek <mbroek@mbse.eu>
parents:
192
diff
changeset
|
544 | line = xstrcat(line, (char *)","); |
d202777ebae5
Added design notes for the csv log format from fermenters. In bmsd configuration added the web_root entry. Switched fermenter DLOG messages to store the log in flat csv files instead of the database. This is much faster and the graphs look better.
Michiel Broek <mbroek@mbse.eu>
parents:
192
diff
changeset
|
545 | snprintf(buf, 64, "%.1f", log->setpoint_low); |
d202777ebae5
Added design notes for the csv log format from fermenters. In bmsd configuration added the web_root entry. Switched fermenter DLOG messages to store the log in flat csv files instead of the database. This is much faster and the graphs look better.
Michiel Broek <mbroek@mbse.eu>
parents:
192
diff
changeset
|
546 | line = xstrcat(line, buf); |
d202777ebae5
Added design notes for the csv log format from fermenters. In bmsd configuration added the web_root entry. Switched fermenter DLOG messages to store the log in flat csv files instead of the database. This is much faster and the graphs look better.
Michiel Broek <mbroek@mbse.eu>
parents:
192
diff
changeset
|
547 | line = xstrcat(line, (char *)","); |
d202777ebae5
Added design notes for the csv log format from fermenters. In bmsd configuration added the web_root entry. Switched fermenter DLOG messages to store the log in flat csv files instead of the database. This is much faster and the graphs look better.
Michiel Broek <mbroek@mbse.eu>
parents:
192
diff
changeset
|
548 | snprintf(buf, 64, "%.1f", log->setpoint_high); |
d202777ebae5
Added design notes for the csv log format from fermenters. In bmsd configuration added the web_root entry. Switched fermenter DLOG messages to store the log in flat csv files instead of the database. This is much faster and the graphs look better.
Michiel Broek <mbroek@mbse.eu>
parents:
192
diff
changeset
|
549 | line = xstrcat(line, buf); |
d202777ebae5
Added design notes for the csv log format from fermenters. In bmsd configuration added the web_root entry. Switched fermenter DLOG messages to store the log in flat csv files instead of the database. This is much faster and the graphs look better.
Michiel Broek <mbroek@mbse.eu>
parents:
192
diff
changeset
|
550 | line = xstrcat(line, (char *)","); |
d202777ebae5
Added design notes for the csv log format from fermenters. In bmsd configuration added the web_root entry. Switched fermenter DLOG messages to store the log in flat csv files instead of the database. This is much faster and the graphs look better.
Michiel Broek <mbroek@mbse.eu>
parents:
192
diff
changeset
|
551 | snprintf(buf, 64, "%d", log->heater_power); |
d202777ebae5
Added design notes for the csv log format from fermenters. In bmsd configuration added the web_root entry. Switched fermenter DLOG messages to store the log in flat csv files instead of the database. This is much faster and the graphs look better.
Michiel Broek <mbroek@mbse.eu>
parents:
192
diff
changeset
|
552 | line = xstrcat(line, buf); |
d202777ebae5
Added design notes for the csv log format from fermenters. In bmsd configuration added the web_root entry. Switched fermenter DLOG messages to store the log in flat csv files instead of the database. This is much faster and the graphs look better.
Michiel Broek <mbroek@mbse.eu>
parents:
192
diff
changeset
|
553 | line = xstrcat(line, (char *)","); |
d202777ebae5
Added design notes for the csv log format from fermenters. In bmsd configuration added the web_root entry. Switched fermenter DLOG messages to store the log in flat csv files instead of the database. This is much faster and the graphs look better.
Michiel Broek <mbroek@mbse.eu>
parents:
192
diff
changeset
|
554 | snprintf(buf, 64, "%ld", log->heater_usage); |
d202777ebae5
Added design notes for the csv log format from fermenters. In bmsd configuration added the web_root entry. Switched fermenter DLOG messages to store the log in flat csv files instead of the database. This is much faster and the graphs look better.
Michiel Broek <mbroek@mbse.eu>
parents:
192
diff
changeset
|
555 | line = xstrcat(line, buf); |
d202777ebae5
Added design notes for the csv log format from fermenters. In bmsd configuration added the web_root entry. Switched fermenter DLOG messages to store the log in flat csv files instead of the database. This is much faster and the graphs look better.
Michiel Broek <mbroek@mbse.eu>
parents:
192
diff
changeset
|
556 | line = xstrcat(line, (char *)","); |
d202777ebae5
Added design notes for the csv log format from fermenters. In bmsd configuration added the web_root entry. Switched fermenter DLOG messages to store the log in flat csv files instead of the database. This is much faster and the graphs look better.
Michiel Broek <mbroek@mbse.eu>
parents:
192
diff
changeset
|
557 | snprintf(buf, 64, "%d", log->cooler_power); |
d202777ebae5
Added design notes for the csv log format from fermenters. In bmsd configuration added the web_root entry. Switched fermenter DLOG messages to store the log in flat csv files instead of the database. This is much faster and the graphs look better.
Michiel Broek <mbroek@mbse.eu>
parents:
192
diff
changeset
|
558 | line = xstrcat(line, buf); |
d202777ebae5
Added design notes for the csv log format from fermenters. In bmsd configuration added the web_root entry. Switched fermenter DLOG messages to store the log in flat csv files instead of the database. This is much faster and the graphs look better.
Michiel Broek <mbroek@mbse.eu>
parents:
192
diff
changeset
|
559 | line = xstrcat(line, (char *)","); |
d202777ebae5
Added design notes for the csv log format from fermenters. In bmsd configuration added the web_root entry. Switched fermenter DLOG messages to store the log in flat csv files instead of the database. This is much faster and the graphs look better.
Michiel Broek <mbroek@mbse.eu>
parents:
192
diff
changeset
|
560 | snprintf(buf, 64, "%ld", log->cooler_usage); |
d202777ebae5
Added design notes for the csv log format from fermenters. In bmsd configuration added the web_root entry. Switched fermenter DLOG messages to store the log in flat csv files instead of the database. This is much faster and the graphs look better.
Michiel Broek <mbroek@mbse.eu>
parents:
192
diff
changeset
|
561 | line = xstrcat(line, buf); |
d202777ebae5
Added design notes for the csv log format from fermenters. In bmsd configuration added the web_root entry. Switched fermenter DLOG messages to store the log in flat csv files instead of the database. This is much faster and the graphs look better.
Michiel Broek <mbroek@mbse.eu>
parents:
192
diff
changeset
|
562 | line = xstrcat(line, (char *)","); |
d202777ebae5
Added design notes for the csv log format from fermenters. In bmsd configuration added the web_root entry. Switched fermenter DLOG messages to store the log in flat csv files instead of the database. This is much faster and the graphs look better.
Michiel Broek <mbroek@mbse.eu>
parents:
192
diff
changeset
|
563 | if (log->event) |
d202777ebae5
Added design notes for the csv log format from fermenters. In bmsd configuration added the web_root entry. Switched fermenter DLOG messages to store the log in flat csv files instead of the database. This is much faster and the graphs look better.
Michiel Broek <mbroek@mbse.eu>
parents:
192
diff
changeset
|
564 | line = xstrcat(line, log->event); |
d202777ebae5
Added design notes for the csv log format from fermenters. In bmsd configuration added the web_root entry. Switched fermenter DLOG messages to store the log in flat csv files instead of the database. This is much faster and the graphs look better.
Michiel Broek <mbroek@mbse.eu>
parents:
192
diff
changeset
|
565 | line = xstrcat(line, (char *)","); |
d202777ebae5
Added design notes for the csv log format from fermenters. In bmsd configuration added the web_root entry. Switched fermenter DLOG messages to store the log in flat csv files instead of the database. This is much faster and the graphs look better.
Michiel Broek <mbroek@mbse.eu>
parents:
192
diff
changeset
|
566 | if (log->fermenter_uuid) |
d202777ebae5
Added design notes for the csv log format from fermenters. In bmsd configuration added the web_root entry. Switched fermenter DLOG messages to store the log in flat csv files instead of the database. This is much faster and the graphs look better.
Michiel Broek <mbroek@mbse.eu>
parents:
192
diff
changeset
|
567 | line = xstrcat(line, log->fermenter_uuid); |
d202777ebae5
Added design notes for the csv log format from fermenters. In bmsd configuration added the web_root entry. Switched fermenter DLOG messages to store the log in flat csv files instead of the database. This is much faster and the graphs look better.
Michiel Broek <mbroek@mbse.eu>
parents:
192
diff
changeset
|
568 | |
d202777ebae5
Added design notes for the csv log format from fermenters. In bmsd configuration added the web_root entry. Switched fermenter DLOG messages to store the log in flat csv files instead of the database. This is much faster and the graphs look better.
Michiel Broek <mbroek@mbse.eu>
parents:
192
diff
changeset
|
569 | /* |
d202777ebae5
Added design notes for the csv log format from fermenters. In bmsd configuration added the web_root entry. Switched fermenter DLOG messages to store the log in flat csv files instead of the database. This is much faster and the graphs look better.
Michiel Broek <mbroek@mbse.eu>
parents:
192
diff
changeset
|
570 | * Build logfile name |
d202777ebae5
Added design notes for the csv log format from fermenters. In bmsd configuration added the web_root entry. Switched fermenter DLOG messages to store the log in flat csv files instead of the database. This is much faster and the graphs look better.
Michiel Broek <mbroek@mbse.eu>
parents:
192
diff
changeset
|
571 | */ |
d202777ebae5
Added design notes for the csv log format from fermenters. In bmsd configuration added the web_root entry. Switched fermenter DLOG messages to store the log in flat csv files instead of the database. This is much faster and the graphs look better.
Michiel Broek <mbroek@mbse.eu>
parents:
192
diff
changeset
|
572 | logfile = xstrcpy(Config.web_root); |
d202777ebae5
Added design notes for the csv log format from fermenters. In bmsd configuration added the web_root entry. Switched fermenter DLOG messages to store the log in flat csv files instead of the database. This is much faster and the graphs look better.
Michiel Broek <mbroek@mbse.eu>
parents:
192
diff
changeset
|
573 | logfile = xstrcat(logfile, (char *)"/log/fermentation/"); |
d202777ebae5
Added design notes for the csv log format from fermenters. In bmsd configuration added the web_root entry. Switched fermenter DLOG messages to store the log in flat csv files instead of the database. This is much faster and the graphs look better.
Michiel Broek <mbroek@mbse.eu>
parents:
192
diff
changeset
|
574 | logfile = xstrcat(logfile, log->product_code); |
d202777ebae5
Added design notes for the csv log format from fermenters. In bmsd configuration added the web_root entry. Switched fermenter DLOG messages to store the log in flat csv files instead of the database. This is much faster and the graphs look better.
Michiel Broek <mbroek@mbse.eu>
parents:
192
diff
changeset
|
575 | logfile = xstrcat(logfile, (char *)" "); |
d202777ebae5
Added design notes for the csv log format from fermenters. In bmsd configuration added the web_root entry. Switched fermenter DLOG messages to store the log in flat csv files instead of the database. This is much faster and the graphs look better.
Michiel Broek <mbroek@mbse.eu>
parents:
192
diff
changeset
|
576 | logfile = xstrcat(logfile, log->product_name); |
d202777ebae5
Added design notes for the csv log format from fermenters. In bmsd configuration added the web_root entry. Switched fermenter DLOG messages to store the log in flat csv files instead of the database. This is much faster and the graphs look better.
Michiel Broek <mbroek@mbse.eu>
parents:
192
diff
changeset
|
577 | logfile = xstrcat(logfile, (char *)".log"); |
d202777ebae5
Added design notes for the csv log format from fermenters. In bmsd configuration added the web_root entry. Switched fermenter DLOG messages to store the log in flat csv files instead of the database. This is much faster and the graphs look better.
Michiel Broek <mbroek@mbse.eu>
parents:
192
diff
changeset
|
578 | |
d202777ebae5
Added design notes for the csv log format from fermenters. In bmsd configuration added the web_root entry. Switched fermenter DLOG messages to store the log in flat csv files instead of the database. This is much faster and the graphs look better.
Michiel Broek <mbroek@mbse.eu>
parents:
192
diff
changeset
|
579 | if (debug) |
d202777ebae5
Added design notes for the csv log format from fermenters. In bmsd configuration added the web_root entry. Switched fermenter DLOG messages to store the log in flat csv files instead of the database. This is much faster and the graphs look better.
Michiel Broek <mbroek@mbse.eu>
parents:
192
diff
changeset
|
580 | fprintf(stdout, "%s %s\n", logfile, line); |
d202777ebae5
Added design notes for the csv log format from fermenters. In bmsd configuration added the web_root entry. Switched fermenter DLOG messages to store the log in flat csv files instead of the database. This is much faster and the graphs look better.
Michiel Broek <mbroek@mbse.eu>
parents:
192
diff
changeset
|
581 | |
d202777ebae5
Added design notes for the csv log format from fermenters. In bmsd configuration added the web_root entry. Switched fermenter DLOG messages to store the log in flat csv files instead of the database. This is much faster and the graphs look better.
Michiel Broek <mbroek@mbse.eu>
parents:
192
diff
changeset
|
582 | fp = fopen(logfile, "a"); |
d202777ebae5
Added design notes for the csv log format from fermenters. In bmsd configuration added the web_root entry. Switched fermenter DLOG messages to store the log in flat csv files instead of the database. This is much faster and the graphs look better.
Michiel Broek <mbroek@mbse.eu>
parents:
192
diff
changeset
|
583 | if (fp) { |
d202777ebae5
Added design notes for the csv log format from fermenters. In bmsd configuration added the web_root entry. Switched fermenter DLOG messages to store the log in flat csv files instead of the database. This is much faster and the graphs look better.
Michiel Broek <mbroek@mbse.eu>
parents:
192
diff
changeset
|
584 | fprintf(fp, "%s\n", line); |
d202777ebae5
Added design notes for the csv log format from fermenters. In bmsd configuration added the web_root entry. Switched fermenter DLOG messages to store the log in flat csv files instead of the database. This is much faster and the graphs look better.
Michiel Broek <mbroek@mbse.eu>
parents:
192
diff
changeset
|
585 | fclose(fp); |
d202777ebae5
Added design notes for the csv log format from fermenters. In bmsd configuration added the web_root entry. Switched fermenter DLOG messages to store the log in flat csv files instead of the database. This is much faster and the graphs look better.
Michiel Broek <mbroek@mbse.eu>
parents:
192
diff
changeset
|
586 | } else { |
d202777ebae5
Added design notes for the csv log format from fermenters. In bmsd configuration added the web_root entry. Switched fermenter DLOG messages to store the log in flat csv files instead of the database. This is much faster and the graphs look better.
Michiel Broek <mbroek@mbse.eu>
parents:
192
diff
changeset
|
587 | syslog(LOG_NOTICE, "cannot append to `%s'", logfile); |
d202777ebae5
Added design notes for the csv log format from fermenters. In bmsd configuration added the web_root entry. Switched fermenter DLOG messages to store the log in flat csv files instead of the database. This is much faster and the graphs look better.
Michiel Broek <mbroek@mbse.eu>
parents:
192
diff
changeset
|
588 | } |
d202777ebae5
Added design notes for the csv log format from fermenters. In bmsd configuration added the web_root entry. Switched fermenter DLOG messages to store the log in flat csv files instead of the database. This is much faster and the graphs look better.
Michiel Broek <mbroek@mbse.eu>
parents:
192
diff
changeset
|
589 | |
d202777ebae5
Added design notes for the csv log format from fermenters. In bmsd configuration added the web_root entry. Switched fermenter DLOG messages to store the log in flat csv files instead of the database. This is much faster and the graphs look better.
Michiel Broek <mbroek@mbse.eu>
parents:
192
diff
changeset
|
590 | free(logfile); |
d202777ebae5
Added design notes for the csv log format from fermenters. In bmsd configuration added the web_root entry. Switched fermenter DLOG messages to store the log in flat csv files instead of the database. This is much faster and the graphs look better.
Michiel Broek <mbroek@mbse.eu>
parents:
192
diff
changeset
|
591 | logfile = NULL; |
d202777ebae5
Added design notes for the csv log format from fermenters. In bmsd configuration added the web_root entry. Switched fermenter DLOG messages to store the log in flat csv files instead of the database. This is much faster and the graphs look better.
Michiel Broek <mbroek@mbse.eu>
parents:
192
diff
changeset
|
592 | free(line); |
d202777ebae5
Added design notes for the csv log format from fermenters. In bmsd configuration added the web_root entry. Switched fermenter DLOG messages to store the log in flat csv files instead of the database. This is much faster and the graphs look better.
Michiel Broek <mbroek@mbse.eu>
parents:
192
diff
changeset
|
593 | line = NULL; |
d202777ebae5
Added design notes for the csv log format from fermenters. In bmsd configuration added the web_root entry. Switched fermenter DLOG messages to store the log in flat csv files instead of the database. This is much faster and the graphs look better.
Michiel Broek <mbroek@mbse.eu>
parents:
192
diff
changeset
|
594 | |
0 | 595 | if (log->datetime) |
596 | free(log->datetime); | |
597 | if (log->product_uuid ) | |
598 | free(log->product_uuid ); | |
599 | if (log->product_code ) | |
600 | free(log->product_code ); | |
601 | if (log->product_name ) | |
602 | free(log->product_name ); | |
603 | if (log->stage) | |
604 | free(log->stage); | |
605 | if (log->mode) | |
606 | free(log->mode); | |
607 | if (log->event) | |
608 | free(log->event); | |
609 | if (log->fermenter_uuid) | |
610 | free(log->fermenter_uuid); | |
611 | if (log->fermenter_node) | |
612 | free(log->fermenter_node); | |
613 | if (log->fermenter_alias) | |
614 | free(log->fermenter_alias); | |
615 | free(log); | |
616 | } | |
617 | ||
618 | ||
619 | ||
620 | void fermenter_dump(sys_fermenter_list *fermenter) | |
621 | { | |
622 | if (debug) { | |
623 | printf("uuid %s\n", fermenter->uuid); | |
624 | printf("alias %s\n", fermenter->alias); | |
625 | printf("node %s\n", fermenter->node); | |
626 | printf("online %s\n", fermenter->online ? "yes":"no"); | |
627 | printf("product %s / %s\n", fermenter->beercode, fermenter->beername); | |
628 | if (fermenter->air_address) | |
629 | printf("Air %-36s %10s %8.3f\n", fermenter->air_address, fermenter->air_state, fermenter->air_temperature); | |
630 | if (fermenter->beer_address) | |
631 | printf("Beer %-36s %10s %8.3f\n", fermenter->beer_address, fermenter->beer_state, fermenter->beer_temperature); | |
632 | if (fermenter->chiller_address) | |
633 | printf("Chiller %-36s %10s %8.3f\n", fermenter->chiller_address, fermenter->chiller_state, fermenter->chiller_temperature); | |
634 | if (fermenter->heater_address) | |
635 | printf("Heater %-36s %9d%% %8lu\n", fermenter->heater_address, fermenter->heater_state, fermenter->heater_usage); | |
636 | if (fermenter->cooler_address) | |
637 | printf("Cooler %-36s %9d%% %8lu\n", fermenter->cooler_address, fermenter->cooler_state, fermenter->cooler_usage); | |
638 | if (fermenter->fan_address) | |
639 | printf("Fan %-36s %9d%% %8lu\n", fermenter->fan_address, fermenter->fan_state, fermenter->fan_usage); | |
640 | if (fermenter->light_address) | |
641 | printf("Light %-36s %9d%% %8lu\n", fermenter->light_address, fermenter->light_state, fermenter->light_usage); | |
642 | if (fermenter->door_address) | |
643 | printf("Door %-36s %10d\n", fermenter->door_address, fermenter->door_state); | |
644 | if (fermenter->psu_address) | |
645 | printf("PSU %-36s %10d\n", fermenter->psu_address, fermenter->psu_state); | |
646 | printf("mode %s\n", fermenter->mode); | |
647 | printf("alarm %04x\n", fermenter->alarm); | |
648 | printf("sp high %8.3f\n", fermenter->setpoint_high); | |
649 | printf("sp low %8.3f\n", fermenter->setpoint_low); | |
650 | if (fermenter->profile_uuid) { | |
651 | printf("profile uuid %s\n", fermenter->profile_uuid); | |
652 | printf("profile name %s\n", fermenter->profile_name); | |
653 | printf("profile state %s\n", fermenter->profile_state); | |
654 | printf("profile percent %d\n", fermenter->profile_percent); | |
655 | printf("profile sp high %.3f\n", fermenter->profile_inittemp_high); | |
656 | printf("profile sp low %.3f\n", fermenter->profile_inittemp_low); | |
657 | printf("profile steps %s\n", fermenter->profile_steps); | |
658 | } | |
659 | } | |
660 | } | |
661 | ||
662 | ||
663 | ||
664 | void fermenter_death(char *topic) | |
665 | { | |
666 | char *edge_node, *alias; | |
667 | sys_fermenter_list *tmpp; | |
668 | ||
669 | printf("fermenter_death: %s\n", topic); | |
670 | strtok(topic, "/"); // ignore namespace | |
671 | strtok(NULL, "/"); // ignore group_id | |
672 | strtok(NULL, "/"); // ignore message_type | |
673 | edge_node = strtok(NULL, "/\0"); | |
674 | alias = strtok(NULL, "/\0"); | |
675 | ||
676 | fermenter_mysql_death(edge_node, alias); | |
677 | ||
678 | if (alias) { | |
679 | for (tmpp = fermenters; tmpp; tmpp = tmpp->next) { | |
680 | if ((strcmp(tmpp->node, edge_node) == 0) && (strcmp(tmpp->alias, alias) == 0)) { | |
681 | if (tmpp->online) | |
682 | syslog(LOG_NOTICE, "Offline fermenter %s/%s", tmpp->node, tmpp->alias); | |
683 | tmpp->online = false; | |
684 | break; | |
685 | } | |
686 | } | |
687 | } else { | |
688 | for (tmpp = fermenters; tmpp; tmpp = tmpp->next) { | |
689 | if (strcmp(tmpp->node, edge_node) == 0) { | |
690 | if (tmpp->online) | |
691 | syslog(LOG_NOTICE, "Offline fermenter %s/%s", tmpp->node, tmpp->alias); | |
692 | tmpp->online = false; | |
693 | } | |
694 | } | |
695 | } | |
696 | } | |
697 | ||
698 |