# HG changeset patch # User Michiel Broek # Date 1589289186 -7200 # Node ID a27af02ab16a2647bb62abcdfdf0a09e906e63b2 # Parent c865e3cdee049fd8c98cb4e3623c1c1569ff0b47 Added iSpindel to the websockets. Better offline detection for websockets. diff -r c865e3cdee04 -r a27af02ab16a bmsd/Makefile --- a/bmsd/Makefile Tue May 12 14:24:45 2020 +0200 +++ b/bmsd/Makefile Tue May 12 15:13:06 2020 +0200 @@ -61,7 +61,7 @@ futil.o: bms.h futil.h fermenters.o: bms.h xutil.h fermenters.h mysql.h websocket.h co2meters.o: bms.h xutil.h co2meters.h mysql.h websocket.h -ispindels.o: bms.h xutil.h ispindels.h mysql.h nodes.h +ispindels.o: bms.h xutil.h ispindels.h mysql.h nodes.h websocket.h bms.o: bms.h xutil.h futil.h rdconfig.h lock.h mqtt.h mysql.h nodes.h websocket.h xutil.o: bms.h xutil.h rdconfig.o: bms.h xutil.h futil.h rdconfig.h diff -r c865e3cdee04 -r a27af02ab16a bmsd/ispindels.c --- a/bmsd/ispindels.c Tue May 12 14:24:45 2020 +0200 +++ b/bmsd/ispindels.c Tue May 12 15:13:06 2020 +0200 @@ -28,6 +28,7 @@ #include "ispindels.h" #include "mysql.h" #include "nodes.h" +#include "websocket.h" sys_ispindel_list *ispindels = NULL; @@ -45,7 +46,7 @@ sys_ispindel_list *ispindel, *tmpp; struct json_object *jobj, *metric, *val; bool new_ispindel = true; - char *datetime, buf[65], *line, *logfile; + char *datetime, buf[65], *line, *logfile, *msg = NULL; struct tm *mytime; time_t timestamp; FILE *fp; @@ -121,6 +122,34 @@ } } + msg = xstrcpy((char *)"{\"device\":\"ispindel\",\"node\":\""); + msg = xstrcat(msg, node); + msg = xstrcat(msg, (char *)"\",\"unit\":\""); + msg = xstrcat(msg, ispindel->alias); + msg = xstrcat(msg, (char *)"\",\"online\":"); + msg = xstrcat(msg, ispindel->online ? (char *)"1":(char *)"0"); + msg = xstrcat(msg, (char *)",\"mode\":\""); + msg = xstrcat(msg, ispindel->mode); + msg = xstrcat(msg, (char *)"\",\"temperature\":"); + snprintf(buf, 64, "%.4f", ispindel->temperature); + msg = xstrcat(msg, buf); + msg = xstrcat(msg, (char *)",\"angle\":"); + snprintf(buf, 64, "%.5f", ispindel->angle); + msg = xstrcat(msg, buf); + msg = xstrcat(msg, (char *)",\"battery\":"); + snprintf(buf, 64, "%.6f", ispindel->battery); + msg = xstrcat(msg, buf); + msg = xstrcat(msg, (char *)",\"gravity\":"); + snprintf(buf, 64, "%.5f", ispindel->gravity); + msg = xstrcat(msg, buf); + msg = xstrcat(msg, (char *)",\"alarm\":"); + snprintf(buf, 64, "%d", ispindel->alarm); + msg = xstrcat(msg, buf); + msg = xstrcat(msg, (char *)"}"); + ws_broadcast(msg); + free(msg); + msg = NULL; + // ispindel_dump(ispindel); if (new_ispindel) { diff -r c865e3cdee04 -r a27af02ab16a bmsd/nodes.c --- a/bmsd/nodes.c Tue May 12 14:24:45 2020 +0200 +++ b/bmsd/nodes.c Tue May 12 15:13:06 2020 +0200 @@ -308,6 +308,7 @@ msg = xstrcat(msg, tmpn->group_id); msg = xstrcat(msg, (char *)"\",\"online\":0}"); ws_broadcast(msg); +syslog(LOG_NOTICE, msg); free(msg); msg = NULL; @@ -323,6 +324,7 @@ msg = xstrcat(msg, tmpf->alias); msg = xstrcat(msg, (char *)"\",\"online\":0}"); ws_broadcast(msg); +syslog(LOG_NOTICE, msg); free(msg); msg = NULL; } @@ -341,6 +343,7 @@ msg = xstrcat(msg, tmpc->alias); msg = xstrcat(msg, (char *)"\",\"online\":0}"); ws_broadcast(msg); +syslog(LOG_NOTICE, msg); free(msg); msg = NULL; } @@ -359,6 +362,7 @@ msg = xstrcat(msg, tmpi->alias); msg = xstrcat(msg, (char *)"\",\"online\":0}"); ws_broadcast(msg); +syslog(LOG_NOTICE, msg); free(msg); msg = NULL; } diff -r c865e3cdee04 -r a27af02ab16a bmsd/websocket.c --- a/bmsd/websocket.c Tue May 12 14:24:45 2020 +0200 +++ b/bmsd/websocket.c Tue May 12 15:13:06 2020 +0200 @@ -161,7 +161,7 @@ * {"node":"host","group":"group","online":1,"lastseen":"datetime","temperature":20.5,"humidity":47,"ip":"ipaddr","rssi":-1} * {"device":"fermenter","node":"seaport","unit":"unit0","online":1,"mode":"FRIDGE","yeast_lo":12.0,"yeast_hi":24.0,"air":19.875,"beer":19.812,"chiller":1.500,"heater":100,"cooler":0,"fan":100,"light":0,"door":0,"sp_lo":17.0,"sp_hi":17.5,"alarm":0,"stage":"PRIMARY"} * {"device":"co2meter","node":"seaport","unit":"unit0","online":1,"mode":"ON","temperature":20.875,"pressure_channel":6,"pressure_voltage":0.834,"pressure_zero":0.110,"pressure_bar":2.3,"alarm":0} - * {"device":"ispindel","node":"seaport","unit":"unit0","online":1,"mode":"ON","temperature":20.875,"tilt":45.223,"battery":4.121,"plato":14.832,"alarm":0} + * {"device":"ispindel","node":"seaport","unit":"unit0","online":1,"mode":"ON","temperature":20.875,"angle":45.223,"battery":4.121,"gravity":14.832,"alarm":0} */ void ws_broadcast(char *msg) {