Sat, 12 Sep 2020 16:29:26 +0200
Version 0.3.36. Removed debug logs for websocket received messages. Fixed some default enum values send to the MySQL server.
502
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
1 | /** |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
2 | * @file co2meters.c |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
3 | * @brief Handle co2meters status |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
4 | * @author Michiel Broek <mbroek at mbse dot eu> |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
5 | * |
673
9924b1218d39
Added co2meters to the websockets. Added node and units offline messages to the websockets.
Michiel Broek <mbroek@mbse.eu>
parents:
558
diff
changeset
|
6 | * Copyright (C) 2019-2020 |
502
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
7 | * |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
8 | * This file is part of the bms (Brewery Management System) |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
9 | * |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
10 | * This is free software; you can redistribute it and/or modify it |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
11 | * under the terms of the GNU General Public License as published by the |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
12 | * Free Software Foundation; either version 2, or (at your option) any |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
13 | * later version. |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
14 | * |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
15 | * bms is distributed in the hope that it will be useful, but |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
16 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
18 | * General Public License for more details. |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
19 | * |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
20 | * You should have received a copy of the GNU General Public License |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
21 | * along with ThermFerm; see the file COPYING. If not, write to the Free |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
22 | * Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
23 | */ |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
24 | |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
25 | |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
26 | #include "bms.h" |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
27 | #include "xutil.h" |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
28 | #include "co2meters.h" |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
29 | #include "mysql.h" |
673
9924b1218d39
Added co2meters to the websockets. Added node and units offline messages to the websockets.
Michiel Broek <mbroek@mbse.eu>
parents:
558
diff
changeset
|
30 | #include "websocket.h" |
684
ccb9f24d0fe9
Report any online status change via websocket broadcast. When starting, load all in memory tables sorted. The websocket status on the web pages has it's own panel. Prepared the menu system for dynamic updates.
Michiel Broek <mbroek@mbse.eu>
parents:
680
diff
changeset
|
31 | #include "nodes.h" |
502
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
32 | |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
33 | |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
34 | sys_co2meter_list *co2meters = NULL; |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
35 | |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
36 | extern int debug; |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
37 | extern sys_config Config; |
506
8ab0e87d579e
Added beer selection in the CO2 meter screen. Added CO2 pressure logging.
Michiel Broek <mbroek@mbse.eu>
parents:
505
diff
changeset
|
38 | extern MYSQL *con; |
8ab0e87d579e
Added beer selection in the CO2 meter screen. Added CO2 pressure logging.
Michiel Broek <mbroek@mbse.eu>
parents:
505
diff
changeset
|
39 | extern MYSQL_RES *res_set; |
8ab0e87d579e
Added beer selection in the CO2 meter screen. Added CO2 pressure logging.
Michiel Broek <mbroek@mbse.eu>
parents:
505
diff
changeset
|
40 | extern MYSQL_ROW row; |
502
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
41 | |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
42 | |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
43 | |
678
14322825cb3d
The co2meters monitor screen rebuild to use websockets instead of data polling.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
44 | void co2meter_ws_send(sys_co2meter_list *co2meter) |
14322825cb3d
The co2meters monitor screen rebuild to use websockets instead of data polling.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
45 | { |
14322825cb3d
The co2meters monitor screen rebuild to use websockets instead of data polling.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
46 | char *msg = NULL, buf[65]; |
14322825cb3d
The co2meters monitor screen rebuild to use websockets instead of data polling.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
47 | |
14322825cb3d
The co2meters monitor screen rebuild to use websockets instead of data polling.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
48 | msg = xstrcpy((char *)"{\"device\":\"co2meters\",\"node\":\""); |
14322825cb3d
The co2meters monitor screen rebuild to use websockets instead of data polling.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
49 | msg = xstrcat(msg, co2meter->node); |
14322825cb3d
The co2meters monitor screen rebuild to use websockets instead of data polling.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
50 | msg = xstrcat(msg, (char *)"\",\"unit\":\""); |
14322825cb3d
The co2meters monitor screen rebuild to use websockets instead of data polling.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
51 | msg = xstrcat(msg, co2meter->alias); |
14322825cb3d
The co2meters monitor screen rebuild to use websockets instead of data polling.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
52 | msg = xstrcat(msg, (char *)"\",\"online\":"); |
14322825cb3d
The co2meters monitor screen rebuild to use websockets instead of data polling.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
53 | msg = xstrcat(msg, co2meter->online ? (char *)"1":(char *)"0"); |
14322825cb3d
The co2meters monitor screen rebuild to use websockets instead of data polling.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
54 | msg = xstrcat(msg, (char *)",\"mode\":\""); |
14322825cb3d
The co2meters monitor screen rebuild to use websockets instead of data polling.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
55 | msg = xstrcat(msg, co2meter->mode); |
680
0bb48333d133
Fixed missing co2meters websocket data. Added websockets and removed polling for the mon-ispindel screen. The iSpindel SG gauge adjusts the resolution to the highest detected OG.
Michiel Broek <mbroek@mbse.eu>
parents:
678
diff
changeset
|
56 | msg = xstrcat(msg, (char *)"\",\"beeruuid\":\""); |
0bb48333d133
Fixed missing co2meters websocket data. Added websockets and removed polling for the mon-ispindel screen. The iSpindel SG gauge adjusts the resolution to the highest detected OG.
Michiel Broek <mbroek@mbse.eu>
parents:
678
diff
changeset
|
57 | msg = xstrcat(msg, co2meter->beeruuid); |
678
14322825cb3d
The co2meters monitor screen rebuild to use websockets instead of data polling.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
58 | msg = xstrcat(msg, (char *)"\",\"beercode\":\""); |
14322825cb3d
The co2meters monitor screen rebuild to use websockets instead of data polling.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
59 | msg = xstrcat(msg, co2meter->beercode); |
14322825cb3d
The co2meters monitor screen rebuild to use websockets instead of data polling.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
60 | msg = xstrcat(msg, (char *)"\",\"beername\":\""); |
14322825cb3d
The co2meters monitor screen rebuild to use websockets instead of data polling.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
61 | msg = xstrcat(msg, co2meter->beername); |
680
0bb48333d133
Fixed missing co2meters websocket data. Added websockets and removed polling for the mon-ispindel screen. The iSpindel SG gauge adjusts the resolution to the highest detected OG.
Michiel Broek <mbroek@mbse.eu>
parents:
678
diff
changeset
|
62 | msg = xstrcat(msg, (char *)"\",\"temperature_state\":\""); |
0bb48333d133
Fixed missing co2meters websocket data. Added websockets and removed polling for the mon-ispindel screen. The iSpindel SG gauge adjusts the resolution to the highest detected OG.
Michiel Broek <mbroek@mbse.eu>
parents:
678
diff
changeset
|
63 | msg = xstrcat(msg, co2meter->temperature_state); |
0bb48333d133
Fixed missing co2meters websocket data. Added websockets and removed polling for the mon-ispindel screen. The iSpindel SG gauge adjusts the resolution to the highest detected OG.
Michiel Broek <mbroek@mbse.eu>
parents:
678
diff
changeset
|
64 | msg = xstrcat(msg, (char *)"\",\"temperature_address\":\""); |
0bb48333d133
Fixed missing co2meters websocket data. Added websockets and removed polling for the mon-ispindel screen. The iSpindel SG gauge adjusts the resolution to the highest detected OG.
Michiel Broek <mbroek@mbse.eu>
parents:
678
diff
changeset
|
65 | msg = xstrcat(msg, co2meter->temperature_address); |
678
14322825cb3d
The co2meters monitor screen rebuild to use websockets instead of data polling.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
66 | msg = xstrcat(msg, (char *)"\",\"temperature\":"); |
14322825cb3d
The co2meters monitor screen rebuild to use websockets instead of data polling.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
67 | snprintf(buf, 64, "%.3f", co2meter->temperature); |
14322825cb3d
The co2meters monitor screen rebuild to use websockets instead of data polling.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
68 | msg = xstrcat(msg, buf); |
680
0bb48333d133
Fixed missing co2meters websocket data. Added websockets and removed polling for the mon-ispindel screen. The iSpindel SG gauge adjusts the resolution to the highest detected OG.
Michiel Broek <mbroek@mbse.eu>
parents:
678
diff
changeset
|
69 | msg = xstrcat(msg, (char *)",\"pressure_state\":\""); |
0bb48333d133
Fixed missing co2meters websocket data. Added websockets and removed polling for the mon-ispindel screen. The iSpindel SG gauge adjusts the resolution to the highest detected OG.
Michiel Broek <mbroek@mbse.eu>
parents:
678
diff
changeset
|
70 | msg = xstrcat(msg, co2meter->pressure_state); |
0bb48333d133
Fixed missing co2meters websocket data. Added websockets and removed polling for the mon-ispindel screen. The iSpindel SG gauge adjusts the resolution to the highest detected OG.
Michiel Broek <mbroek@mbse.eu>
parents:
678
diff
changeset
|
71 | msg = xstrcat(msg, (char *)"\",\"pressure_channel\":"); |
678
14322825cb3d
The co2meters monitor screen rebuild to use websockets instead of data polling.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
72 | snprintf(buf, 64, "%d", co2meter->pressure_channel); |
14322825cb3d
The co2meters monitor screen rebuild to use websockets instead of data polling.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
73 | msg = xstrcat(msg, buf); |
14322825cb3d
The co2meters monitor screen rebuild to use websockets instead of data polling.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
74 | msg = xstrcat(msg, (char *)",\"pressure_voltage\":"); |
14322825cb3d
The co2meters monitor screen rebuild to use websockets instead of data polling.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
75 | snprintf(buf, 64, "%.3f", co2meter->pressure_voltage); |
14322825cb3d
The co2meters monitor screen rebuild to use websockets instead of data polling.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
76 | msg = xstrcat(msg, buf); |
14322825cb3d
The co2meters monitor screen rebuild to use websockets instead of data polling.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
77 | msg = xstrcat(msg, (char *)",\"pressure_zero\":"); |
14322825cb3d
The co2meters monitor screen rebuild to use websockets instead of data polling.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
78 | snprintf(buf, 64, "%.3f", co2meter->pressure_zero); |
14322825cb3d
The co2meters monitor screen rebuild to use websockets instead of data polling.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
79 | msg = xstrcat(msg, buf); |
14322825cb3d
The co2meters monitor screen rebuild to use websockets instead of data polling.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
80 | msg = xstrcat(msg, (char *)",\"pressure_bar\":"); |
14322825cb3d
The co2meters monitor screen rebuild to use websockets instead of data polling.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
81 | snprintf(buf, 64, "%.3f", co2meter->pressure_bar); |
14322825cb3d
The co2meters monitor screen rebuild to use websockets instead of data polling.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
82 | msg = xstrcat(msg, buf); |
14322825cb3d
The co2meters monitor screen rebuild to use websockets instead of data polling.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
83 | msg = xstrcat(msg, (char *)",\"alarm\":"); |
14322825cb3d
The co2meters monitor screen rebuild to use websockets instead of data polling.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
84 | snprintf(buf, 64, "%d", co2meter->alarm); |
14322825cb3d
The co2meters monitor screen rebuild to use websockets instead of data polling.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
85 | msg = xstrcat(msg, buf); |
14322825cb3d
The co2meters monitor screen rebuild to use websockets instead of data polling.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
86 | msg = xstrcat(msg, (char *)"}"); |
14322825cb3d
The co2meters monitor screen rebuild to use websockets instead of data polling.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
87 | ws_broadcast(msg); |
14322825cb3d
The co2meters monitor screen rebuild to use websockets instead of data polling.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
88 | free(msg); |
14322825cb3d
The co2meters monitor screen rebuild to use websockets instead of data polling.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
89 | msg = NULL; |
14322825cb3d
The co2meters monitor screen rebuild to use websockets instead of data polling.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
90 | } |
14322825cb3d
The co2meters monitor screen rebuild to use websockets instead of data polling.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
91 | |
14322825cb3d
The co2meters monitor screen rebuild to use websockets instead of data polling.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
92 | |
14322825cb3d
The co2meters monitor screen rebuild to use websockets instead of data polling.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
93 | |
14322825cb3d
The co2meters monitor screen rebuild to use websockets instead of data polling.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
94 | void co2meter_ws_receive(char *payload) |
14322825cb3d
The co2meters monitor screen rebuild to use websockets instead of data polling.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
95 | { |
14322825cb3d
The co2meters monitor screen rebuild to use websockets instead of data polling.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
96 | struct json_object *jobj, *val; |
14322825cb3d
The co2meters monitor screen rebuild to use websockets instead of data polling.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
97 | sys_co2meter_list *tmpp; |
14322825cb3d
The co2meters monitor screen rebuild to use websockets instead of data polling.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
98 | char *node = NULL, *alias = NULL, *beeruuid = NULL, *beercode = NULL, *beername = NULL; |
14322825cb3d
The co2meters monitor screen rebuild to use websockets instead of data polling.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
99 | char query[512], *end; |
14322825cb3d
The co2meters monitor screen rebuild to use websockets instead of data polling.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
100 | MYSQL *con2 = NULL; |
14322825cb3d
The co2meters monitor screen rebuild to use websockets instead of data polling.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
101 | |
14322825cb3d
The co2meters monitor screen rebuild to use websockets instead of data polling.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
102 | /* |
14322825cb3d
The co2meters monitor screen rebuild to use websockets instead of data polling.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
103 | * Process the JSON formatted payload. |
14322825cb3d
The co2meters monitor screen rebuild to use websockets instead of data polling.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
104 | */ |
14322825cb3d
The co2meters monitor screen rebuild to use websockets instead of data polling.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
105 | jobj = json_tokener_parse(payload); |
14322825cb3d
The co2meters monitor screen rebuild to use websockets instead of data polling.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
106 | if (json_object_object_get_ex(jobj, "node", &val)) |
14322825cb3d
The co2meters monitor screen rebuild to use websockets instead of data polling.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
107 | node = xstrcpy((char *)json_object_get_string(val)); |
14322825cb3d
The co2meters monitor screen rebuild to use websockets instead of data polling.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
108 | if (json_object_object_get_ex(jobj, "unit", &val)) |
14322825cb3d
The co2meters monitor screen rebuild to use websockets instead of data polling.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
109 | alias = xstrcpy((char *)json_object_get_string(val)); |
14322825cb3d
The co2meters monitor screen rebuild to use websockets instead of data polling.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
110 | if (json_object_object_get_ex(jobj, "beeruuid", &val)) |
14322825cb3d
The co2meters monitor screen rebuild to use websockets instead of data polling.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
111 | beeruuid = xstrcpy((char *)json_object_get_string(val)); |
14322825cb3d
The co2meters monitor screen rebuild to use websockets instead of data polling.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
112 | if (json_object_object_get_ex(jobj, "beercode", &val)) |
14322825cb3d
The co2meters monitor screen rebuild to use websockets instead of data polling.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
113 | beercode = xstrcpy((char *)json_object_get_string(val)); |
14322825cb3d
The co2meters monitor screen rebuild to use websockets instead of data polling.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
114 | if (json_object_object_get_ex(jobj, "beername", &val)) |
14322825cb3d
The co2meters monitor screen rebuild to use websockets instead of data polling.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
115 | beername = xstrcpy((char *)json_object_get_string(val)); |
14322825cb3d
The co2meters monitor screen rebuild to use websockets instead of data polling.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
116 | json_object_put(jobj); |
14322825cb3d
The co2meters monitor screen rebuild to use websockets instead of data polling.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
117 | |
14322825cb3d
The co2meters monitor screen rebuild to use websockets instead of data polling.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
118 | /* |
14322825cb3d
The co2meters monitor screen rebuild to use websockets instead of data polling.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
119 | * Search co2meter record in the memory array and use it if found. |
14322825cb3d
The co2meters monitor screen rebuild to use websockets instead of data polling.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
120 | */ |
14322825cb3d
The co2meters monitor screen rebuild to use websockets instead of data polling.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
121 | if (co2meters) { |
14322825cb3d
The co2meters monitor screen rebuild to use websockets instead of data polling.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
122 | for (tmpp = co2meters; tmpp; tmpp = tmpp->next) { |
14322825cb3d
The co2meters monitor screen rebuild to use websockets instead of data polling.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
123 | if ((strcmp(tmpp->alias, alias) == 0) && (strcmp(tmpp->node, node) == 0)) { |
14322825cb3d
The co2meters monitor screen rebuild to use websockets instead of data polling.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
124 | if (beeruuid && beercode && beername) { |
14322825cb3d
The co2meters monitor screen rebuild to use websockets instead of data polling.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
125 | con2 = mysql_init(NULL); |
14322825cb3d
The co2meters monitor screen rebuild to use websockets instead of data polling.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
126 | if (con2 == NULL) { |
14322825cb3d
The co2meters monitor screen rebuild to use websockets instead of data polling.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
127 | syslog(LOG_NOTICE, "MySQL: mysql_init() failed"); |
14322825cb3d
The co2meters monitor screen rebuild to use websockets instead of data polling.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
128 | } else { |
14322825cb3d
The co2meters monitor screen rebuild to use websockets instead of data polling.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
129 | if (mysql_real_connect(con2, Config.mysql_host, Config.mysql_user, Config.mysql_pass, Config.mysql_database, Config.mysql_port, NULL, 0) == NULL) { |
14322825cb3d
The co2meters monitor screen rebuild to use websockets instead of data polling.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
130 | syslog(LOG_NOTICE, "MySQL: mysql_real_connect() %s", mysql_error(con2)); |
14322825cb3d
The co2meters monitor screen rebuild to use websockets instead of data polling.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
131 | } else { |
14322825cb3d
The co2meters monitor screen rebuild to use websockets instead of data polling.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
132 | end = stpcpy(query, "UPDATE mon_co2meters SET beeruuid='"); |
14322825cb3d
The co2meters monitor screen rebuild to use websockets instead of data polling.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
133 | end += mysql_real_escape_string(con2, end, beeruuid, strlen(beeruuid)); |
14322825cb3d
The co2meters monitor screen rebuild to use websockets instead of data polling.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
134 | end = stpcpy(end, "', beercode='"); |
14322825cb3d
The co2meters monitor screen rebuild to use websockets instead of data polling.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
135 | end += mysql_real_escape_string(con2, end, beercode, strlen(beercode)); |
14322825cb3d
The co2meters monitor screen rebuild to use websockets instead of data polling.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
136 | end = stpcpy(end, "', beername='"); |
14322825cb3d
The co2meters monitor screen rebuild to use websockets instead of data polling.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
137 | end += mysql_real_escape_string(con2, end, beername, strlen(beername)); |
14322825cb3d
The co2meters monitor screen rebuild to use websockets instead of data polling.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
138 | end = stpcpy(end, "' WHERE node='"); |
14322825cb3d
The co2meters monitor screen rebuild to use websockets instead of data polling.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
139 | end += mysql_real_escape_string(con2, end, node, strlen(node)); |
14322825cb3d
The co2meters monitor screen rebuild to use websockets instead of data polling.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
140 | end = stpcpy(end, "' AND alias='"); |
14322825cb3d
The co2meters monitor screen rebuild to use websockets instead of data polling.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
141 | end += mysql_real_escape_string(con2, end, alias, strlen(alias)); |
14322825cb3d
The co2meters monitor screen rebuild to use websockets instead of data polling.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
142 | end = stpcpy(end, "'"); |
14322825cb3d
The co2meters monitor screen rebuild to use websockets instead of data polling.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
143 | |
14322825cb3d
The co2meters monitor screen rebuild to use websockets instead of data polling.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
144 | if (mysql_real_query(con2, query, (unsigned int) (end - query))) { |
14322825cb3d
The co2meters monitor screen rebuild to use websockets instead of data polling.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
145 | syslog(LOG_NOTICE, "MySQL: `%s' error %u (%s))", query, mysql_errno(con2), mysql_error(con2)); |
14322825cb3d
The co2meters monitor screen rebuild to use websockets instead of data polling.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
146 | } else { |
14322825cb3d
The co2meters monitor screen rebuild to use websockets instead of data polling.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
147 | /* Database updated, now update internal memory */ |
14322825cb3d
The co2meters monitor screen rebuild to use websockets instead of data polling.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
148 | //syslog(LOG_NOTICE, "MySQL: `%s' Ok", query); |
14322825cb3d
The co2meters monitor screen rebuild to use websockets instead of data polling.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
149 | if (tmpp->beercode) |
14322825cb3d
The co2meters monitor screen rebuild to use websockets instead of data polling.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
150 | free(tmpp->beercode); |
14322825cb3d
The co2meters monitor screen rebuild to use websockets instead of data polling.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
151 | tmpp->beercode = xstrcpy(beercode); |
14322825cb3d
The co2meters monitor screen rebuild to use websockets instead of data polling.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
152 | if (tmpp->beername) |
14322825cb3d
The co2meters monitor screen rebuild to use websockets instead of data polling.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
153 | free(tmpp->beername); |
14322825cb3d
The co2meters monitor screen rebuild to use websockets instead of data polling.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
154 | tmpp->beername = xstrcpy(beername); |
14322825cb3d
The co2meters monitor screen rebuild to use websockets instead of data polling.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
155 | if (tmpp->beeruuid) |
14322825cb3d
The co2meters monitor screen rebuild to use websockets instead of data polling.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
156 | free(tmpp->beeruuid); |
14322825cb3d
The co2meters monitor screen rebuild to use websockets instead of data polling.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
157 | tmpp->beeruuid = xstrcpy(beeruuid); |
14322825cb3d
The co2meters monitor screen rebuild to use websockets instead of data polling.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
158 | /* Report new state to the client */ |
14322825cb3d
The co2meters monitor screen rebuild to use websockets instead of data polling.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
159 | co2meter_ws_send(tmpp); |
14322825cb3d
The co2meters monitor screen rebuild to use websockets instead of data polling.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
160 | syslog(LOG_NOTICE, "Set co2meter %s/%s new beer %s %s", node, alias, beercode, beername); |
14322825cb3d
The co2meters monitor screen rebuild to use websockets instead of data polling.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
161 | } |
14322825cb3d
The co2meters monitor screen rebuild to use websockets instead of data polling.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
162 | mysql_close(con2); |
14322825cb3d
The co2meters monitor screen rebuild to use websockets instead of data polling.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
163 | } |
14322825cb3d
The co2meters monitor screen rebuild to use websockets instead of data polling.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
164 | } |
14322825cb3d
The co2meters monitor screen rebuild to use websockets instead of data polling.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
165 | } |
14322825cb3d
The co2meters monitor screen rebuild to use websockets instead of data polling.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
166 | break; |
14322825cb3d
The co2meters monitor screen rebuild to use websockets instead of data polling.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
167 | } |
14322825cb3d
The co2meters monitor screen rebuild to use websockets instead of data polling.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
168 | } |
14322825cb3d
The co2meters monitor screen rebuild to use websockets instead of data polling.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
169 | } |
14322825cb3d
The co2meters monitor screen rebuild to use websockets instead of data polling.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
170 | |
14322825cb3d
The co2meters monitor screen rebuild to use websockets instead of data polling.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
171 | if (node) |
14322825cb3d
The co2meters monitor screen rebuild to use websockets instead of data polling.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
172 | free(node); |
14322825cb3d
The co2meters monitor screen rebuild to use websockets instead of data polling.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
173 | if (alias) |
14322825cb3d
The co2meters monitor screen rebuild to use websockets instead of data polling.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
174 | free(alias); |
14322825cb3d
The co2meters monitor screen rebuild to use websockets instead of data polling.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
175 | if (beeruuid) |
14322825cb3d
The co2meters monitor screen rebuild to use websockets instead of data polling.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
176 | free(beeruuid); |
14322825cb3d
The co2meters monitor screen rebuild to use websockets instead of data polling.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
177 | if (beercode) |
14322825cb3d
The co2meters monitor screen rebuild to use websockets instead of data polling.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
178 | free(beercode); |
14322825cb3d
The co2meters monitor screen rebuild to use websockets instead of data polling.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
179 | if (beername) |
14322825cb3d
The co2meters monitor screen rebuild to use websockets instead of data polling.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
180 | free(beername); |
14322825cb3d
The co2meters monitor screen rebuild to use websockets instead of data polling.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
181 | } |
14322825cb3d
The co2meters monitor screen rebuild to use websockets instead of data polling.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
182 | |
14322825cb3d
The co2meters monitor screen rebuild to use websockets instead of data polling.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
183 | |
14322825cb3d
The co2meters monitor screen rebuild to use websockets instead of data polling.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
184 | |
502
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
185 | void co2meter_set(char *edge_node, char *alias, char *payload) |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
186 | { |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
187 | struct json_object *jobj, *val, *sensor; |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
188 | sys_co2meter_list *co2meter, *tmpp; |
686
ca1fbb3bd3db
Removed ws_global function because dynamic menus don't work.
Michiel Broek <mbroek@mbse.eu>
parents:
684
diff
changeset
|
189 | bool new_co2meter = true; |
502
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
190 | |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
191 | // fprintf(stdout, "co2meter_set: %s/%s %s\n", edge_node, alias, payload); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
192 | |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
193 | /* |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
194 | * Search co2meter record in the memory array and use it if found. |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
195 | */ |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
196 | if (co2meters) { |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
197 | for (tmpp = co2meters; tmpp; tmpp = tmpp->next) { |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
198 | if ((strcmp(tmpp->alias, alias) == 0) && (strcmp(tmpp->node, edge_node) == 0)) { |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
199 | new_co2meter = false; |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
200 | co2meter = tmpp; |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
201 | break; |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
202 | } |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
203 | } |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
204 | } |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
205 | |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
206 | // printf("new_co2meter %s\n", new_co2meter ? "true":"false"); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
207 | |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
208 | /* |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
209 | * Allocate new co2meter if not yet known. |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
210 | */ |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
211 | if (new_co2meter) { |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
212 | co2meter = (sys_co2meter_list *)malloc(sizeof(sys_co2meter_list)); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
213 | memset(co2meter, 0, sizeof(sys_co2meter_list)); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
214 | co2meter->alias = xstrcpy(alias); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
215 | co2meter->node = xstrcpy(edge_node); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
216 | co2meter->mode = xstrcpy((char *)"OFF"); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
217 | } |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
218 | |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
219 | if (! co2meter->online) { |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
220 | co2meter->online = true; |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
221 | syslog(LOG_NOTICE, "Online co2meter %s/%s mode %s", edge_node, alias, co2meter->mode); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
222 | } |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
223 | |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
224 | /* |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
225 | * Process the JSON formatted payload. |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
226 | * Update only the fields that are found in the payload. |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
227 | */ |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
228 | jobj = json_tokener_parse(payload); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
229 | |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
230 | if (json_object_object_get_ex(jobj, "uuid", &val)) { |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
231 | if (co2meter->uuid) |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
232 | free(co2meter->uuid); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
233 | co2meter->uuid = xstrcpy((char *)json_object_get_string(val)); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
234 | } |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
235 | if (json_object_object_get_ex(jobj, "mode", &val)) { |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
236 | if (co2meter->mode) { |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
237 | if (strcmp(co2meter->mode, (char *)json_object_get_string(val))) { |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
238 | syslog(LOG_NOTICE, "Change mode co2meter %s/%s: %s to %s", edge_node, alias, co2meter->mode, (char *)json_object_get_string(val)); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
239 | } |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
240 | free(co2meter->mode); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
241 | } |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
242 | co2meter->mode = xstrcpy((char *)json_object_get_string(val)); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
243 | } |
505
c09b67fd8323
Added CO2 meter units alarm led.
Michiel Broek <mbroek@mbse.eu>
parents:
502
diff
changeset
|
244 | if (json_object_object_get_ex(jobj, "alarm", &val)) { |
c09b67fd8323
Added CO2 meter units alarm led.
Michiel Broek <mbroek@mbse.eu>
parents:
502
diff
changeset
|
245 | co2meter->alarm = json_object_get_int(val); |
c09b67fd8323
Added CO2 meter units alarm led.
Michiel Broek <mbroek@mbse.eu>
parents:
502
diff
changeset
|
246 | } |
502
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
247 | if (json_object_object_get_ex(jobj, "temperature", &sensor)) { |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
248 | if (json_object_object_get_ex(sensor, "address", &val)) { |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
249 | if (co2meter->temperature_address) |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
250 | free(co2meter->temperature_address); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
251 | co2meter->temperature_address = xstrcpy((char *)json_object_get_string(val)); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
252 | } |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
253 | if (json_object_object_get_ex(sensor, "state", &val)) { |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
254 | if (co2meter->temperature_state) |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
255 | free(co2meter->temperature_state); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
256 | co2meter->temperature_state = xstrcpy((char *)json_object_get_string(val)); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
257 | } |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
258 | if (json_object_object_get_ex(sensor, "temperature", &val)) { |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
259 | co2meter->temperature = json_object_get_double(val); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
260 | } |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
261 | } |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
262 | if (json_object_object_get_ex(jobj, "pressure", &sensor)) { |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
263 | if (json_object_object_get_ex(sensor, "state", &val)) { |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
264 | if (co2meter->pressure_state) |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
265 | free(co2meter->pressure_state); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
266 | co2meter->pressure_state = xstrcpy((char *)json_object_get_string(val)); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
267 | } |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
268 | if (json_object_object_get_ex(sensor, "channel", &val)) { |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
269 | co2meter->pressure_channel = json_object_get_int(val); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
270 | } |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
271 | if (json_object_object_get_ex(sensor, "voltage", &val)) { |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
272 | co2meter->pressure_voltage = json_object_get_double(val); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
273 | } |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
274 | if (json_object_object_get_ex(sensor, "zero", &val)) { |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
275 | co2meter->pressure_zero = json_object_get_double(val); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
276 | } |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
277 | if (json_object_object_get_ex(sensor, "bar", &val)) { |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
278 | co2meter->pressure_bar = json_object_get_double(val); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
279 | } |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
280 | } |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
281 | json_object_put(jobj); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
282 | |
678
14322825cb3d
The co2meters monitor screen rebuild to use websockets instead of data polling.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
283 | co2meter_ws_send(co2meter); |
673
9924b1218d39
Added co2meters to the websockets. Added node and units offline messages to the websockets.
Michiel Broek <mbroek@mbse.eu>
parents:
558
diff
changeset
|
284 | |
502
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
285 | // co2meter_dump(co2meter); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
286 | |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
287 | if (new_co2meter) { |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
288 | if (co2meters == NULL) { |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
289 | co2meters = co2meter; |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
290 | } else { |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
291 | for (tmpp = co2meters; tmpp; tmpp = tmpp->next) { |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
292 | if (tmpp->next == NULL) { |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
293 | tmpp->next = co2meter; |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
294 | break; |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
295 | } |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
296 | } |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
297 | } |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
298 | co2meter_mysql_insert(co2meter); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
299 | } else { |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
300 | co2meter_mysql_update(co2meter); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
301 | } |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
302 | } |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
303 | |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
304 | |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
305 | |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
306 | /* |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
307 | * With DBIRTH all active co2meters are publishd in an array. |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
308 | */ |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
309 | void co2meter_birth_data(char *topic, char *payload) |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
310 | { |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
311 | char *message_type, *edge_node, *alias; |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
312 | struct json_object *jobj, *val, *metric, *units, *unit; |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
313 | int arraylen; |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
314 | |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
315 | strtok(topic, "/"); // ignore namespace |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
316 | strtok(NULL, "/"); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
317 | message_type = strtok(NULL, "/"); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
318 | edge_node = strtok(NULL, "/\0"); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
319 | alias = strtok(NULL, "/\0"); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
320 | |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
321 | if ((alias == NULL) && (strcmp("DBIRTH", message_type) == 0)) { |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
322 | /* |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
323 | * Global initial DBIRTH message with array of co2meters. |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
324 | */ |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
325 | jobj = json_tokener_parse(payload); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
326 | |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
327 | if (json_object_object_get_ex(jobj, "metric", &metric)) { |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
328 | if (json_object_object_get_ex(metric, "units", &units)) { |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
329 | arraylen = json_object_array_length(units); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
330 | for (int i = 0; i < arraylen; i++) { |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
331 | /* |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
332 | * Parse the array of units |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
333 | */ |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
334 | unit = json_object_array_get_idx(units, i); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
335 | |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
336 | if (json_object_object_get_ex(unit, "alias", &val)) { |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
337 | if (alias) |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
338 | free(alias); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
339 | alias = xstrcpy((char *)json_object_get_string(val)); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
340 | co2meter_set(edge_node, alias, (char *)json_object_to_json_string_ext(unit, 0)); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
341 | free(alias); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
342 | alias = NULL; |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
343 | } |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
344 | } |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
345 | } |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
346 | } |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
347 | json_object_put(jobj); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
348 | return; |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
349 | } |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
350 | |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
351 | /* |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
352 | * The rest are errors. |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
353 | */ |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
354 | printf("ERROR co2meter_birth_data: %s %s %s\n", message_type, edge_node, alias); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
355 | } |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
356 | |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
357 | |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
358 | |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
359 | void co2meter_log(char *topic, char *payload) |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
360 | { |
506
8ab0e87d579e
Added beer selection in the CO2 meter screen. Added CO2 pressure logging.
Michiel Broek <mbroek@mbse.eu>
parents:
505
diff
changeset
|
361 | char *edge_node, *alias, *line, buf[128], *logfile; |
502
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
362 | struct json_object *jobj, *val, *metric; |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
363 | co2pressure_log *log; |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
364 | struct tm *mytime; |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
365 | time_t timestamp; |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
366 | FILE *fp; |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
367 | |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
368 | strtok(topic, "/"); // ignore namespace |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
369 | strtok(NULL, "/"); // group_id |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
370 | strtok(NULL, "/"); // message_type |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
371 | edge_node = strtok(NULL, "/\0"); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
372 | alias = strtok(NULL, "/\0"); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
373 | |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
374 | log = (co2pressure_log *)malloc(sizeof(co2pressure_log)); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
375 | memset(log, 0, sizeof(co2pressure_log)); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
376 | |
506
8ab0e87d579e
Added beer selection in the CO2 meter screen. Added CO2 pressure logging.
Michiel Broek <mbroek@mbse.eu>
parents:
505
diff
changeset
|
377 | log->node = xstrcpy(edge_node); |
8ab0e87d579e
Added beer selection in the CO2 meter screen. Added CO2 pressure logging.
Michiel Broek <mbroek@mbse.eu>
parents:
505
diff
changeset
|
378 | log->alias = xstrcpy(alias); |
502
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
379 | jobj = json_tokener_parse(payload); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
380 | |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
381 | timestamp = time(NULL); |
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:
547
diff
changeset
|
382 | log->datetime = malloc(73); |
502
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
383 | mytime = localtime(×tamp); |
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:
547
diff
changeset
|
384 | snprintf(log->datetime, 72, "%04d-%02d-%02d %02d:%02d:%02d", |
502
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
385 | mytime->tm_year + 1900, mytime->tm_mon + 1, mytime->tm_mday, mytime->tm_hour, mytime->tm_min, mytime->tm_sec); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
386 | |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
387 | if (json_object_object_get_ex(jobj, "metric", &metric)) { |
506
8ab0e87d579e
Added beer selection in the CO2 meter screen. Added CO2 pressure logging.
Michiel Broek <mbroek@mbse.eu>
parents:
505
diff
changeset
|
388 | if (json_object_object_get_ex(metric, "uuid", &val)) { |
502
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
389 | if (strcmp((char *)"(null)", json_object_get_string(val))) |
506
8ab0e87d579e
Added beer selection in the CO2 meter screen. Added CO2 pressure logging.
Michiel Broek <mbroek@mbse.eu>
parents:
505
diff
changeset
|
390 | log->uuid = xstrcpy((char *)json_object_get_string(val)); |
502
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
391 | } |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
392 | if (json_object_object_get_ex(metric, "temperature", &val)) { |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
393 | log->temperature = json_object_get_double(val); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
394 | } |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
395 | if (json_object_object_get_ex(metric, "pressure", &val)) { |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
396 | log->pressure = json_object_get_double(val); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
397 | } |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
398 | } |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
399 | json_object_put(jobj); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
400 | |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
401 | /* |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
402 | * Because co2meters are not so smart and don't hold product information |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
403 | * search the missing pieces in the database. |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
404 | */ |
506
8ab0e87d579e
Added beer selection in the CO2 meter screen. Added CO2 pressure logging.
Michiel Broek <mbroek@mbse.eu>
parents:
505
diff
changeset
|
405 | snprintf(buf, 127, "SELECT beercode,beername,beeruuid FROM mon_co2meters WHERE uuid='%s'", log->uuid); |
8ab0e87d579e
Added beer selection in the CO2 meter screen. Added CO2 pressure logging.
Michiel Broek <mbroek@mbse.eu>
parents:
505
diff
changeset
|
406 | if (mysql_query(con, buf)) { |
8ab0e87d579e
Added beer selection in the CO2 meter screen. Added CO2 pressure logging.
Michiel Broek <mbroek@mbse.eu>
parents:
505
diff
changeset
|
407 | syslog(LOG_NOTICE, "MySQL: %s error %u (%s))", buf, mysql_errno(con), mysql_error(con)); |
8ab0e87d579e
Added beer selection in the CO2 meter screen. Added CO2 pressure logging.
Michiel Broek <mbroek@mbse.eu>
parents:
505
diff
changeset
|
408 | } else { |
8ab0e87d579e
Added beer selection in the CO2 meter screen. Added CO2 pressure logging.
Michiel Broek <mbroek@mbse.eu>
parents:
505
diff
changeset
|
409 | res_set = mysql_store_result(con); |
8ab0e87d579e
Added beer selection in the CO2 meter screen. Added CO2 pressure logging.
Michiel Broek <mbroek@mbse.eu>
parents:
505
diff
changeset
|
410 | if (res_set == NULL) { |
8ab0e87d579e
Added beer selection in the CO2 meter screen. Added CO2 pressure logging.
Michiel Broek <mbroek@mbse.eu>
parents:
505
diff
changeset
|
411 | syslog(LOG_NOTICE, "MySQL: mysq_store_result error %u (%s))", mysql_errno(con), mysql_error(con)); |
8ab0e87d579e
Added beer selection in the CO2 meter screen. Added CO2 pressure logging.
Michiel Broek <mbroek@mbse.eu>
parents:
505
diff
changeset
|
412 | } else { |
8ab0e87d579e
Added beer selection in the CO2 meter screen. Added CO2 pressure logging.
Michiel Broek <mbroek@mbse.eu>
parents:
505
diff
changeset
|
413 | if ((row = mysql_fetch_row(res_set)) != NULL) { |
547
4d9c96545246
Don't log co2pressure for units that have an empty beer_code or beer_name.
Michiel Broek <mbroek@mbse.eu>
parents:
506
diff
changeset
|
414 | /* |
4d9c96545246
Don't log co2pressure for units that have an empty beer_code or beer_name.
Michiel Broek <mbroek@mbse.eu>
parents:
506
diff
changeset
|
415 | * Ignore when the beer_name or beer_code is not set. |
4d9c96545246
Don't log co2pressure for units that have an empty beer_code or beer_name.
Michiel Broek <mbroek@mbse.eu>
parents:
506
diff
changeset
|
416 | */ |
4d9c96545246
Don't log co2pressure for units that have an empty beer_code or beer_name.
Michiel Broek <mbroek@mbse.eu>
parents:
506
diff
changeset
|
417 | if ((int)strlen(row[0]) == 0 || (int)strlen(row[1]) == 0) { |
4d9c96545246
Don't log co2pressure for units that have an empty beer_code or beer_name.
Michiel Broek <mbroek@mbse.eu>
parents:
506
diff
changeset
|
418 | if (log->datetime) |
4d9c96545246
Don't log co2pressure for units that have an empty beer_code or beer_name.
Michiel Broek <mbroek@mbse.eu>
parents:
506
diff
changeset
|
419 | free(log->datetime); |
4d9c96545246
Don't log co2pressure for units that have an empty beer_code or beer_name.
Michiel Broek <mbroek@mbse.eu>
parents:
506
diff
changeset
|
420 | if (log->uuid) |
4d9c96545246
Don't log co2pressure for units that have an empty beer_code or beer_name.
Michiel Broek <mbroek@mbse.eu>
parents:
506
diff
changeset
|
421 | free(log->uuid); |
4d9c96545246
Don't log co2pressure for units that have an empty beer_code or beer_name.
Michiel Broek <mbroek@mbse.eu>
parents:
506
diff
changeset
|
422 | if (log->node) |
4d9c96545246
Don't log co2pressure for units that have an empty beer_code or beer_name.
Michiel Broek <mbroek@mbse.eu>
parents:
506
diff
changeset
|
423 | free(log->node); |
4d9c96545246
Don't log co2pressure for units that have an empty beer_code or beer_name.
Michiel Broek <mbroek@mbse.eu>
parents:
506
diff
changeset
|
424 | if (log->alias) |
4d9c96545246
Don't log co2pressure for units that have an empty beer_code or beer_name.
Michiel Broek <mbroek@mbse.eu>
parents:
506
diff
changeset
|
425 | free(log->alias); |
4d9c96545246
Don't log co2pressure for units that have an empty beer_code or beer_name.
Michiel Broek <mbroek@mbse.eu>
parents:
506
diff
changeset
|
426 | free(log); |
4d9c96545246
Don't log co2pressure for units that have an empty beer_code or beer_name.
Michiel Broek <mbroek@mbse.eu>
parents:
506
diff
changeset
|
427 | return; |
4d9c96545246
Don't log co2pressure for units that have an empty beer_code or beer_name.
Michiel Broek <mbroek@mbse.eu>
parents:
506
diff
changeset
|
428 | } |
506
8ab0e87d579e
Added beer selection in the CO2 meter screen. Added CO2 pressure logging.
Michiel Broek <mbroek@mbse.eu>
parents:
505
diff
changeset
|
429 | log->product_code = xstrcpy(row[0]); |
8ab0e87d579e
Added beer selection in the CO2 meter screen. Added CO2 pressure logging.
Michiel Broek <mbroek@mbse.eu>
parents:
505
diff
changeset
|
430 | log->product_name = xstrcpy(row[1]); |
8ab0e87d579e
Added beer selection in the CO2 meter screen. Added CO2 pressure logging.
Michiel Broek <mbroek@mbse.eu>
parents:
505
diff
changeset
|
431 | log->product_uuid = xstrcpy(row[2]); |
8ab0e87d579e
Added beer selection in the CO2 meter screen. Added CO2 pressure logging.
Michiel Broek <mbroek@mbse.eu>
parents:
505
diff
changeset
|
432 | } |
8ab0e87d579e
Added beer selection in the CO2 meter screen. Added CO2 pressure logging.
Michiel Broek <mbroek@mbse.eu>
parents:
505
diff
changeset
|
433 | } |
8ab0e87d579e
Added beer selection in the CO2 meter screen. Added CO2 pressure logging.
Michiel Broek <mbroek@mbse.eu>
parents:
505
diff
changeset
|
434 | } |
502
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
435 | |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
436 | /* |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
437 | * Build csv log line |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
438 | */ |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
439 | line = xstrcpy(log->datetime); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
440 | line = xstrcat(line, (char *)","); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
441 | snprintf(buf, 64, "%.3f", log->temperature); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
442 | line = xstrcat(line, buf); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
443 | line = xstrcat(line, (char *)","); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
444 | snprintf(buf, 64, "%.3f", log->pressure); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
445 | line = xstrcat(line, buf); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
446 | line = xstrcat(line, (char *)","); |
506
8ab0e87d579e
Added beer selection in the CO2 meter screen. Added CO2 pressure logging.
Michiel Broek <mbroek@mbse.eu>
parents:
505
diff
changeset
|
447 | line = xstrcat(line, log->uuid); |
502
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
448 | |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
449 | /* |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
450 | * Build logfile name |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
451 | */ |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
452 | logfile = xstrcpy(Config.web_root); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
453 | logfile = xstrcat(logfile, (char *)"/log/co2pressure/"); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
454 | logfile = xstrcat(logfile, log->product_code); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
455 | logfile = xstrcat(logfile, (char *)" "); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
456 | logfile = xstrcat(logfile, log->product_name); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
457 | logfile = xstrcat(logfile, (char *)".log"); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
458 | |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
459 | if (debug) |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
460 | fprintf(stdout, "%s %s\n", logfile, line); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
461 | |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
462 | fp = fopen(logfile, "a"); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
463 | if (fp) { |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
464 | fprintf(fp, "%s\n", line); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
465 | fclose(fp); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
466 | } else { |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
467 | syslog(LOG_NOTICE, "cannot append to `%s'", logfile); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
468 | } |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
469 | |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
470 | free(logfile); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
471 | logfile = NULL; |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
472 | free(line); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
473 | line = NULL; |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
474 | |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
475 | if (log->datetime) |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
476 | free(log->datetime); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
477 | if (log->product_uuid ) |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
478 | free(log->product_uuid ); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
479 | if (log->product_code ) |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
480 | free(log->product_code ); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
481 | if (log->product_name ) |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
482 | free(log->product_name ); |
506
8ab0e87d579e
Added beer selection in the CO2 meter screen. Added CO2 pressure logging.
Michiel Broek <mbroek@mbse.eu>
parents:
505
diff
changeset
|
483 | if (log->uuid) |
8ab0e87d579e
Added beer selection in the CO2 meter screen. Added CO2 pressure logging.
Michiel Broek <mbroek@mbse.eu>
parents:
505
diff
changeset
|
484 | free(log->uuid); |
8ab0e87d579e
Added beer selection in the CO2 meter screen. Added CO2 pressure logging.
Michiel Broek <mbroek@mbse.eu>
parents:
505
diff
changeset
|
485 | if (log->node) |
8ab0e87d579e
Added beer selection in the CO2 meter screen. Added CO2 pressure logging.
Michiel Broek <mbroek@mbse.eu>
parents:
505
diff
changeset
|
486 | free(log->node); |
8ab0e87d579e
Added beer selection in the CO2 meter screen. Added CO2 pressure logging.
Michiel Broek <mbroek@mbse.eu>
parents:
505
diff
changeset
|
487 | if (log->alias) |
8ab0e87d579e
Added beer selection in the CO2 meter screen. Added CO2 pressure logging.
Michiel Broek <mbroek@mbse.eu>
parents:
505
diff
changeset
|
488 | free(log->alias); |
502
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
489 | free(log); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
490 | } |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
491 | |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
492 | |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
493 | |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
494 | void co2meter_dump(sys_co2meter_list *co2meter) |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
495 | { |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
496 | if (debug) { |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
497 | printf("uuid %s\n", co2meter->uuid); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
498 | printf("alias %s\n", co2meter->alias); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
499 | printf("node %s\n", co2meter->node); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
500 | printf("online %s\n", co2meter->online ? "yes":"no"); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
501 | printf("product %s / %s\n", co2meter->beercode, co2meter->beername); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
502 | printf("Temperature %-16s %10s %8.3f\n", co2meter->temperature_address, co2meter->temperature_state, co2meter->temperature); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
503 | printf("Pressure %10s %d %.3f %.3f %.3f\n", co2meter->pressure_state, co2meter->pressure_channel, |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
504 | co2meter->pressure_voltage, co2meter->pressure_zero, co2meter->pressure_bar); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
505 | printf("mode %s\n", co2meter->mode); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
506 | } |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
507 | } |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
508 | |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
509 |