bmsd/ispindels.c

Tue, 12 May 2020 16:08:30 +0200

author
Michiel Broek <mbroek@mbse.eu>
date
Tue, 12 May 2020 16:08:30 +0200
changeset 677
6e82fece1f8f
parent 675
a27af02ab16a
child 680
0bb48333d133
permissions
-rw-r--r--

Consistent use of group names is important.

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 *
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
6 * Copyright (C) 2019-2020
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
6bf0afc33e70 Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
43
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
44 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
45 {
6bf0afc33e70 Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
46 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
47 struct json_object *jobj, *metric, *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
48 bool new_ispindel = true;
675
a27af02ab16a Added iSpindel to the websockets. Better offline detection for websockets.
Michiel Broek <mbroek@mbse.eu>
parents: 654
diff changeset
49 char *datetime, buf[65], *line, *logfile, *msg = NULL;
568
6f3c24e21deb Added ispindel logging. Updated the documentation.
Michiel Broek <mbroek@mbse.eu>
parents: 567
diff changeset
50 struct tm *mytime;
6f3c24e21deb Added ispindel logging. Updated the documentation.
Michiel Broek <mbroek@mbse.eu>
parents: 567
diff changeset
51 time_t timestamp;
6f3c24e21deb Added ispindel logging. Updated the documentation.
Michiel Broek <mbroek@mbse.eu>
parents: 567
diff changeset
52 FILE *fp;
567
6bf0afc33e70 Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
53
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
54 // 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
55 // printf("ispindel_set: %s %s\n", node, payload);
567
6bf0afc33e70 Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
56
6bf0afc33e70 Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
57 /*
6bf0afc33e70 Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
58 * 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
59 */
6bf0afc33e70 Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
60 if (ispindels) {
6bf0afc33e70 Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
61 for (tmpp = ispindels; tmpp; tmpp = tmpp->next) {
6bf0afc33e70 Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
62 if (strcmp(tmpp->node, node) == 0) {
6bf0afc33e70 Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
63 new_ispindel = false;
6bf0afc33e70 Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
64 ispindel = tmpp;
6bf0afc33e70 Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
65 break;
6bf0afc33e70 Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
66 }
6bf0afc33e70 Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
67 }
6bf0afc33e70 Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
68 }
6bf0afc33e70 Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
69
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
70 // 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
71 // 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
72
6bf0afc33e70 Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
73 /*
6bf0afc33e70 Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
74 * Allocate new ispindel if not yet known.
6bf0afc33e70 Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
75 */
6bf0afc33e70 Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
76 if (new_ispindel) {
6bf0afc33e70 Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
77 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
78 memset(ispindel, 0, sizeof(sys_ispindel_list));
6bf0afc33e70 Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
79 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
80 ispindel->mode = xstrcpy((char *)"OFF");
567
6bf0afc33e70 Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
81 }
6bf0afc33e70 Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
82
6bf0afc33e70 Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
83 if (! ispindel->online) {
6bf0afc33e70 Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
84 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
85 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
86 }
6bf0afc33e70 Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
87
6bf0afc33e70 Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
88 /*
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
89 * 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
90 * 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
91 */
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
92 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
93
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
94 if (json_object_object_get_ex(jobj, "unit", &metric)) {
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
95 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
96 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
97 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
98 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
99 }
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
100 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
101 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
102 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
103 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
104 }
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
105 if (json_object_object_get_ex(metric, "alarm", &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
106 ispindel->alarm = json_object_get_int(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
107 }
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
108 if (json_object_object_get_ex(metric, "interval", &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
109 ispindel->interval = json_object_get_int(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
110 }
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
111 if (json_object_object_get_ex(metric, "angle", &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
112 ispindel->angle = json_object_get_double(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
113 }
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
114 if (json_object_object_get_ex(metric, "temperature", &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
115 ispindel->temperature = json_object_get_double(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
116 }
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
117 if (json_object_object_get_ex(metric, "battery", &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
118 ispindel->battery = json_object_get_double(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
119 }
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
120 if (json_object_object_get_ex(metric, "gravity", &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
121 ispindel->gravity = json_object_get_double(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
122 }
567
6bf0afc33e70 Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
123 }
6bf0afc33e70 Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
124
677
6e82fece1f8f Consistent use of group names is important.
Michiel Broek <mbroek@mbse.eu>
parents: 675
diff changeset
125 msg = xstrcpy((char *)"{\"device\":\"ispindels\",\"node\":\"");
675
a27af02ab16a Added iSpindel to the websockets. Better offline detection for websockets.
Michiel Broek <mbroek@mbse.eu>
parents: 654
diff changeset
126 msg = xstrcat(msg, node);
a27af02ab16a Added iSpindel to the websockets. Better offline detection for websockets.
Michiel Broek <mbroek@mbse.eu>
parents: 654
diff changeset
127 msg = xstrcat(msg, (char *)"\",\"unit\":\"");
a27af02ab16a Added iSpindel to the websockets. Better offline detection for websockets.
Michiel Broek <mbroek@mbse.eu>
parents: 654
diff changeset
128 msg = xstrcat(msg, ispindel->alias);
a27af02ab16a Added iSpindel to the websockets. Better offline detection for websockets.
Michiel Broek <mbroek@mbse.eu>
parents: 654
diff changeset
129 msg = xstrcat(msg, (char *)"\",\"online\":");
a27af02ab16a Added iSpindel to the websockets. Better offline detection for websockets.
Michiel Broek <mbroek@mbse.eu>
parents: 654
diff changeset
130 msg = xstrcat(msg, ispindel->online ? (char *)"1":(char *)"0");
a27af02ab16a Added iSpindel to the websockets. Better offline detection for websockets.
Michiel Broek <mbroek@mbse.eu>
parents: 654
diff changeset
131 msg = xstrcat(msg, (char *)",\"mode\":\"");
a27af02ab16a Added iSpindel to the websockets. Better offline detection for websockets.
Michiel Broek <mbroek@mbse.eu>
parents: 654
diff changeset
132 msg = xstrcat(msg, ispindel->mode);
a27af02ab16a Added iSpindel to the websockets. Better offline detection for websockets.
Michiel Broek <mbroek@mbse.eu>
parents: 654
diff changeset
133 msg = xstrcat(msg, (char *)"\",\"temperature\":");
a27af02ab16a Added iSpindel to the websockets. Better offline detection for websockets.
Michiel Broek <mbroek@mbse.eu>
parents: 654
diff changeset
134 snprintf(buf, 64, "%.4f", ispindel->temperature);
a27af02ab16a Added iSpindel to the websockets. Better offline detection for websockets.
Michiel Broek <mbroek@mbse.eu>
parents: 654
diff changeset
135 msg = xstrcat(msg, buf);
a27af02ab16a Added iSpindel to the websockets. Better offline detection for websockets.
Michiel Broek <mbroek@mbse.eu>
parents: 654
diff changeset
136 msg = xstrcat(msg, (char *)",\"angle\":");
a27af02ab16a Added iSpindel to the websockets. Better offline detection for websockets.
Michiel Broek <mbroek@mbse.eu>
parents: 654
diff changeset
137 snprintf(buf, 64, "%.5f", ispindel->angle);
a27af02ab16a Added iSpindel to the websockets. Better offline detection for websockets.
Michiel Broek <mbroek@mbse.eu>
parents: 654
diff changeset
138 msg = xstrcat(msg, buf);
a27af02ab16a Added iSpindel to the websockets. Better offline detection for websockets.
Michiel Broek <mbroek@mbse.eu>
parents: 654
diff changeset
139 msg = xstrcat(msg, (char *)",\"battery\":");
a27af02ab16a Added iSpindel to the websockets. Better offline detection for websockets.
Michiel Broek <mbroek@mbse.eu>
parents: 654
diff changeset
140 snprintf(buf, 64, "%.6f", ispindel->battery);
a27af02ab16a Added iSpindel to the websockets. Better offline detection for websockets.
Michiel Broek <mbroek@mbse.eu>
parents: 654
diff changeset
141 msg = xstrcat(msg, buf);
a27af02ab16a Added iSpindel to the websockets. Better offline detection for websockets.
Michiel Broek <mbroek@mbse.eu>
parents: 654
diff changeset
142 msg = xstrcat(msg, (char *)",\"gravity\":");
a27af02ab16a Added iSpindel to the websockets. Better offline detection for websockets.
Michiel Broek <mbroek@mbse.eu>
parents: 654
diff changeset
143 snprintf(buf, 64, "%.5f", ispindel->gravity);
a27af02ab16a Added iSpindel to the websockets. Better offline detection for websockets.
Michiel Broek <mbroek@mbse.eu>
parents: 654
diff changeset
144 msg = xstrcat(msg, buf);
a27af02ab16a Added iSpindel to the websockets. Better offline detection for websockets.
Michiel Broek <mbroek@mbse.eu>
parents: 654
diff changeset
145 msg = xstrcat(msg, (char *)",\"alarm\":");
a27af02ab16a Added iSpindel to the websockets. Better offline detection for websockets.
Michiel Broek <mbroek@mbse.eu>
parents: 654
diff changeset
146 snprintf(buf, 64, "%d", ispindel->alarm);
a27af02ab16a Added iSpindel to the websockets. Better offline detection for websockets.
Michiel Broek <mbroek@mbse.eu>
parents: 654
diff changeset
147 msg = xstrcat(msg, buf);
a27af02ab16a Added iSpindel to the websockets. Better offline detection for websockets.
Michiel Broek <mbroek@mbse.eu>
parents: 654
diff changeset
148 msg = xstrcat(msg, (char *)"}");
a27af02ab16a Added iSpindel to the websockets. Better offline detection for websockets.
Michiel Broek <mbroek@mbse.eu>
parents: 654
diff changeset
149 ws_broadcast(msg);
a27af02ab16a Added iSpindel to the websockets. Better offline detection for websockets.
Michiel Broek <mbroek@mbse.eu>
parents: 654
diff changeset
150 free(msg);
a27af02ab16a Added iSpindel to the websockets. Better offline detection for websockets.
Michiel Broek <mbroek@mbse.eu>
parents: 654
diff changeset
151 msg = NULL;
a27af02ab16a Added iSpindel to the websockets. Better offline detection for websockets.
Michiel Broek <mbroek@mbse.eu>
parents: 654
diff changeset
152
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
153 // ispindel_dump(ispindel);
567
6bf0afc33e70 Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
154
6bf0afc33e70 Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
155 if (new_ispindel) {
6bf0afc33e70 Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
156 if (ispindels == NULL) {
6bf0afc33e70 Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
157 ispindels = ispindel;
6bf0afc33e70 Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
158 } else {
6bf0afc33e70 Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
159 for (tmpp = ispindels; tmpp; tmpp = tmpp->next) {
6bf0afc33e70 Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
160 if (tmpp->next == NULL) {
6bf0afc33e70 Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
161 tmpp->next = ispindel;
6bf0afc33e70 Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
162 break;
6bf0afc33e70 Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
163 }
6bf0afc33e70 Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
164 }
6bf0afc33e70 Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
165 }
6bf0afc33e70 Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
166 ispindel_mysql_insert(ispindel);
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
167 } else {
567
6bf0afc33e70 Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
168 ispindel_mysql_update(ispindel);
6bf0afc33e70 Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
169 }
568
6f3c24e21deb Added ispindel logging. Updated the documentation.
Michiel Broek <mbroek@mbse.eu>
parents: 567
diff changeset
170
6f3c24e21deb Added ispindel logging. Updated the documentation.
Michiel Broek <mbroek@mbse.eu>
parents: 567
diff changeset
171 /*
6f3c24e21deb Added ispindel logging. Updated the documentation.
Michiel Broek <mbroek@mbse.eu>
parents: 567
diff changeset
172 * 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
173 */
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
174 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
175 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
176 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
177 timestamp = time(NULL);
568
6f3c24e21deb Added ispindel logging. Updated the documentation.
Michiel Broek <mbroek@mbse.eu>
parents: 567
diff changeset
178 mytime = localtime(&timestamp);
6f3c24e21deb Added ispindel logging. Updated the documentation.
Michiel Broek <mbroek@mbse.eu>
parents: 567
diff changeset
179 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
180 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
181
6f3c24e21deb Added ispindel logging. Updated the documentation.
Michiel Broek <mbroek@mbse.eu>
parents: 567
diff changeset
182 line = xstrcpy(datetime);
6f3c24e21deb Added ispindel logging. Updated the documentation.
Michiel Broek <mbroek@mbse.eu>
parents: 567
diff changeset
183 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
184 snprintf(buf, 64, "%.4f", ispindel->temperature);
568
6f3c24e21deb Added ispindel logging. Updated the documentation.
Michiel Broek <mbroek@mbse.eu>
parents: 567
diff changeset
185 line = xstrcat(line, buf);
6f3c24e21deb Added ispindel logging. Updated the documentation.
Michiel Broek <mbroek@mbse.eu>
parents: 567
diff changeset
186 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
187 snprintf(buf, 64, "%.5f", ispindel->gravity);
568
6f3c24e21deb Added ispindel logging. Updated the documentation.
Michiel Broek <mbroek@mbse.eu>
parents: 567
diff changeset
188 line = xstrcat(line, buf);
6f3c24e21deb Added ispindel logging. Updated the documentation.
Michiel Broek <mbroek@mbse.eu>
parents: 567
diff changeset
189 line = xstrcat(line, (char *)",");
654
0aef416dbceb Version 0.3.31 Switched plato to sg calculation in bmsd.
Michiel Broek <mbroek@mbse.eu>
parents: 587
diff changeset
190 // snprintf(buf, 64, "%.5f", 1 + (ispindel->gravity / (258.6 - ((ispindel->gravity / 258.2) * 227.1))));
0aef416dbceb Version 0.3.31 Switched plato to sg calculation in bmsd.
Michiel Broek <mbroek@mbse.eu>
parents: 587
diff changeset
191 snprintf(buf, 64, "%.5f", 1.00001 + (0.0038661 * ispindel->gravity) + (1.3488e-5 * ispindel->gravity * ispindel->gravity) +
0aef416dbceb Version 0.3.31 Switched plato to sg calculation in bmsd.
Michiel Broek <mbroek@mbse.eu>
parents: 587
diff changeset
192 (4.3074e-8 * ispindel->gravity * ispindel->gravity * 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
193 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
194 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
195 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
196 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
197 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
198 snprintf(buf, 64, "%.5f", ispindel->angle);
568
6f3c24e21deb Added ispindel logging. Updated the documentation.
Michiel Broek <mbroek@mbse.eu>
parents: 567
diff changeset
199 line = xstrcat(line, buf);
6f3c24e21deb Added ispindel logging. Updated the documentation.
Michiel Broek <mbroek@mbse.eu>
parents: 567
diff changeset
200 line = xstrcat(line, (char *)",");
6f3c24e21deb Added ispindel logging. Updated the documentation.
Michiel Broek <mbroek@mbse.eu>
parents: 567
diff changeset
201 snprintf(buf, 64, "%d", ispindel->interval);
6f3c24e21deb Added ispindel logging. Updated the documentation.
Michiel Broek <mbroek@mbse.eu>
parents: 567
diff changeset
202 line = xstrcat(line, buf);
6f3c24e21deb Added ispindel logging. Updated the documentation.
Michiel Broek <mbroek@mbse.eu>
parents: 567
diff changeset
203 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
204 line = xstrcat(line, ispindel->uuid);
568
6f3c24e21deb Added ispindel logging. Updated the documentation.
Michiel Broek <mbroek@mbse.eu>
parents: 567
diff changeset
205
6f3c24e21deb Added ispindel logging. Updated the documentation.
Michiel Broek <mbroek@mbse.eu>
parents: 567
diff changeset
206 /*
6f3c24e21deb Added ispindel logging. Updated the documentation.
Michiel Broek <mbroek@mbse.eu>
parents: 567
diff changeset
207 * Build logfile name
6f3c24e21deb Added ispindel logging. Updated the documentation.
Michiel Broek <mbroek@mbse.eu>
parents: 567
diff changeset
208 */
6f3c24e21deb Added ispindel logging. Updated the documentation.
Michiel Broek <mbroek@mbse.eu>
parents: 567
diff changeset
209 logfile = xstrcpy(Config.web_root);
6f3c24e21deb Added ispindel logging. Updated the documentation.
Michiel Broek <mbroek@mbse.eu>
parents: 567
diff changeset
210 logfile = xstrcat(logfile, (char *)"/log/ispindel/");
6f3c24e21deb Added ispindel logging. Updated the documentation.
Michiel Broek <mbroek@mbse.eu>
parents: 567
diff changeset
211 logfile = xstrcat(logfile, ispindel->beercode);
6f3c24e21deb Added ispindel logging. Updated the documentation.
Michiel Broek <mbroek@mbse.eu>
parents: 567
diff changeset
212 logfile = xstrcat(logfile, (char *)" ");
6f3c24e21deb Added ispindel logging. Updated the documentation.
Michiel Broek <mbroek@mbse.eu>
parents: 567
diff changeset
213 logfile = xstrcat(logfile, ispindel->beername);
6f3c24e21deb Added ispindel logging. Updated the documentation.
Michiel Broek <mbroek@mbse.eu>
parents: 567
diff changeset
214 logfile = xstrcat(logfile, (char *)".log");
6f3c24e21deb Added ispindel logging. Updated the documentation.
Michiel Broek <mbroek@mbse.eu>
parents: 567
diff changeset
215
6f3c24e21deb Added ispindel logging. Updated the documentation.
Michiel Broek <mbroek@mbse.eu>
parents: 567
diff changeset
216 fp = fopen(logfile, "a");
6f3c24e21deb Added ispindel logging. Updated the documentation.
Michiel Broek <mbroek@mbse.eu>
parents: 567
diff changeset
217 if (fp) {
6f3c24e21deb Added ispindel logging. Updated the documentation.
Michiel Broek <mbroek@mbse.eu>
parents: 567
diff changeset
218 fprintf(fp, "%s\n", line);
6f3c24e21deb Added ispindel logging. Updated the documentation.
Michiel Broek <mbroek@mbse.eu>
parents: 567
diff changeset
219 fclose(fp);
6f3c24e21deb Added ispindel logging. Updated the documentation.
Michiel Broek <mbroek@mbse.eu>
parents: 567
diff changeset
220 } else {
6f3c24e21deb Added ispindel logging. Updated the documentation.
Michiel Broek <mbroek@mbse.eu>
parents: 567
diff changeset
221 syslog(LOG_NOTICE, "cannot append to `%s'", logfile);
6f3c24e21deb Added ispindel logging. Updated the documentation.
Michiel Broek <mbroek@mbse.eu>
parents: 567
diff changeset
222 }
6f3c24e21deb Added ispindel logging. Updated the documentation.
Michiel Broek <mbroek@mbse.eu>
parents: 567
diff changeset
223
6f3c24e21deb Added ispindel logging. Updated the documentation.
Michiel Broek <mbroek@mbse.eu>
parents: 567
diff changeset
224 free(logfile);
6f3c24e21deb Added ispindel logging. Updated the documentation.
Michiel Broek <mbroek@mbse.eu>
parents: 567
diff changeset
225 logfile = NULL;
6f3c24e21deb Added ispindel logging. Updated the documentation.
Michiel Broek <mbroek@mbse.eu>
parents: 567
diff changeset
226 free(line);
6f3c24e21deb Added ispindel logging. Updated the documentation.
Michiel Broek <mbroek@mbse.eu>
parents: 567
diff changeset
227 line = NULL;
6f3c24e21deb Added ispindel logging. Updated the documentation.
Michiel Broek <mbroek@mbse.eu>
parents: 567
diff changeset
228 free(datetime);
6f3c24e21deb Added ispindel logging. Updated the documentation.
Michiel Broek <mbroek@mbse.eu>
parents: 567
diff changeset
229 datetime = NULL;
6f3c24e21deb Added ispindel logging. Updated the documentation.
Michiel Broek <mbroek@mbse.eu>
parents: 567
diff changeset
230 }
567
6bf0afc33e70 Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
231 }
6bf0afc33e70 Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
232
6bf0afc33e70 Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
233
6bf0afc33e70 Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
234
6bf0afc33e70 Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
235 /*
6bf0afc33e70 Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
236 * Process iSpindel MQTT message.
6bf0afc33e70 Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
237 */
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
238 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
239 {
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
240 char *message_type, *edge_node;
567
6bf0afc33e70 Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
241
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
242 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
243 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
244 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
245 edge_node = strtok(NULL, "/\0");
567
6bf0afc33e70 Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
246
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
247 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
248 ispindel_set(edge_node, payload);
567
6bf0afc33e70 Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
249 }
6bf0afc33e70 Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
250 }
6bf0afc33e70 Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
251
6bf0afc33e70 Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
252
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 void ispindel_dump(sys_ispindel_list *ispindel)
6bf0afc33e70 Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
255 {
6bf0afc33e70 Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
256 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
257 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
258 printf("uuid %s\n", ispindel->uuid);
567
6bf0afc33e70 Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
259 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
260 printf("mode %s\n", ispindel->mode);
567
6bf0afc33e70 Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
261 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
262 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
263 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
264 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
265 printf("gravity %.5f\n", ispindel->gravity);
567
6bf0afc33e70 Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
266 printf("interval %d\n", ispindel->interval);
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
6bf0afc33e70 Initial code for iSpindel support in the daemon
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
270

mercurial