Wed, 18 Oct 2023 10:06:11 +0200
Version 0.3.45. Removed all writing to ascii logfiles in the webserver environment, only log to MySQL.
567
6bf0afc33e70
Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
1 | /** |
6bf0afc33e70
Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
2 | * @file ispindels.c |
568
6f3c24e21deb
Added ispindel logging. Updated the documentation.
Michiel Broek <mbroek@mbse.eu>
parents:
567
diff
changeset
|
3 | * @brief Handle ispindels data |
567
6bf0afc33e70
Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
4 | * @author Michiel Broek <mbroek at mbse dot eu> |
6bf0afc33e70
Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
5 | * |
843
29e7223e37ae
Version 0.3.42 added yeast_lo and yeast_hi fields to the iSpindel records and structures.
Michiel Broek <mbroek@mbse.eu>
parents:
799
diff
changeset
|
6 | * Copyright (C) 2019-2023 |
567
6bf0afc33e70
Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
7 | * |
6bf0afc33e70
Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
8 | * This file is part of the bms (Brewery Management System) |
6bf0afc33e70
Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
9 | * |
6bf0afc33e70
Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
10 | * This is free software; you can redistribute it and/or modify it |
6bf0afc33e70
Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
11 | * under the terms of the GNU General Public License as published by the |
6bf0afc33e70
Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
12 | * Free Software Foundation; either version 2, or (at your option) any |
6bf0afc33e70
Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
13 | * later version. |
6bf0afc33e70
Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
14 | * |
6bf0afc33e70
Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
15 | * bms is distributed in the hope that it will be useful, but |
6bf0afc33e70
Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
16 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
6bf0afc33e70
Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
6bf0afc33e70
Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
18 | * General Public License for more details. |
6bf0afc33e70
Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
19 | * |
6bf0afc33e70
Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
20 | * You should have received a copy of the GNU General Public License |
6bf0afc33e70
Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
21 | * along with ThermFerm; see the file COPYING. If not, write to the Free |
6bf0afc33e70
Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
22 | * Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. |
6bf0afc33e70
Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
23 | */ |
6bf0afc33e70
Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
24 | |
6bf0afc33e70
Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
25 | |
6bf0afc33e70
Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
26 | #include "bms.h" |
6bf0afc33e70
Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
27 | #include "xutil.h" |
6bf0afc33e70
Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
28 | #include "ispindels.h" |
6bf0afc33e70
Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
29 | #include "mysql.h" |
6bf0afc33e70
Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
30 | #include "nodes.h" |
675
a27af02ab16a
Added iSpindel to the websockets. Better offline detection for websockets.
Michiel Broek <mbroek@mbse.eu>
parents:
654
diff
changeset
|
31 | #include "websocket.h" |
567
6bf0afc33e70
Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
32 | |
6bf0afc33e70
Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
33 | |
6bf0afc33e70
Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
34 | sys_ispindel_list *ispindels = NULL; |
6bf0afc33e70
Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
35 | |
6bf0afc33e70
Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
36 | extern int debug; |
6bf0afc33e70
Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
37 | extern sys_config Config; |
6bf0afc33e70
Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
38 | extern MYSQL *con; |
6bf0afc33e70
Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
39 | extern MYSQL_RES *res_set; |
6bf0afc33e70
Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
40 | extern MYSQL_ROW row; |
6bf0afc33e70
Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
41 | |
6bf0afc33e70
Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
42 | |
849
16079aef4c4c
Version 0.3.44. Moved iSpindel Plato calculation from the php script to bmsd. This uses calibration data in the mon_ispindels table. Setup of this data will be done by the bmsapp applications. Default settings are stored in MySQL. From now on you don't need to store calibration data in the iSpindel.
Michiel Broek <mbroek@mbse.eu>
parents:
843
diff
changeset
|
43 | |
16079aef4c4c
Version 0.3.44. Moved iSpindel Plato calculation from the php script to bmsd. This uses calibration data in the mon_ispindels table. Setup of this data will be done by the bmsapp applications. Default settings are stored in MySQL. From now on you don't need to store calibration data in the iSpindel.
Michiel Broek <mbroek@mbse.eu>
parents:
843
diff
changeset
|
44 | double plato_to_sg(double plato) |
16079aef4c4c
Version 0.3.44. Moved iSpindel Plato calculation from the php script to bmsd. This uses calibration data in the mon_ispindels table. Setup of this data will be done by the bmsapp applications. Default settings are stored in MySQL. From now on you don't need to store calibration data in the iSpindel.
Michiel Broek <mbroek@mbse.eu>
parents:
843
diff
changeset
|
45 | { |
16079aef4c4c
Version 0.3.44. Moved iSpindel Plato calculation from the php script to bmsd. This uses calibration data in the mon_ispindels table. Setup of this data will be done by the bmsapp applications. Default settings are stored in MySQL. From now on you don't need to store calibration data in the iSpindel.
Michiel Broek <mbroek@mbse.eu>
parents:
843
diff
changeset
|
46 | return 1.00001 + (0.0038661 * plato) + (1.3488e-5 * pow(plato, 2)) + (4.3074e-8 * pow(plato, 3)); |
16079aef4c4c
Version 0.3.44. Moved iSpindel Plato calculation from the php script to bmsd. This uses calibration data in the mon_ispindels table. Setup of this data will be done by the bmsapp applications. Default settings are stored in MySQL. From now on you don't need to store calibration data in the iSpindel.
Michiel Broek <mbroek@mbse.eu>
parents:
843
diff
changeset
|
47 | } |
16079aef4c4c
Version 0.3.44. Moved iSpindel Plato calculation from the php script to bmsd. This uses calibration data in the mon_ispindels table. Setup of this data will be done by the bmsapp applications. Default settings are stored in MySQL. From now on you don't need to store calibration data in the iSpindel.
Michiel Broek <mbroek@mbse.eu>
parents:
843
diff
changeset
|
48 | |
16079aef4c4c
Version 0.3.44. Moved iSpindel Plato calculation from the php script to bmsd. This uses calibration data in the mon_ispindels table. Setup of this data will be done by the bmsapp applications. Default settings are stored in MySQL. From now on you don't need to store calibration data in the iSpindel.
Michiel Broek <mbroek@mbse.eu>
parents:
843
diff
changeset
|
49 | |
16079aef4c4c
Version 0.3.44. Moved iSpindel Plato calculation from the php script to bmsd. This uses calibration data in the mon_ispindels table. Setup of this data will be done by the bmsapp applications. Default settings are stored in MySQL. From now on you don't need to store calibration data in the iSpindel.
Michiel Broek <mbroek@mbse.eu>
parents:
843
diff
changeset
|
50 | |
680
0bb48333d133
Fixed missing co2meters websocket data. Added websockets and removed polling for the mon-ispindel screen. The iSpindel SG gauge adjusts the resolution to the highest detected OG.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
51 | void ispindel_ws_send(sys_ispindel_list *ispindel) |
0bb48333d133
Fixed missing co2meters websocket data. Added websockets and removed polling for the mon-ispindel screen. The iSpindel SG gauge adjusts the resolution to the highest detected OG.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
52 | { |
0bb48333d133
Fixed missing co2meters websocket data. Added websockets and removed polling for the mon-ispindel screen. The iSpindel SG gauge adjusts the resolution to the highest detected OG.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
53 | char *msg = NULL, buf[65]; |
0bb48333d133
Fixed missing co2meters websocket data. Added websockets and removed polling for the mon-ispindel screen. The iSpindel SG gauge adjusts the resolution to the highest detected OG.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
54 | |
0bb48333d133
Fixed missing co2meters websocket data. Added websockets and removed polling for the mon-ispindel screen. The iSpindel SG gauge adjusts the resolution to the highest detected OG.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
55 | msg = xstrcpy((char *)"{\"device\":\"ispindels\",\"node\":\""); |
0bb48333d133
Fixed missing co2meters websocket data. Added websockets and removed polling for the mon-ispindel screen. The iSpindel SG gauge adjusts the resolution to the highest detected OG.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
56 | msg = xstrcat(msg, ispindel->node); |
0bb48333d133
Fixed missing co2meters websocket data. Added websockets and removed polling for the mon-ispindel screen. The iSpindel SG gauge adjusts the resolution to the highest detected OG.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
57 | msg = xstrcat(msg, (char *)"\",\"unit\":\""); |
0bb48333d133
Fixed missing co2meters websocket data. Added websockets and removed polling for the mon-ispindel screen. The iSpindel SG gauge adjusts the resolution to the highest detected OG.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
58 | msg = xstrcat(msg, ispindel->alias); |
0bb48333d133
Fixed missing co2meters websocket data. Added websockets and removed polling for the mon-ispindel screen. The iSpindel SG gauge adjusts the resolution to the highest detected OG.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
59 | msg = xstrcat(msg, (char *)"\",\"online\":"); |
0bb48333d133
Fixed missing co2meters websocket data. Added websockets and removed polling for the mon-ispindel screen. The iSpindel SG gauge adjusts the resolution to the highest detected OG.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
60 | msg = xstrcat(msg, ispindel->online ? (char *)"1":(char *)"0"); |
0bb48333d133
Fixed missing co2meters websocket data. Added websockets and removed polling for the mon-ispindel screen. The iSpindel SG gauge adjusts the resolution to the highest detected OG.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
61 | msg = xstrcat(msg, (char *)",\"mode\":\""); |
0bb48333d133
Fixed missing co2meters websocket data. Added websockets and removed polling for the mon-ispindel screen. The iSpindel SG gauge adjusts the resolution to the highest detected OG.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
62 | msg = xstrcat(msg, ispindel->mode); |
0bb48333d133
Fixed missing co2meters websocket data. Added websockets and removed polling for the mon-ispindel screen. The iSpindel SG gauge adjusts the resolution to the highest detected OG.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
63 | msg = xstrcat(msg, (char *)"\",\"beeruuid\":\""); |
0bb48333d133
Fixed missing co2meters websocket data. Added websockets and removed polling for the mon-ispindel screen. The iSpindel SG gauge adjusts the resolution to the highest detected OG.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
64 | msg = xstrcat(msg, ispindel->beeruuid); |
0bb48333d133
Fixed missing co2meters websocket data. Added websockets and removed polling for the mon-ispindel screen. The iSpindel SG gauge adjusts the resolution to the highest detected OG.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
65 | msg = xstrcat(msg, (char *)"\",\"beercode\":\""); |
0bb48333d133
Fixed missing co2meters websocket data. Added websockets and removed polling for the mon-ispindel screen. The iSpindel SG gauge adjusts the resolution to the highest detected OG.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
66 | msg = xstrcat(msg, ispindel->beercode); |
0bb48333d133
Fixed missing co2meters websocket data. Added websockets and removed polling for the mon-ispindel screen. The iSpindel SG gauge adjusts the resolution to the highest detected OG.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
67 | msg = xstrcat(msg, (char *)"\",\"beername\":\""); |
0bb48333d133
Fixed missing co2meters websocket data. Added websockets and removed polling for the mon-ispindel screen. The iSpindel SG gauge adjusts the resolution to the highest detected OG.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
68 | msg = xstrcat(msg, ispindel->beername); |
843
29e7223e37ae
Version 0.3.42 added yeast_lo and yeast_hi fields to the iSpindel records and structures.
Michiel Broek <mbroek@mbse.eu>
parents:
799
diff
changeset
|
69 | msg = xstrcat(msg, (char *)"\",\"yeast_lo\":"); |
29e7223e37ae
Version 0.3.42 added yeast_lo and yeast_hi fields to the iSpindel records and structures.
Michiel Broek <mbroek@mbse.eu>
parents:
799
diff
changeset
|
70 | snprintf(buf, 64, "%.3f", ispindel->yeast_lo); |
29e7223e37ae
Version 0.3.42 added yeast_lo and yeast_hi fields to the iSpindel records and structures.
Michiel Broek <mbroek@mbse.eu>
parents:
799
diff
changeset
|
71 | msg = xstrcat(msg, buf); |
29e7223e37ae
Version 0.3.42 added yeast_lo and yeast_hi fields to the iSpindel records and structures.
Michiel Broek <mbroek@mbse.eu>
parents:
799
diff
changeset
|
72 | msg = xstrcat(msg, (char *)",\"yeast_hi\":"); |
29e7223e37ae
Version 0.3.42 added yeast_lo and yeast_hi fields to the iSpindel records and structures.
Michiel Broek <mbroek@mbse.eu>
parents:
799
diff
changeset
|
73 | snprintf(buf, 64, "%.3f", ispindel->yeast_hi); |
29e7223e37ae
Version 0.3.42 added yeast_lo and yeast_hi fields to the iSpindel records and structures.
Michiel Broek <mbroek@mbse.eu>
parents:
799
diff
changeset
|
74 | msg = xstrcat(msg, buf); |
29e7223e37ae
Version 0.3.42 added yeast_lo and yeast_hi fields to the iSpindel records and structures.
Michiel Broek <mbroek@mbse.eu>
parents:
799
diff
changeset
|
75 | msg = xstrcat(msg, (char *)",\"temperature\":"); |
680
0bb48333d133
Fixed missing co2meters websocket data. Added websockets and removed polling for the mon-ispindel screen. The iSpindel SG gauge adjusts the resolution to the highest detected OG.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
76 | snprintf(buf, 64, "%.4f", ispindel->temperature); |
0bb48333d133
Fixed missing co2meters websocket data. Added websockets and removed polling for the mon-ispindel screen. The iSpindel SG gauge adjusts the resolution to the highest detected OG.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
77 | msg = xstrcat(msg, buf); |
0bb48333d133
Fixed missing co2meters websocket data. Added websockets and removed polling for the mon-ispindel screen. The iSpindel SG gauge adjusts the resolution to the highest detected OG.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
78 | msg = xstrcat(msg, (char *)",\"angle\":"); |
0bb48333d133
Fixed missing co2meters websocket data. Added websockets and removed polling for the mon-ispindel screen. The iSpindel SG gauge adjusts the resolution to the highest detected OG.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
79 | snprintf(buf, 64, "%.6f", ispindel->angle); |
0bb48333d133
Fixed missing co2meters websocket data. Added websockets and removed polling for the mon-ispindel screen. The iSpindel SG gauge adjusts the resolution to the highest detected OG.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
80 | msg = xstrcat(msg, buf); |
0bb48333d133
Fixed missing co2meters websocket data. Added websockets and removed polling for the mon-ispindel screen. The iSpindel SG gauge adjusts the resolution to the highest detected OG.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
81 | msg = xstrcat(msg, (char *)",\"battery\":"); |
0bb48333d133
Fixed missing co2meters websocket data. Added websockets and removed polling for the mon-ispindel screen. The iSpindel SG gauge adjusts the resolution to the highest detected OG.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
82 | snprintf(buf, 64, "%.6f", ispindel->battery); |
0bb48333d133
Fixed missing co2meters websocket data. Added websockets and removed polling for the mon-ispindel screen. The iSpindel SG gauge adjusts the resolution to the highest detected OG.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
83 | msg = xstrcat(msg, buf); |
0bb48333d133
Fixed missing co2meters websocket data. Added websockets and removed polling for the mon-ispindel screen. The iSpindel SG gauge adjusts the resolution to the highest detected OG.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
84 | msg = xstrcat(msg, (char *)",\"gravity\":"); |
0bb48333d133
Fixed missing co2meters websocket data. Added websockets and removed polling for the mon-ispindel screen. The iSpindel SG gauge adjusts the resolution to the highest detected OG.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
85 | snprintf(buf, 64, "%.6f", ispindel->gravity); |
0bb48333d133
Fixed missing co2meters websocket data. Added websockets and removed polling for the mon-ispindel screen. The iSpindel SG gauge adjusts the resolution to the highest detected OG.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
86 | msg = xstrcat(msg, buf); |
0bb48333d133
Fixed missing co2meters websocket data. Added websockets and removed polling for the mon-ispindel screen. The iSpindel SG gauge adjusts the resolution to the highest detected OG.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
87 | msg = xstrcat(msg, (char *)",\"og_gravity\":"); |
0bb48333d133
Fixed missing co2meters websocket data. Added websockets and removed polling for the mon-ispindel screen. The iSpindel SG gauge adjusts the resolution to the highest detected OG.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
88 | snprintf(buf, 64, "%.6f", ispindel->og_gravity); |
0bb48333d133
Fixed missing co2meters websocket data. Added websockets and removed polling for the mon-ispindel screen. The iSpindel SG gauge adjusts the resolution to the highest detected OG.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
89 | msg = xstrcat(msg, buf); |
0bb48333d133
Fixed missing co2meters websocket data. Added websockets and removed polling for the mon-ispindel screen. The iSpindel SG gauge adjusts the resolution to the highest detected OG.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
90 | msg = xstrcat(msg, (char *)",\"alarm\":"); |
0bb48333d133
Fixed missing co2meters websocket data. Added websockets and removed polling for the mon-ispindel screen. The iSpindel SG gauge adjusts the resolution to the highest detected OG.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
91 | snprintf(buf, 64, "%d", ispindel->alarm); |
0bb48333d133
Fixed missing co2meters websocket data. Added websockets and removed polling for the mon-ispindel screen. The iSpindel SG gauge adjusts the resolution to the highest detected OG.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
92 | msg = xstrcat(msg, buf); |
850
26cc7ea0f790
Send lastseen iSpindel over websocket. Disabled a debug logmessage again.
Michiel Broek <mbroek@mbse.eu>
parents:
849
diff
changeset
|
93 | msg = xstrcat(msg, (char *)",\"lastseen\":"); |
26cc7ea0f790
Send lastseen iSpindel over websocket. Disabled a debug logmessage again.
Michiel Broek <mbroek@mbse.eu>
parents:
849
diff
changeset
|
94 | snprintf(buf, 64, "%ld", ispindel->lastseen); |
26cc7ea0f790
Send lastseen iSpindel over websocket. Disabled a debug logmessage again.
Michiel Broek <mbroek@mbse.eu>
parents:
849
diff
changeset
|
95 | msg = xstrcat(msg, buf); |
680
0bb48333d133
Fixed missing co2meters websocket data. Added websockets and removed polling for the mon-ispindel screen. The iSpindel SG gauge adjusts the resolution to the highest detected OG.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
96 | msg = xstrcat(msg, (char *)"}"); |
0bb48333d133
Fixed missing co2meters websocket data. Added websockets and removed polling for the mon-ispindel screen. The iSpindel SG gauge adjusts the resolution to the highest detected OG.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
97 | ws_broadcast(msg); |
0bb48333d133
Fixed missing co2meters websocket data. Added websockets and removed polling for the mon-ispindel screen. The iSpindel SG gauge adjusts the resolution to the highest detected OG.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
98 | free(msg); |
0bb48333d133
Fixed missing co2meters websocket data. Added websockets and removed polling for the mon-ispindel screen. The iSpindel SG gauge adjusts the resolution to the highest detected OG.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
99 | msg = NULL; |
0bb48333d133
Fixed missing co2meters websocket data. Added websockets and removed polling for the mon-ispindel screen. The iSpindel SG gauge adjusts the resolution to the highest detected OG.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
100 | } |
0bb48333d133
Fixed missing co2meters websocket data. Added websockets and removed polling for the mon-ispindel screen. The iSpindel SG gauge adjusts the resolution to the highest detected OG.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
101 | |
0bb48333d133
Fixed missing co2meters websocket data. Added websockets and removed polling for the mon-ispindel screen. The iSpindel SG gauge adjusts the resolution to the highest detected OG.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
102 | |
0bb48333d133
Fixed missing co2meters websocket data. Added websockets and removed polling for the mon-ispindel screen. The iSpindel SG gauge adjusts the resolution to the highest detected OG.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
103 | |
0bb48333d133
Fixed missing co2meters websocket data. Added websockets and removed polling for the mon-ispindel screen. The iSpindel SG gauge adjusts the resolution to the highest detected OG.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
104 | void ispindel_ws_receive(char *payload) |
0bb48333d133
Fixed missing co2meters websocket data. Added websockets and removed polling for the mon-ispindel screen. The iSpindel SG gauge adjusts the resolution to the highest detected OG.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
105 | { |
0bb48333d133
Fixed missing co2meters websocket data. Added websockets and removed polling for the mon-ispindel screen. The iSpindel SG gauge adjusts the resolution to the highest detected OG.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
106 | struct json_object *jobj, *val; |
0bb48333d133
Fixed missing co2meters websocket data. Added websockets and removed polling for the mon-ispindel screen. The iSpindel SG gauge adjusts the resolution to the highest detected OG.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
107 | sys_ispindel_list *tmpp; |
0bb48333d133
Fixed missing co2meters websocket data. Added websockets and removed polling for the mon-ispindel screen. The iSpindel SG gauge adjusts the resolution to the highest detected OG.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
108 | char *node = NULL, *alias = NULL, *mode = NULL, *beeruuid = NULL, *beercode = NULL, *beername = NULL; |
843
29e7223e37ae
Version 0.3.42 added yeast_lo and yeast_hi fields to the iSpindel records and structures.
Michiel Broek <mbroek@mbse.eu>
parents:
799
diff
changeset
|
109 | float yeast_lo = 20, yeast_hi = 25; |
29e7223e37ae
Version 0.3.42 added yeast_lo and yeast_hi fields to the iSpindel records and structures.
Michiel Broek <mbroek@mbse.eu>
parents:
799
diff
changeset
|
110 | char query[512], buf[65], *end; |
680
0bb48333d133
Fixed missing co2meters websocket data. Added websockets and removed polling for the mon-ispindel screen. The iSpindel SG gauge adjusts the resolution to the highest detected OG.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
111 | MYSQL *con2 = NULL; |
0bb48333d133
Fixed missing co2meters websocket data. Added websockets and removed polling for the mon-ispindel screen. The iSpindel SG gauge adjusts the resolution to the highest detected OG.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
112 | |
0bb48333d133
Fixed missing co2meters websocket data. Added websockets and removed polling for the mon-ispindel screen. The iSpindel SG gauge adjusts the resolution to the highest detected OG.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
113 | /* |
0bb48333d133
Fixed missing co2meters websocket data. Added websockets and removed polling for the mon-ispindel screen. The iSpindel SG gauge adjusts the resolution to the highest detected OG.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
114 | * Process the JSON formatted payload. |
0bb48333d133
Fixed missing co2meters websocket data. Added websockets and removed polling for the mon-ispindel screen. The iSpindel SG gauge adjusts the resolution to the highest detected OG.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
115 | */ |
0bb48333d133
Fixed missing co2meters websocket data. Added websockets and removed polling for the mon-ispindel screen. The iSpindel SG gauge adjusts the resolution to the highest detected OG.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
116 | jobj = json_tokener_parse(payload); |
0bb48333d133
Fixed missing co2meters websocket data. Added websockets and removed polling for the mon-ispindel screen. The iSpindel SG gauge adjusts the resolution to the highest detected OG.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
117 | if (json_object_object_get_ex(jobj, "node", &val)) |
0bb48333d133
Fixed missing co2meters websocket data. Added websockets and removed polling for the mon-ispindel screen. The iSpindel SG gauge adjusts the resolution to the highest detected OG.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
118 | node = xstrcpy((char *)json_object_get_string(val)); |
0bb48333d133
Fixed missing co2meters websocket data. Added websockets and removed polling for the mon-ispindel screen. The iSpindel SG gauge adjusts the resolution to the highest detected OG.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
119 | if (json_object_object_get_ex(jobj, "unit", &val)) |
0bb48333d133
Fixed missing co2meters websocket data. Added websockets and removed polling for the mon-ispindel screen. The iSpindel SG gauge adjusts the resolution to the highest detected OG.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
120 | alias = xstrcpy((char *)json_object_get_string(val)); |
0bb48333d133
Fixed missing co2meters websocket data. Added websockets and removed polling for the mon-ispindel screen. The iSpindel SG gauge adjusts the resolution to the highest detected OG.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
121 | if (json_object_object_get_ex(jobj, "beeruuid", &val)) |
0bb48333d133
Fixed missing co2meters websocket data. Added websockets and removed polling for the mon-ispindel screen. The iSpindel SG gauge adjusts the resolution to the highest detected OG.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
122 | beeruuid = xstrcpy((char *)json_object_get_string(val)); |
0bb48333d133
Fixed missing co2meters websocket data. Added websockets and removed polling for the mon-ispindel screen. The iSpindel SG gauge adjusts the resolution to the highest detected OG.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
123 | if (json_object_object_get_ex(jobj, "beercode", &val)) |
0bb48333d133
Fixed missing co2meters websocket data. Added websockets and removed polling for the mon-ispindel screen. The iSpindel SG gauge adjusts the resolution to the highest detected OG.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
124 | beercode = xstrcpy((char *)json_object_get_string(val)); |
0bb48333d133
Fixed missing co2meters websocket data. Added websockets and removed polling for the mon-ispindel screen. The iSpindel SG gauge adjusts the resolution to the highest detected OG.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
125 | if (json_object_object_get_ex(jobj, "beername", &val)) |
0bb48333d133
Fixed missing co2meters websocket data. Added websockets and removed polling for the mon-ispindel screen. The iSpindel SG gauge adjusts the resolution to the highest detected OG.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
126 | beername = xstrcpy((char *)json_object_get_string(val)); |
843
29e7223e37ae
Version 0.3.42 added yeast_lo and yeast_hi fields to the iSpindel records and structures.
Michiel Broek <mbroek@mbse.eu>
parents:
799
diff
changeset
|
127 | if (json_object_object_get_ex(jobj, "yeast_lo", &val)) |
29e7223e37ae
Version 0.3.42 added yeast_lo and yeast_hi fields to the iSpindel records and structures.
Michiel Broek <mbroek@mbse.eu>
parents:
799
diff
changeset
|
128 | yeast_lo = json_object_get_double(val); |
29e7223e37ae
Version 0.3.42 added yeast_lo and yeast_hi fields to the iSpindel records and structures.
Michiel Broek <mbroek@mbse.eu>
parents:
799
diff
changeset
|
129 | if (json_object_object_get_ex(jobj, "yeast_hi", &val)) |
29e7223e37ae
Version 0.3.42 added yeast_lo and yeast_hi fields to the iSpindel records and structures.
Michiel Broek <mbroek@mbse.eu>
parents:
799
diff
changeset
|
130 | yeast_hi = json_object_get_double(val); |
680
0bb48333d133
Fixed missing co2meters websocket data. Added websockets and removed polling for the mon-ispindel screen. The iSpindel SG gauge adjusts the resolution to the highest detected OG.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
131 | if (json_object_object_get_ex(jobj, "mode", &val)) |
0bb48333d133
Fixed missing co2meters websocket data. Added websockets and removed polling for the mon-ispindel screen. The iSpindel SG gauge adjusts the resolution to the highest detected OG.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
132 | mode = xstrcpy((char *)json_object_get_string(val)); |
0bb48333d133
Fixed missing co2meters websocket data. Added websockets and removed polling for the mon-ispindel screen. The iSpindel SG gauge adjusts the resolution to the highest detected OG.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
133 | json_object_put(jobj); |
0bb48333d133
Fixed missing co2meters websocket data. Added websockets and removed polling for the mon-ispindel screen. The iSpindel SG gauge adjusts the resolution to the highest detected OG.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
134 | |
0bb48333d133
Fixed missing co2meters websocket data. Added websockets and removed polling for the mon-ispindel screen. The iSpindel SG gauge adjusts the resolution to the highest detected OG.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
135 | /* |
0bb48333d133
Fixed missing co2meters websocket data. Added websockets and removed polling for the mon-ispindel screen. The iSpindel SG gauge adjusts the resolution to the highest detected OG.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
136 | * Search ispindel record in the memory array and use it if found. |
0bb48333d133
Fixed missing co2meters websocket data. Added websockets and removed polling for the mon-ispindel screen. The iSpindel SG gauge adjusts the resolution to the highest detected OG.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
137 | */ |
0bb48333d133
Fixed missing co2meters websocket data. Added websockets and removed polling for the mon-ispindel screen. The iSpindel SG gauge adjusts the resolution to the highest detected OG.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
138 | if (ispindels) { |
0bb48333d133
Fixed missing co2meters websocket data. Added websockets and removed polling for the mon-ispindel screen. The iSpindel SG gauge adjusts the resolution to the highest detected OG.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
139 | for (tmpp = ispindels; tmpp; tmpp = tmpp->next) { |
0bb48333d133
Fixed missing co2meters websocket data. Added websockets and removed polling for the mon-ispindel screen. The iSpindel SG gauge adjusts the resolution to the highest detected OG.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
140 | if (strcmp(tmpp->node, node) == 0) { |
0bb48333d133
Fixed missing co2meters websocket data. Added websockets and removed polling for the mon-ispindel screen. The iSpindel SG gauge adjusts the resolution to the highest detected OG.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
141 | con2 = mysql_init(NULL); |
0bb48333d133
Fixed missing co2meters websocket data. Added websockets and removed polling for the mon-ispindel screen. The iSpindel SG gauge adjusts the resolution to the highest detected OG.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
142 | if (con2 == NULL) { |
0bb48333d133
Fixed missing co2meters websocket data. Added websockets and removed polling for the mon-ispindel screen. The iSpindel SG gauge adjusts the resolution to the highest detected OG.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
143 | syslog(LOG_NOTICE, "MySQL: mysql_init() failed"); |
0bb48333d133
Fixed missing co2meters websocket data. Added websockets and removed polling for the mon-ispindel screen. The iSpindel SG gauge adjusts the resolution to the highest detected OG.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
144 | } else { |
0bb48333d133
Fixed missing co2meters websocket data. Added websockets and removed polling for the mon-ispindel screen. The iSpindel SG gauge adjusts the resolution to the highest detected OG.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
145 | if (mysql_real_connect(con2, Config.mysql_host, Config.mysql_user, Config.mysql_pass, Config.mysql_database, Config.mysql_port, NULL, 0) == NULL) { |
0bb48333d133
Fixed missing co2meters websocket data. Added websockets and removed polling for the mon-ispindel screen. The iSpindel SG gauge adjusts the resolution to the highest detected OG.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
146 | syslog(LOG_NOTICE, "MySQL: mysql_real_connect() %s", mysql_error(con2)); |
0bb48333d133
Fixed missing co2meters websocket data. Added websockets and removed polling for the mon-ispindel screen. The iSpindel SG gauge adjusts the resolution to the highest detected OG.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
147 | } else { |
0bb48333d133
Fixed missing co2meters websocket data. Added websockets and removed polling for the mon-ispindel screen. The iSpindel SG gauge adjusts the resolution to the highest detected OG.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
148 | if (beeruuid && beercode && beername) { |
0bb48333d133
Fixed missing co2meters websocket data. Added websockets and removed polling for the mon-ispindel screen. The iSpindel SG gauge adjusts the resolution to the highest detected OG.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
149 | end = stpcpy(query, "UPDATE mon_ispindels SET beeruuid='"); |
0bb48333d133
Fixed missing co2meters websocket data. Added websockets and removed polling for the mon-ispindel screen. The iSpindel SG gauge adjusts the resolution to the highest detected OG.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
150 | end += mysql_real_escape_string(con2, end, beeruuid, strlen(beeruuid)); |
0bb48333d133
Fixed missing co2meters websocket data. Added websockets and removed polling for the mon-ispindel screen. The iSpindel SG gauge adjusts the resolution to the highest detected OG.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
151 | end = stpcpy(end, "', beercode='"); |
0bb48333d133
Fixed missing co2meters websocket data. Added websockets and removed polling for the mon-ispindel screen. The iSpindel SG gauge adjusts the resolution to the highest detected OG.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
152 | end += mysql_real_escape_string(con2, end, beercode, strlen(beercode)); |
0bb48333d133
Fixed missing co2meters websocket data. Added websockets and removed polling for the mon-ispindel screen. The iSpindel SG gauge adjusts the resolution to the highest detected OG.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
153 | end = stpcpy(end, "', beername='"); |
0bb48333d133
Fixed missing co2meters websocket data. Added websockets and removed polling for the mon-ispindel screen. The iSpindel SG gauge adjusts the resolution to the highest detected OG.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
154 | end += mysql_real_escape_string(con2, end, beername, strlen(beername)); |
843
29e7223e37ae
Version 0.3.42 added yeast_lo and yeast_hi fields to the iSpindel records and structures.
Michiel Broek <mbroek@mbse.eu>
parents:
799
diff
changeset
|
155 | end = stpcpy(end, "', og_gravity='0.0', yeast_lo='"); |
29e7223e37ae
Version 0.3.42 added yeast_lo and yeast_hi fields to the iSpindel records and structures.
Michiel Broek <mbroek@mbse.eu>
parents:
799
diff
changeset
|
156 | snprintf(buf, 64, "%.3f", yeast_lo); |
29e7223e37ae
Version 0.3.42 added yeast_lo and yeast_hi fields to the iSpindel records and structures.
Michiel Broek <mbroek@mbse.eu>
parents:
799
diff
changeset
|
157 | end = stpcpy(end, buf); |
29e7223e37ae
Version 0.3.42 added yeast_lo and yeast_hi fields to the iSpindel records and structures.
Michiel Broek <mbroek@mbse.eu>
parents:
799
diff
changeset
|
158 | end = stpcpy(end, "', yeast_hi='"); |
29e7223e37ae
Version 0.3.42 added yeast_lo and yeast_hi fields to the iSpindel records and structures.
Michiel Broek <mbroek@mbse.eu>
parents:
799
diff
changeset
|
159 | snprintf(buf, 64, "%.3f", yeast_hi); |
29e7223e37ae
Version 0.3.42 added yeast_lo and yeast_hi fields to the iSpindel records and structures.
Michiel Broek <mbroek@mbse.eu>
parents:
799
diff
changeset
|
160 | end = stpcpy(end, buf); |
29e7223e37ae
Version 0.3.42 added yeast_lo and yeast_hi fields to the iSpindel records and structures.
Michiel Broek <mbroek@mbse.eu>
parents:
799
diff
changeset
|
161 | end = stpcpy(end, "' WHERE node='"); |
680
0bb48333d133
Fixed missing co2meters websocket data. Added websockets and removed polling for the mon-ispindel screen. The iSpindel SG gauge adjusts the resolution to the highest detected OG.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
162 | end += mysql_real_escape_string(con2, end, node, strlen(node)); |
0bb48333d133
Fixed missing co2meters websocket data. Added websockets and removed polling for the mon-ispindel screen. The iSpindel SG gauge adjusts the resolution to the highest detected OG.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
163 | end = stpcpy(end, "'"); |
0bb48333d133
Fixed missing co2meters websocket data. Added websockets and removed polling for the mon-ispindel screen. The iSpindel SG gauge adjusts the resolution to the highest detected OG.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
164 | |
0bb48333d133
Fixed missing co2meters websocket data. Added websockets and removed polling for the mon-ispindel screen. The iSpindel SG gauge adjusts the resolution to the highest detected OG.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
165 | if (mysql_real_query(con2, query, (unsigned int) (end - query))) { |
0bb48333d133
Fixed missing co2meters websocket data. Added websockets and removed polling for the mon-ispindel screen. The iSpindel SG gauge adjusts the resolution to the highest detected OG.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
166 | syslog(LOG_NOTICE, "MySQL: `%s' error %u (%s))", query, mysql_errno(con2), mysql_error(con2)); |
0bb48333d133
Fixed missing co2meters websocket data. Added websockets and removed polling for the mon-ispindel screen. The iSpindel SG gauge adjusts the resolution to the highest detected OG.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
167 | } else { |
0bb48333d133
Fixed missing co2meters websocket data. Added websockets and removed polling for the mon-ispindel screen. The iSpindel SG gauge adjusts the resolution to the highest detected OG.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
168 | /* Database updated, now update internal memory */ |
0bb48333d133
Fixed missing co2meters websocket data. Added websockets and removed polling for the mon-ispindel screen. The iSpindel SG gauge adjusts the resolution to the highest detected OG.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
169 | if (tmpp->beercode) |
0bb48333d133
Fixed missing co2meters websocket data. Added websockets and removed polling for the mon-ispindel screen. The iSpindel SG gauge adjusts the resolution to the highest detected OG.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
170 | free(tmpp->beercode); |
0bb48333d133
Fixed missing co2meters websocket data. Added websockets and removed polling for the mon-ispindel screen. The iSpindel SG gauge adjusts the resolution to the highest detected OG.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
171 | tmpp->beercode = xstrcpy(beercode); |
0bb48333d133
Fixed missing co2meters websocket data. Added websockets and removed polling for the mon-ispindel screen. The iSpindel SG gauge adjusts the resolution to the highest detected OG.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
172 | if (tmpp->beername) |
0bb48333d133
Fixed missing co2meters websocket data. Added websockets and removed polling for the mon-ispindel screen. The iSpindel SG gauge adjusts the resolution to the highest detected OG.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
173 | free(tmpp->beername); |
0bb48333d133
Fixed missing co2meters websocket data. Added websockets and removed polling for the mon-ispindel screen. The iSpindel SG gauge adjusts the resolution to the highest detected OG.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
174 | tmpp->beername = xstrcpy(beername); |
0bb48333d133
Fixed missing co2meters websocket data. Added websockets and removed polling for the mon-ispindel screen. The iSpindel SG gauge adjusts the resolution to the highest detected OG.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
175 | if (tmpp->beeruuid) |
0bb48333d133
Fixed missing co2meters websocket data. Added websockets and removed polling for the mon-ispindel screen. The iSpindel SG gauge adjusts the resolution to the highest detected OG.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
176 | free(tmpp->beeruuid); |
0bb48333d133
Fixed missing co2meters websocket data. Added websockets and removed polling for the mon-ispindel screen. The iSpindel SG gauge adjusts the resolution to the highest detected OG.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
177 | tmpp->beeruuid = xstrcpy(beeruuid); |
0bb48333d133
Fixed missing co2meters websocket data. Added websockets and removed polling for the mon-ispindel screen. The iSpindel SG gauge adjusts the resolution to the highest detected OG.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
178 | tmpp->og_gravity = 0.0; |
843
29e7223e37ae
Version 0.3.42 added yeast_lo and yeast_hi fields to the iSpindel records and structures.
Michiel Broek <mbroek@mbse.eu>
parents:
799
diff
changeset
|
179 | tmpp->yeast_lo = yeast_lo; |
29e7223e37ae
Version 0.3.42 added yeast_lo and yeast_hi fields to the iSpindel records and structures.
Michiel Broek <mbroek@mbse.eu>
parents:
799
diff
changeset
|
180 | tmpp->yeast_hi = yeast_hi; |
680
0bb48333d133
Fixed missing co2meters websocket data. Added websockets and removed polling for the mon-ispindel screen. The iSpindel SG gauge adjusts the resolution to the highest detected OG.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
181 | /* Report new state to the client */ |
0bb48333d133
Fixed missing co2meters websocket data. Added websockets and removed polling for the mon-ispindel screen. The iSpindel SG gauge adjusts the resolution to the highest detected OG.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
182 | ispindel_ws_send(tmpp); |
0bb48333d133
Fixed missing co2meters websocket data. Added websockets and removed polling for the mon-ispindel screen. The iSpindel SG gauge adjusts the resolution to the highest detected OG.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
183 | syslog(LOG_NOTICE, "Set ispindel %s/%s new beer %s %s", node, alias, beercode, beername); |
0bb48333d133
Fixed missing co2meters websocket data. Added websockets and removed polling for the mon-ispindel screen. The iSpindel SG gauge adjusts the resolution to the highest detected OG.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
184 | } |
0bb48333d133
Fixed missing co2meters websocket data. Added websockets and removed polling for the mon-ispindel screen. The iSpindel SG gauge adjusts the resolution to the highest detected OG.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
185 | } |
0bb48333d133
Fixed missing co2meters websocket data. Added websockets and removed polling for the mon-ispindel screen. The iSpindel SG gauge adjusts the resolution to the highest detected OG.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
186 | if (mode) { |
0bb48333d133
Fixed missing co2meters websocket data. Added websockets and removed polling for the mon-ispindel screen. The iSpindel SG gauge adjusts the resolution to the highest detected OG.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
187 | end = stpcpy(query, "UPDATE mon_ispindels SET mode='"); |
0bb48333d133
Fixed missing co2meters websocket data. Added websockets and removed polling for the mon-ispindel screen. The iSpindel SG gauge adjusts the resolution to the highest detected OG.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
188 | end += mysql_real_escape_string(con2, end, mode, strlen(mode)); |
0bb48333d133
Fixed missing co2meters websocket data. Added websockets and removed polling for the mon-ispindel screen. The iSpindel SG gauge adjusts the resolution to the highest detected OG.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
189 | end = stpcpy(end, "' WHERE node='"); |
0bb48333d133
Fixed missing co2meters websocket data. Added websockets and removed polling for the mon-ispindel screen. The iSpindel SG gauge adjusts the resolution to the highest detected OG.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
190 | end += mysql_real_escape_string(con2, end, node, strlen(node)); |
0bb48333d133
Fixed missing co2meters websocket data. Added websockets and removed polling for the mon-ispindel screen. The iSpindel SG gauge adjusts the resolution to the highest detected OG.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
191 | end = stpcpy(end, "'"); |
0bb48333d133
Fixed missing co2meters websocket data. Added websockets and removed polling for the mon-ispindel screen. The iSpindel SG gauge adjusts the resolution to the highest detected OG.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
192 | |
0bb48333d133
Fixed missing co2meters websocket data. Added websockets and removed polling for the mon-ispindel screen. The iSpindel SG gauge adjusts the resolution to the highest detected OG.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
193 | if (mysql_real_query(con2, query, (unsigned int) (end - query))) { |
0bb48333d133
Fixed missing co2meters websocket data. Added websockets and removed polling for the mon-ispindel screen. The iSpindel SG gauge adjusts the resolution to the highest detected OG.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
194 | syslog(LOG_NOTICE, "MySQL: `%s' error %u (%s))", query, mysql_errno(con2), mysql_error(con2)); |
0bb48333d133
Fixed missing co2meters websocket data. Added websockets and removed polling for the mon-ispindel screen. The iSpindel SG gauge adjusts the resolution to the highest detected OG.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
195 | } else { |
0bb48333d133
Fixed missing co2meters websocket data. Added websockets and removed polling for the mon-ispindel screen. The iSpindel SG gauge adjusts the resolution to the highest detected OG.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
196 | /* Database updated, now update internal memory */ |
0bb48333d133
Fixed missing co2meters websocket data. Added websockets and removed polling for the mon-ispindel screen. The iSpindel SG gauge adjusts the resolution to the highest detected OG.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
197 | if (tmpp->mode) |
0bb48333d133
Fixed missing co2meters websocket data. Added websockets and removed polling for the mon-ispindel screen. The iSpindel SG gauge adjusts the resolution to the highest detected OG.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
198 | free(tmpp->mode); |
0bb48333d133
Fixed missing co2meters websocket data. Added websockets and removed polling for the mon-ispindel screen. The iSpindel SG gauge adjusts the resolution to the highest detected OG.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
199 | tmpp->mode = xstrcpy(mode); |
0bb48333d133
Fixed missing co2meters websocket data. Added websockets and removed polling for the mon-ispindel screen. The iSpindel SG gauge adjusts the resolution to the highest detected OG.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
200 | /* Report new state to the client */ |
0bb48333d133
Fixed missing co2meters websocket data. Added websockets and removed polling for the mon-ispindel screen. The iSpindel SG gauge adjusts the resolution to the highest detected OG.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
201 | ispindel_ws_send(tmpp); |
0bb48333d133
Fixed missing co2meters websocket data. Added websockets and removed polling for the mon-ispindel screen. The iSpindel SG gauge adjusts the resolution to the highest detected OG.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
202 | syslog(LOG_NOTICE, "Set ispindel %s/%s new mode %s", node, alias, mode); |
0bb48333d133
Fixed missing co2meters websocket data. Added websockets and removed polling for the mon-ispindel screen. The iSpindel SG gauge adjusts the resolution to the highest detected OG.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
203 | } |
0bb48333d133
Fixed missing co2meters websocket data. Added websockets and removed polling for the mon-ispindel screen. The iSpindel SG gauge adjusts the resolution to the highest detected OG.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
204 | } |
0bb48333d133
Fixed missing co2meters websocket data. Added websockets and removed polling for the mon-ispindel screen. The iSpindel SG gauge adjusts the resolution to the highest detected OG.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
205 | mysql_close(con2); |
0bb48333d133
Fixed missing co2meters websocket data. Added websockets and removed polling for the mon-ispindel screen. The iSpindel SG gauge adjusts the resolution to the highest detected OG.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
206 | } |
0bb48333d133
Fixed missing co2meters websocket data. Added websockets and removed polling for the mon-ispindel screen. The iSpindel SG gauge adjusts the resolution to the highest detected OG.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
207 | } |
0bb48333d133
Fixed missing co2meters websocket data. Added websockets and removed polling for the mon-ispindel screen. The iSpindel SG gauge adjusts the resolution to the highest detected OG.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
208 | break; |
0bb48333d133
Fixed missing co2meters websocket data. Added websockets and removed polling for the mon-ispindel screen. The iSpindel SG gauge adjusts the resolution to the highest detected OG.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
209 | } |
0bb48333d133
Fixed missing co2meters websocket data. Added websockets and removed polling for the mon-ispindel screen. The iSpindel SG gauge adjusts the resolution to the highest detected OG.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
210 | } |
0bb48333d133
Fixed missing co2meters websocket data. Added websockets and removed polling for the mon-ispindel screen. The iSpindel SG gauge adjusts the resolution to the highest detected OG.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
211 | } |
0bb48333d133
Fixed missing co2meters websocket data. Added websockets and removed polling for the mon-ispindel screen. The iSpindel SG gauge adjusts the resolution to the highest detected OG.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
212 | |
0bb48333d133
Fixed missing co2meters websocket data. Added websockets and removed polling for the mon-ispindel screen. The iSpindel SG gauge adjusts the resolution to the highest detected OG.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
213 | if (node) |
0bb48333d133
Fixed missing co2meters websocket data. Added websockets and removed polling for the mon-ispindel screen. The iSpindel SG gauge adjusts the resolution to the highest detected OG.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
214 | free(node); |
0bb48333d133
Fixed missing co2meters websocket data. Added websockets and removed polling for the mon-ispindel screen. The iSpindel SG gauge adjusts the resolution to the highest detected OG.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
215 | if (alias) |
0bb48333d133
Fixed missing co2meters websocket data. Added websockets and removed polling for the mon-ispindel screen. The iSpindel SG gauge adjusts the resolution to the highest detected OG.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
216 | free(alias); |
0bb48333d133
Fixed missing co2meters websocket data. Added websockets and removed polling for the mon-ispindel screen. The iSpindel SG gauge adjusts the resolution to the highest detected OG.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
217 | if (mode) |
0bb48333d133
Fixed missing co2meters websocket data. Added websockets and removed polling for the mon-ispindel screen. The iSpindel SG gauge adjusts the resolution to the highest detected OG.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
218 | free(mode); |
0bb48333d133
Fixed missing co2meters websocket data. Added websockets and removed polling for the mon-ispindel screen. The iSpindel SG gauge adjusts the resolution to the highest detected OG.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
219 | if (beeruuid) |
0bb48333d133
Fixed missing co2meters websocket data. Added websockets and removed polling for the mon-ispindel screen. The iSpindel SG gauge adjusts the resolution to the highest detected OG.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
220 | free(beeruuid); |
0bb48333d133
Fixed missing co2meters websocket data. Added websockets and removed polling for the mon-ispindel screen. The iSpindel SG gauge adjusts the resolution to the highest detected OG.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
221 | if (beercode) |
0bb48333d133
Fixed missing co2meters websocket data. Added websockets and removed polling for the mon-ispindel screen. The iSpindel SG gauge adjusts the resolution to the highest detected OG.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
222 | free(beercode); |
0bb48333d133
Fixed missing co2meters websocket data. Added websockets and removed polling for the mon-ispindel screen. The iSpindel SG gauge adjusts the resolution to the highest detected OG.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
223 | if (beername) |
0bb48333d133
Fixed missing co2meters websocket data. Added websockets and removed polling for the mon-ispindel screen. The iSpindel SG gauge adjusts the resolution to the highest detected OG.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
224 | free(beername); |
0bb48333d133
Fixed missing co2meters websocket data. Added websockets and removed polling for the mon-ispindel screen. The iSpindel SG gauge adjusts the resolution to the highest detected OG.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
225 | } |
0bb48333d133
Fixed missing co2meters websocket data. Added websockets and removed polling for the mon-ispindel screen. The iSpindel SG gauge adjusts the resolution to the highest detected OG.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
226 | |
0bb48333d133
Fixed missing co2meters websocket data. Added websockets and removed polling for the mon-ispindel screen. The iSpindel SG gauge adjusts the resolution to the highest detected OG.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
227 | |
567
6bf0afc33e70
Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
228 | |
578
e75ce5bbda73
Changed the interface from the iSpindels to be the same as other devices. A webpage converts each call to two standard MQTT messages. The nodes MQTT message extended with an interval parameter. iSpindels now have a generated uuid made up from the chipid.
Michiel Broek <mbroek@mbse.eu>
parents:
572
diff
changeset
|
229 | void ispindel_set(char *node, char *payload) |
567
6bf0afc33e70
Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
230 | { |
6bf0afc33e70
Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
231 | sys_ispindel_list *ispindel, *tmpp; |
578
e75ce5bbda73
Changed the interface from the iSpindels to be the same as other devices. A webpage converts each call to two standard MQTT messages. The nodes MQTT message extended with an interval parameter. iSpindels now have a generated uuid made up from the chipid.
Michiel Broek <mbroek@mbse.eu>
parents:
572
diff
changeset
|
232 | struct json_object *jobj, *metric, *val; |
686
ca1fbb3bd3db
Removed ws_global function because dynamic menus don't work.
Michiel Broek <mbroek@mbse.eu>
parents:
684
diff
changeset
|
233 | bool new_ispindel = true; |
852
71f0fa38b634
Version 0.3.45. Removed all writing to ascii logfiles in the webserver environment, only log to MySQL.
Michiel Broek <mbroek@mbse.eu>
parents:
850
diff
changeset
|
234 | char *datetime, *query = malloc(512); |
568
6f3c24e21deb
Added ispindel logging. Updated the documentation.
Michiel Broek <mbroek@mbse.eu>
parents:
567
diff
changeset
|
235 | struct tm *mytime; |
6f3c24e21deb
Added ispindel logging. Updated the documentation.
Michiel Broek <mbroek@mbse.eu>
parents:
567
diff
changeset
|
236 | time_t timestamp; |
567
6bf0afc33e70
Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
237 | |
850
26cc7ea0f790
Send lastseen iSpindel over websocket. Disabled a debug logmessage again.
Michiel Broek <mbroek@mbse.eu>
parents:
849
diff
changeset
|
238 | //syslog(LOG_NOTICE, "ispindel_set: %s %s", node, payload); |
567
6bf0afc33e70
Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
239 | |
6bf0afc33e70
Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
240 | /* |
6bf0afc33e70
Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
241 | * Search ispindel record in the memory array and use it if found. |
6bf0afc33e70
Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
242 | */ |
6bf0afc33e70
Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
243 | if (ispindels) { |
6bf0afc33e70
Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
244 | for (tmpp = ispindels; tmpp; tmpp = tmpp->next) { |
6bf0afc33e70
Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
245 | if (strcmp(tmpp->node, node) == 0) { |
6bf0afc33e70
Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
246 | new_ispindel = false; |
6bf0afc33e70
Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
247 | ispindel = tmpp; |
6bf0afc33e70
Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
248 | break; |
6bf0afc33e70
Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
249 | } |
6bf0afc33e70
Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
250 | } |
6bf0afc33e70
Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
251 | } |
6bf0afc33e70
Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
252 | |
579
1253a237b620
Added check for database changes for iSpindels such as a new beer, or changing mode. Added denity in Plato and SG to the iSpindel web screen. The iSpindels must be calibrated in Plato! A bit of documentation updated.
Michiel Broek <mbroek@mbse.eu>
parents:
578
diff
changeset
|
253 | // if (debug) |
1253a237b620
Added check for database changes for iSpindels such as a new beer, or changing mode. Added denity in Plato and SG to the iSpindel web screen. The iSpindels must be calibrated in Plato! A bit of documentation updated.
Michiel Broek <mbroek@mbse.eu>
parents:
578
diff
changeset
|
254 | // printf("new_ispindel %s\n", new_ispindel ? "true":"false"); |
567
6bf0afc33e70
Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
255 | |
6bf0afc33e70
Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
256 | /* |
6bf0afc33e70
Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
257 | * Allocate new ispindel if not yet known. |
6bf0afc33e70
Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
258 | */ |
6bf0afc33e70
Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
259 | if (new_ispindel) { |
6bf0afc33e70
Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
260 | ispindel = (sys_ispindel_list *)malloc(sizeof(sys_ispindel_list)); |
6bf0afc33e70
Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
261 | memset(ispindel, 0, sizeof(sys_ispindel_list)); |
6bf0afc33e70
Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
262 | ispindel->node = xstrcpy(node); |
578
e75ce5bbda73
Changed the interface from the iSpindels to be the same as other devices. A webpage converts each call to two standard MQTT messages. The nodes MQTT message extended with an interval parameter. iSpindels now have a generated uuid made up from the chipid.
Michiel Broek <mbroek@mbse.eu>
parents:
572
diff
changeset
|
263 | ispindel->mode = xstrcpy((char *)"OFF"); |
567
6bf0afc33e70
Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
264 | } |
6bf0afc33e70
Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
265 | |
6bf0afc33e70
Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
266 | if (! ispindel->online) { |
6bf0afc33e70
Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
267 | ispindel->online = true; |
578
e75ce5bbda73
Changed the interface from the iSpindels to be the same as other devices. A webpage converts each call to two standard MQTT messages. The nodes MQTT message extended with an interval parameter. iSpindels now have a generated uuid made up from the chipid.
Michiel Broek <mbroek@mbse.eu>
parents:
572
diff
changeset
|
268 | syslog(LOG_NOTICE, "Online ispindel %s mode %s", node, ispindel->mode); |
567
6bf0afc33e70
Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
269 | } |
6bf0afc33e70
Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
270 | |
6bf0afc33e70
Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
271 | /* |
578
e75ce5bbda73
Changed the interface from the iSpindels to be the same as other devices. A webpage converts each call to two standard MQTT messages. The nodes MQTT message extended with an interval parameter. iSpindels now have a generated uuid made up from the chipid.
Michiel Broek <mbroek@mbse.eu>
parents:
572
diff
changeset
|
272 | * Process the JSON formatted payload. |
e75ce5bbda73
Changed the interface from the iSpindels to be the same as other devices. A webpage converts each call to two standard MQTT messages. The nodes MQTT message extended with an interval parameter. iSpindels now have a generated uuid made up from the chipid.
Michiel Broek <mbroek@mbse.eu>
parents:
572
diff
changeset
|
273 | * Update only the fields that are found in the payload. |
567
6bf0afc33e70
Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
274 | */ |
578
e75ce5bbda73
Changed the interface from the iSpindels to be the same as other devices. A webpage converts each call to two standard MQTT messages. The nodes MQTT message extended with an interval parameter. iSpindels now have a generated uuid made up from the chipid.
Michiel Broek <mbroek@mbse.eu>
parents:
572
diff
changeset
|
275 | jobj = json_tokener_parse(payload); |
e75ce5bbda73
Changed the interface from the iSpindels to be the same as other devices. A webpage converts each call to two standard MQTT messages. The nodes MQTT message extended with an interval parameter. iSpindels now have a generated uuid made up from the chipid.
Michiel Broek <mbroek@mbse.eu>
parents:
572
diff
changeset
|
276 | |
e75ce5bbda73
Changed the interface from the iSpindels to be the same as other devices. A webpage converts each call to two standard MQTT messages. The nodes MQTT message extended with an interval parameter. iSpindels now have a generated uuid made up from the chipid.
Michiel Broek <mbroek@mbse.eu>
parents:
572
diff
changeset
|
277 | if (json_object_object_get_ex(jobj, "unit", &metric)) { |
849
16079aef4c4c
Version 0.3.44. Moved iSpindel Plato calculation from the php script to bmsd. This uses calibration data in the mon_ispindels table. Setup of this data will be done by the bmsapp applications. Default settings are stored in MySQL. From now on you don't need to store calibration data in the iSpindel.
Michiel Broek <mbroek@mbse.eu>
parents:
843
diff
changeset
|
278 | ispindel->lastseen = time(NULL); |
578
e75ce5bbda73
Changed the interface from the iSpindels to be the same as other devices. A webpage converts each call to two standard MQTT messages. The nodes MQTT message extended with an interval parameter. iSpindels now have a generated uuid made up from the chipid.
Michiel Broek <mbroek@mbse.eu>
parents:
572
diff
changeset
|
279 | if (json_object_object_get_ex(metric, "uuid", &val)) { |
e75ce5bbda73
Changed the interface from the iSpindels to be the same as other devices. A webpage converts each call to two standard MQTT messages. The nodes MQTT message extended with an interval parameter. iSpindels now have a generated uuid made up from the chipid.
Michiel Broek <mbroek@mbse.eu>
parents:
572
diff
changeset
|
280 | if (ispindel->uuid) |
e75ce5bbda73
Changed the interface from the iSpindels to be the same as other devices. A webpage converts each call to two standard MQTT messages. The nodes MQTT message extended with an interval parameter. iSpindels now have a generated uuid made up from the chipid.
Michiel Broek <mbroek@mbse.eu>
parents:
572
diff
changeset
|
281 | free(ispindel->uuid); |
e75ce5bbda73
Changed the interface from the iSpindels to be the same as other devices. A webpage converts each call to two standard MQTT messages. The nodes MQTT message extended with an interval parameter. iSpindels now have a generated uuid made up from the chipid.
Michiel Broek <mbroek@mbse.eu>
parents:
572
diff
changeset
|
282 | ispindel->uuid = xstrcpy((char *)json_object_get_string(val)); |
e75ce5bbda73
Changed the interface from the iSpindels to be the same as other devices. A webpage converts each call to two standard MQTT messages. The nodes MQTT message extended with an interval parameter. iSpindels now have a generated uuid made up from the chipid.
Michiel Broek <mbroek@mbse.eu>
parents:
572
diff
changeset
|
283 | } |
e75ce5bbda73
Changed the interface from the iSpindels to be the same as other devices. A webpage converts each call to two standard MQTT messages. The nodes MQTT message extended with an interval parameter. iSpindels now have a generated uuid made up from the chipid.
Michiel Broek <mbroek@mbse.eu>
parents:
572
diff
changeset
|
284 | if (json_object_object_get_ex(metric, "alias", &val)) { |
e75ce5bbda73
Changed the interface from the iSpindels to be the same as other devices. A webpage converts each call to two standard MQTT messages. The nodes MQTT message extended with an interval parameter. iSpindels now have a generated uuid made up from the chipid.
Michiel Broek <mbroek@mbse.eu>
parents:
572
diff
changeset
|
285 | if (ispindel->alias) |
e75ce5bbda73
Changed the interface from the iSpindels to be the same as other devices. A webpage converts each call to two standard MQTT messages. The nodes MQTT message extended with an interval parameter. iSpindels now have a generated uuid made up from the chipid.
Michiel Broek <mbroek@mbse.eu>
parents:
572
diff
changeset
|
286 | free(ispindel->alias); |
e75ce5bbda73
Changed the interface from the iSpindels to be the same as other devices. A webpage converts each call to two standard MQTT messages. The nodes MQTT message extended with an interval parameter. iSpindels now have a generated uuid made up from the chipid.
Michiel Broek <mbroek@mbse.eu>
parents:
572
diff
changeset
|
287 | ispindel->alias = xstrcpy((char *)json_object_get_string(val)); |
e75ce5bbda73
Changed the interface from the iSpindels to be the same as other devices. A webpage converts each call to two standard MQTT messages. The nodes MQTT message extended with an interval parameter. iSpindels now have a generated uuid made up from the chipid.
Michiel Broek <mbroek@mbse.eu>
parents:
572
diff
changeset
|
288 | } |
680
0bb48333d133
Fixed missing co2meters websocket data. Added websockets and removed polling for the mon-ispindel screen. The iSpindel SG gauge adjusts the resolution to the highest detected OG.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
289 | if (json_object_object_get_ex(metric, "alarm", &val)) |
578
e75ce5bbda73
Changed the interface from the iSpindels to be the same as other devices. A webpage converts each call to two standard MQTT messages. The nodes MQTT message extended with an interval parameter. iSpindels now have a generated uuid made up from the chipid.
Michiel Broek <mbroek@mbse.eu>
parents:
572
diff
changeset
|
290 | ispindel->alarm = json_object_get_int(val); |
680
0bb48333d133
Fixed missing co2meters websocket data. Added websockets and removed polling for the mon-ispindel screen. The iSpindel SG gauge adjusts the resolution to the highest detected OG.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
291 | if (json_object_object_get_ex(metric, "interval", &val)) |
578
e75ce5bbda73
Changed the interface from the iSpindels to be the same as other devices. A webpage converts each call to two standard MQTT messages. The nodes MQTT message extended with an interval parameter. iSpindels now have a generated uuid made up from the chipid.
Michiel Broek <mbroek@mbse.eu>
parents:
572
diff
changeset
|
292 | ispindel->interval = json_object_get_int(val); |
680
0bb48333d133
Fixed missing co2meters websocket data. Added websockets and removed polling for the mon-ispindel screen. The iSpindel SG gauge adjusts the resolution to the highest detected OG.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
293 | if (json_object_object_get_ex(metric, "angle", &val)) |
578
e75ce5bbda73
Changed the interface from the iSpindels to be the same as other devices. A webpage converts each call to two standard MQTT messages. The nodes MQTT message extended with an interval parameter. iSpindels now have a generated uuid made up from the chipid.
Michiel Broek <mbroek@mbse.eu>
parents:
572
diff
changeset
|
294 | ispindel->angle = json_object_get_double(val); |
680
0bb48333d133
Fixed missing co2meters websocket data. Added websockets and removed polling for the mon-ispindel screen. The iSpindel SG gauge adjusts the resolution to the highest detected OG.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
295 | if (json_object_object_get_ex(metric, "temperature", &val)) |
578
e75ce5bbda73
Changed the interface from the iSpindels to be the same as other devices. A webpage converts each call to two standard MQTT messages. The nodes MQTT message extended with an interval parameter. iSpindels now have a generated uuid made up from the chipid.
Michiel Broek <mbroek@mbse.eu>
parents:
572
diff
changeset
|
296 | ispindel->temperature = json_object_get_double(val); |
680
0bb48333d133
Fixed missing co2meters websocket data. Added websockets and removed polling for the mon-ispindel screen. The iSpindel SG gauge adjusts the resolution to the highest detected OG.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
297 | if (json_object_object_get_ex(metric, "battery", &val)) |
578
e75ce5bbda73
Changed the interface from the iSpindels to be the same as other devices. A webpage converts each call to two standard MQTT messages. The nodes MQTT message extended with an interval parameter. iSpindels now have a generated uuid made up from the chipid.
Michiel Broek <mbroek@mbse.eu>
parents:
572
diff
changeset
|
298 | ispindel->battery = json_object_get_double(val); |
849
16079aef4c4c
Version 0.3.44. Moved iSpindel Plato calculation from the php script to bmsd. This uses calibration data in the mon_ispindels table. Setup of this data will be done by the bmsapp applications. Default settings are stored in MySQL. From now on you don't need to store calibration data in the iSpindel.
Michiel Broek <mbroek@mbse.eu>
parents:
843
diff
changeset
|
299 | if (json_object_object_get_ex(metric, "gravity", &val)) |
578
e75ce5bbda73
Changed the interface from the iSpindels to be the same as other devices. A webpage converts each call to two standard MQTT messages. The nodes MQTT message extended with an interval parameter. iSpindels now have a generated uuid made up from the chipid.
Michiel Broek <mbroek@mbse.eu>
parents:
572
diff
changeset
|
300 | ispindel->gravity = json_object_get_double(val); |
567
6bf0afc33e70
Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
301 | } |
6bf0afc33e70
Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
302 | |
849
16079aef4c4c
Version 0.3.44. Moved iSpindel Plato calculation from the php script to bmsd. This uses calibration data in the mon_ispindels table. Setup of this data will be done by the bmsapp applications. Default settings are stored in MySQL. From now on you don't need to store calibration data in the iSpindel.
Michiel Broek <mbroek@mbse.eu>
parents:
843
diff
changeset
|
303 | //ispindel_dump(ispindel); |
675
a27af02ab16a
Added iSpindel to the websockets. Better offline detection for websockets.
Michiel Broek <mbroek@mbse.eu>
parents:
654
diff
changeset
|
304 | |
849
16079aef4c4c
Version 0.3.44. Moved iSpindel Plato calculation from the php script to bmsd. This uses calibration data in the mon_ispindels table. Setup of this data will be done by the bmsapp applications. Default settings are stored in MySQL. From now on you don't need to store calibration data in the iSpindel.
Michiel Broek <mbroek@mbse.eu>
parents:
843
diff
changeset
|
305 | /* |
16079aef4c4c
Version 0.3.44. Moved iSpindel Plato calculation from the php script to bmsd. This uses calibration data in the mon_ispindels table. Setup of this data will be done by the bmsapp applications. Default settings are stored in MySQL. From now on you don't need to store calibration data in the iSpindel.
Michiel Broek <mbroek@mbse.eu>
parents:
843
diff
changeset
|
306 | * If a new iSpindel, insert record. |
16079aef4c4c
Version 0.3.44. Moved iSpindel Plato calculation from the php script to bmsd. This uses calibration data in the mon_ispindels table. Setup of this data will be done by the bmsapp applications. Default settings are stored in MySQL. From now on you don't need to store calibration data in the iSpindel.
Michiel Broek <mbroek@mbse.eu>
parents:
843
diff
changeset
|
307 | */ |
567
6bf0afc33e70
Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
308 | if (new_ispindel) { |
6bf0afc33e70
Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
309 | if (ispindels == NULL) { |
6bf0afc33e70
Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
310 | ispindels = ispindel; |
6bf0afc33e70
Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
311 | } else { |
6bf0afc33e70
Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
312 | for (tmpp = ispindels; tmpp; tmpp = tmpp->next) { |
6bf0afc33e70
Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
313 | if (tmpp->next == NULL) { |
6bf0afc33e70
Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
314 | tmpp->next = ispindel; |
6bf0afc33e70
Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
315 | break; |
6bf0afc33e70
Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
316 | } |
6bf0afc33e70
Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
317 | } |
6bf0afc33e70
Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
318 | } |
6bf0afc33e70
Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
319 | ispindel_mysql_insert(ispindel); |
6bf0afc33e70
Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
320 | } |
849
16079aef4c4c
Version 0.3.44. Moved iSpindel Plato calculation from the php script to bmsd. This uses calibration data in the mon_ispindels table. Setup of this data will be done by the bmsapp applications. Default settings are stored in MySQL. From now on you don't need to store calibration data in the iSpindel.
Michiel Broek <mbroek@mbse.eu>
parents:
843
diff
changeset
|
321 | |
16079aef4c4c
Version 0.3.44. Moved iSpindel Plato calculation from the php script to bmsd. This uses calibration data in the mon_ispindels table. Setup of this data will be done by the bmsapp applications. Default settings are stored in MySQL. From now on you don't need to store calibration data in the iSpindel.
Michiel Broek <mbroek@mbse.eu>
parents:
843
diff
changeset
|
322 | /* |
16079aef4c4c
Version 0.3.44. Moved iSpindel Plato calculation from the php script to bmsd. This uses calibration data in the mon_ispindels table. Setup of this data will be done by the bmsapp applications. Default settings are stored in MySQL. From now on you don't need to store calibration data in the iSpindel.
Michiel Broek <mbroek@mbse.eu>
parents:
843
diff
changeset
|
323 | * Calculate Plato using the calibration data. |
16079aef4c4c
Version 0.3.44. Moved iSpindel Plato calculation from the php script to bmsd. This uses calibration data in the mon_ispindels table. Setup of this data will be done by the bmsapp applications. Default settings are stored in MySQL. From now on you don't need to store calibration data in the iSpindel.
Michiel Broek <mbroek@mbse.eu>
parents:
843
diff
changeset
|
324 | * Then update again and make it available. |
16079aef4c4c
Version 0.3.44. Moved iSpindel Plato calculation from the php script to bmsd. This uses calibration data in the mon_ispindels table. Setup of this data will be done by the bmsapp applications. Default settings are stored in MySQL. From now on you don't need to store calibration data in the iSpindel.
Michiel Broek <mbroek@mbse.eu>
parents:
843
diff
changeset
|
325 | */ |
16079aef4c4c
Version 0.3.44. Moved iSpindel Plato calculation from the php script to bmsd. This uses calibration data in the mon_ispindels table. Setup of this data will be done by the bmsapp applications. Default settings are stored in MySQL. From now on you don't need to store calibration data in the iSpindel.
Michiel Broek <mbroek@mbse.eu>
parents:
843
diff
changeset
|
326 | ispindel->gravity = ispindel_mysql_plato(ispindel->uuid, ispindel->angle); |
16079aef4c4c
Version 0.3.44. Moved iSpindel Plato calculation from the php script to bmsd. This uses calibration data in the mon_ispindels table. Setup of this data will be done by the bmsapp applications. Default settings are stored in MySQL. From now on you don't need to store calibration data in the iSpindel.
Michiel Broek <mbroek@mbse.eu>
parents:
843
diff
changeset
|
327 | if (ispindel->gravity > ispindel->og_gravity) |
16079aef4c4c
Version 0.3.44. Moved iSpindel Plato calculation from the php script to bmsd. This uses calibration data in the mon_ispindels table. Setup of this data will be done by the bmsapp applications. Default settings are stored in MySQL. From now on you don't need to store calibration data in the iSpindel.
Michiel Broek <mbroek@mbse.eu>
parents:
843
diff
changeset
|
328 | ispindel->og_gravity = ispindel->gravity; |
16079aef4c4c
Version 0.3.44. Moved iSpindel Plato calculation from the php script to bmsd. This uses calibration data in the mon_ispindels table. Setup of this data will be done by the bmsapp applications. Default settings are stored in MySQL. From now on you don't need to store calibration data in the iSpindel.
Michiel Broek <mbroek@mbse.eu>
parents:
843
diff
changeset
|
329 | ispindel_mysql_update(ispindel); |
680
0bb48333d133
Fixed missing co2meters websocket data. Added websockets and removed polling for the mon-ispindel screen. The iSpindel SG gauge adjusts the resolution to the highest detected OG.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
330 | ispindel_ws_send(ispindel); |
568
6f3c24e21deb
Added ispindel logging. Updated the documentation.
Michiel Broek <mbroek@mbse.eu>
parents:
567
diff
changeset
|
331 | |
6f3c24e21deb
Added ispindel logging. Updated the documentation.
Michiel Broek <mbroek@mbse.eu>
parents:
567
diff
changeset
|
332 | /* |
6f3c24e21deb
Added ispindel logging. Updated the documentation.
Michiel Broek <mbroek@mbse.eu>
parents:
567
diff
changeset
|
333 | * The data is complete, see if we can write a log entry. |
6f3c24e21deb
Added ispindel logging. Updated the documentation.
Michiel Broek <mbroek@mbse.eu>
parents:
567
diff
changeset
|
334 | */ |
578
e75ce5bbda73
Changed the interface from the iSpindels to be the same as other devices. A webpage converts each call to two standard MQTT messages. The nodes MQTT message extended with an interval parameter. iSpindels now have a generated uuid made up from the chipid.
Michiel Broek <mbroek@mbse.eu>
parents:
572
diff
changeset
|
335 | if (ispindel->beercode && strlen(ispindel->beercode) && ispindel->beername && strlen(ispindel->beername) && |
579
1253a237b620
Added check for database changes for iSpindels such as a new beer, or changing mode. Added denity in Plato and SG to the iSpindel web screen. The iSpindels must be calibrated in Plato! A bit of documentation updated.
Michiel Broek <mbroek@mbse.eu>
parents:
578
diff
changeset
|
336 | ispindel->online && (strcmp(ispindel->mode, (char *)"ON") == 0)) { |
568
6f3c24e21deb
Added ispindel logging. Updated the documentation.
Michiel Broek <mbroek@mbse.eu>
parents:
567
diff
changeset
|
337 | datetime = malloc(72); |
579
1253a237b620
Added check for database changes for iSpindels such as a new beer, or changing mode. Added denity in Plato and SG to the iSpindel web screen. The iSpindels must be calibrated in Plato! A bit of documentation updated.
Michiel Broek <mbroek@mbse.eu>
parents:
578
diff
changeset
|
338 | timestamp = time(NULL); |
568
6f3c24e21deb
Added ispindel logging. Updated the documentation.
Michiel Broek <mbroek@mbse.eu>
parents:
567
diff
changeset
|
339 | mytime = localtime(×tamp); |
6f3c24e21deb
Added ispindel logging. Updated the documentation.
Michiel Broek <mbroek@mbse.eu>
parents:
567
diff
changeset
|
340 | snprintf(datetime, 72, "%04d-%02d-%02d %02d:%02d:%02d", |
6f3c24e21deb
Added ispindel logging. Updated the documentation.
Michiel Broek <mbroek@mbse.eu>
parents:
567
diff
changeset
|
341 | mytime->tm_year + 1900, mytime->tm_mon + 1, mytime->tm_mday, mytime->tm_hour, mytime->tm_min, mytime->tm_sec); |
6f3c24e21deb
Added ispindel logging. Updated the documentation.
Michiel Broek <mbroek@mbse.eu>
parents:
567
diff
changeset
|
342 | |
799
cf145b35d65f
Version 0.3.41. Use INSERT IGNORE .. for insert log messages from fermenters, co2meters and ispindels. Connect to MySQL servers with MYSQL_OPT_RECONNECT instead of manual working around the connection lost problem if a mysql server is restarted. Removed unused bms_mysql_ping function.
Michiel Broek <mbroek@mbse.eu>
parents:
790
diff
changeset
|
343 | snprintf(query, 511, "INSERT IGNORE INTO log_ispindel SET code='%s', datetime='%s', " \ |
790
98bd22f6629b
Version 0.3.39. Log ispindel, fermenters and co2pressure in MySQL. Limit logging to at most once per 10 minutes.
Michiel Broek <mbroek@mbse.eu>
parents:
718
diff
changeset
|
344 | "temperature='%.4f', plato='%.5f', sg='%.5f', battery='%.6f', " \ |
98bd22f6629b
Version 0.3.39. Log ispindel, fermenters and co2pressure in MySQL. Limit logging to at most once per 10 minutes.
Michiel Broek <mbroek@mbse.eu>
parents:
718
diff
changeset
|
345 | "angle='%.5f', refresh='%d', uuid='%s'", |
849
16079aef4c4c
Version 0.3.44. Moved iSpindel Plato calculation from the php script to bmsd. This uses calibration data in the mon_ispindels table. Setup of this data will be done by the bmsapp applications. Default settings are stored in MySQL. From now on you don't need to store calibration data in the iSpindel.
Michiel Broek <mbroek@mbse.eu>
parents:
843
diff
changeset
|
346 | ispindel->beercode, datetime, ispindel->temperature, ispindel->gravity, plato_to_sg(ispindel->gravity), |
790
98bd22f6629b
Version 0.3.39. Log ispindel, fermenters and co2pressure in MySQL. Limit logging to at most once per 10 minutes.
Michiel Broek <mbroek@mbse.eu>
parents:
718
diff
changeset
|
347 | ispindel->battery, ispindel->angle, ispindel->interval, ispindel->uuid); |
852
71f0fa38b634
Version 0.3.45. Removed all writing to ascii logfiles in the webserver environment, only log to MySQL.
Michiel Broek <mbroek@mbse.eu>
parents:
850
diff
changeset
|
348 | syslog(LOG_NOTICE, "%s", query); |
790
98bd22f6629b
Version 0.3.39. Log ispindel, fermenters and co2pressure in MySQL. Limit logging to at most once per 10 minutes.
Michiel Broek <mbroek@mbse.eu>
parents:
718
diff
changeset
|
349 | bms_mysql_query(query); |
98bd22f6629b
Version 0.3.39. Log ispindel, fermenters and co2pressure in MySQL. Limit logging to at most once per 10 minutes.
Michiel Broek <mbroek@mbse.eu>
parents:
718
diff
changeset
|
350 | |
568
6f3c24e21deb
Added ispindel logging. Updated the documentation.
Michiel Broek <mbroek@mbse.eu>
parents:
567
diff
changeset
|
351 | free(datetime); |
6f3c24e21deb
Added ispindel logging. Updated the documentation.
Michiel Broek <mbroek@mbse.eu>
parents:
567
diff
changeset
|
352 | datetime = NULL; |
6f3c24e21deb
Added ispindel logging. Updated the documentation.
Michiel Broek <mbroek@mbse.eu>
parents:
567
diff
changeset
|
353 | } |
567
6bf0afc33e70
Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
354 | } |
6bf0afc33e70
Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
355 | |
6bf0afc33e70
Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
356 | |
6bf0afc33e70
Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
357 | |
6bf0afc33e70
Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
358 | /* |
6bf0afc33e70
Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
359 | * Process iSpindel MQTT message. |
6bf0afc33e70
Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
360 | */ |
578
e75ce5bbda73
Changed the interface from the iSpindels to be the same as other devices. A webpage converts each call to two standard MQTT messages. The nodes MQTT message extended with an interval parameter. iSpindels now have a generated uuid made up from the chipid.
Michiel Broek <mbroek@mbse.eu>
parents:
572
diff
changeset
|
361 | void ispindel_birth_data(char *topic, char *payload) |
567
6bf0afc33e70
Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
362 | { |
578
e75ce5bbda73
Changed the interface from the iSpindels to be the same as other devices. A webpage converts each call to two standard MQTT messages. The nodes MQTT message extended with an interval parameter. iSpindels now have a generated uuid made up from the chipid.
Michiel Broek <mbroek@mbse.eu>
parents:
572
diff
changeset
|
363 | char *message_type, *edge_node; |
567
6bf0afc33e70
Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
364 | |
578
e75ce5bbda73
Changed the interface from the iSpindels to be the same as other devices. A webpage converts each call to two standard MQTT messages. The nodes MQTT message extended with an interval parameter. iSpindels now have a generated uuid made up from the chipid.
Michiel Broek <mbroek@mbse.eu>
parents:
572
diff
changeset
|
365 | strtok(topic, "/"); // ignore namespace |
e75ce5bbda73
Changed the interface from the iSpindels to be the same as other devices. A webpage converts each call to two standard MQTT messages. The nodes MQTT message extended with an interval parameter. iSpindels now have a generated uuid made up from the chipid.
Michiel Broek <mbroek@mbse.eu>
parents:
572
diff
changeset
|
366 | strtok(NULL, "/"); |
e75ce5bbda73
Changed the interface from the iSpindels to be the same as other devices. A webpage converts each call to two standard MQTT messages. The nodes MQTT message extended with an interval parameter. iSpindels now have a generated uuid made up from the chipid.
Michiel Broek <mbroek@mbse.eu>
parents:
572
diff
changeset
|
367 | message_type = strtok(NULL, "/"); |
e75ce5bbda73
Changed the interface from the iSpindels to be the same as other devices. A webpage converts each call to two standard MQTT messages. The nodes MQTT message extended with an interval parameter. iSpindels now have a generated uuid made up from the chipid.
Michiel Broek <mbroek@mbse.eu>
parents:
572
diff
changeset
|
368 | edge_node = strtok(NULL, "/\0"); |
567
6bf0afc33e70
Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
369 | |
578
e75ce5bbda73
Changed the interface from the iSpindels to be the same as other devices. A webpage converts each call to two standard MQTT messages. The nodes MQTT message extended with an interval parameter. iSpindels now have a generated uuid made up from the chipid.
Michiel Broek <mbroek@mbse.eu>
parents:
572
diff
changeset
|
370 | if (strcmp("DBIRTH", message_type) == 0) { |
e75ce5bbda73
Changed the interface from the iSpindels to be the same as other devices. A webpage converts each call to two standard MQTT messages. The nodes MQTT message extended with an interval parameter. iSpindels now have a generated uuid made up from the chipid.
Michiel Broek <mbroek@mbse.eu>
parents:
572
diff
changeset
|
371 | ispindel_set(edge_node, payload); |
567
6bf0afc33e70
Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
372 | } |
6bf0afc33e70
Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
373 | } |
6bf0afc33e70
Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
374 | |
6bf0afc33e70
Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
375 | |
6bf0afc33e70
Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
376 | |
6bf0afc33e70
Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
377 | void ispindel_dump(sys_ispindel_list *ispindel) |
6bf0afc33e70
Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
378 | { |
6bf0afc33e70
Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
379 | if (debug) { |
578
e75ce5bbda73
Changed the interface from the iSpindels to be the same as other devices. A webpage converts each call to two standard MQTT messages. The nodes MQTT message extended with an interval parameter. iSpindels now have a generated uuid made up from the chipid.
Michiel Broek <mbroek@mbse.eu>
parents:
572
diff
changeset
|
380 | printf("node/alias %s / %s\n", ispindel->node, ispindel->alias); |
e75ce5bbda73
Changed the interface from the iSpindels to be the same as other devices. A webpage converts each call to two standard MQTT messages. The nodes MQTT message extended with an interval parameter. iSpindels now have a generated uuid made up from the chipid.
Michiel Broek <mbroek@mbse.eu>
parents:
572
diff
changeset
|
381 | printf("uuid %s\n", ispindel->uuid); |
567
6bf0afc33e70
Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
382 | printf("online %s\n", ispindel->online ? "yes":"no"); |
578
e75ce5bbda73
Changed the interface from the iSpindels to be the same as other devices. A webpage converts each call to two standard MQTT messages. The nodes MQTT message extended with an interval parameter. iSpindels now have a generated uuid made up from the chipid.
Michiel Broek <mbroek@mbse.eu>
parents:
572
diff
changeset
|
383 | printf("mode %s\n", ispindel->mode); |
567
6bf0afc33e70
Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
384 | printf("product %s / %s\n", ispindel->beercode, ispindel->beername); |
578
e75ce5bbda73
Changed the interface from the iSpindels to be the same as other devices. A webpage converts each call to two standard MQTT messages. The nodes MQTT message extended with an interval parameter. iSpindels now have a generated uuid made up from the chipid.
Michiel Broek <mbroek@mbse.eu>
parents:
572
diff
changeset
|
385 | printf("tilt %.5f\n", ispindel->angle); |
587
31caffee8c9c
Changed several float precision values. Changed some database fields to double. Everything has now the same precision as received values from the iSpindel.
Michiel Broek <mbroek@mbse.eu>
parents:
579
diff
changeset
|
386 | printf("temperature %.4f\n", ispindel->temperature); |
31caffee8c9c
Changed several float precision values. Changed some database fields to double. Everything has now the same precision as received values from the iSpindel.
Michiel Broek <mbroek@mbse.eu>
parents:
579
diff
changeset
|
387 | printf("battery %.6f\n", ispindel->battery); |
578
e75ce5bbda73
Changed the interface from the iSpindels to be the same as other devices. A webpage converts each call to two standard MQTT messages. The nodes MQTT message extended with an interval parameter. iSpindels now have a generated uuid made up from the chipid.
Michiel Broek <mbroek@mbse.eu>
parents:
572
diff
changeset
|
388 | printf("gravity %.5f\n", ispindel->gravity); |
849
16079aef4c4c
Version 0.3.44. Moved iSpindel Plato calculation from the php script to bmsd. This uses calibration data in the mon_ispindels table. Setup of this data will be done by the bmsapp applications. Default settings are stored in MySQL. From now on you don't need to store calibration data in the iSpindel.
Michiel Broek <mbroek@mbse.eu>
parents:
843
diff
changeset
|
389 | printf("last seen %ld\n", ispindel->lastseen); |
567
6bf0afc33e70
Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
390 | printf("interval %d\n", ispindel->interval); |
680
0bb48333d133
Fixed missing co2meters websocket data. Added websockets and removed polling for the mon-ispindel screen. The iSpindel SG gauge adjusts the resolution to the highest detected OG.
Michiel Broek <mbroek@mbse.eu>
parents:
677
diff
changeset
|
391 | printf("og_gravity %.5f\n", ispindel->og_gravity); |
849
16079aef4c4c
Version 0.3.44. Moved iSpindel Plato calculation from the php script to bmsd. This uses calibration data in the mon_ispindels table. Setup of this data will be done by the bmsapp applications. Default settings are stored in MySQL. From now on you don't need to store calibration data in the iSpindel.
Michiel Broek <mbroek@mbse.eu>
parents:
843
diff
changeset
|
392 | printf("yeast_lo %.1f\n", ispindel->yeast_lo); |
16079aef4c4c
Version 0.3.44. Moved iSpindel Plato calculation from the php script to bmsd. This uses calibration data in the mon_ispindels table. Setup of this data will be done by the bmsapp applications. Default settings are stored in MySQL. From now on you don't need to store calibration data in the iSpindel.
Michiel Broek <mbroek@mbse.eu>
parents:
843
diff
changeset
|
393 | printf("yeast_hi %.1f\n", ispindel->yeast_hi); |
16079aef4c4c
Version 0.3.44. Moved iSpindel Plato calculation from the php script to bmsd. This uses calibration data in the mon_ispindels table. Setup of this data will be done by the bmsapp applications. Default settings are stored in MySQL. From now on you don't need to store calibration data in the iSpindel.
Michiel Broek <mbroek@mbse.eu>
parents:
843
diff
changeset
|
394 | printf("calibrate %s\n", ispindel->calibrate); |
567
6bf0afc33e70
Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
395 | } |
6bf0afc33e70
Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
396 | } |
6bf0afc33e70
Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
397 | |
6bf0afc33e70
Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
398 |