bmsd/nodes.c

changeset 578
e75ce5bbda73
parent 572
7a03181d29a3
child 672
23f959713fcb
equal deleted inserted replaced
577:b4bfed3684d0 578:e75ce5bbda73
1 /** 1 /**
2 * @file nodes.c 2 * @file nodes.c
3 * @brief Handle nodes status 3 * @brief Handle nodes status
4 * @author Michiel Broek <mbroek at mbse dot eu> 4 * @author Michiel Broek <mbroek at mbse dot eu>
5 * 5 *
6 * Copyright (C) 2018-2019 6 * Copyright (C) 2018-2020
7 * 7 *
8 * This file is part of the bms (Brewery Management System) 8 * This file is part of the bms (Brewery Management System)
9 * 9 *
10 * This is free software; you can redistribute it and/or modify it 10 * This is free software; you can redistribute it and/or modify it
11 * under the terms of the GNU General Public License as published by the 11 * under the terms of the GNU General Public License as published by the
80 node->firstseen = node->lastseen = time(NULL); 80 node->firstseen = node->lastseen = time(NULL);
81 node->temperature = node->humidity = node->barometer = 0.0; 81 node->temperature = node->humidity = node->barometer = 0.0;
82 node->gps_latitude = node->gps_longitude = node->gps_altitude = 0.0; 82 node->gps_latitude = node->gps_longitude = node->gps_altitude = 0.0;
83 node->net_address = node->net_ifname = NULL; 83 node->net_address = node->net_ifname = NULL;
84 node->net_rssi = 0; 84 node->net_rssi = 0;
85 node->interval = 300;
85 } 86 }
86 87
87 /* 88 /*
88 * Process the JSON formatted payload. 89 * Process the JSON formatted payload.
89 * Update only the fields that are found in the payload. 90 * Update only the fields that are found in the payload.
108 if (json_object_object_get_ex(jobj, "metric", &metric)) { 109 if (json_object_object_get_ex(jobj, "metric", &metric)) {
109 if (json_object_object_get_ex(metric, "uuid", &val)) { 110 if (json_object_object_get_ex(metric, "uuid", &val)) {
110 if (node->uuid) 111 if (node->uuid)
111 free(node->uuid); 112 free(node->uuid);
112 node->uuid = xstrcpy((char *)json_object_get_string(val)); 113 node->uuid = xstrcpy((char *)json_object_get_string(val));
114 }
115 if (json_object_object_get_ex(metric, "interval", &val)) {
116 node->interval = json_object_get_int(val);
113 } 117 }
114 if (json_object_object_get_ex(metric, "properties", &metric2)) { 118 if (json_object_object_get_ex(metric, "properties", &metric2)) {
115 if (json_object_object_get_ex(metric2, "hardwaremake", &val)) { 119 if (json_object_object_get_ex(metric2, "hardwaremake", &val)) {
116 if (node->hardwaremake) 120 if (node->hardwaremake)
117 free(node->hardwaremake); 121 free(node->hardwaremake);
212 printf("first %ld last %ld\n", node->firstseen, node->lastseen); 216 printf("first %ld last %ld\n", node->firstseen, node->lastseen);
213 printf("THB %.2f %.2f %.2f\n", node->temperature, node->humidity, node->barometer); 217 printf("THB %.2f %.2f %.2f\n", node->temperature, node->humidity, node->barometer);
214 printf("GPS %.5f %.5f %.5f\n", node->gps_latitude, node->gps_longitude, node->gps_altitude); 218 printf("GPS %.5f %.5f %.5f\n", node->gps_latitude, node->gps_longitude, node->gps_altitude);
215 printf("net %s:%s\n", node->net_ifname, node->net_address); 219 printf("net %s:%s\n", node->net_ifname, node->net_address);
216 printf("rssi %d\n", node->net_rssi); 220 printf("rssi %d\n", node->net_rssi);
221 printf("interval %d\n", node->interval);
217 } 222 }
218 } 223 }
219 224
220 225
221 226
249 sys_co2meter_list *tmpc; 254 sys_co2meter_list *tmpc;
250 sys_ispindel_list *tmpi; 255 sys_ispindel_list *tmpi;
251 time_t now = time(NULL); 256 time_t now = time(NULL);
252 257
253 for (tmpn = nodes; tmpn; tmpn = tmpn->next) { 258 for (tmpn = nodes; tmpn; tmpn = tmpn->next) {
254 if (debug) 259 // if (debug)
255 printf("%-20s online %s %ld %d\n", tmpn->node, tmpn->online ? "yes":"no ", tmpn->lastseen, tmpn->interval); 260 // printf("%-20s online %s %ld %d\n", tmpn->node, tmpn->online ? "yes":"no ", tmpn->lastseen, tmpn->interval);
256 if (tmpn->online && ((now - tmpn->lastseen) > (tmpn->interval * 2 + 5))) { // 2 times interval + 5 seconds 261 if (tmpn->online && ((now - tmpn->lastseen) > (tmpn->interval * 2 + 5))) { // 2 times interval + 5 seconds
257 syslog(LOG_NOTICE, "Timeout node `%s/%s' after %ld seconds", tmpn->group_id, tmpn->node, (now - tmpn->lastseen)); 262 syslog(LOG_NOTICE, "Timeout node `%s/%s' after %ld seconds", tmpn->group_id, tmpn->node, (now - tmpn->lastseen));
258 tmpn->online = false; 263 tmpn->online = false;
259 node_mysql_death(tmpn->node); 264 node_mysql_death(tmpn->node);
260 265

mercurial