From e6e79ca02d323e9a10f115ade7ba6ac9c0d7a3f0 Mon Sep 17 00:00:00 2001
From: guowenxue <guowenxue@gmail.com>
Date: Sat, 03 Aug 2019 18:17:33 +0800
Subject: [PATCH] Merge branch 'master' of ssh://master.iot-yun.club:2280/raspberrypi

---
 mqttd/main.c |   24 +++++++++++++++++++++++-
 1 files changed, 23 insertions(+), 1 deletions(-)

diff --git a/mqttd/main.c b/mqttd/main.c
index 98cf2d6..0d2522f 100644
--- a/mqttd/main.c
+++ b/mqttd/main.c
@@ -254,7 +254,8 @@
     mqtt_ctx_t             *ctx = (mqtt_ctx_t *)userdata;
     int                     rv = 0;
     char                    msg[128];  
-    float                   temp = 0.0;
+    float                   temp = 0.0; /* temperature */
+    float                   rh = 0.0;   /* relative humidity */
     int                     retain = 0;
 
     if( result )
@@ -274,6 +275,26 @@
         else 
             snprintf(msg, sizeof(msg), "{ \"id\":%s, \"temp\":\"%.2f\" }", ctx->id, temp);
 
+        rv = mosquitto_publish(mosq, NULL, ctx->pubTopic, strlen(msg), msg, ctx->pubQos, retain);
+        if( rv )
+        {
+            log_err("Publisher broadcast message '%s' failure: %d\n", msg, rv);
+        }
+        else 
+        {
+            log_nrml("Publisher broadcast message '%s' ok\n", msg);
+        }
+    }
+
+    if( ctx->hwconf.sht2x )
+    {
+        memset(msg, 0, sizeof(msg));
+        
+        if( sht2x_get_temp_humidity(&temp, &rh) < 0 )
+            snprintf(msg, sizeof(msg), "{ \"id\":%s, \"temp\":\"error\", \"RH\":\"error\" }", ctx->id);
+        else 
+            snprintf(msg, sizeof(msg), "{ \"id\":%s, \"temp\":\"%.2f\", \"RH\":\"%.2f\" }", ctx->id, temp, rh);
+
         rv = mosquitto_publish(mosq, NULL, ctx->pubTopic, strlen(msg)+1, msg, ctx->pubQos, retain);
         if( rv )
         {
@@ -284,6 +305,7 @@
             log_nrml("Publisher broadcast message '%s' ok\n", msg);
         }
     }
+
     
     log_nrml("Publisher broadcast over and disconnect broker now\n", ctx->host, ctx->port); 
     mosquitto_disconnect(mosq);

--
Gitblit v1.9.1