1 /** |
1 /** |
2 * @file ispindels.c |
2 * @file ispindels.c |
3 * @brief Handle ispindels data |
3 * @brief Handle ispindels data |
4 * @author Michiel Broek <mbroek at mbse dot eu> |
4 * @author Michiel Broek <mbroek at mbse dot eu> |
5 * |
5 * |
6 * Copyright (C) 2019-2020 |
6 * Copyright (C) 2019-2022 |
7 * |
7 * |
8 * This file is part of the bms (Brewery Management System) |
8 * This file is part of the bms (Brewery Management System) |
9 * |
9 * |
10 * This is free software; you can redistribute it and/or modify it |
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 |
11 * under the terms of the GNU General Public License as published by the |
199 void ispindel_set(char *node, char *payload) |
199 void ispindel_set(char *node, char *payload) |
200 { |
200 { |
201 sys_ispindel_list *ispindel, *tmpp; |
201 sys_ispindel_list *ispindel, *tmpp; |
202 struct json_object *jobj, *metric, *val; |
202 struct json_object *jobj, *metric, *val; |
203 bool new_ispindel = true; |
203 bool new_ispindel = true; |
204 char *datetime, buf[65], *line, *logfile; |
204 char *datetime, buf[65], *line, *logfile, *query = malloc(512); |
205 struct tm *mytime; |
205 struct tm *mytime; |
206 time_t timestamp; |
206 time_t timestamp; |
207 FILE *fp; |
207 FILE *fp; |
208 |
208 |
209 // syslog(LOG_NOTICE, "ispindel_set: %s %s", node, payload); |
209 // syslog(LOG_NOTICE, "ispindel_set: %s %s", node, payload); |
325 snprintf(buf, 64, "%d", ispindel->interval); |
325 snprintf(buf, 64, "%d", ispindel->interval); |
326 line = xstrcat(line, buf); |
326 line = xstrcat(line, buf); |
327 line = xstrcat(line, (char *)","); |
327 line = xstrcat(line, (char *)","); |
328 line = xstrcat(line, ispindel->uuid); |
328 line = xstrcat(line, ispindel->uuid); |
329 |
329 |
|
330 snprintf(query, 511, "INSERT INTO log_ispindel SET code='%s', datetime='%s', " \ |
|
331 "temperature='%.4f', plato='%.5f', sg='%.5f', battery='%.6f', " \ |
|
332 "angle='%.5f', refresh='%d', uuid='%s'", |
|
333 ispindel->beercode, datetime, ispindel->temperature, ispindel->gravity, |
|
334 1.00001 + (0.0038661 * ispindel->gravity) + (1.3488e-5 * ispindel->gravity * ispindel->gravity) + |
|
335 (4.3074e-8 * ispindel->gravity * ispindel->gravity * ispindel->gravity), |
|
336 ispindel->battery, ispindel->angle, ispindel->interval, ispindel->uuid); |
|
337 //syslog(LOG_NOTICE, "%s", query); |
|
338 bms_mysql_query(query); |
|
339 |
330 /* |
340 /* |
331 * Build logfile name |
341 * Build logfile name |
332 */ |
342 */ |
333 logfile = xstrcpy(Config.web_root); |
343 logfile = xstrcpy(Config.web_root); |
334 logfile = xstrcat(logfile, (char *)"/log/ispindel/"); |
344 logfile = xstrcat(logfile, (char *)"/log/ispindel/"); |