bmsd/ispindels.c

Thu, 12 Oct 2023 14:19:46 +0200

author
Michiel Broek <mbroek@mbse.eu>
date
Thu, 12 Oct 2023 14:19:46 +0200
changeset 849
16079aef4c4c
parent 843
29e7223e37ae
child 850
26cc7ea0f790
permissions
-rw-r--r--

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.

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);
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
93 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
94 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
95 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
96 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
97 }
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
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
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 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
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 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
104 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
105 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
106 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
107 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
108 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
109
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
110 /*
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 * 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
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 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
114 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
115 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
116 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
117 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
118 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
119 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
120 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
121 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
122 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
123 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
124 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
125 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
126 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
127 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
128 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
129 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
130 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
131
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 /*
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 * 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
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 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
136 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
137 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
138 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
139 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
140 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
141 } 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
142 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
143 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
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 (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
146 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
147 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
148 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
149 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
150 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
151 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
152 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
153 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
154 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
155 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
156 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
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, "' 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
159 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
160 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
161
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 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
163 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
164 } 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
165 /* 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
166 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
167 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
168 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
169 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
170 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
171 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
172 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
173 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
174 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
175 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
176 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
177 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
178 /* 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
179 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
180 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
181 }
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 }
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 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
184 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
185 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
186 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
187 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
188 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
189
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 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
191 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
192 } 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
193 /* 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
194 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
195 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
196 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
197 /* 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
198 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
199 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
200 }
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 }
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 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
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 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
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 }
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 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
211 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
212 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
213 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
214 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
215 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
216 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
217 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
218 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
219 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
220 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
221 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
222 }
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
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
567
6bf0afc33e70 Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
225
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
226 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
227 {
6bf0afc33e70 Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
228 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
229 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
230 bool new_ispindel = true;
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
231 char *datetime, buf[65], *line, *logfile, *query = malloc(512);
568
6f3c24e21deb Added ispindel logging. Updated the documentation.
Michiel Broek <mbroek@mbse.eu>
parents: 567
diff changeset
232 struct tm *mytime;
6f3c24e21deb Added ispindel logging. Updated the documentation.
Michiel Broek <mbroek@mbse.eu>
parents: 567
diff changeset
233 time_t timestamp;
6f3c24e21deb Added ispindel logging. Updated the documentation.
Michiel Broek <mbroek@mbse.eu>
parents: 567
diff changeset
234 FILE *fp;
567
6bf0afc33e70 Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
235
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
236 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
237
6bf0afc33e70 Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
238 /*
6bf0afc33e70 Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
239 * 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
240 */
6bf0afc33e70 Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
241 if (ispindels) {
6bf0afc33e70 Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
242 for (tmpp = ispindels; tmpp; tmpp = tmpp->next) {
6bf0afc33e70 Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
243 if (strcmp(tmpp->node, node) == 0) {
6bf0afc33e70 Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
244 new_ispindel = false;
6bf0afc33e70 Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
245 ispindel = tmpp;
6bf0afc33e70 Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
246 break;
6bf0afc33e70 Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
247 }
6bf0afc33e70 Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
248 }
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
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
251 // 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
252 // 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
253
6bf0afc33e70 Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
254 /*
6bf0afc33e70 Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
255 * Allocate new ispindel if not yet known.
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 if (new_ispindel) {
6bf0afc33e70 Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
258 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
259 memset(ispindel, 0, sizeof(sys_ispindel_list));
6bf0afc33e70 Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
260 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
261 ispindel->mode = xstrcpy((char *)"OFF");
567
6bf0afc33e70 Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
262 }
6bf0afc33e70 Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
263
6bf0afc33e70 Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
264 if (! ispindel->online) {
6bf0afc33e70 Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
265 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
266 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
267 }
6bf0afc33e70 Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
268
6bf0afc33e70 Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
269 /*
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
270 * 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
271 * 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
272 */
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
273 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
274
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 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
276 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
277 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
278 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
279 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
280 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
281 }
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 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
283 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
284 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
285 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
286 }
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
287 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
288 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
289 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
290 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
291 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
292 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
293 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
294 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
295 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
296 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
297 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
298 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
299 }
6bf0afc33e70 Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
300
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
301 //ispindel_dump(ispindel);
675
a27af02ab16a Added iSpindel to the websockets. Better offline detection for websockets.
Michiel Broek <mbroek@mbse.eu>
parents: 654
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 /*
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
304 * 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
305 */
567
6bf0afc33e70 Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
306 if (new_ispindel) {
6bf0afc33e70 Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
307 if (ispindels == NULL) {
6bf0afc33e70 Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
308 ispindels = ispindel;
6bf0afc33e70 Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
309 } else {
6bf0afc33e70 Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
310 for (tmpp = ispindels; tmpp; tmpp = tmpp->next) {
6bf0afc33e70 Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
311 if (tmpp->next == NULL) {
6bf0afc33e70 Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
312 tmpp->next = ispindel;
6bf0afc33e70 Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
313 break;
6bf0afc33e70 Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
314 }
6bf0afc33e70 Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
315 }
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 ispindel_mysql_insert(ispindel);
6bf0afc33e70 Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
318 }
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
319
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
320 /*
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 * 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
322 * 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
323 */
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 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
325 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
326 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
327 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
328 ispindel_ws_send(ispindel);
568
6f3c24e21deb Added ispindel logging. Updated the documentation.
Michiel Broek <mbroek@mbse.eu>
parents: 567
diff changeset
329
6f3c24e21deb Added ispindel logging. Updated the documentation.
Michiel Broek <mbroek@mbse.eu>
parents: 567
diff changeset
330 /*
6f3c24e21deb Added ispindel logging. Updated the documentation.
Michiel Broek <mbroek@mbse.eu>
parents: 567
diff changeset
331 * 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
332 */
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
333 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
334 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
335 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
336 timestamp = time(NULL);
568
6f3c24e21deb Added ispindel logging. Updated the documentation.
Michiel Broek <mbroek@mbse.eu>
parents: 567
diff changeset
337 mytime = localtime(&timestamp);
6f3c24e21deb Added ispindel logging. Updated the documentation.
Michiel Broek <mbroek@mbse.eu>
parents: 567
diff changeset
338 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
339 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
340
6f3c24e21deb Added ispindel logging. Updated the documentation.
Michiel Broek <mbroek@mbse.eu>
parents: 567
diff changeset
341 line = xstrcpy(datetime);
6f3c24e21deb Added ispindel logging. Updated the documentation.
Michiel Broek <mbroek@mbse.eu>
parents: 567
diff changeset
342 line = xstrcat(line, (char *)",");
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
343 snprintf(buf, 64, "%.4f", ispindel->temperature);
568
6f3c24e21deb Added ispindel logging. Updated the documentation.
Michiel Broek <mbroek@mbse.eu>
parents: 567
diff changeset
344 line = xstrcat(line, buf);
6f3c24e21deb Added ispindel logging. Updated the documentation.
Michiel Broek <mbroek@mbse.eu>
parents: 567
diff changeset
345 line = xstrcat(line, (char *)",");
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
346 snprintf(buf, 64, "%.5f", ispindel->gravity);
568
6f3c24e21deb Added ispindel logging. Updated the documentation.
Michiel Broek <mbroek@mbse.eu>
parents: 567
diff changeset
347 line = xstrcat(line, buf);
6f3c24e21deb Added ispindel logging. Updated the documentation.
Michiel Broek <mbroek@mbse.eu>
parents: 567
diff changeset
348 line = xstrcat(line, (char *)",");
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
349 snprintf(buf, 64, "%.5f", plato_to_sg(ispindel->gravity));
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
350 line = xstrcat(line, buf);
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
351 line = xstrcat(line, (char *)",");
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
352 snprintf(buf, 64, "%.6f", 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
353 line = xstrcat(line, buf);
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
354 line = xstrcat(line, (char *)",");
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
355 snprintf(buf, 64, "%.5f", ispindel->angle);
568
6f3c24e21deb Added ispindel logging. Updated the documentation.
Michiel Broek <mbroek@mbse.eu>
parents: 567
diff changeset
356 line = xstrcat(line, buf);
6f3c24e21deb Added ispindel logging. Updated the documentation.
Michiel Broek <mbroek@mbse.eu>
parents: 567
diff changeset
357 line = xstrcat(line, (char *)",");
6f3c24e21deb Added ispindel logging. Updated the documentation.
Michiel Broek <mbroek@mbse.eu>
parents: 567
diff changeset
358 snprintf(buf, 64, "%d", ispindel->interval);
6f3c24e21deb Added ispindel logging. Updated the documentation.
Michiel Broek <mbroek@mbse.eu>
parents: 567
diff changeset
359 line = xstrcat(line, buf);
6f3c24e21deb Added ispindel logging. Updated the documentation.
Michiel Broek <mbroek@mbse.eu>
parents: 567
diff changeset
360 line = xstrcat(line, (char *)",");
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 line = xstrcat(line, ispindel->uuid);
568
6f3c24e21deb Added ispindel logging. Updated the documentation.
Michiel Broek <mbroek@mbse.eu>
parents: 567
diff changeset
362
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
363 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
364 "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
365 "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
366 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
367 ispindel->battery, ispindel->angle, ispindel->interval, ispindel->uuid);
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
368 //syslog(LOG_NOTICE, "%s", 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
369 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
370
568
6f3c24e21deb Added ispindel logging. Updated the documentation.
Michiel Broek <mbroek@mbse.eu>
parents: 567
diff changeset
371 /*
6f3c24e21deb Added ispindel logging. Updated the documentation.
Michiel Broek <mbroek@mbse.eu>
parents: 567
diff changeset
372 * Build logfile name
6f3c24e21deb Added ispindel logging. Updated the documentation.
Michiel Broek <mbroek@mbse.eu>
parents: 567
diff changeset
373 */
6f3c24e21deb Added ispindel logging. Updated the documentation.
Michiel Broek <mbroek@mbse.eu>
parents: 567
diff changeset
374 logfile = xstrcpy(Config.web_root);
6f3c24e21deb Added ispindel logging. Updated the documentation.
Michiel Broek <mbroek@mbse.eu>
parents: 567
diff changeset
375 logfile = xstrcat(logfile, (char *)"/log/ispindel/");
6f3c24e21deb Added ispindel logging. Updated the documentation.
Michiel Broek <mbroek@mbse.eu>
parents: 567
diff changeset
376 logfile = xstrcat(logfile, ispindel->beercode);
6f3c24e21deb Added ispindel logging. Updated the documentation.
Michiel Broek <mbroek@mbse.eu>
parents: 567
diff changeset
377 logfile = xstrcat(logfile, (char *)" ");
6f3c24e21deb Added ispindel logging. Updated the documentation.
Michiel Broek <mbroek@mbse.eu>
parents: 567
diff changeset
378 logfile = xstrcat(logfile, ispindel->beername);
6f3c24e21deb Added ispindel logging. Updated the documentation.
Michiel Broek <mbroek@mbse.eu>
parents: 567
diff changeset
379 logfile = xstrcat(logfile, (char *)".log");
6f3c24e21deb Added ispindel logging. Updated the documentation.
Michiel Broek <mbroek@mbse.eu>
parents: 567
diff changeset
380
6f3c24e21deb Added ispindel logging. Updated the documentation.
Michiel Broek <mbroek@mbse.eu>
parents: 567
diff changeset
381 fp = fopen(logfile, "a");
6f3c24e21deb Added ispindel logging. Updated the documentation.
Michiel Broek <mbroek@mbse.eu>
parents: 567
diff changeset
382 if (fp) {
6f3c24e21deb Added ispindel logging. Updated the documentation.
Michiel Broek <mbroek@mbse.eu>
parents: 567
diff changeset
383 fprintf(fp, "%s\n", line);
6f3c24e21deb Added ispindel logging. Updated the documentation.
Michiel Broek <mbroek@mbse.eu>
parents: 567
diff changeset
384 fclose(fp);
6f3c24e21deb Added ispindel logging. Updated the documentation.
Michiel Broek <mbroek@mbse.eu>
parents: 567
diff changeset
385 } else {
6f3c24e21deb Added ispindel logging. Updated the documentation.
Michiel Broek <mbroek@mbse.eu>
parents: 567
diff changeset
386 syslog(LOG_NOTICE, "cannot append to `%s'", logfile);
6f3c24e21deb Added ispindel logging. Updated the documentation.
Michiel Broek <mbroek@mbse.eu>
parents: 567
diff changeset
387 }
6f3c24e21deb Added ispindel logging. Updated the documentation.
Michiel Broek <mbroek@mbse.eu>
parents: 567
diff changeset
388
6f3c24e21deb Added ispindel logging. Updated the documentation.
Michiel Broek <mbroek@mbse.eu>
parents: 567
diff changeset
389 free(logfile);
6f3c24e21deb Added ispindel logging. Updated the documentation.
Michiel Broek <mbroek@mbse.eu>
parents: 567
diff changeset
390 logfile = NULL;
6f3c24e21deb Added ispindel logging. Updated the documentation.
Michiel Broek <mbroek@mbse.eu>
parents: 567
diff changeset
391 free(line);
6f3c24e21deb Added ispindel logging. Updated the documentation.
Michiel Broek <mbroek@mbse.eu>
parents: 567
diff changeset
392 line = NULL;
6f3c24e21deb Added ispindel logging. Updated the documentation.
Michiel Broek <mbroek@mbse.eu>
parents: 567
diff changeset
393 free(datetime);
6f3c24e21deb Added ispindel logging. Updated the documentation.
Michiel Broek <mbroek@mbse.eu>
parents: 567
diff changeset
394 datetime = NULL;
6f3c24e21deb Added ispindel logging. Updated the documentation.
Michiel Broek <mbroek@mbse.eu>
parents: 567
diff changeset
395 }
567
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
6bf0afc33e70 Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
399
6bf0afc33e70 Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
400 /*
6bf0afc33e70 Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
401 * Process iSpindel MQTT message.
6bf0afc33e70 Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
402 */
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
403 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
404 {
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
405 char *message_type, *edge_node;
567
6bf0afc33e70 Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
406
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
407 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
408 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
409 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
410 edge_node = strtok(NULL, "/\0");
567
6bf0afc33e70 Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
411
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
412 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
413 ispindel_set(edge_node, payload);
567
6bf0afc33e70 Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
414 }
6bf0afc33e70 Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
415 }
6bf0afc33e70 Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
416
6bf0afc33e70 Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
417
6bf0afc33e70 Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
418
6bf0afc33e70 Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
419 void ispindel_dump(sys_ispindel_list *ispindel)
6bf0afc33e70 Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
420 {
6bf0afc33e70 Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
421 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
422 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
423 printf("uuid %s\n", ispindel->uuid);
567
6bf0afc33e70 Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
424 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
425 printf("mode %s\n", ispindel->mode);
567
6bf0afc33e70 Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
426 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
427 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
428 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
429 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
430 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
431 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
432 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
433 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
434 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
435 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
436 printf("calibrate %s\n", ispindel->calibrate);
567
6bf0afc33e70 Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
437 }
6bf0afc33e70 Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
438 }
6bf0afc33e70 Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
439
6bf0afc33e70 Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
440

mercurial