开发者学堂课程【基于STM32的端到端物联网全栈开发:Paho MQTT 客户端接入阿里云物联网平台(1)】学习笔记,与课程紧密联系,让用户快速学习知识。
课程地址:https://developer.aliyun.com/learning/course/574/detail/7937
Paho MQTT 客户端接入阿里云物联网平台(1)
目录
一、课程场景
二、项目例程流程图
三、运行效果
一、课程场景
每5秒上报温湿度值,闪烁绿灯
温度超[阈值]亮红灯,并在每10秒向用户服务器报
警,直到温度恢复[阈值]以下或者收到警报解除消息
收到警报解除信息后红灯闪烁
温度恢复到[阈值]以下灭红灯
湿度值被阿里云 loT 转发到用户服务器,进行数据库存储,
同时在 web 端显示近期温湿度数据曲线
报警消息被阿里云 loT 转发到用户服务器,在 web 端显示
用户通过 web 端页面解除报警
用户通过 web 端页面设置[阙值]参数
二、项目例程流程图
三、运行效果
运行效果 – 节点端串口打印
AppIication parer. init. Send alarm when temprature>= 28 degrees Celsius,turn off Red LED when temprature<27 degrees Celsius
xxx WIFI connection xxx
Push the User button (B]ue) within the next 5 seconds if you want to upda
te the WIFI net work conf igurat ion.
( 若要重新配置wifl热点,需要5秒内按下 user 键)
Your WiF1 parameters need to be entered to proceed
Enter SSID: 输入热点名称和密码
You have entered as the ssid.
Enter. Security Mode (0 - Open, 1 WEP.2
一HPA. 3 - WPA2):3
You have entered 3 as the security mode
Enter password
Initializing the WiFi module.
firmware vers 1on 15 : basle. AT V2.1.2
ok
>WiFI module MAC address 15: BO:F8: 93: 17:BC:E2
Connecting to AP Attempt 1/3 …
Connected to AP
Retrleving the IP address.892.168.43.203(
热点连接成功)
Push the User button (Blue) wIthin the next 5 seconds If you want to upde
te the device security parameters or credentials
,
Start to enter A11 Device Parameters: Region ID, Product Key ,Device Name and Device Secret
Enter. Region ID: (example: n-shanghat cn-shangha)
若要连接到自己的 iot 设备,需要5秒内按下 user 键
cn- shanghai
Enter. Prgduct Key: (example: a1bosUexx )
a1 jAqF a0Zng
read:----)
a1 jAqF a0Zng
Enter. device name: (example: my devicenam
输入 regionID, ProductKey
5 mart thermometer
device name, device secre I
read: ---
5 mart the r momet er
Enter
bTuur
K4Fk&x
secret: (examples, 7o 76J3odUE7pPn e07dz xxxxxxxxxx )
read:
OTuurK4rWK3x
K-
MQTT server address Is :a1jAqF aOZng. lot -a5 -mqtt . cn-shanghal . al 1 yuncs . com
xx Start connectir.
MQTT server ww
Server address: a1 JAqF aQZng .1ot -as -mqt t . cn- shanghal. al lyuncs.com : 1883
TCP Connection in progress:
Attempt 1/3
计算 MQTT 服务器地址
connected to server
Processing HQTT Connect ion
HOTL Client ID is : bof 89317bce2 Isecurenode =3. s ignne t hod hnac s ha1
,t inestanp -82370
站算阿里云 loT 平台 MQTT 连接参数:
HQTT Us e rn ane
S nart t he rnone t e r8a 1jAqFaOZng
' MQTT Client ID
Cuntentraettemsldbaf 89317ce2deu iceNane
。Rart the rnone terproduc t Ke ya1 jAqFa0Zngt ines M不Cp9F358Fhame
key: OTuurK4rWK3x2
HQTT password gene rated succes S fully:809cf d7bf c1fa018
MQT T password
HQTT Connect ion At tenpt
subscribe to topic: /a1 jAqFaOZng/s nart t he rnone t e r/ enpThre S ho 1dSet
subscribe to topic: /a1 jAqFaOZng s nart t he rno ne t e r/C le arA larn
publish device status successfully : tenprature . 25. hunidity . 36
publish device status successfully : tenprature = 24. hunidity = 36
订阅两个主题:
publish device status successfully : tenprature = 24. hunidity = 36
1.温度报警门限值设置
publish device status successfully : tenprature
24. hunidity = 36
2清除报警
publish device status successfully : tenprature . 24, hunidity = 36
publish device status successfully : tenprature . 24, hunidity = 36
每5秒上报节点温湿度值
publish device status successfully : tenprature . 24, hunidity .36
publish device status successfully : tenprature = 24, hunidity = 36
publish device status successfully : tenprature = 24, hunidity = 36
publish device status successfully : tenprature . 24. hunidity = 36
publish device status successfully : tenprature . 24, hunidity - 36
publish device status successfully : tenprature . 24. hunidity = 36
运行效果-阿里云 lot 平台侧
设备名称为 “smarthermometer' 的节点上线
设备名称为 “smartthermometer’ 的节点每5秒发布一次消息
运行效果-应用服务器侧(用户修改温度报警阈值)
运行效果-节点端串口打印(温度阈值被改变,触发节点端报警行为)
publish device status successfully : tenprature . 24. hunidity .32
publish device status successfully : tenprature . 24. hunidity .37
publich device status cuccessfully : tenprature . 24. hunidity .37
publish device status successfully : tenprature = 24, hunidity = 37
[D]. HQTT payload received is:
收到订阅的主题的消息:温度阈值> 20
rece ived Tenprature thre sho 1d:20
publish tenpe rature alarn succes sfully : tenprature . 24
publish device status successfully : tenprature .24. hunidity .37
publich tenperature alarn successfully : tenprature . 24
publish device status successfully : tenprature .24. hunidity .37
节点设备发送“报警”事件给 loT 平台
publish device status successfully : tenprature . 24. hunidity = 37
publish terperature a larn successfully : tenprature . 24
publish device status successfully : tenprature . 24, hunidity .37
publish device status successfully : tenprature . 24. hunidity . 37
[D]. MQTT payload rece ived is:
收到订阅的主题的消息:清除报警
ClearAlarn ne. ase
pu
publsh deuIce SEaCus
successf w11
: tenprature .24. hunidity .37
节点设备停止发送“报警”事件给 IoT 平台
publish device status successfully : tenprature . 24. hunidity .37
publish device status successfully : tenprature . 24. hunidity .37
publish device status successfully : tenprature . 24. hunidity . 37