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/lightd/config.c | 49 +++++++++++++++++++++++++++++++++----------------
1 files changed, 33 insertions(+), 16 deletions(-)
diff --git a/project/lightd/config.c b/project/lightd/config.c
index f9c646c..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);
@@ -94,7 +94,25 @@
*| parser hardware module configuration |
*+------------------------------------------------------+*/
- /* parser GPIO output pins */
+ /* DS18B20 temperature sensor status */
+ hwinfo->ds18b20=iniparser_getint(ini, "hardware:ds18b20", 0);
+ if( !hwinfo->ds18b20 )
+ log_warn("Parser DS18B20 temperature module disabled\n");
+ else
+ log_info("Parser DS18B20 temperature module enabled\n");
+
+ /* TSL2561 lux sensor status */
+ hwinfo->tsl2561=iniparser_getint(ini, "hardware:tsl2561", 0);
+ if( !hwinfo->tsl2561)
+ log_warn("Parser TSL2561 lux sensor module disabled\n");
+ else
+ log_info("Parser TSL2561 lux sensor module enabled\n");
+
+ /* TSL2561 lux sensor threshold value */
+ hwinfo->lux_threshold = iniparser_getdouble(ini, "hardware:lux_threshold", 0.1);
+ log_info("parser LUX enable and threshold value set be [%.03f]\n", hwinfo->lux_threshold);
+
+ /* parser GPIO output pins for relay */
if( !(str=iniparser_getstring(ini, "hardware:gpio_outpin", NULL)) )
{
log_warn("parser no GPIO output pins\n");
@@ -108,7 +126,7 @@
hwinfo->light_intval = iniparser_getint(ini, "hardware:light_intval", 20);
log_info("parser relay controled light interval time [%d]\n", hwinfo->light_intval);
- /* parser GPIO input pins */
+ /* parser GPIO input pins for infrared */
if( !(str=iniparser_getstring(ini, "hardware:gpio_inpin", NULL)) )
{
log_warn("parser no GPIO input pins\n");
@@ -118,10 +136,6 @@
parser_gpio_info(_TYPE_INPUT, &hwinfo->gpio, (char *)str);
log_info("parser [%d] GPIO input pins\n", hwinfo->gpio.incnt);
}
-
- hwinfo->lux_threshold = iniparser_getdouble(ini, "hardware:lux_threshold", 0.1);
- log_info("parser LUX enable and threshold value set be [%.03f]\n", hwinfo->lux_threshold);
-
/*+------------------------------------------------------+
*| parser broker settings |
@@ -144,17 +158,20 @@
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) );
+ 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 )
- log_info("Parser broker author by [%s:%s]\n", 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);
log_info("Parser broker keepalive timeout [%d] seconds\n", mqtt->keepalive);
--
Gitblit v1.9.1