bmsd/nodes.c

Wed, 20 May 2020 21:49:09 +0200

author
Michiel Broek <mbroek@mbse.eu>
date
Wed, 20 May 2020 21:49:09 +0200
changeset 684
ccb9f24d0fe9
parent 677
6e82fece1f8f
child 686
ca1fbb3bd3db
permissions
-rw-r--r--

Report any online status change via websocket broadcast. When starting, load all in memory tables sorted. The websocket status on the web pages has it's own panel. Prepared the menu system for dynamic updates.

0
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1 /**
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
2 * @file nodes.c
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
3 * @brief Handle nodes status
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
4 * @author Michiel Broek <mbroek at mbse dot eu>
033898178630 Versio 0.0.2 initial check in
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) 2018-2020
0
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
7 *
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
8 * This file is part of the bms (Brewery Management System)
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
9 *
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
10 * This is free software; you can redistribute it and/or modify it
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
11 * under the terms of the GNU General Public License as published by the
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
12 * Free Software Foundation; either version 2, or (at your option) any
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
13 * later version.
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
14 *
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
15 * bms is distributed in the hope that it will be useful, but
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
16 * WITHOUT ANY WARRANTY; without even the implied warranty of
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
18 * General Public License for more details.
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
19 *
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
20 * You should have received a copy of the GNU General Public License
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
21 * along with ThermFerm; see the file COPYING. If not, write to the Free
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
22 * Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
23 */
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
24
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
25
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
26 #include "bms.h"
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
27 #include "xutil.h"
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
28 #include "nodes.h"
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
29 #include "mysql.h"
672
23f959713fcb Added websockets for node status changes.
Michiel Broek <mbroek@mbse.eu>
parents: 578
diff changeset
30 #include "websocket.h"
0
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
31
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
32
384
442d23455ae4 The bms daemon now checks if a node went away of no data is received for 10 minutes.
Michiel Broek <mbroek@mbse.eu>
parents: 0
diff changeset
33 sys_node_list *nodes = NULL;
0
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
34
384
442d23455ae4 The bms daemon now checks if a node went away of no data is received for 10 minutes.
Michiel Broek <mbroek@mbse.eu>
parents: 0
diff changeset
35 extern int debug;
442d23455ae4 The bms daemon now checks if a node went away of no data is received for 10 minutes.
Michiel Broek <mbroek@mbse.eu>
parents: 0
diff changeset
36 extern sys_fermenter_list *fermenters;
502
a8a6901b5a99 Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents: 384
diff changeset
37 extern sys_co2meter_list *co2meters;
572
7a03181d29a3 Version 0.3.27 More code for iSpindels. All online/offline data in the database is now handles as integers. Nodes timeout use the configured interval time from the nodes.
Michiel Broek <mbroek@mbse.eu>
parents: 502
diff changeset
38 extern sys_ispindel_list *ispindels;
0
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
39
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
40
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
41 void node_birth_data(char *topic, char *payload)
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
42 {
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
43 struct json_object *jobj, *val, *metric, *metric2;
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
44 sys_node_list *node, *tmpp;
672
23f959713fcb Added websockets for node status changes.
Michiel Broek <mbroek@mbse.eu>
parents: 578
diff changeset
45 struct tm *mytime;
23f959713fcb Added websockets for node status changes.
Michiel Broek <mbroek@mbse.eu>
parents: 578
diff changeset
46 char *group_id, *message_type, *edge_node, *msg = NULL, buf[74];
0
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
47 bool new_node = true;
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
48
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
49 // fprintf(stdout, "node_birth: %s %s\n", topic, payload);
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
50
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
51 strtok(topic, "/"); // ignore namespace
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
52 group_id = strtok(NULL, "/");
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
53 message_type = strtok(NULL, "/");
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
54 edge_node = strtok(NULL, "/\0");
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
55
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
56 /*
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
57 * Search node record in the memory array and use it if found.
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
58 */
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
59 if (nodes) {
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
60 for (tmpp = nodes; tmpp; tmpp = tmpp->next) {
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
61 if ((strcmp(tmpp->group_id, group_id) == 0) && (strcmp(tmpp->node, edge_node) == 0)) {
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
62 new_node = false;
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
63 node = tmpp;
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
64 node->lastseen = time(NULL);
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
65 node->online = true;
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
66 break;
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
67 }
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
68 }
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
69 }
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
70
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
71 /*
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
72 * Allocate new node if not yet known.
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
73 */
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
74 if (new_node) {
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
75 node = (sys_node_list *)malloc(sizeof(sys_node_list));
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
76 node->uuid = NULL;
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
77 node->next = NULL;
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
78 node->group_id = xstrcpy(group_id);
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
79 node->node = xstrcpy(edge_node);
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
80 node->online = true;
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
81 node->hardwaremake = node->hardwaremodel = node->os = node->os_version = node->firmware = NULL;
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
82 node->firstseen = node->lastseen = time(NULL);
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
83 node->temperature = node->humidity = node->barometer = 0.0;
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
84 node->gps_latitude = node->gps_longitude = node->gps_altitude = 0.0;
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
85 node->net_address = node->net_ifname = NULL;
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
86 node->net_rssi = 0;
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
87 node->interval = 300;
0
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
88 }
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
89
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
90 /*
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
91 * Process the JSON formatted payload.
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
92 * Update only the fields that are found in the payload.
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
93 */
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
94 jobj = json_tokener_parse(payload);
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
95
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
96 if (json_object_object_get_ex(jobj, "timestamp", &val)) {
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
97 if (strcmp((char *)"NDATA", message_type)) {
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
98 node->firstseen = json_object_get_int(val);
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
99 syslog(LOG_NOTICE, "Online node `%s/%s'", node->group_id, node->node);
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
100 } else {
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
101 node->lastseen = json_object_get_int(val);
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
102 }
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
103 }
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
104
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
105 if (json_object_object_get_ex(jobj, "metric", &metric)) {
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
106 if (json_object_object_get_ex(metric, "uuid", &val)) {
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
107 if (node->uuid)
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
108 free(node->uuid);
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
109 node->uuid = xstrcpy((char *)json_object_get_string(val));
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
110 }
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
111 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
112 node->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
113 }
0
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
114 if (json_object_object_get_ex(metric, "properties", &metric2)) {
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
115 if (json_object_object_get_ex(metric2, "hardwaremake", &val)) {
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
116 if (node->hardwaremake)
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
117 free(node->hardwaremake);
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
118 node->hardwaremake = xstrcpy((char *)json_object_get_string(val));
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
119 }
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
120 if (json_object_object_get_ex(metric2, "hardwaremodel", &val)) {
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
121 if (node->hardwaremodel)
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
122 free(node->hardwaremodel);
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
123 node->hardwaremodel = xstrcpy((char *)json_object_get_string(val));
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
124 }
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
125 if (json_object_object_get_ex(metric2, "os", &val)) {
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
126 if (node->os)
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
127 free(node->os);
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
128 node->os = xstrcpy((char *)json_object_get_string(val));
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
129 }
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
130 if (json_object_object_get_ex(metric2, "os_version", &val)) {
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
131 if (node->os_version)
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
132 free(node->os_version);
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
133 node->os_version = xstrcpy((char *)json_object_get_string(val));
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
134 }
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
135 if (json_object_object_get_ex(metric2, "FW", &val)) {
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
136 if (node->firmware)
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
137 free(node->firmware);
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
138 node->firmware = xstrcpy((char *)json_object_get_string(val));
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
139 }
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
140 }
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
141 if (json_object_object_get_ex(metric, "THB", &metric2)) {
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
142 if (json_object_object_get_ex(metric2, "temperature", &val)) {
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
143 node->temperature = json_object_get_double(val);
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
144 }
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
145 if (json_object_object_get_ex(metric2, "humidity", &val)) {
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
146 node->humidity= json_object_get_double(val);
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
147 }
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
148 if (json_object_object_get_ex(metric2, "barometer", &val)) {
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
149 node->barometer = json_object_get_double(val);
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
150 }
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
151 }
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
152 if (json_object_object_get_ex(metric, "GPS", &metric2)) {
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
153 if (json_object_object_get_ex(metric2, "latitude", &val)) {
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
154 node->gps_latitude = json_object_get_double(val);
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
155 }
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
156 if (json_object_object_get_ex(metric2, "longitude", &val)) {
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
157 node->gps_longitude = json_object_get_double(val);
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
158 }
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
159 if (json_object_object_get_ex(metric2, "altitude", &val)) {
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
160 node->gps_altitude = json_object_get_double(val);
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
161 }
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
162 }
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
163 if (json_object_object_get_ex(metric, "net", &metric2)) {
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
164 if (json_object_object_get_ex(metric2, "address", &val)) {
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
165 if (node->net_address)
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
166 free(node->net_address);
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
167 node->net_address = xstrcpy((char *)json_object_get_string(val));
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
168 }
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
169 if (json_object_object_get_ex(metric2, "ifname", &val)) {
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
170 if (node->net_ifname)
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
171 free(node->net_ifname);
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
172 node->net_ifname = xstrcpy((char *)json_object_get_string(val));
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
173 }
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
174 if (json_object_object_get_ex(metric2, "rssi", &val)) {
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
175 node->net_rssi = json_object_get_int(val);
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
176 }
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
177 }
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
178 }
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
179 json_object_put(jobj);
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
180
672
23f959713fcb Added websockets for node status changes.
Michiel Broek <mbroek@mbse.eu>
parents: 578
diff changeset
181 msg = xstrcpy((char *)"{\"node\":\"");
23f959713fcb Added websockets for node status changes.
Michiel Broek <mbroek@mbse.eu>
parents: 578
diff changeset
182 msg = xstrcat(msg, edge_node);
23f959713fcb Added websockets for node status changes.
Michiel Broek <mbroek@mbse.eu>
parents: 578
diff changeset
183 msg = xstrcat(msg, (char *)"\",\"group\":\"");
23f959713fcb Added websockets for node status changes.
Michiel Broek <mbroek@mbse.eu>
parents: 578
diff changeset
184 msg = xstrcat(msg, group_id);
23f959713fcb Added websockets for node status changes.
Michiel Broek <mbroek@mbse.eu>
parents: 578
diff changeset
185 msg = xstrcat(msg, (char *)"\",\"online\":");
23f959713fcb Added websockets for node status changes.
Michiel Broek <mbroek@mbse.eu>
parents: 578
diff changeset
186 msg = xstrcat(msg, node->online ? (char *)"1":(char *)"0");
23f959713fcb Added websockets for node status changes.
Michiel Broek <mbroek@mbse.eu>
parents: 578
diff changeset
187 msg = xstrcat(msg, (char *)",\"lastseen\":\"");
23f959713fcb Added websockets for node status changes.
Michiel Broek <mbroek@mbse.eu>
parents: 578
diff changeset
188 mytime = localtime(&node->lastseen);
23f959713fcb Added websockets for node status changes.
Michiel Broek <mbroek@mbse.eu>
parents: 578
diff changeset
189 snprintf(buf, 73, "%04d-%02d-%02d %02d:%02d:%02d",
23f959713fcb Added websockets for node status changes.
Michiel Broek <mbroek@mbse.eu>
parents: 578
diff changeset
190 mytime->tm_year + 1900, mytime->tm_mon + 1, mytime->tm_mday, mytime->tm_hour, mytime->tm_min, mytime->tm_sec);
23f959713fcb Added websockets for node status changes.
Michiel Broek <mbroek@mbse.eu>
parents: 578
diff changeset
191 msg = xstrcat(msg, buf);
23f959713fcb Added websockets for node status changes.
Michiel Broek <mbroek@mbse.eu>
parents: 578
diff changeset
192 msg = xstrcat(msg, (char *)"\"");
23f959713fcb Added websockets for node status changes.
Michiel Broek <mbroek@mbse.eu>
parents: 578
diff changeset
193 if (node->temperature) {
23f959713fcb Added websockets for node status changes.
Michiel Broek <mbroek@mbse.eu>
parents: 578
diff changeset
194 msg = xstrcat(msg, (char *)",\"temperature\":");
23f959713fcb Added websockets for node status changes.
Michiel Broek <mbroek@mbse.eu>
parents: 578
diff changeset
195 snprintf(buf, 64, "%.1f", node->temperature);
23f959713fcb Added websockets for node status changes.
Michiel Broek <mbroek@mbse.eu>
parents: 578
diff changeset
196 msg = xstrcat(msg, buf);
23f959713fcb Added websockets for node status changes.
Michiel Broek <mbroek@mbse.eu>
parents: 578
diff changeset
197 }
23f959713fcb Added websockets for node status changes.
Michiel Broek <mbroek@mbse.eu>
parents: 578
diff changeset
198 if (node->humidity) {
23f959713fcb Added websockets for node status changes.
Michiel Broek <mbroek@mbse.eu>
parents: 578
diff changeset
199 msg = xstrcat(msg, (char *)",\"humidity\":");
23f959713fcb Added websockets for node status changes.
Michiel Broek <mbroek@mbse.eu>
parents: 578
diff changeset
200 snprintf(buf, 64, "%.1f", node->humidity);
23f959713fcb Added websockets for node status changes.
Michiel Broek <mbroek@mbse.eu>
parents: 578
diff changeset
201 msg = xstrcat(msg, buf);
23f959713fcb Added websockets for node status changes.
Michiel Broek <mbroek@mbse.eu>
parents: 578
diff changeset
202 }
23f959713fcb Added websockets for node status changes.
Michiel Broek <mbroek@mbse.eu>
parents: 578
diff changeset
203 msg = xstrcat(msg, (char *)",\"ip\":\"");
23f959713fcb Added websockets for node status changes.
Michiel Broek <mbroek@mbse.eu>
parents: 578
diff changeset
204 msg = xstrcat(msg, node->net_address);
23f959713fcb Added websockets for node status changes.
Michiel Broek <mbroek@mbse.eu>
parents: 578
diff changeset
205 msg = xstrcat(msg, (char *)"\"");
23f959713fcb Added websockets for node status changes.
Michiel Broek <mbroek@mbse.eu>
parents: 578
diff changeset
206 if (node->net_rssi != 0) {
23f959713fcb Added websockets for node status changes.
Michiel Broek <mbroek@mbse.eu>
parents: 578
diff changeset
207 msg = xstrcat(msg, (char *)",\"rssi\":");
23f959713fcb Added websockets for node status changes.
Michiel Broek <mbroek@mbse.eu>
parents: 578
diff changeset
208 snprintf(buf, 64, "%d", node->net_rssi);
23f959713fcb Added websockets for node status changes.
Michiel Broek <mbroek@mbse.eu>
parents: 578
diff changeset
209 msg = xstrcat(msg, buf);
23f959713fcb Added websockets for node status changes.
Michiel Broek <mbroek@mbse.eu>
parents: 578
diff changeset
210 }
23f959713fcb Added websockets for node status changes.
Michiel Broek <mbroek@mbse.eu>
parents: 578
diff changeset
211 msg = xstrcat(msg, (char *)"}");
23f959713fcb Added websockets for node status changes.
Michiel Broek <mbroek@mbse.eu>
parents: 578
diff changeset
212 ws_broadcast(msg);
23f959713fcb Added websockets for node status changes.
Michiel Broek <mbroek@mbse.eu>
parents: 578
diff changeset
213 free(msg);
23f959713fcb Added websockets for node status changes.
Michiel Broek <mbroek@mbse.eu>
parents: 578
diff changeset
214 msg = NULL;
23f959713fcb Added websockets for node status changes.
Michiel Broek <mbroek@mbse.eu>
parents: 578
diff changeset
215
0
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
216 // node_dump(node);
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
217
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
218 if (new_node) {
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
219 if (nodes == NULL) {
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
220 nodes = node;
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
221 } else {
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
222 for (tmpp = nodes; tmpp; tmpp = tmpp->next) {
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
223 if (tmpp->next == NULL) {
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
224 tmpp->next = node;
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
225 break;
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
226 }
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
227 }
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
228 }
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
229 node_mysql_insert(node);
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
230 } else {
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
231 node_mysql_update(node);
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
232 }
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
233 }
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
234
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
235
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
236
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
237 void node_dump(sys_node_list *node)
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
238 {
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
239 if (debug) {
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
240 printf("online %s\n", node->online ? "yes":"no");
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
241 printf("uuid %s\n", node->uuid);
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
242 printf("node %s\n", node->node);
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
243 printf("group %s\n", node->group_id);
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
244 printf("hw make %s model %s\n", node->hardwaremake, node->hardwaremodel);
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
245 printf("os %s version %s\n", node->os, node->os_version);
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
246 printf("firmware %s\n", node->firmware);
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
247 printf("first %ld last %ld\n", node->firstseen, node->lastseen);
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
248 printf("THB %.2f %.2f %.2f\n", node->temperature, node->humidity, node->barometer);
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
249 printf("GPS %.5f %.5f %.5f\n", node->gps_latitude, node->gps_longitude, node->gps_altitude);
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
250 printf("net %s:%s\n", node->net_ifname, node->net_address);
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
251 printf("rssi %d\n", node->net_rssi);
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
252 printf("interval %d\n", node->interval);
0
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
253 }
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
254 }
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
255
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
256
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
257
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
258 void node_death(char *topic)
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
259 {
672
23f959713fcb Added websockets for node status changes.
Michiel Broek <mbroek@mbse.eu>
parents: 578
diff changeset
260 char *group_id, *edge_node, *msg;
0
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
261 sys_node_list *tmpp;
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
262
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
263 strtok(topic, "/"); // ignore namespace
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
264 group_id = strtok(NULL, "/");
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
265 strtok(NULL, "/"); // ignore message_type
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
266 edge_node = strtok(NULL, "/\0");
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
267
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
268 syslog(LOG_NOTICE, "Offline node `%s/%s'", group_id, edge_node);
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
269 node_mysql_death(edge_node);
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
270
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
271 for (tmpp = nodes; tmpp; tmpp = tmpp->next) {
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
272 if (strcmp(tmpp->node, edge_node) == 0) {
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
273 tmpp->online = false;
672
23f959713fcb Added websockets for node status changes.
Michiel Broek <mbroek@mbse.eu>
parents: 578
diff changeset
274 msg = xstrcpy((char *)"{\"node\":\"");
23f959713fcb Added websockets for node status changes.
Michiel Broek <mbroek@mbse.eu>
parents: 578
diff changeset
275 msg = xstrcat(msg, edge_node);
23f959713fcb Added websockets for node status changes.
Michiel Broek <mbroek@mbse.eu>
parents: 578
diff changeset
276 msg = xstrcat(msg, (char *)"\",\"group\":\"");
23f959713fcb Added websockets for node status changes.
Michiel Broek <mbroek@mbse.eu>
parents: 578
diff changeset
277 msg = xstrcat(msg, group_id);
23f959713fcb Added websockets for node status changes.
Michiel Broek <mbroek@mbse.eu>
parents: 578
diff changeset
278 msg = xstrcat(msg, (char *)"\",\"online\":0}");
23f959713fcb Added websockets for node status changes.
Michiel Broek <mbroek@mbse.eu>
parents: 578
diff changeset
279 ws_broadcast(msg);
23f959713fcb Added websockets for node status changes.
Michiel Broek <mbroek@mbse.eu>
parents: 578
diff changeset
280 free(msg);
23f959713fcb Added websockets for node status changes.
Michiel Broek <mbroek@mbse.eu>
parents: 578
diff changeset
281 msg = NULL;
0
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
282 break;
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
283 }
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
284 }
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
285 }
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
286
033898178630 Versio 0.0.2 initial check in
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
287
384
442d23455ae4 The bms daemon now checks if a node went away of no data is received for 10 minutes.
Michiel Broek <mbroek@mbse.eu>
parents: 0
diff changeset
288
442d23455ae4 The bms daemon now checks if a node went away of no data is received for 10 minutes.
Michiel Broek <mbroek@mbse.eu>
parents: 0
diff changeset
289 void nodes_check_online()
442d23455ae4 The bms daemon now checks if a node went away of no data is received for 10 minutes.
Michiel Broek <mbroek@mbse.eu>
parents: 0
diff changeset
290 {
442d23455ae4 The bms daemon now checks if a node went away of no data is received for 10 minutes.
Michiel Broek <mbroek@mbse.eu>
parents: 0
diff changeset
291 sys_node_list *tmpn;
442d23455ae4 The bms daemon now checks if a node went away of no data is received for 10 minutes.
Michiel Broek <mbroek@mbse.eu>
parents: 0
diff changeset
292 sys_fermenter_list *tmpf;
502
a8a6901b5a99 Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents: 384
diff changeset
293 sys_co2meter_list *tmpc;
572
7a03181d29a3 Version 0.3.27 More code for iSpindels. All online/offline data in the database is now handles as integers. Nodes timeout use the configured interval time from the nodes.
Michiel Broek <mbroek@mbse.eu>
parents: 502
diff changeset
294 sys_ispindel_list *tmpi;
384
442d23455ae4 The bms daemon now checks if a node went away of no data is received for 10 minutes.
Michiel Broek <mbroek@mbse.eu>
parents: 0
diff changeset
295 time_t now = time(NULL);
672
23f959713fcb Added websockets for node status changes.
Michiel Broek <mbroek@mbse.eu>
parents: 578
diff changeset
296 char *msg = NULL;
684
ccb9f24d0fe9 Report any online status change via websocket broadcast. When starting, load all in memory tables sorted. The websocket status on the web pages has it's own panel. Prepared the menu system for dynamic updates.
Michiel Broek <mbroek@mbse.eu>
parents: 677
diff changeset
297 bool report = false;
384
442d23455ae4 The bms daemon now checks if a node went away of no data is received for 10 minutes.
Michiel Broek <mbroek@mbse.eu>
parents: 0
diff changeset
298
442d23455ae4 The bms daemon now checks if a node went away of no data is received for 10 minutes.
Michiel Broek <mbroek@mbse.eu>
parents: 0
diff changeset
299 for (tmpn = nodes; tmpn; tmpn = tmpn->next) {
578
e75ce5bbda73 Changed the interface from the iSpindels to be the same as other devices. A webpage converts each call to two standard MQTT messages. The nodes MQTT message extended with an interval parameter. iSpindels now have a generated uuid made up from the chipid.
Michiel Broek <mbroek@mbse.eu>
parents: 572
diff changeset
300 // if (debug)
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
301 // printf("%-20s online %s %ld %d\n", tmpn->node, tmpn->online ? "yes":"no ", tmpn->lastseen, tmpn->interval);
572
7a03181d29a3 Version 0.3.27 More code for iSpindels. All online/offline data in the database is now handles as integers. Nodes timeout use the configured interval time from the nodes.
Michiel Broek <mbroek@mbse.eu>
parents: 502
diff changeset
302 if (tmpn->online && ((now - tmpn->lastseen) > (tmpn->interval * 2 + 5))) { // 2 times interval + 5 seconds
7a03181d29a3 Version 0.3.27 More code for iSpindels. All online/offline data in the database is now handles as integers. Nodes timeout use the configured interval time from the nodes.
Michiel Broek <mbroek@mbse.eu>
parents: 502
diff changeset
303 syslog(LOG_NOTICE, "Timeout node `%s/%s' after %ld seconds", tmpn->group_id, tmpn->node, (now - tmpn->lastseen));
684
ccb9f24d0fe9 Report any online status change via websocket broadcast. When starting, load all in memory tables sorted. The websocket status on the web pages has it's own panel. Prepared the menu system for dynamic updates.
Michiel Broek <mbroek@mbse.eu>
parents: 677
diff changeset
304 report = true;
384
442d23455ae4 The bms daemon now checks if a node went away of no data is received for 10 minutes.
Michiel Broek <mbroek@mbse.eu>
parents: 0
diff changeset
305 tmpn->online = false;
442d23455ae4 The bms daemon now checks if a node went away of no data is received for 10 minutes.
Michiel Broek <mbroek@mbse.eu>
parents: 0
diff changeset
306 node_mysql_death(tmpn->node);
672
23f959713fcb Added websockets for node status changes.
Michiel Broek <mbroek@mbse.eu>
parents: 578
diff changeset
307 msg = xstrcpy((char *)"{\"node\":\"");
23f959713fcb Added websockets for node status changes.
Michiel Broek <mbroek@mbse.eu>
parents: 578
diff changeset
308 msg = xstrcat(msg, tmpn->node);
23f959713fcb Added websockets for node status changes.
Michiel Broek <mbroek@mbse.eu>
parents: 578
diff changeset
309 msg = xstrcat(msg, (char *)"\",\"group\":\"");
23f959713fcb Added websockets for node status changes.
Michiel Broek <mbroek@mbse.eu>
parents: 578
diff changeset
310 msg = xstrcat(msg, tmpn->group_id);
23f959713fcb Added websockets for node status changes.
Michiel Broek <mbroek@mbse.eu>
parents: 578
diff changeset
311 msg = xstrcat(msg, (char *)"\",\"online\":0}");
23f959713fcb Added websockets for node status changes.
Michiel Broek <mbroek@mbse.eu>
parents: 578
diff changeset
312 ws_broadcast(msg);
675
a27af02ab16a Added iSpindel to the websockets. Better offline detection for websockets.
Michiel Broek <mbroek@mbse.eu>
parents: 673
diff changeset
313 syslog(LOG_NOTICE, msg);
672
23f959713fcb Added websockets for node status changes.
Michiel Broek <mbroek@mbse.eu>
parents: 578
diff changeset
314 free(msg);
23f959713fcb Added websockets for node status changes.
Michiel Broek <mbroek@mbse.eu>
parents: 578
diff changeset
315 msg = NULL;
384
442d23455ae4 The bms daemon now checks if a node went away of no data is received for 10 minutes.
Michiel Broek <mbroek@mbse.eu>
parents: 0
diff changeset
316
442d23455ae4 The bms daemon now checks if a node went away of no data is received for 10 minutes.
Michiel Broek <mbroek@mbse.eu>
parents: 0
diff changeset
317 for (tmpf = fermenters; tmpf; tmpf = tmpf->next) {
442d23455ae4 The bms daemon now checks if a node went away of no data is received for 10 minutes.
Michiel Broek <mbroek@mbse.eu>
parents: 0
diff changeset
318 if (strcmp(tmpf->node, tmpn->node) == 0) {
442d23455ae4 The bms daemon now checks if a node went away of no data is received for 10 minutes.
Michiel Broek <mbroek@mbse.eu>
parents: 0
diff changeset
319 if (tmpf->online) {
442d23455ae4 The bms daemon now checks if a node went away of no data is received for 10 minutes.
Michiel Broek <mbroek@mbse.eu>
parents: 0
diff changeset
320 syslog(LOG_NOTICE, "Timeout fermenter %s/%s", tmpf->node, tmpf->alias);
442d23455ae4 The bms daemon now checks if a node went away of no data is received for 10 minutes.
Michiel Broek <mbroek@mbse.eu>
parents: 0
diff changeset
321 tmpf->online = false;
442d23455ae4 The bms daemon now checks if a node went away of no data is received for 10 minutes.
Michiel Broek <mbroek@mbse.eu>
parents: 0
diff changeset
322 fermenter_mysql_death(tmpf->node, tmpf->alias);
677
6e82fece1f8f Consistent use of group names is important.
Michiel Broek <mbroek@mbse.eu>
parents: 675
diff changeset
323 msg = xstrcpy((char *)"{\"device\":\"fermenters\",\"node\":\"");
673
9924b1218d39 Added co2meters to the websockets. Added node and units offline messages to the websockets.
Michiel Broek <mbroek@mbse.eu>
parents: 672
diff changeset
324 msg = xstrcat(msg, tmpf->node);
9924b1218d39 Added co2meters to the websockets. Added node and units offline messages to the websockets.
Michiel Broek <mbroek@mbse.eu>
parents: 672
diff changeset
325 msg = xstrcat(msg, (char *)"\",\"unit\":\"");
9924b1218d39 Added co2meters to the websockets. Added node and units offline messages to the websockets.
Michiel Broek <mbroek@mbse.eu>
parents: 672
diff changeset
326 msg = xstrcat(msg, tmpf->alias);
9924b1218d39 Added co2meters to the websockets. Added node and units offline messages to the websockets.
Michiel Broek <mbroek@mbse.eu>
parents: 672
diff changeset
327 msg = xstrcat(msg, (char *)"\",\"online\":0}");
9924b1218d39 Added co2meters to the websockets. Added node and units offline messages to the websockets.
Michiel Broek <mbroek@mbse.eu>
parents: 672
diff changeset
328 ws_broadcast(msg);
675
a27af02ab16a Added iSpindel to the websockets. Better offline detection for websockets.
Michiel Broek <mbroek@mbse.eu>
parents: 673
diff changeset
329 syslog(LOG_NOTICE, msg);
673
9924b1218d39 Added co2meters to the websockets. Added node and units offline messages to the websockets.
Michiel Broek <mbroek@mbse.eu>
parents: 672
diff changeset
330 free(msg);
9924b1218d39 Added co2meters to the websockets. Added node and units offline messages to the websockets.
Michiel Broek <mbroek@mbse.eu>
parents: 672
diff changeset
331 msg = NULL;
384
442d23455ae4 The bms daemon now checks if a node went away of no data is received for 10 minutes.
Michiel Broek <mbroek@mbse.eu>
parents: 0
diff changeset
332 }
442d23455ae4 The bms daemon now checks if a node went away of no data is received for 10 minutes.
Michiel Broek <mbroek@mbse.eu>
parents: 0
diff changeset
333 }
442d23455ae4 The bms daemon now checks if a node went away of no data is received for 10 minutes.
Michiel Broek <mbroek@mbse.eu>
parents: 0
diff changeset
334 }
502
a8a6901b5a99 Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents: 384
diff changeset
335
a8a6901b5a99 Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents: 384
diff changeset
336 for (tmpc = co2meters; tmpc; tmpc = tmpc->next) {
a8a6901b5a99 Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents: 384
diff changeset
337 if (strcmp(tmpc->node, tmpn->node) == 0) {
a8a6901b5a99 Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents: 384
diff changeset
338 if (tmpc->online) {
a8a6901b5a99 Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents: 384
diff changeset
339 syslog(LOG_NOTICE, "Timeout co2meter %s/%s", tmpc->node, tmpc->alias);
a8a6901b5a99 Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents: 384
diff changeset
340 tmpc->online = false;
a8a6901b5a99 Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents: 384
diff changeset
341 co2meter_mysql_death(tmpc->node, tmpc->alias);
677
6e82fece1f8f Consistent use of group names is important.
Michiel Broek <mbroek@mbse.eu>
parents: 675
diff changeset
342 msg = xstrcpy((char *)"{\"device\":\"co2meters\",\"node\":\"");
673
9924b1218d39 Added co2meters to the websockets. Added node and units offline messages to the websockets.
Michiel Broek <mbroek@mbse.eu>
parents: 672
diff changeset
343 msg = xstrcat(msg, tmpc->node);
9924b1218d39 Added co2meters to the websockets. Added node and units offline messages to the websockets.
Michiel Broek <mbroek@mbse.eu>
parents: 672
diff changeset
344 msg = xstrcat(msg, (char *)"\",\"unit\":\"");
9924b1218d39 Added co2meters to the websockets. Added node and units offline messages to the websockets.
Michiel Broek <mbroek@mbse.eu>
parents: 672
diff changeset
345 msg = xstrcat(msg, tmpc->alias);
9924b1218d39 Added co2meters to the websockets. Added node and units offline messages to the websockets.
Michiel Broek <mbroek@mbse.eu>
parents: 672
diff changeset
346 msg = xstrcat(msg, (char *)"\",\"online\":0}");
9924b1218d39 Added co2meters to the websockets. Added node and units offline messages to the websockets.
Michiel Broek <mbroek@mbse.eu>
parents: 672
diff changeset
347 ws_broadcast(msg);
675
a27af02ab16a Added iSpindel to the websockets. Better offline detection for websockets.
Michiel Broek <mbroek@mbse.eu>
parents: 673
diff changeset
348 syslog(LOG_NOTICE, msg);
673
9924b1218d39 Added co2meters to the websockets. Added node and units offline messages to the websockets.
Michiel Broek <mbroek@mbse.eu>
parents: 672
diff changeset
349 free(msg);
9924b1218d39 Added co2meters to the websockets. Added node and units offline messages to the websockets.
Michiel Broek <mbroek@mbse.eu>
parents: 672
diff changeset
350 msg = NULL;
502
a8a6901b5a99 Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents: 384
diff changeset
351 }
a8a6901b5a99 Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents: 384
diff changeset
352 }
a8a6901b5a99 Added CO2 meter units to the daemon.
Michiel Broek <mbroek@mbse.eu>
parents: 384
diff changeset
353 }
572
7a03181d29a3 Version 0.3.27 More code for iSpindels. All online/offline data in the database is now handles as integers. Nodes timeout use the configured interval time from the nodes.
Michiel Broek <mbroek@mbse.eu>
parents: 502
diff changeset
354
7a03181d29a3 Version 0.3.27 More code for iSpindels. All online/offline data in the database is now handles as integers. Nodes timeout use the configured interval time from the nodes.
Michiel Broek <mbroek@mbse.eu>
parents: 502
diff changeset
355 for (tmpi = ispindels; tmpi; tmpi = tmpi->next) {
7a03181d29a3 Version 0.3.27 More code for iSpindels. All online/offline data in the database is now handles as integers. Nodes timeout use the configured interval time from the nodes.
Michiel Broek <mbroek@mbse.eu>
parents: 502
diff changeset
356 if (strcmp(tmpi->node, tmpn->node) == 0) {
7a03181d29a3 Version 0.3.27 More code for iSpindels. All online/offline data in the database is now handles as integers. Nodes timeout use the configured interval time from the nodes.
Michiel Broek <mbroek@mbse.eu>
parents: 502
diff changeset
357 if (tmpi->online) {
7a03181d29a3 Version 0.3.27 More code for iSpindels. All online/offline data in the database is now handles as integers. Nodes timeout use the configured interval time from the nodes.
Michiel Broek <mbroek@mbse.eu>
parents: 502
diff changeset
358 syslog(LOG_NOTICE, "Timeout ispindel %s", tmpi->node);
7a03181d29a3 Version 0.3.27 More code for iSpindels. All online/offline data in the database is now handles as integers. Nodes timeout use the configured interval time from the nodes.
Michiel Broek <mbroek@mbse.eu>
parents: 502
diff changeset
359 tmpi->online = false;
7a03181d29a3 Version 0.3.27 More code for iSpindels. All online/offline data in the database is now handles as integers. Nodes timeout use the configured interval time from the nodes.
Michiel Broek <mbroek@mbse.eu>
parents: 502
diff changeset
360 ispindel_mysql_death(tmpi->node);
677
6e82fece1f8f Consistent use of group names is important.
Michiel Broek <mbroek@mbse.eu>
parents: 675
diff changeset
361 msg = xstrcpy((char *)"{\"device\":\"ispindels\",\"node\":\"");
673
9924b1218d39 Added co2meters to the websockets. Added node and units offline messages to the websockets.
Michiel Broek <mbroek@mbse.eu>
parents: 672
diff changeset
362 msg = xstrcat(msg, tmpi->node);
9924b1218d39 Added co2meters to the websockets. Added node and units offline messages to the websockets.
Michiel Broek <mbroek@mbse.eu>
parents: 672
diff changeset
363 msg = xstrcat(msg, (char *)"\",\"unit\":\"");
9924b1218d39 Added co2meters to the websockets. Added node and units offline messages to the websockets.
Michiel Broek <mbroek@mbse.eu>
parents: 672
diff changeset
364 msg = xstrcat(msg, tmpi->alias);
9924b1218d39 Added co2meters to the websockets. Added node and units offline messages to the websockets.
Michiel Broek <mbroek@mbse.eu>
parents: 672
diff changeset
365 msg = xstrcat(msg, (char *)"\",\"online\":0}");
9924b1218d39 Added co2meters to the websockets. Added node and units offline messages to the websockets.
Michiel Broek <mbroek@mbse.eu>
parents: 672
diff changeset
366 ws_broadcast(msg);
675
a27af02ab16a Added iSpindel to the websockets. Better offline detection for websockets.
Michiel Broek <mbroek@mbse.eu>
parents: 673
diff changeset
367 syslog(LOG_NOTICE, msg);
673
9924b1218d39 Added co2meters to the websockets. Added node and units offline messages to the websockets.
Michiel Broek <mbroek@mbse.eu>
parents: 672
diff changeset
368 free(msg);
9924b1218d39 Added co2meters to the websockets. Added node and units offline messages to the websockets.
Michiel Broek <mbroek@mbse.eu>
parents: 672
diff changeset
369 msg = NULL;
572
7a03181d29a3 Version 0.3.27 More code for iSpindels. All online/offline data in the database is now handles as integers. Nodes timeout use the configured interval time from the nodes.
Michiel Broek <mbroek@mbse.eu>
parents: 502
diff changeset
370 }
7a03181d29a3 Version 0.3.27 More code for iSpindels. All online/offline data in the database is now handles as integers. Nodes timeout use the configured interval time from the nodes.
Michiel Broek <mbroek@mbse.eu>
parents: 502
diff changeset
371 }
7a03181d29a3 Version 0.3.27 More code for iSpindels. All online/offline data in the database is now handles as integers. Nodes timeout use the configured interval time from the nodes.
Michiel Broek <mbroek@mbse.eu>
parents: 502
diff changeset
372 }
384
442d23455ae4 The bms daemon now checks if a node went away of no data is received for 10 minutes.
Michiel Broek <mbroek@mbse.eu>
parents: 0
diff changeset
373 }
442d23455ae4 The bms daemon now checks if a node went away of no data is received for 10 minutes.
Michiel Broek <mbroek@mbse.eu>
parents: 0
diff changeset
374 }
684
ccb9f24d0fe9 Report any online status change via websocket broadcast. When starting, load all in memory tables sorted. The websocket status on the web pages has it's own panel. Prepared the menu system for dynamic updates.
Michiel Broek <mbroek@mbse.eu>
parents: 677
diff changeset
375
ccb9f24d0fe9 Report any online status change via websocket broadcast. When starting, load all in memory tables sorted. The websocket status on the web pages has it's own panel. Prepared the menu system for dynamic updates.
Michiel Broek <mbroek@mbse.eu>
parents: 677
diff changeset
376 if (report)
ccb9f24d0fe9 Report any online status change via websocket broadcast. When starting, load all in memory tables sorted. The websocket status on the web pages has it's own panel. Prepared the menu system for dynamic updates.
Michiel Broek <mbroek@mbse.eu>
parents: 677
diff changeset
377 status_change();
384
442d23455ae4 The bms daemon now checks if a node went away of no data is received for 10 minutes.
Michiel Broek <mbroek@mbse.eu>
parents: 0
diff changeset
378 }
442d23455ae4 The bms daemon now checks if a node went away of no data is received for 10 minutes.
Michiel Broek <mbroek@mbse.eu>
parents: 0
diff changeset
379
442d23455ae4 The bms daemon now checks if a node went away of no data is received for 10 minutes.
Michiel Broek <mbroek@mbse.eu>
parents: 0
diff changeset
380
684
ccb9f24d0fe9 Report any online status change via websocket broadcast. When starting, load all in memory tables sorted. The websocket status on the web pages has it's own panel. Prepared the menu system for dynamic updates.
Michiel Broek <mbroek@mbse.eu>
parents: 677
diff changeset
381
ccb9f24d0fe9 Report any online status change via websocket broadcast. When starting, load all in memory tables sorted. The websocket status on the web pages has it's own panel. Prepared the menu system for dynamic updates.
Michiel Broek <mbroek@mbse.eu>
parents: 677
diff changeset
382 void status_change(void)
ccb9f24d0fe9 Report any online status change via websocket broadcast. When starting, load all in memory tables sorted. The websocket status on the web pages has it's own panel. Prepared the menu system for dynamic updates.
Michiel Broek <mbroek@mbse.eu>
parents: 677
diff changeset
383 {
ccb9f24d0fe9 Report any online status change via websocket broadcast. When starting, load all in memory tables sorted. The websocket status on the web pages has it's own panel. Prepared the menu system for dynamic updates.
Michiel Broek <mbroek@mbse.eu>
parents: 677
diff changeset
384 sys_node_list *tmpn;
ccb9f24d0fe9 Report any online status change via websocket broadcast. When starting, load all in memory tables sorted. The websocket status on the web pages has it's own panel. Prepared the menu system for dynamic updates.
Michiel Broek <mbroek@mbse.eu>
parents: 677
diff changeset
385 sys_fermenter_list *tmpf;
ccb9f24d0fe9 Report any online status change via websocket broadcast. When starting, load all in memory tables sorted. The websocket status on the web pages has it's own panel. Prepared the menu system for dynamic updates.
Michiel Broek <mbroek@mbse.eu>
parents: 677
diff changeset
386 sys_co2meter_list *tmpc;
ccb9f24d0fe9 Report any online status change via websocket broadcast. When starting, load all in memory tables sorted. The websocket status on the web pages has it's own panel. Prepared the menu system for dynamic updates.
Michiel Broek <mbroek@mbse.eu>
parents: 677
diff changeset
387 sys_ispindel_list *tmpi;
ccb9f24d0fe9 Report any online status change via websocket broadcast. When starting, load all in memory tables sorted. The websocket status on the web pages has it's own panel. Prepared the menu system for dynamic updates.
Michiel Broek <mbroek@mbse.eu>
parents: 677
diff changeset
388 char *msg = NULL;
ccb9f24d0fe9 Report any online status change via websocket broadcast. When starting, load all in memory tables sorted. The websocket status on the web pages has it's own panel. Prepared the menu system for dynamic updates.
Michiel Broek <mbroek@mbse.eu>
parents: 677
diff changeset
389 bool comma = false;
ccb9f24d0fe9 Report any online status change via websocket broadcast. When starting, load all in memory tables sorted. The websocket status on the web pages has it's own panel. Prepared the menu system for dynamic updates.
Michiel Broek <mbroek@mbse.eu>
parents: 677
diff changeset
390
ccb9f24d0fe9 Report any online status change via websocket broadcast. When starting, load all in memory tables sorted. The websocket status on the web pages has it's own panel. Prepared the menu system for dynamic updates.
Michiel Broek <mbroek@mbse.eu>
parents: 677
diff changeset
391 msg = xstrcpy((char *)"{\"status\":{\"nodes\":[");
ccb9f24d0fe9 Report any online status change via websocket broadcast. When starting, load all in memory tables sorted. The websocket status on the web pages has it's own panel. Prepared the menu system for dynamic updates.
Michiel Broek <mbroek@mbse.eu>
parents: 677
diff changeset
392
ccb9f24d0fe9 Report any online status change via websocket broadcast. When starting, load all in memory tables sorted. The websocket status on the web pages has it's own panel. Prepared the menu system for dynamic updates.
Michiel Broek <mbroek@mbse.eu>
parents: 677
diff changeset
393 for (tmpn = nodes; tmpn; tmpn = tmpn->next) {
ccb9f24d0fe9 Report any online status change via websocket broadcast. When starting, load all in memory tables sorted. The websocket status on the web pages has it's own panel. Prepared the menu system for dynamic updates.
Michiel Broek <mbroek@mbse.eu>
parents: 677
diff changeset
394 if (comma)
ccb9f24d0fe9 Report any online status change via websocket broadcast. When starting, load all in memory tables sorted. The websocket status on the web pages has it's own panel. Prepared the menu system for dynamic updates.
Michiel Broek <mbroek@mbse.eu>
parents: 677
diff changeset
395 msg = xstrcat(msg, (char *)",");
ccb9f24d0fe9 Report any online status change via websocket broadcast. When starting, load all in memory tables sorted. The websocket status on the web pages has it's own panel. Prepared the menu system for dynamic updates.
Michiel Broek <mbroek@mbse.eu>
parents: 677
diff changeset
396 comma = true;
ccb9f24d0fe9 Report any online status change via websocket broadcast. When starting, load all in memory tables sorted. The websocket status on the web pages has it's own panel. Prepared the menu system for dynamic updates.
Michiel Broek <mbroek@mbse.eu>
parents: 677
diff changeset
397 msg = xstrcat(msg, (char *)"{\"uuid\":\"");
ccb9f24d0fe9 Report any online status change via websocket broadcast. When starting, load all in memory tables sorted. The websocket status on the web pages has it's own panel. Prepared the menu system for dynamic updates.
Michiel Broek <mbroek@mbse.eu>
parents: 677
diff changeset
398 msg = xstrcat(msg, tmpn->uuid);
ccb9f24d0fe9 Report any online status change via websocket broadcast. When starting, load all in memory tables sorted. The websocket status on the web pages has it's own panel. Prepared the menu system for dynamic updates.
Michiel Broek <mbroek@mbse.eu>
parents: 677
diff changeset
399 msg = xstrcat(msg, (char *)"\",\"node\":\"");
ccb9f24d0fe9 Report any online status change via websocket broadcast. When starting, load all in memory tables sorted. The websocket status on the web pages has it's own panel. Prepared the menu system for dynamic updates.
Michiel Broek <mbroek@mbse.eu>
parents: 677
diff changeset
400 msg = xstrcat(msg, tmpn->node);
ccb9f24d0fe9 Report any online status change via websocket broadcast. When starting, load all in memory tables sorted. The websocket status on the web pages has it's own panel. Prepared the menu system for dynamic updates.
Michiel Broek <mbroek@mbse.eu>
parents: 677
diff changeset
401 msg = xstrcat(msg, (char *)"\",\"online\":");
ccb9f24d0fe9 Report any online status change via websocket broadcast. When starting, load all in memory tables sorted. The websocket status on the web pages has it's own panel. Prepared the menu system for dynamic updates.
Michiel Broek <mbroek@mbse.eu>
parents: 677
diff changeset
402 msg = xstrcat(msg, (tmpn->online) ? (char *)"1":(char *)"0");
ccb9f24d0fe9 Report any online status change via websocket broadcast. When starting, load all in memory tables sorted. The websocket status on the web pages has it's own panel. Prepared the menu system for dynamic updates.
Michiel Broek <mbroek@mbse.eu>
parents: 677
diff changeset
403 msg = xstrcat(msg, (char *)"}");
ccb9f24d0fe9 Report any online status change via websocket broadcast. When starting, load all in memory tables sorted. The websocket status on the web pages has it's own panel. Prepared the menu system for dynamic updates.
Michiel Broek <mbroek@mbse.eu>
parents: 677
diff changeset
404 }
ccb9f24d0fe9 Report any online status change via websocket broadcast. When starting, load all in memory tables sorted. The websocket status on the web pages has it's own panel. Prepared the menu system for dynamic updates.
Michiel Broek <mbroek@mbse.eu>
parents: 677
diff changeset
405
ccb9f24d0fe9 Report any online status change via websocket broadcast. When starting, load all in memory tables sorted. The websocket status on the web pages has it's own panel. Prepared the menu system for dynamic updates.
Michiel Broek <mbroek@mbse.eu>
parents: 677
diff changeset
406 msg = xstrcat(msg, (char *)"],\"fermenters\":[");
ccb9f24d0fe9 Report any online status change via websocket broadcast. When starting, load all in memory tables sorted. The websocket status on the web pages has it's own panel. Prepared the menu system for dynamic updates.
Michiel Broek <mbroek@mbse.eu>
parents: 677
diff changeset
407 comma = false;
ccb9f24d0fe9 Report any online status change via websocket broadcast. When starting, load all in memory tables sorted. The websocket status on the web pages has it's own panel. Prepared the menu system for dynamic updates.
Michiel Broek <mbroek@mbse.eu>
parents: 677
diff changeset
408 for (tmpf = fermenters; tmpf; tmpf = tmpf->next) {
ccb9f24d0fe9 Report any online status change via websocket broadcast. When starting, load all in memory tables sorted. The websocket status on the web pages has it's own panel. Prepared the menu system for dynamic updates.
Michiel Broek <mbroek@mbse.eu>
parents: 677
diff changeset
409 if (comma)
ccb9f24d0fe9 Report any online status change via websocket broadcast. When starting, load all in memory tables sorted. The websocket status on the web pages has it's own panel. Prepared the menu system for dynamic updates.
Michiel Broek <mbroek@mbse.eu>
parents: 677
diff changeset
410 msg = xstrcat(msg, (char *)",");
ccb9f24d0fe9 Report any online status change via websocket broadcast. When starting, load all in memory tables sorted. The websocket status on the web pages has it's own panel. Prepared the menu system for dynamic updates.
Michiel Broek <mbroek@mbse.eu>
parents: 677
diff changeset
411 comma = true;
ccb9f24d0fe9 Report any online status change via websocket broadcast. When starting, load all in memory tables sorted. The websocket status on the web pages has it's own panel. Prepared the menu system for dynamic updates.
Michiel Broek <mbroek@mbse.eu>
parents: 677
diff changeset
412 msg = xstrcat(msg, (char *)"{\"uuid\":\"");
ccb9f24d0fe9 Report any online status change via websocket broadcast. When starting, load all in memory tables sorted. The websocket status on the web pages has it's own panel. Prepared the menu system for dynamic updates.
Michiel Broek <mbroek@mbse.eu>
parents: 677
diff changeset
413 msg = xstrcat(msg, tmpf->uuid);
ccb9f24d0fe9 Report any online status change via websocket broadcast. When starting, load all in memory tables sorted. The websocket status on the web pages has it's own panel. Prepared the menu system for dynamic updates.
Michiel Broek <mbroek@mbse.eu>
parents: 677
diff changeset
414 msg = xstrcat(msg, (char *)"\",\"node\":\"");
ccb9f24d0fe9 Report any online status change via websocket broadcast. When starting, load all in memory tables sorted. The websocket status on the web pages has it's own panel. Prepared the menu system for dynamic updates.
Michiel Broek <mbroek@mbse.eu>
parents: 677
diff changeset
415 msg = xstrcat(msg, tmpf->node);
ccb9f24d0fe9 Report any online status change via websocket broadcast. When starting, load all in memory tables sorted. The websocket status on the web pages has it's own panel. Prepared the menu system for dynamic updates.
Michiel Broek <mbroek@mbse.eu>
parents: 677
diff changeset
416 msg = xstrcat(msg, (char *)"\",\"unit\":\"");
ccb9f24d0fe9 Report any online status change via websocket broadcast. When starting, load all in memory tables sorted. The websocket status on the web pages has it's own panel. Prepared the menu system for dynamic updates.
Michiel Broek <mbroek@mbse.eu>
parents: 677
diff changeset
417 msg = xstrcat(msg, tmpf->alias);
ccb9f24d0fe9 Report any online status change via websocket broadcast. When starting, load all in memory tables sorted. The websocket status on the web pages has it's own panel. Prepared the menu system for dynamic updates.
Michiel Broek <mbroek@mbse.eu>
parents: 677
diff changeset
418 msg = xstrcat(msg, (char *)"\",\"online\":");
ccb9f24d0fe9 Report any online status change via websocket broadcast. When starting, load all in memory tables sorted. The websocket status on the web pages has it's own panel. Prepared the menu system for dynamic updates.
Michiel Broek <mbroek@mbse.eu>
parents: 677
diff changeset
419 msg = xstrcat(msg, (tmpf->online) ? (char *)"1":(char *)"0");
ccb9f24d0fe9 Report any online status change via websocket broadcast. When starting, load all in memory tables sorted. The websocket status on the web pages has it's own panel. Prepared the menu system for dynamic updates.
Michiel Broek <mbroek@mbse.eu>
parents: 677
diff changeset
420 msg = xstrcat(msg, (char *)"}");
ccb9f24d0fe9 Report any online status change via websocket broadcast. When starting, load all in memory tables sorted. The websocket status on the web pages has it's own panel. Prepared the menu system for dynamic updates.
Michiel Broek <mbroek@mbse.eu>
parents: 677
diff changeset
421 }
ccb9f24d0fe9 Report any online status change via websocket broadcast. When starting, load all in memory tables sorted. The websocket status on the web pages has it's own panel. Prepared the menu system for dynamic updates.
Michiel Broek <mbroek@mbse.eu>
parents: 677
diff changeset
422
ccb9f24d0fe9 Report any online status change via websocket broadcast. When starting, load all in memory tables sorted. The websocket status on the web pages has it's own panel. Prepared the menu system for dynamic updates.
Michiel Broek <mbroek@mbse.eu>
parents: 677
diff changeset
423 msg = xstrcat(msg, (char *)"],\"co2meters\":[");
ccb9f24d0fe9 Report any online status change via websocket broadcast. When starting, load all in memory tables sorted. The websocket status on the web pages has it's own panel. Prepared the menu system for dynamic updates.
Michiel Broek <mbroek@mbse.eu>
parents: 677
diff changeset
424 comma = false;
ccb9f24d0fe9 Report any online status change via websocket broadcast. When starting, load all in memory tables sorted. The websocket status on the web pages has it's own panel. Prepared the menu system for dynamic updates.
Michiel Broek <mbroek@mbse.eu>
parents: 677
diff changeset
425 for (tmpc = co2meters; tmpc; tmpc = tmpc->next) {
ccb9f24d0fe9 Report any online status change via websocket broadcast. When starting, load all in memory tables sorted. The websocket status on the web pages has it's own panel. Prepared the menu system for dynamic updates.
Michiel Broek <mbroek@mbse.eu>
parents: 677
diff changeset
426 if (comma)
ccb9f24d0fe9 Report any online status change via websocket broadcast. When starting, load all in memory tables sorted. The websocket status on the web pages has it's own panel. Prepared the menu system for dynamic updates.
Michiel Broek <mbroek@mbse.eu>
parents: 677
diff changeset
427 msg = xstrcat(msg, (char *)",");
ccb9f24d0fe9 Report any online status change via websocket broadcast. When starting, load all in memory tables sorted. The websocket status on the web pages has it's own panel. Prepared the menu system for dynamic updates.
Michiel Broek <mbroek@mbse.eu>
parents: 677
diff changeset
428 comma = true;
ccb9f24d0fe9 Report any online status change via websocket broadcast. When starting, load all in memory tables sorted. The websocket status on the web pages has it's own panel. Prepared the menu system for dynamic updates.
Michiel Broek <mbroek@mbse.eu>
parents: 677
diff changeset
429 msg = xstrcat(msg, (char *)"{\"uuid\":\"");
ccb9f24d0fe9 Report any online status change via websocket broadcast. When starting, load all in memory tables sorted. The websocket status on the web pages has it's own panel. Prepared the menu system for dynamic updates.
Michiel Broek <mbroek@mbse.eu>
parents: 677
diff changeset
430 msg = xstrcat(msg, tmpc->uuid);
ccb9f24d0fe9 Report any online status change via websocket broadcast. When starting, load all in memory tables sorted. The websocket status on the web pages has it's own panel. Prepared the menu system for dynamic updates.
Michiel Broek <mbroek@mbse.eu>
parents: 677
diff changeset
431 msg = xstrcat(msg, (char *)"\",\"node\":\"");
ccb9f24d0fe9 Report any online status change via websocket broadcast. When starting, load all in memory tables sorted. The websocket status on the web pages has it's own panel. Prepared the menu system for dynamic updates.
Michiel Broek <mbroek@mbse.eu>
parents: 677
diff changeset
432 msg = xstrcat(msg, tmpc->node);
ccb9f24d0fe9 Report any online status change via websocket broadcast. When starting, load all in memory tables sorted. The websocket status on the web pages has it's own panel. Prepared the menu system for dynamic updates.
Michiel Broek <mbroek@mbse.eu>
parents: 677
diff changeset
433 msg = xstrcat(msg, (char *)"\",\"unit\":\"");
ccb9f24d0fe9 Report any online status change via websocket broadcast. When starting, load all in memory tables sorted. The websocket status on the web pages has it's own panel. Prepared the menu system for dynamic updates.
Michiel Broek <mbroek@mbse.eu>
parents: 677
diff changeset
434 msg = xstrcat(msg, tmpc->alias);
ccb9f24d0fe9 Report any online status change via websocket broadcast. When starting, load all in memory tables sorted. The websocket status on the web pages has it's own panel. Prepared the menu system for dynamic updates.
Michiel Broek <mbroek@mbse.eu>
parents: 677
diff changeset
435 msg = xstrcat(msg, (char *)"\",\"online\":");
ccb9f24d0fe9 Report any online status change via websocket broadcast. When starting, load all in memory tables sorted. The websocket status on the web pages has it's own panel. Prepared the menu system for dynamic updates.
Michiel Broek <mbroek@mbse.eu>
parents: 677
diff changeset
436 msg = xstrcat(msg, (tmpc->online) ? (char *)"1":(char *)"0");
ccb9f24d0fe9 Report any online status change via websocket broadcast. When starting, load all in memory tables sorted. The websocket status on the web pages has it's own panel. Prepared the menu system for dynamic updates.
Michiel Broek <mbroek@mbse.eu>
parents: 677
diff changeset
437 msg = xstrcat(msg, (char *)"}");
ccb9f24d0fe9 Report any online status change via websocket broadcast. When starting, load all in memory tables sorted. The websocket status on the web pages has it's own panel. Prepared the menu system for dynamic updates.
Michiel Broek <mbroek@mbse.eu>
parents: 677
diff changeset
438 }
ccb9f24d0fe9 Report any online status change via websocket broadcast. When starting, load all in memory tables sorted. The websocket status on the web pages has it's own panel. Prepared the menu system for dynamic updates.
Michiel Broek <mbroek@mbse.eu>
parents: 677
diff changeset
439
ccb9f24d0fe9 Report any online status change via websocket broadcast. When starting, load all in memory tables sorted. The websocket status on the web pages has it's own panel. Prepared the menu system for dynamic updates.
Michiel Broek <mbroek@mbse.eu>
parents: 677
diff changeset
440 msg = xstrcat(msg, (char *)"],\"ispindels\":[");
ccb9f24d0fe9 Report any online status change via websocket broadcast. When starting, load all in memory tables sorted. The websocket status on the web pages has it's own panel. Prepared the menu system for dynamic updates.
Michiel Broek <mbroek@mbse.eu>
parents: 677
diff changeset
441 comma = false;
ccb9f24d0fe9 Report any online status change via websocket broadcast. When starting, load all in memory tables sorted. The websocket status on the web pages has it's own panel. Prepared the menu system for dynamic updates.
Michiel Broek <mbroek@mbse.eu>
parents: 677
diff changeset
442 for (tmpi = ispindels; tmpi; tmpi = tmpi->next) {
ccb9f24d0fe9 Report any online status change via websocket broadcast. When starting, load all in memory tables sorted. The websocket status on the web pages has it's own panel. Prepared the menu system for dynamic updates.
Michiel Broek <mbroek@mbse.eu>
parents: 677
diff changeset
443 if (comma)
ccb9f24d0fe9 Report any online status change via websocket broadcast. When starting, load all in memory tables sorted. The websocket status on the web pages has it's own panel. Prepared the menu system for dynamic updates.
Michiel Broek <mbroek@mbse.eu>
parents: 677
diff changeset
444 msg = xstrcat(msg, (char *)",");
ccb9f24d0fe9 Report any online status change via websocket broadcast. When starting, load all in memory tables sorted. The websocket status on the web pages has it's own panel. Prepared the menu system for dynamic updates.
Michiel Broek <mbroek@mbse.eu>
parents: 677
diff changeset
445 comma = true;
ccb9f24d0fe9 Report any online status change via websocket broadcast. When starting, load all in memory tables sorted. The websocket status on the web pages has it's own panel. Prepared the menu system for dynamic updates.
Michiel Broek <mbroek@mbse.eu>
parents: 677
diff changeset
446 msg = xstrcat(msg, (char *)"{\"uuid\":\"");
ccb9f24d0fe9 Report any online status change via websocket broadcast. When starting, load all in memory tables sorted. The websocket status on the web pages has it's own panel. Prepared the menu system for dynamic updates.
Michiel Broek <mbroek@mbse.eu>
parents: 677
diff changeset
447 msg = xstrcat(msg, tmpi->uuid);
ccb9f24d0fe9 Report any online status change via websocket broadcast. When starting, load all in memory tables sorted. The websocket status on the web pages has it's own panel. Prepared the menu system for dynamic updates.
Michiel Broek <mbroek@mbse.eu>
parents: 677
diff changeset
448 msg = xstrcat(msg, (char *)"\",\"node\":\"");
ccb9f24d0fe9 Report any online status change via websocket broadcast. When starting, load all in memory tables sorted. The websocket status on the web pages has it's own panel. Prepared the menu system for dynamic updates.
Michiel Broek <mbroek@mbse.eu>
parents: 677
diff changeset
449 msg = xstrcat(msg, tmpi->node);
ccb9f24d0fe9 Report any online status change via websocket broadcast. When starting, load all in memory tables sorted. The websocket status on the web pages has it's own panel. Prepared the menu system for dynamic updates.
Michiel Broek <mbroek@mbse.eu>
parents: 677
diff changeset
450 msg = xstrcat(msg, (char *)"\",\"unit\":\"");
ccb9f24d0fe9 Report any online status change via websocket broadcast. When starting, load all in memory tables sorted. The websocket status on the web pages has it's own panel. Prepared the menu system for dynamic updates.
Michiel Broek <mbroek@mbse.eu>
parents: 677
diff changeset
451 msg = xstrcat(msg, tmpi->alias);
ccb9f24d0fe9 Report any online status change via websocket broadcast. When starting, load all in memory tables sorted. The websocket status on the web pages has it's own panel. Prepared the menu system for dynamic updates.
Michiel Broek <mbroek@mbse.eu>
parents: 677
diff changeset
452 msg = xstrcat(msg, (char *)"\",\"online\":");
ccb9f24d0fe9 Report any online status change via websocket broadcast. When starting, load all in memory tables sorted. The websocket status on the web pages has it's own panel. Prepared the menu system for dynamic updates.
Michiel Broek <mbroek@mbse.eu>
parents: 677
diff changeset
453 msg = xstrcat(msg, (tmpi->online) ? (char *)"1":(char *)"0");
ccb9f24d0fe9 Report any online status change via websocket broadcast. When starting, load all in memory tables sorted. The websocket status on the web pages has it's own panel. Prepared the menu system for dynamic updates.
Michiel Broek <mbroek@mbse.eu>
parents: 677
diff changeset
454 msg = xstrcat(msg, (char *)"}");
ccb9f24d0fe9 Report any online status change via websocket broadcast. When starting, load all in memory tables sorted. The websocket status on the web pages has it's own panel. Prepared the menu system for dynamic updates.
Michiel Broek <mbroek@mbse.eu>
parents: 677
diff changeset
455 }
ccb9f24d0fe9 Report any online status change via websocket broadcast. When starting, load all in memory tables sorted. The websocket status on the web pages has it's own panel. Prepared the menu system for dynamic updates.
Michiel Broek <mbroek@mbse.eu>
parents: 677
diff changeset
456
ccb9f24d0fe9 Report any online status change via websocket broadcast. When starting, load all in memory tables sorted. The websocket status on the web pages has it's own panel. Prepared the menu system for dynamic updates.
Michiel Broek <mbroek@mbse.eu>
parents: 677
diff changeset
457 msg = xstrcat(msg, (char *)"]}}");
ccb9f24d0fe9 Report any online status change via websocket broadcast. When starting, load all in memory tables sorted. The websocket status on the web pages has it's own panel. Prepared the menu system for dynamic updates.
Michiel Broek <mbroek@mbse.eu>
parents: 677
diff changeset
458 // syslog(LOG_NOTICE, msg);
ccb9f24d0fe9 Report any online status change via websocket broadcast. When starting, load all in memory tables sorted. The websocket status on the web pages has it's own panel. Prepared the menu system for dynamic updates.
Michiel Broek <mbroek@mbse.eu>
parents: 677
diff changeset
459 ws_broadcast(msg);
ccb9f24d0fe9 Report any online status change via websocket broadcast. When starting, load all in memory tables sorted. The websocket status on the web pages has it's own panel. Prepared the menu system for dynamic updates.
Michiel Broek <mbroek@mbse.eu>
parents: 677
diff changeset
460 free(msg);
ccb9f24d0fe9 Report any online status change via websocket broadcast. When starting, load all in memory tables sorted. The websocket status on the web pages has it's own panel. Prepared the menu system for dynamic updates.
Michiel Broek <mbroek@mbse.eu>
parents: 677
diff changeset
461 msg = NULL;
ccb9f24d0fe9 Report any online status change via websocket broadcast. When starting, load all in memory tables sorted. The websocket status on the web pages has it's own panel. Prepared the menu system for dynamic updates.
Michiel Broek <mbroek@mbse.eu>
parents: 677
diff changeset
462 }
ccb9f24d0fe9 Report any online status change via websocket broadcast. When starting, load all in memory tables sorted. The websocket status on the web pages has it's own panel. Prepared the menu system for dynamic updates.
Michiel Broek <mbroek@mbse.eu>
parents: 677
diff changeset
463
ccb9f24d0fe9 Report any online status change via websocket broadcast. When starting, load all in memory tables sorted. The websocket status on the web pages has it's own panel. Prepared the menu system for dynamic updates.
Michiel Broek <mbroek@mbse.eu>
parents: 677
diff changeset
464

mercurial