Thu, 14 May 2020 14:38:20 +0200
The co2meters monitor screen rebuild to use websockets instead of data polling.
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" |
502
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
31 | |
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 | sys_co2meter_list *co2meters = NULL; |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
34 | |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
35 | extern int debug; |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
36 | 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
|
37 | 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
|
38 | 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
|
39 | extern MYSQL_ROW row; |
502
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
40 | |
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 | |
678
14322825cb3d
The co2meters monitor screen rebuild to use websockets instead of data polling.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
43 | 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
|
44 | { |
14322825cb3d
The co2meters monitor screen rebuild to use websockets instead of data polling.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
45 | 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
|
46 | |
14322825cb3d
The co2meters monitor screen rebuild to use websockets instead of data polling.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
47 | 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
|
48 | 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
|
49 | 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
|
50 | 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
|
51 | 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
|
52 | 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
|
53 | 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
|
54 | msg = xstrcat(msg, co2meter->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, (char *)"\",\"beercode\":\""); |
14322825cb3d
The co2meters monitor screen rebuild to use websockets instead of data polling.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
56 | 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
|
57 | 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
|
58 | msg = xstrcat(msg, co2meter->beername); |
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, (char *)"\",\"temperature\":"); |
14322825cb3d
The co2meters monitor screen rebuild to use websockets instead of data polling.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
60 | 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
|
61 | 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
|
62 | msg = xstrcat(msg, (char *)",\"pressure_channel\":"); |
14322825cb3d
The co2meters monitor screen rebuild to use websockets instead of data polling.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
63 | 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
|
64 | 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
|
65 | 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
|
66 | 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
|
67 | 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
|
68 | 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
|
69 | 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
|
70 | 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
|
71 | 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
|
72 | 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
|
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 *)",\"alarm\":"); |
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, "%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
|
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 *)"}"); |
14322825cb3d
The co2meters monitor screen rebuild to use websockets instead of data polling.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
78 | 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
|
79 | free(msg); |
14322825cb3d
The co2meters monitor screen rebuild to use websockets instead of data polling.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
80 | msg = NULL; |
14322825cb3d
The co2meters monitor screen rebuild to use websockets instead of data polling.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
81 | |
14322825cb3d
The co2meters monitor screen rebuild to use websockets instead of data polling.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
82 | } |
14322825cb3d
The co2meters monitor screen rebuild to use websockets instead of data polling.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
83 | |
14322825cb3d
The co2meters monitor screen rebuild to use websockets instead of data polling.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
84 | |
14322825cb3d
The co2meters monitor screen rebuild to use websockets instead of data polling.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
85 | |
14322825cb3d
The co2meters monitor screen rebuild to use websockets instead of data polling.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
86 | 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
|
87 | { |
14322825cb3d
The co2meters monitor screen rebuild to use websockets instead of data polling.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
88 | 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
|
89 | 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
|
90 | 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
|
91 | 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
|
92 | 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
|
93 | |
14322825cb3d
The co2meters monitor screen rebuild to use websockets instead of data polling.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
94 | syslog(LOG_NOTICE, "co2meter_ws_receive(%s)", 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 | /* |
14322825cb3d
The co2meters monitor screen rebuild to use websockets instead of data polling.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
97 | * 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
|
98 | */ |
14322825cb3d
The co2meters monitor screen rebuild to use websockets instead of data polling.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
99 | 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
|
100 | 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
|
101 | 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
|
102 | 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
|
103 | 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
|
104 | 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
|
105 | 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
|
106 | 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
|
107 | 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
|
108 | 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
|
109 | 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
|
110 | 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
|
111 | |
14322825cb3d
The co2meters monitor screen rebuild to use websockets instead of data polling.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
112 | /* |
14322825cb3d
The co2meters monitor screen rebuild to use websockets instead of data polling.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
113 | * 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
|
114 | */ |
14322825cb3d
The co2meters monitor screen rebuild to use websockets instead of data polling.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
115 | if (co2meters) { |
14322825cb3d
The co2meters monitor screen rebuild to use websockets instead of data polling.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
116 | 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
|
117 | 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
|
118 | 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
|
119 | 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
|
120 | 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
|
121 | 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
|
122 | } else { |
14322825cb3d
The co2meters monitor screen rebuild to use websockets instead of data polling.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
123 | 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
|
124 | 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
|
125 | } else { |
14322825cb3d
The co2meters monitor screen rebuild to use websockets instead of data polling.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
126 | 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
|
127 | 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
|
128 | 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
|
129 | 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
|
130 | 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
|
131 | 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
|
132 | 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
|
133 | 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
|
134 | 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
|
135 | 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
|
136 | 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
|
137 | |
14322825cb3d
The co2meters monitor screen rebuild to use websockets instead of data polling.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
138 | 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
|
139 | 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
|
140 | } else { |
14322825cb3d
The co2meters monitor screen rebuild to use websockets instead of data polling.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
141 | /* 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
|
142 | //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
|
143 | 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
|
144 | 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
|
145 | 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
|
146 | 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
|
147 | 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
|
148 | 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
|
149 | 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
|
150 | 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
|
151 | 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
|
152 | /* 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
|
153 | 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
|
154 | 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
|
155 | } |
14322825cb3d
The co2meters monitor screen rebuild to use websockets instead of data polling.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
156 | 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
|
157 | } |
14322825cb3d
The co2meters monitor screen rebuild to use websockets instead of data polling.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
158 | } |
14322825cb3d
The co2meters monitor screen rebuild to use websockets instead of data polling.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
159 | } |
14322825cb3d
The co2meters monitor screen rebuild to use websockets instead of data polling.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
160 | break; |
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 | } |
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 | if (node) |
14322825cb3d
The co2meters monitor screen rebuild to use websockets instead of data polling.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
166 | free(node); |
14322825cb3d
The co2meters monitor screen rebuild to use websockets instead of data polling.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
167 | if (alias) |
14322825cb3d
The co2meters monitor screen rebuild to use websockets instead of data polling.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
168 | free(alias); |
14322825cb3d
The co2meters monitor screen rebuild to use websockets instead of data polling.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
169 | if (beeruuid) |
14322825cb3d
The co2meters monitor screen rebuild to use websockets instead of data polling.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
170 | free(beeruuid); |
14322825cb3d
The co2meters monitor screen rebuild to use websockets instead of data polling.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
171 | if (beercode) |
14322825cb3d
The co2meters monitor screen rebuild to use websockets instead of data polling.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
172 | free(beercode); |
14322825cb3d
The co2meters monitor screen rebuild to use websockets instead of data polling.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
173 | if (beername) |
14322825cb3d
The co2meters monitor screen rebuild to use websockets instead of data polling.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
174 | free(beername); |
14322825cb3d
The co2meters monitor screen rebuild to use websockets instead of data polling.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
175 | } |
14322825cb3d
The co2meters monitor screen rebuild to use websockets instead of data polling.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
176 | |
14322825cb3d
The co2meters monitor screen rebuild to use websockets instead of data polling.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
177 | |
14322825cb3d
The co2meters monitor screen rebuild to use websockets instead of data polling.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
178 | |
502
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
179 | 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
|
180 | { |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
181 | struct json_object *jobj, *val, *sensor; |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
182 | sys_co2meter_list *co2meter, *tmpp; |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
183 | bool new_co2meter = true; |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
184 | |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
185 | // 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
|
186 | |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
187 | /* |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
188 | * 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
|
189 | */ |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
190 | if (co2meters) { |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
191 | for (tmpp = co2meters; tmpp; tmpp = tmpp->next) { |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
192 | 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
|
193 | new_co2meter = false; |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
194 | co2meter = tmpp; |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
195 | break; |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
196 | } |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
197 | } |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
198 | } |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
199 | |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
200 | // 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
|
201 | |
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 | * Allocate new co2meter if not yet known. |
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 | if (new_co2meter) { |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
206 | 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
|
207 | memset(co2meter, 0, sizeof(sys_co2meter_list)); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
208 | co2meter->alias = xstrcpy(alias); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
209 | co2meter->node = xstrcpy(edge_node); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
210 | co2meter->mode = xstrcpy((char *)"OFF"); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
211 | } |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
212 | |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
213 | if (! co2meter->online) { |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
214 | co2meter->online = true; |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
215 | 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
|
216 | } |
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 | * Process the JSON formatted payload. |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
220 | * 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
|
221 | */ |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
222 | jobj = json_tokener_parse(payload); |
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 | 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
|
225 | if (co2meter->uuid) |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
226 | free(co2meter->uuid); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
227 | 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
|
228 | } |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
229 | 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
|
230 | if (co2meter->mode) { |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
231 | 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
|
232 | 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
|
233 | } |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
234 | free(co2meter->mode); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
235 | } |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
236 | 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
|
237 | } |
505
c09b67fd8323
Added CO2 meter units alarm led.
Michiel Broek <mbroek@mbse.eu>
parents:
502
diff
changeset
|
238 | 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
|
239 | co2meter->alarm = json_object_get_int(val); |
c09b67fd8323
Added CO2 meter units alarm led.
Michiel Broek <mbroek@mbse.eu>
parents:
502
diff
changeset
|
240 | } |
502
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
241 | 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
|
242 | 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
|
243 | if (co2meter->temperature_address) |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
244 | free(co2meter->temperature_address); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
245 | 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
|
246 | } |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
247 | 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
|
248 | if (co2meter->temperature_state) |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
249 | free(co2meter->temperature_state); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
250 | 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
|
251 | } |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
252 | 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
|
253 | co2meter->temperature = json_object_get_double(val); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
254 | } |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
255 | } |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
256 | 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
|
257 | 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
|
258 | if (co2meter->pressure_state) |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
259 | free(co2meter->pressure_state); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
260 | 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
|
261 | } |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
262 | 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
|
263 | co2meter->pressure_channel = json_object_get_int(val); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
264 | } |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
265 | 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
|
266 | co2meter->pressure_voltage = json_object_get_double(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, "zero", &val)) { |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
269 | co2meter->pressure_zero = json_object_get_double(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, "bar", &val)) { |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
272 | co2meter->pressure_bar = 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 | } |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
275 | json_object_put(jobj); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
276 | |
678
14322825cb3d
The co2meters monitor screen rebuild to use websockets instead of data polling.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
277 | 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
|
278 | |
502
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
279 | // co2meter_dump(co2meter); |
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 | if (new_co2meter) { |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
282 | if (co2meters == NULL) { |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
283 | co2meters = co2meter; |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
284 | } else { |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
285 | for (tmpp = co2meters; tmpp; tmpp = tmpp->next) { |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
286 | if (tmpp->next == NULL) { |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
287 | tmpp->next = co2meter; |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
288 | break; |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
289 | } |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
290 | } |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
291 | } |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
292 | co2meter_mysql_insert(co2meter); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
293 | } else { |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
294 | co2meter_mysql_update(co2meter); |
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 | |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
299 | |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
300 | |
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 | * 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
|
303 | */ |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
304 | void co2meter_birth_data(char *topic, char *payload) |
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 | char *message_type, *edge_node, *alias; |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
307 | struct json_object *jobj, *val, *metric, *units, *unit; |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
308 | int arraylen; |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
309 | |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
310 | strtok(topic, "/"); // ignore namespace |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
311 | strtok(NULL, "/"); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
312 | message_type = strtok(NULL, "/"); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
313 | edge_node = strtok(NULL, "/\0"); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
314 | alias = strtok(NULL, "/\0"); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
315 | |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
316 | if ((alias == NULL) && (strcmp("DBIRTH", message_type) == 0)) { |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
317 | /* |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
318 | * Global initial DBIRTH message with array of co2meters. |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
319 | */ |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
320 | jobj = json_tokener_parse(payload); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
321 | |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
322 | 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
|
323 | 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
|
324 | arraylen = json_object_array_length(units); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
325 | for (int i = 0; i < arraylen; i++) { |
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 | * Parse the array of units |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
328 | */ |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
329 | unit = json_object_array_get_idx(units, i); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
330 | |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
331 | 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
|
332 | if (alias) |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
333 | free(alias); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
334 | alias = xstrcpy((char *)json_object_get_string(val)); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
335 | 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
|
336 | free(alias); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
337 | alias = NULL; |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
338 | } |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
339 | } |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
340 | } |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
341 | } |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
342 | json_object_put(jobj); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
343 | return; |
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 | * The rest are errors. |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
348 | */ |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
349 | 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
|
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 | |
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 | void co2meter_log(char *topic, char *payload) |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
355 | { |
506
8ab0e87d579e
Added beer selection in the CO2 meter screen. Added CO2 pressure logging.
Michiel Broek <mbroek@mbse.eu>
parents:
505
diff
changeset
|
356 | 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
|
357 | struct json_object *jobj, *val, *metric; |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
358 | co2pressure_log *log; |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
359 | struct tm *mytime; |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
360 | time_t timestamp; |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
361 | FILE *fp; |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
362 | |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
363 | strtok(topic, "/"); // ignore namespace |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
364 | strtok(NULL, "/"); // group_id |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
365 | strtok(NULL, "/"); // message_type |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
366 | edge_node = strtok(NULL, "/\0"); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
367 | alias = strtok(NULL, "/\0"); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
368 | |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
369 | log = (co2pressure_log *)malloc(sizeof(co2pressure_log)); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
370 | memset(log, 0, sizeof(co2pressure_log)); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
371 | |
506
8ab0e87d579e
Added beer selection in the CO2 meter screen. Added CO2 pressure logging.
Michiel Broek <mbroek@mbse.eu>
parents:
505
diff
changeset
|
372 | 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
|
373 | log->alias = xstrcpy(alias); |
502
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
374 | jobj = json_tokener_parse(payload); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
375 | |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
376 | 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
|
377 | log->datetime = malloc(73); |
502
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
378 | 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
|
379 | 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
|
380 | 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
|
381 | |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
382 | 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
|
383 | 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
|
384 | 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
|
385 | 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
|
386 | } |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
387 | 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
|
388 | log->temperature = json_object_get_double(val); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
389 | } |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
390 | 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
|
391 | log->pressure = json_object_get_double(val); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
392 | } |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
393 | } |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
394 | json_object_put(jobj); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
395 | |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
396 | /* |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
397 | * 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
|
398 | * search the missing pieces in the database. |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
399 | */ |
506
8ab0e87d579e
Added beer selection in the CO2 meter screen. Added CO2 pressure logging.
Michiel Broek <mbroek@mbse.eu>
parents:
505
diff
changeset
|
400 | 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
|
401 | 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
|
402 | 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
|
403 | } else { |
8ab0e87d579e
Added beer selection in the CO2 meter screen. Added CO2 pressure logging.
Michiel Broek <mbroek@mbse.eu>
parents:
505
diff
changeset
|
404 | 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
|
405 | 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
|
406 | 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
|
407 | } else { |
8ab0e87d579e
Added beer selection in the CO2 meter screen. Added CO2 pressure logging.
Michiel Broek <mbroek@mbse.eu>
parents:
505
diff
changeset
|
408 | 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
|
409 | /* |
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
|
410 | * 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
|
411 | */ |
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
|
412 | 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
|
413 | 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
|
414 | 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
|
415 | 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
|
416 | 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
|
417 | 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
|
418 | 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
|
419 | 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
|
420 | 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
|
421 | 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
|
422 | 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
|
423 | } |
506
8ab0e87d579e
Added beer selection in the CO2 meter screen. Added CO2 pressure logging.
Michiel Broek <mbroek@mbse.eu>
parents:
505
diff
changeset
|
424 | 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
|
425 | 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
|
426 | 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
|
427 | } |
8ab0e87d579e
Added beer selection in the CO2 meter screen. Added CO2 pressure logging.
Michiel Broek <mbroek@mbse.eu>
parents:
505
diff
changeset
|
428 | } |
8ab0e87d579e
Added beer selection in the CO2 meter screen. Added CO2 pressure logging.
Michiel Broek <mbroek@mbse.eu>
parents:
505
diff
changeset
|
429 | } |
502
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
430 | |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
431 | /* |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
432 | * Build csv log line |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
433 | */ |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
434 | line = xstrcpy(log->datetime); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
435 | line = xstrcat(line, (char *)","); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
436 | snprintf(buf, 64, "%.3f", log->temperature); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
437 | line = xstrcat(line, buf); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
438 | line = xstrcat(line, (char *)","); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
439 | snprintf(buf, 64, "%.3f", log->pressure); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
440 | line = xstrcat(line, buf); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
441 | 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
|
442 | line = xstrcat(line, log->uuid); |
502
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
443 | |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
444 | /* |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
445 | * Build logfile name |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
446 | */ |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
447 | logfile = xstrcpy(Config.web_root); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
448 | logfile = xstrcat(logfile, (char *)"/log/co2pressure/"); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
449 | logfile = xstrcat(logfile, log->product_code); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
450 | logfile = xstrcat(logfile, (char *)" "); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
451 | logfile = xstrcat(logfile, log->product_name); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
452 | logfile = xstrcat(logfile, (char *)".log"); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
453 | |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
454 | if (debug) |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
455 | fprintf(stdout, "%s %s\n", logfile, line); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
456 | |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
457 | fp = fopen(logfile, "a"); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
458 | if (fp) { |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
459 | fprintf(fp, "%s\n", line); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
460 | fclose(fp); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
461 | } else { |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
462 | syslog(LOG_NOTICE, "cannot append to `%s'", logfile); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
463 | } |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
464 | |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
465 | free(logfile); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
466 | logfile = NULL; |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
467 | free(line); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
468 | line = NULL; |
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 | if (log->datetime) |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
471 | free(log->datetime); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
472 | if (log->product_uuid ) |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
473 | free(log->product_uuid ); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
474 | if (log->product_code ) |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
475 | free(log->product_code ); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
476 | if (log->product_name ) |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
477 | 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
|
478 | 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
|
479 | 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
|
480 | 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
|
481 | 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
|
482 | 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
|
483 | free(log->alias); |
502
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
484 | free(log); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
485 | } |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
486 | |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
487 | |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
488 | |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
489 | void co2meter_dump(sys_co2meter_list *co2meter) |
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 | if (debug) { |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
492 | printf("uuid %s\n", co2meter->uuid); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
493 | printf("alias %s\n", co2meter->alias); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
494 | printf("node %s\n", co2meter->node); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
495 | printf("online %s\n", co2meter->online ? "yes":"no"); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
496 | 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
|
497 | 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
|
498 | 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
|
499 | 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
|
500 | printf("mode %s\n", co2meter->mode); |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
501 | } |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
502 | } |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
503 | |
a8a6901b5a99
Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
504 |