bmsd/co2meters.c

changeset 673
9924b1218d39
parent 558
a8e065a9f851
child 677
6e82fece1f8f
--- a/bmsd/co2meters.c	Mon May 11 22:09:41 2020 +0200
+++ b/bmsd/co2meters.c	Tue May 12 13:16:25 2020 +0200
@@ -3,7 +3,7 @@
  * @brief Handle co2meters status
  * @author Michiel Broek <mbroek at mbse dot eu>
  *
- * Copyright (C) 2019
+ * Copyright (C) 2019-2020
  *
  * This file is part of the bms (Brewery Management System)
  *
@@ -27,6 +27,7 @@
 #include "xutil.h"
 #include "co2meters.h"
 #include "mysql.h"
+#include "websocket.h"
 
 
 sys_co2meter_list	*co2meters = NULL;
@@ -44,6 +45,7 @@
     struct json_object	*jobj, *val, *sensor;
     sys_co2meter_list	*co2meter, *tmpp;
     bool		new_co2meter = true;
+    char		*msg = NULL, buf[65];
 
 //    fprintf(stdout, "co2meter_set: %s/%s %s\n", edge_node, alias, payload);
 
@@ -137,6 +139,37 @@
     }
     json_object_put(jobj);
 
+    msg = xstrcpy((char *)"{\"device\":\"co2meter\",\"node\":\"");
+    msg = xstrcat(msg, edge_node);
+    msg = xstrcat(msg, (char *)"\",\"unit\":\"");
+    msg = xstrcat(msg, alias);
+    msg = xstrcat(msg, (char *)"\",\"online\":");
+    msg = xstrcat(msg, co2meter->online ? (char *)"1":(char *)"0");
+    msg = xstrcat(msg, (char *)",\"mode\":\"");
+    msg = xstrcat(msg, co2meter->mode);
+    msg = xstrcat(msg, (char *)"\",\"temperature\":");
+    snprintf(buf, 64, "%.3f", co2meter->temperature);
+    msg = xstrcat(msg, buf);
+    msg = xstrcat(msg, (char *)",\"pressure_channel\":");
+    snprintf(buf, 64, "%d", co2meter->pressure_channel);
+    msg = xstrcat(msg, buf);
+    msg = xstrcat(msg, (char *)",\"pressure_voltage\":");
+    snprintf(buf, 64, "%.3f", co2meter->pressure_voltage);
+    msg = xstrcat(msg, buf);
+    msg = xstrcat(msg, (char *)",\"pressure_zero\":");
+    snprintf(buf, 64, "%.3f", co2meter->pressure_zero);
+    msg = xstrcat(msg, buf);
+    msg = xstrcat(msg, (char *)",\"pressure_bar\":");
+    snprintf(buf, 64, "%.3f", co2meter->pressure_bar);
+    msg = xstrcat(msg, buf);
+    msg = xstrcat(msg, (char *)",\"alarm\":");
+    snprintf(buf, 64, "%d", co2meter->alarm);
+    msg = xstrcat(msg, buf);
+    msg = xstrcat(msg, (char *)"}");
+    ws_broadcast(msg);
+    free(msg);
+    msg = NULL;
+
 //    co2meter_dump(co2meter);
 
     if (new_co2meter) {

mercurial