From a574ce7edf7f31847be882f9f08dcd1ab8e5ebe0 Mon Sep 17 00:00:00 2001
From: guowenxue <guowenxue@gmail.com>
Date: Tue, 18 Nov 2025 16:00:47 +0800
Subject: [PATCH] update lightd and thingsboard
---
project/modules/relay.c | 1
project/thingsboard/thingsboard.c | 4 +-
project/thingsboard/etc/thingsboard.conf | 2
project/lightd/config.c | 22 ++++++-----
project/modules/sht20.c | 4 +-
project/lightd/config.h | 2
project/thingsboard/config.c | 22 ++++++-----
project/modules/pwm.c | 2 -
project/lightd/lightd.c | 4 +-
project/thingsboard/config.h | 2
project/thingsboard/makefile | 4 +-
11 files changed, 36 insertions(+), 33 deletions(-)
diff --git a/project/lightd/config.c b/project/lightd/config.c
index cb5aae8..c33dd7e 100644
--- a/project/lightd/config.c
+++ b/project/lightd/config.c
@@ -3,7 +3,7 @@
* All rights reserved.
*
* Filename: config.c
- * Description: This file is mqttd configure file parser function
+ * Description: This file is lightd configure file parser function
*
* Version: 1.0.0(2019年06月25日)
* Author: Guo Wenxue <guowenxue@gmail.com>
@@ -86,7 +86,7 @@
goto cleanup;
}
/* cJSON parser ID will get "" */
- snprintf(mqtt->devid, sizeof(mqtt->devid), "\"%s\"", str);
+ strncpy(mqtt->devid, str, sizeof(mqtt->devid));
log_info("Parser device ID [%s]\n", mqtt->devid);
@@ -158,17 +158,19 @@
mqtt->port = val;
log_info("Parser MQTT broker server [%s:%d]\n", mqtt->host, mqtt->port);
- str=iniparser_getstring(ini, "broker:token", NULL);
- strncpy(mqtt->token, str, sizeof(mqtt->uid) );
- log_info("Parser broker token [%s]\n", mqtt->token);
+ if( (str=iniparser_getstring(ini, "broker:token", NULL)) )
+ {
+ strncpy(mqtt->token, str, sizeof(mqtt->uid) );
+ log_info("Parser broker token [%s]\n", mqtt->token);
+ }
- str=iniparser_getstring(ini, "broker:username", NULL);
- strncpy(mqtt->uid, str, sizeof(mqtt->uid) );
+ if( (str=iniparser_getstring(ini, "broker:username", NULL)) )
+ strncpy(mqtt->uid, str, sizeof(mqtt->uid) );
- str=iniparser_getstring(ini, "broker:password", NULL);
- strncpy(mqtt->pwd, str, sizeof(mqtt->pwd) );
+ if( (str=iniparser_getstring(ini, "broker:password", NULL)) )
+ strncpy(mqtt->pwd, str, sizeof(mqtt->pwd) );
- if( mqtt->uid && mqtt->pwd )
+ if( mqtt->uid )
log_info("Parser broker account [%s:%s]\n", mqtt->uid, mqtt->pwd);
mqtt->keepalive = iniparser_getint(ini, "broker:keepalive", DEF_KEEPALIVE);
diff --git a/project/lightd/config.h b/project/lightd/config.h
index 5c0bc98..1c21700 100644
--- a/project/lightd/config.h
+++ b/project/lightd/config.h
@@ -3,7 +3,7 @@
* All rights reserved.
*
* Filename: config.h
- * Description: This file is mqttd configure file parser function
+ * Description: This file is lightd configure file parser function
*
* Version: 1.0.0(2019年06月25日)
* Author: Guo Wenxue <guowenxue@gmail.com>
diff --git a/project/lightd/lightd.c b/project/lightd/lightd.c
index e3df1ec..f4f9af7 100644
--- a/project/lightd/lightd.c
+++ b/project/lightd/lightd.c
@@ -2,8 +2,8 @@
* Copyright: (C) 2019 LingYun IoT System Studio
* All rights reserved.
*
- * Filename: main.c
- * Description: This file
+ * Filename: lightd.c
+ * Description: This file is infrared detect auto light program on RaspberryPi
*
* Version: 1.0.0(29/01/19)
* Author: Guo Wenxue <guowenxue@gmail.com>
diff --git a/project/modules/pwm.c b/project/modules/pwm.c
index ffaa7be..134b799 100644
--- a/project/modules/pwm.c
+++ b/project/modules/pwm.c
@@ -118,8 +118,6 @@
int init_pwm(int channel, int freq, int duty)
{
int rv;
- char buf[32];
- char path[256];
if( (rv=export_pwm(channel, 1)) )
{
diff --git a/project/modules/relay.c b/project/modules/relay.c
index 35695ae..97e494c 100644
--- a/project/modules/relay.c
+++ b/project/modules/relay.c
@@ -139,6 +139,7 @@
}
relay = &ctx.relay[which];
+ log_info("turn Led %s %s\n", relay->name, cmd?"on":"off");
if( OFF == cmd )
{
diff --git a/project/modules/sht20.c b/project/modules/sht20.c
index a96d0c6..4b6a585 100644
--- a/project/modules/sht20.c
+++ b/project/modules/sht20.c
@@ -90,7 +90,7 @@
memset(buf, 0, sizeof(buf));
i2c_read(fd, SHT20_I2CADDR, buf, 3);
- log_dump(LOG_LEVEL_TRACE, "Temperature sample data: ", buf, 3);
+ log_dump(LOG_LEVEL_TRACE, "Temperature sample data: ", (char *)buf, 3);
if( !sht20_checksum(buf, 2, buf[2]) )
{
@@ -113,7 +113,7 @@
memset(buf, 0, sizeof(buf));
i2c_read(fd, SHT20_I2CADDR, buf, 3);
- log_dump(LOG_LEVEL_TRACE, "Relative humidity sample data: ", buf, 3);
+ log_dump(LOG_LEVEL_TRACE, "Relative humidity sample data: ", (char *)buf, 3);
if( !sht20_checksum(buf, 2, buf[2]) )
{
diff --git a/project/thingsboard/config.c b/project/thingsboard/config.c
index 4115908..197f545 100644
--- a/project/thingsboard/config.c
+++ b/project/thingsboard/config.c
@@ -3,7 +3,7 @@
* All rights reserved.
*
* Filename: config.c
- * Description: This file is mqttd configure file parser function
+ * Description: This file is thingsboard configure file parser function
*
* Version: 1.0.0(2019年06月25日)
* Author: Guo Wenxue <guowenxue@gmail.com>
@@ -79,7 +79,7 @@
goto cleanup;
}
/* cJSON parser ID will get "" */
- snprintf(mqtt->devid, sizeof(mqtt->devid), "\"%s\"", str);
+ strncpy(mqtt->devid, str, sizeof(mqtt->devid));
log_info("Parser device ID [%s]\n", mqtt->devid);
@@ -150,17 +150,19 @@
mqtt->port = val;
log_info("Parser MQTT broker server [%s:%d]\n", mqtt->host, mqtt->port);
- str=iniparser_getstring(ini, "broker:token", NULL);
- strncpy(mqtt->token, str, sizeof(mqtt->uid) );
- log_info("Parser broker token [%s]\n", mqtt->token);
+ if( (str=iniparser_getstring(ini, "broker:token", NULL)) )
+ {
+ strncpy(mqtt->token, str, sizeof(mqtt->uid) );
+ log_info("Parser broker token [%s]\n", mqtt->token);
+ }
- str=iniparser_getstring(ini, "broker:username", NULL);
- strncpy(mqtt->uid, str, sizeof(mqtt->uid) );
+ if( (str=iniparser_getstring(ini, "broker:username", NULL)) )
+ strncpy(mqtt->uid, str, sizeof(mqtt->uid) );
- str=iniparser_getstring(ini, "broker:password", NULL);
- strncpy(mqtt->pwd, str, sizeof(mqtt->pwd) );
+ if( (str=iniparser_getstring(ini, "broker:password", NULL)) )
+ strncpy(mqtt->pwd, str, sizeof(mqtt->pwd) );
- if( mqtt->uid && mqtt->pwd )
+ if( mqtt->uid )
log_info("Parser broker account [%s:%s]\n", mqtt->uid, mqtt->pwd);
mqtt->keepalive = iniparser_getint(ini, "broker:keepalive", DEF_KEEPALIVE);
diff --git a/project/thingsboard/config.h b/project/thingsboard/config.h
index 6a57b08..7f9a43c 100644
--- a/project/thingsboard/config.h
+++ b/project/thingsboard/config.h
@@ -3,7 +3,7 @@
* All rights reserved.
*
* Filename: config.h
- * Description: This file is mqttd configure file parser function
+ * Description: This file is thingsboard configure file parser function
*
* Version: 1.0.0(2019年06月25日)
* Author: Guo Wenxue <guowenxue@gmail.com>
diff --git a/project/thingsboard/etc/thingsboard.conf b/project/thingsboard/etc/thingsboard.conf
index d218d64..2a8e579 100644
--- a/project/thingsboard/etc/thingsboard.conf
+++ b/project/thingsboard/etc/thingsboard.conf
@@ -1,7 +1,7 @@
[common]
devid="RaspberryPi#4B"
-# 树莓派连接的外设信息,0:禁用或未连接 其他: 使能或相关硬件连接的Pin管脚(wPI模式)
+# 树莓派连接的外设信息,0:禁用或未连接
[hardware]
# 是否使能 RGB 三色灯模块,0:禁用 1:使能
diff --git a/project/thingsboard/makefile b/project/thingsboard/makefile
index 796bb6c..f204d55 100644
--- a/project/thingsboard/makefile
+++ b/project/thingsboard/makefile
@@ -39,7 +39,7 @@
# libraries
libs=openlibs ${SRCS}
-LDFLAGS+=-lmosquitto -lcjson -lssl -lcrypto -lgpiod
+LDFLAGS+=-lmosquitto -lcjson -lssl -lcrypto -lgpiod -lm
LDFLAGS+=-lpthread
@@ -51,7 +51,7 @@
subdir:
@for dir in ${libs} ; do if [ ! -e $${dir} ] ; then ln -s ../$${dir}; fi; done
- @for dir in ${libs} ; do make -C $${dir} ; done
+ @for dir in ${libs} ; do CFLAGS="${CFLAGS}" make -C $${dir} ; done
install:
cp ${APP_NAME} /tftp
diff --git a/project/thingsboard/thingsboard.c b/project/thingsboard/thingsboard.c
index d1b4f41..7f59ea7 100644
--- a/project/thingsboard/thingsboard.c
+++ b/project/thingsboard/thingsboard.c
@@ -2,8 +2,8 @@
* Copyright: (C) 2019 LingYun IoT System Studio
* All rights reserved.
*
- * Filename: main.c
- * Description: This file
+ * Filename: thingsboard.c
+ * Description: This file is thingsboard platform device daemon program.
*
* Version: 1.0.0(29/01/19)
* Author: Guo Wenxue <guowenxue@gmail.com>
--
Gitblit v1.9.1