From d399ece9a16d2c9fe053a07912037a770f9fe1e5 Mon Sep 17 00:00:00 2001 From: guowenxue <guowenxue@gmail.com> Date: Thu, 08 Aug 2019 13:06:23 +0800 Subject: [PATCH] Merge branch 'master' of ssh://master.iot-yun.club:2280/raspberrypi --- mqttd/etc/mqttd-02.conf | 71 +++++++++++++++++++++++++++++++++++ mqttd/hal/hal.h | 1 mqttd/main.c | 14 +++++- 3 files changed, 83 insertions(+), 3 deletions(-) diff --git a/mqttd/etc/mqttd-02.conf b/mqttd/etc/mqttd-02.conf new file mode 100644 index 0000000..0566e04 --- /dev/null +++ b/mqttd/etc/mqttd-02.conf @@ -0,0 +1,71 @@ +[common] +id="RPi.3B-GP-0002" + +# 树莓派连接的外设信息,0:禁用或未连接 其他: 使能或相关硬件连接的Pin管脚(wPI模式) +[hardware] + +# 是否使能硬件支持,如果是在X86上调试该程序,可以把该选项设置为0 +enable=1 + +# 控制蜂鸣器,0: 禁用 !0:蜂鸣器连接树莓派的wPI管脚编号, PIN#12(wPI 1#) can be used as PWM +beep_pin=1 + +# 蜂鸣器响的次数: 0: 不响 >0: 蜂鸣器响的次数 +beep_times=2 + +# RGB三色LED, 全0:禁用 !0: 三色LED相关引脚连接树莓派的wPI管脚编号 +red_pin=24 +green_pin=25 +blue_pin=23 + +# 是否使能 DS18b20 温度传感器模块,0:禁用 1:使能 +#ds18b20=1 + +# 是否使能 SHT2X 温湿度传感器模块,0:禁用 1:使能 +sht2x=1 + +[logger] + +# 日志记录文件 +file=/tmp/mqttd.log + +# 日志级别: 0:Disable 1:Fatal 2:ERROR 3:warnning 4:Normal 5:Debug 6:Infor 7:Trace +level=4 + +# 日志回滚大小 +size=1024 + + +[broker] + +# broker 服务器地址和端口号 +hostname="master.iot-yun.club" +port=10883 + +# broker 认证连接的用户名和密码 +username="lingyun" +password="lingyun-emb" + +# broker给subsciber和publisher发送PING报文保持 keepalive 的时间周期,单位是秒 +keepalive=30 + + +# Qos0: 发送者只发送一次消息,不进行重试,Broker不会返回确认消息。在Qos0情况下,Broker可能没有接受到消息 +# Qos1: 发送者最少发送一次消息,确保消息到达Broker,Broker需要返回确认消息PUBACK。在Qos1情况下,Broker可能接受到重复消息 +# Qos2: Qos2使用两阶段确认来保证消息的不丢失和不重复。在Qos2情况下,Broker肯定会收到消息,且只收到一次 + +[publisher] + +pubTopic="$Sys/Studio/Uplink" +pubQos=0 + +# Publisher上报传感器数据的周期,单位是秒 +interval=300 + +[subsciber] + +subTopic="$Sys/Studio/Downlink" +subQos=0 + + + diff --git a/mqttd/hal/hal.h b/mqttd/hal/hal.h index 37e1510..53e0826 100644 --- a/mqttd/hal/hal.h +++ b/mqttd/hal/hal.h @@ -22,6 +22,7 @@ #include "ds18b20.h" #include "sht20.h" #include "tsl2561.h" +#include "beep.h" #define OFF 0 #define ON 1 diff --git a/mqttd/main.c b/mqttd/main.c index 1692422..f021966 100644 --- a/mqttd/main.c +++ b/mqttd/main.c @@ -275,7 +275,7 @@ else snprintf(msg, sizeof(msg), "{ \"id\":%s, \"temp\":\"%.2f\" }", ctx->id, temp); - rv = mosquitto_publish(mosq, NULL, ctx->pubTopic, strlen(msg)+1, msg, ctx->pubQos, retain); + 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); @@ -295,7 +295,7 @@ 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); + 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); @@ -464,7 +464,15 @@ { if( strcasestr(value, "on") ) { - log_nrml("Turn buzzer on [%d] times\n", hwconf->beep_times); + turn_passive_beep(ON, BEEP_FREQ); + } + else if( strcasestr(value, "off") ) + { + turn_passive_beep(OFF, BEEP_FREQ); + } + else if( strcasestr(value, "music") ) + { + play_little_star(); } } -- Gitblit v1.9.1