RaspberrPi project source code
guowenxue
8 hours ago a574ce7edf7f31847be882f9f08dcd1ab8e5ebe0
update lightd and thingsboard
11 files modified
53 ■■■■ changed files
project/lightd/config.c 14 ●●●●● patch | view | raw | blame | history
project/lightd/config.h 2 ●●● patch | view | raw | blame | history
project/lightd/lightd.c 4 ●●●● patch | view | raw | blame | history
project/modules/pwm.c 2 ●●●●● patch | view | raw | blame | history
project/modules/relay.c 1 ●●●● patch | view | raw | blame | history
project/modules/sht20.c 4 ●●●● patch | view | raw | blame | history
project/thingsboard/config.c 14 ●●●●● patch | view | raw | blame | history
project/thingsboard/config.h 2 ●●● patch | view | raw | blame | history
project/thingsboard/etc/thingsboard.conf 2 ●●● patch | view | raw | blame | history
project/thingsboard/makefile 4 ●●●● patch | view | raw | blame | history
project/thingsboard/thingsboard.c 4 ●●●● patch | view | raw | blame | history
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);
    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);
    if( (str=iniparser_getstring(ini, "broker:username", NULL)) )
    strncpy(mqtt->uid, str, sizeof(mqtt->uid) );
    str=iniparser_getstring(ini, "broker:password", NULL);
    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);
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>
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>
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)) )
    {
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 )
    {
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]) )
    {
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);
    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);
    if( (str=iniparser_getstring(ini, "broker:username", NULL)) )
    strncpy(mqtt->uid, str, sizeof(mqtt->uid) );
    str=iniparser_getstring(ini, "broker:password", NULL);
    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);
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>
project/thingsboard/etc/thingsboard.conf
@@ -1,7 +1,7 @@
[common]
devid="RaspberryPi#4B"
# 树莓派连接的外设信息,0:禁用或未连接  其他: 使能或相关硬件连接的Pin管脚(wPI模式)
# 树莓派连接的外设信息,0:禁用或未连接
[hardware]
# 是否使能 RGB 三色灯模块,0:禁用  1:使能
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
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>