bmsd/ispindels.c

changeset 675
a27af02ab16a
parent 654
0aef416dbceb
child 677
6e82fece1f8f
--- 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) {

mercurial