From 0fa05ec9d808e1872a1c7d75bffeaa3114a3be61 Mon Sep 17 00:00:00 2001
From: guowenxue <guowenxue@gmail.com>
Date: Wed, 21 Apr 2021 16:22:53 +0800
Subject: [PATCH] Publisher test ok in iotd

---
 iotd/conf/conf.c |    1 +
 iotd/makefile    |    2 +-
 iotd/main.c      |   12 +++++-------
 3 files changed, 7 insertions(+), 8 deletions(-)

diff --git a/iotd/conf/conf.c b/iotd/conf/conf.c
index 6c3ebcf..7797af6 100644
--- a/iotd/conf/conf.c
+++ b/iotd/conf/conf.c
@@ -289,6 +289,7 @@
     {
         strncpy(mqtt_ctx->pubTopic, str, sizeof(mqtt_ctx->pubTopic) );
         mqtt_ctx->pubQos = iniparser_getint(ini, "publisher:pubQos", 0);
+        mqtt_ctx->interval = iniparser_getint(ini, "publisher:interval", 60);
         mqtt_ctx->pub_enable = 1;
 
         log_nrml("Parser publisher topic \"%s\" with Qos[%d]\n", mqtt_ctx->pubTopic, mqtt_ctx->pubQos);
diff --git a/iotd/main.c b/iotd/main.c
index 80e90e7..cbc0d85 100644
--- a/iotd/main.c
+++ b/iotd/main.c
@@ -31,7 +31,7 @@
 #define PROG_VERSION               "v1.0.0"
 #define DAEMON_PIDFILE             "/tmp/.iotd.pid"
 
-void control_thread_loop(void *ctx);
+void control_thread_loop(void *args);
 
 static void program_usage(char *progname)
 {
@@ -117,10 +117,8 @@
     }
     log_nrml("Initialise hardware okay.\n");
 
-    return 0;  /* todo: debug and removed  */
 
     install_default_signal();
-
     if( check_set_program_running(daemon, DAEMON_PIDFILE) < 0 ) 
         goto OUT;
 
@@ -142,7 +140,6 @@
             log_nrml("Start MQTT subsciber worker thread ok\n"); 
         }
     }
-
 
     /*+--------------------------------------------+
      *|  Start  MQTT publisher thread if enable    |
@@ -176,19 +173,19 @@
 
 void control_thread_loop(void *args)
 {
-    iotd_ctx_t            *ctx = (iotd_ctx_t *)ctx;
+    iotd_ctx_t            *ctx = (iotd_ctx_t *)args;
     hal_ctx_t             *hal_ctx;
     float                  lux = 0.0;
 
     hal_ctx = &ctx->hal_ctx;
-
-    log_nrml("Start control thread working...\n");
 
     while( ! g_signal.stop )
     { 
         if( hal_ctx->lux_enable )
         {
             lux = tsl2561_get_lux(); 
+            log_dbg("TSL2561 get Lux[%.3f].\n", lux);
+
             if( lux > hal_ctx->lux_threshold )
             {
                 log_nrml("Lux[%.3f] > Treshold[%.3f], don't need light on.\n", lux, hal_ctx->lux_threshold);
@@ -205,6 +202,7 @@
             log_nrml("Lux[%.3f] < Treshold[%.3f], auto light on now..\n", lux, hal_ctx->lux_threshold);
         }
 #endif
+        sleep(1);
     }
 }
 
diff --git a/iotd/makefile b/iotd/makefile
index 8386ab1..0977668 100644
--- a/iotd/makefile
+++ b/iotd/makefile
@@ -26,7 +26,7 @@
 export STRIP=${CROSSTOOL}strip
 export LDFLAGS
 
-DIRS= conf hal lylib mqtt
+DIRS= conf mqtt hal lylib
 
 DIRS_PATH=$(patsubst %,${PRJ_PATH}/%,$(DIRS))
 CFLAGS=$(patsubst %,-I%,$(DIRS_PATH))

--
Gitblit v1.9.1