Tue, 04 Jun 2019 19:50:06 +0200
Added console logging in the grid write callback functions. Removed grid sorting, it is done on the server side. Alert popup for block row edit functions. Better grid live updates. In recipe and product print show the whirlpool time. The checklist now shows misc ingredients added in the mash. Show hops added in the whirlpool. Most ingredient names are now quoted.
0 | 1 | /** |
2 | * @file bms.h | |
3 | */ | |
4 | ||
5 | #ifndef _BMS_H | |
6 | #define _BMS_H | |
7 | ||
8 | #define TRUE 1 | |
9 | #define FALSE 0 | |
10 | ||
11 | #include "../config.h" | |
12 | ||
13 | #include <stdlib.h> | |
14 | #include <stdio.h> | |
15 | #include <stdint.h> | |
16 | #include <stdarg.h> | |
17 | #include <string.h> | |
18 | #include <ctype.h> | |
19 | #include <sys/types.h> | |
20 | #include <sys/socket.h> | |
21 | #include <sys/stat.h> | |
22 | #include <sys/time.h> | |
23 | #include <sys/un.h> | |
24 | #include <sys/utsname.h> | |
25 | #include <pwd.h> | |
26 | #include <time.h> | |
27 | #include <fcntl.h> | |
28 | #include <syslog.h> | |
29 | #include <unistd.h> | |
30 | #include <errno.h> | |
31 | #include <signal.h> | |
32 | #include <getopt.h> | |
33 | #include <limits.h> | |
34 | #include <sys/socket.h> | |
35 | #include <arpa/inet.h> | |
36 | #include <netdb.h> | |
37 | #include <poll.h> | |
38 | #include <dirent.h> | |
39 | #include <uuid/uuid.h> | |
40 | #include <math.h> | |
41 | #include <assert.h> | |
42 | #include <libgen.h> | |
43 | #include <libxml/xmlmemory.h> | |
44 | #include <libxml/parser.h> | |
45 | #include <libxml/encoding.h> | |
46 | #include <libxml/xmlwriter.h> | |
47 | #include <mosquitto.h> | |
48 | #include <mysql/mysql.h> | |
49 | #include <json-c/json.h> | |
50 | ||
51 | ||
52 | #define MBSE_SS(x) (x)?(x):"(null)" | |
53 | ||
54 | ||
55 | #define MQTT_NODE_CONTROL 0x0001 ///< Show node control | |
56 | ||
57 | ||
58 | ||
59 | /** | |
60 | * @brief Configuration structure. Stored in a flat ascii file ~/.bms/bms.config | |
61 | */ | |
62 | typedef struct _sys_config { | |
63 | char *bms_name; ///< Brewery name | |
64 | char *bms_uuid; ///< Brewery uuid | |
65 | char *mysql_host; ///< MySQL host | |
66 | int mysql_port; ///< MySQL port | |
67 | char *mysql_user; ///< MySQL user name | |
68 | char *mysql_pass; ///< MySQL password | |
69 | char *mysql_database; ///< MySQL database | |
70 | char *mqtt_host; ///< MQTT host | |
71 | int mqtt_port; ///< MQTT port | |
72 | char *mqtt_user; ///< MQTT username of NULL | |
73 | char *mqtt_pass; ///< MQTT password of NULL | |
194
d202777ebae5
Added design notes for the csv log format from fermenters. In bmsd configuration added the web_root entry. Switched fermenter DLOG messages to store the log in flat csv files instead of the database. This is much faster and the graphs look better.
Michiel Broek <mbroek@mbse.eu>
parents:
192
diff
changeset
|
74 | char *web_root; ///< WWW root directory |
0 | 75 | } sys_config; |
76 | ||
77 | ||
78 | /** | |
79 | * @brief Structure for the nodes. Database table 'nodes'. | |
80 | */ | |
81 | typedef struct _sys_node_list { | |
82 | struct _sys_node_list *next; | |
83 | char *uuid; ///< uuid string | |
84 | char *node; ///< nodename | |
85 | bool online; ///< on-line state | |
86 | char *group_id; ///< group type | |
87 | char *hardwaremake; ///< hardware make | |
88 | char *hardwaremodel; ///< hardware model | |
89 | char *os; ///< os type | |
90 | char *os_version; ///< os version | |
91 | char *firmware; ///< application version | |
92 | time_t firstseen; ///< First seen this session | |
93 | time_t lastseen; ///< Last seen this session | |
94 | float temperature; ///< environment temperature | |
95 | float humidity; ///< environment humidity | |
96 | float barometer; ///< environment barometer pressure | |
97 | float gps_latitude; ///< GPS latitude | |
98 | float gps_longitude; ///< GPS longitude | |
99 | float gps_altitude; ///< GPS altitude | |
100 | char *net_address; ///< IPv4 or IPv6 address | |
101 | char *net_ifname; ///< Interface name | |
102 | int net_rssi; ///< RSSI value if wireless. | |
103 | } sys_node_list; | |
104 | ||
105 | ||
106 | /** | |
107 | * @brief Fermenting profile steps | |
108 | */ | |
109 | typedef struct _prof_step { | |
110 | struct _prof_step *next; | |
111 | int steptime; ///< Step time to target in hours | |
112 | int resttime; ///< Rest time on target in hours | |
113 | float target_lo; ///< Low Target temperature | |
114 | float target_hi; ///< High target temperature | |
115 | int fridge_mode; ///< Fridge or beer mode | |
116 | } prof_step; | |
117 | ||
118 | ||
119 | typedef enum | |
120 | { | |
121 | FERMENTER_MODE_OFF = 0, ///< Fermenter is off. | |
122 | FERMENTER_MODE_NONE, ///< Fermenter on but does nothing. | |
123 | FERMENTER_MODE_FRIDGE, ///< Fermenter acts as a fridge. | |
124 | FERMENTER_MODE_BEER, ///< Fermenter acts as beer cooler. | |
125 | FERMENTER_MODE_PROFILE, ///< Fermenter runs in profile mode. | |
126 | } FERMENTER_MODE; | |
127 | ||
128 | typedef enum | |
129 | { | |
130 | FERMENTER_STAGE_PRIMARY = 0, ///< Fermentation primage stage. | |
131 | FERMENTER_STAGE_SECONDARY, ///< Fermenter secondary stage. | |
132 | FERMENTER_STAGE_TERTIARY, ///< Fermenter tertiary stage. | |
34 | 133 | FERMENTER_STAGE_CARBONATION, ///< Fermenter carbonation stage. |
0 | 134 | } FERMENTER_STAGE; |
135 | ||
136 | typedef enum | |
137 | { | |
138 | DEVPRESENT_UNDEF = 0, ///< Precence not detectable. | |
139 | DEVPRESENT_NO, ///< Device is missing. | |
140 | DEVPRESENT_YES, ///< Device is present and Ok. | |
141 | DEVPRESENT_ERROR, ///< Device is present but in error state. | |
142 | } DEVPRESENT_STATE; | |
143 | ||
144 | ||
145 | typedef enum | |
146 | { | |
147 | ALARM_FLAG_DOOR = 0x0001, ///< Door open | |
148 | ALARM_FLAG_PSU = 0x0002, ///< PSU problem | |
149 | ALARM_FLAG_CHILLER = 0x0100, ///< Chiller too warm | |
150 | } ALARM_FLAGS; | |
151 | ||
152 | ||
153 | /** | |
154 | * @brief Structure for the fermenters. Stored in database table 'fermenters'. | |
155 | */ | |
156 | typedef struct _fermenter_list { | |
157 | struct _fermenter_list *next; | |
158 | char *uuid; ///< Fixed uuid string | |
159 | char *alias; ///< Fixed short name | |
160 | char *node; ///< Fixed node name | |
161 | bool online; ///< Online status | |
162 | char *beercode; ///< Beer unique code | |
163 | char *beername; ///< Beer name in fermenter | |
192
7f69b43e6084
Implemented beer uuid product in monitor fermenters.
Michiel Broek <mbroek@mbse.eu>
parents:
81
diff
changeset
|
164 | char *beeruuid; ///< Beer uuid in fermenter |
0 | 165 | char *air_address; ///< Air sensor address |
166 | char *air_state; ///< Air sensor state | |
167 | float air_temperature; ///< Air temperature | |
168 | char *beer_address; ///< Beer sensor address | |
169 | char *beer_state; ///< Beer sensor state | |
170 | float beer_temperature; ///< Beer temperature | |
171 | char *chiller_address; ///< Chiller sensor address | |
172 | char *chiller_state; ///< Chiller sensor state | |
173 | float chiller_temperature; ///< Chiller temperature | |
174 | char *heater_address; ///< Heater address | |
175 | int heater_state; ///< Heater state | |
176 | uint64_t heater_usage; ///< Heater usage | |
177 | char *cooler_address; ///< Cooler address | |
178 | int cooler_state; ///< Cooler state | |
179 | uint64_t cooler_usage; ///> Cooler usage | |
180 | char *fan_address; ///< Fan address | |
181 | int fan_state; ///< Fan state | |
182 | uint64_t fan_usage; ///< Fan usage | |
183 | char *light_address; ///< Light address | |
184 | int light_state; ///< Light state | |
185 | uint64_t light_usage; ///< Light usage | |
186 | char *door_address; ///< Door address | |
187 | int door_state; ///< Door state | |
188 | char *psu_address; ///< PSU address | |
189 | int psu_state; ///< PSU state | |
190 | char *mode; ///< Fermenter mode | |
191 | char *stage; ///< Fermentation stage | |
192 | uint32_t alarm; ///< Alarm flag | |
193 | float setpoint_high; ///< Setpoint high | |
194 | float setpoint_low; ///< Setpoint low | |
195 | char *profile_uuid; ///< Profile uuid | |
196 | char *profile_name; ///< Profile name | |
197 | char *profile_state; ///< Profile state | |
198 | int profile_percent; ///< Profile percent done | |
199 | float profile_inittemp_high; ///< Profile init temp high | |
200 | float profile_inittemp_low; ///< Profile init temp low | |
201 | char *profile_steps; ///< Profile steps in JSON | |
299
047ead629d4a
Accept yeast temperature limits from thermferm via MQTT. Send yeat temperature ranges to thermferm together with the beer parameters. Store yeast temperature limits in the mon_fermenters database table. The monitor fermenters screen adjusts the temperature color ranges.
Michiel Broek <mbroek@mbse.eu>
parents:
194
diff
changeset
|
202 | float yeast_lo; ///< Yeast minimum temperature |
047ead629d4a
Accept yeast temperature limits from thermferm via MQTT. Send yeat temperature ranges to thermferm together with the beer parameters. Store yeast temperature limits in the mon_fermenters database table. The monitor fermenters screen adjusts the temperature color ranges.
Michiel Broek <mbroek@mbse.eu>
parents:
194
diff
changeset
|
203 | float yeast_hi; ///< Yeast maximum temperature |
334
26c6f8e5d58e
Added webcam_url and webcam_light fields to the mon_fermenters database table. Currently these fields need to be set using phpMyAdmin or another tool. If the webcam_url field is set, then on the mon_fermenter webpage a button is added to show a webcam page.
Michiel Broek <mbroek@mbse.eu>
parents:
299
diff
changeset
|
204 | char *webcam_url; ///< Webcam url to the stream |
26c6f8e5d58e
Added webcam_url and webcam_light fields to the mon_fermenters database table. Currently these fields need to be set using phpMyAdmin or another tool. If the webcam_url field is set, then on the mon_fermenter webpage a button is added to show a webcam page.
Michiel Broek <mbroek@mbse.eu>
parents:
299
diff
changeset
|
205 | int webcam_light; ///< Webcam control lights |
0 | 206 | } sys_fermenter_list; |
207 | ||
208 | ||
209 | ||
210 | typedef enum | |
211 | { | |
212 | PROFILE_OFF = 0, ///< Profile not active | |
213 | PROFILE_PAUSE, ///< Profile pause | |
214 | PROFILE_RUN, ///< Profile is running | |
215 | PROFILE_DONE, ///< Profile is finished | |
216 | PROFILE_ABORT, ///< Profile abort | |
217 | } PROFILE_STATE; | |
218 | ||
219 | ||
220 | ||
221 | /** | |
222 | * @brief Strcuture holding a fermentation log entry. | |
223 | */ | |
224 | typedef struct fermenting_log { | |
225 | char *datetime; ///< Date/time stamp | |
226 | char *product_uuid; ///< Product uuid | |
227 | char *product_code; ///< Product code | |
228 | char *product_name; ///< Product name | |
229 | float temperature_air; ///< Temperature air | |
230 | float temperature_beer; ///< Temperature beer | |
231 | float temperature_chiller; ///< Temperature chiller (if pressent) | |
232 | float temperature_room; ///< Temperature room | |
233 | int heater_power; ///< Heater power 0..100 | |
234 | uint64_t heater_usage; ///< Heater usage counter in seconds. | |
235 | int cooler_power; ///< Cooler power 0..100 | |
236 | uint64_t cooler_usage; ///< Cooler usage counter in seconds. | |
237 | int fan_power; ///< Fan power 0 or 100 | |
238 | uint64_t fan_usage; ///< Fan usage counter in seconds | |
239 | float setpoint_low; ///< Target temperature low | |
240 | float setpoint_high; ///< Tarhet temperature high | |
241 | char *mode; ///< Working mode. | |
242 | char *stage; ///< Fermentation stage | |
243 | char *event; ///< Optional event | |
244 | char *fermenter_uuid; ///< Fermenter in use | |
245 | char *fermenter_node; ///< Fermenter node | |
246 | char *fermenter_alias; ///< Fermenter_alias | |
247 | } fermentation_log; | |
248 | ||
249 | ||
250 | ||
251 | /** | |
252 | * @brief Brew computer controllers. Must have hardware + installation + recipe data. | |
253 | */ | |
254 | typedef struct _brewer_list { | |
255 | struct _brewer_list *next; | |
256 | char *uuid; | |
257 | } brewer_list; | |
258 | ||
259 | ||
260 | // Make it universal and make it connectable with a fermenter. | |
261 | typedef struct _ispindel_list { | |
262 | struct _ispindel_list *next; | |
263 | char *uuid; ///< Fixed uuid string | |
264 | char *name; ///< Name or description (Red iSpindle). | |
265 | char *beercode; ///< Beer code if in use. | |
266 | float temperature; ///< Temperature of the beer. | |
267 | float gravity; ///< Measured gravity | |
268 | // What nore, battery? | |
269 | } ispindel_list; | |
270 | ||
271 | ||
272 | // Hergisting meters. | |
273 | ||
274 | /** | |
275 | * @brief Standalone temperature loggers. (Freezers, refrigerators, chambers). | |
276 | */ | |
277 | typedef struct _thb_list { | |
278 | struct _thb_list *next; | |
279 | char *uuit; ///< Fixed uuid string | |
280 | char *name; ///< Name or description | |
281 | char *beercode; ///< Beer code if needed. | |
282 | float temperature; ///< Temperature in Celcius | |
283 | float humidity; ///< Humidity in % | |
284 | float barometer; ///< Air pressure. | |
285 | float gps_latitude; ///< GPS latitude | |
286 | float gps_longitude; ///< GPS longitide | |
287 | float gps_altitude; ///< GPS altitude | |
288 | } thb_list; | |
289 | ||
290 | ||
291 | #endif |