Paho MQTT 客户端接入阿里云物联网平台(1)| 学习笔记

简介: 快速学习 Paho MQTT 客户端接入阿里云物联网平台(1)

开发者学堂课程【基于STM32的端到端物联网全栈开发Paho MQTT 客户端接入阿里云物联网平台(1)】学习笔记,与课程紧密联系,让用户快速学习知识。

课程地址:https://developer.aliyun.com/learning/course/574/detail/7937


Paho MQTT 客户端接入阿里云物联网平台(1)


目录

一、课程场景

二、项目例程流程图

三、运行效果


一、课程场景

image.png

5秒上报温湿度值,闪烁绿灯

温度超[阈值]亮红灯,并在每10秒向用户服务器报

警,直到温度恢复[阈值]以下或者收到警报解除消息

收到警报解除信息后红灯闪烁

温度恢复到[阈值]以下灭红灯

湿度值被阿里云 loT 转发到用户服务器,进行数据库存储,

同时在 web 端显示近期温湿度数据曲线

报警消息被阿里云 loT 转发到用户服务器,在 web 端显示

用户通过 web 端页面解除报警

用户通过 web 端页面设置[阙值]参数


二、项目例程流程图

image.png


三、运行效果

运行效果 节点端串口打印

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.2HPA. 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

输入 regionIDProductKey

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 ha1t inestanp -82370

站算阿里云 loT 平台 MQTT 连接参数:

HQTT Us e rn ane

S nart t he rnone t e r8a 1jAqFaOZng

' MQTT Client ID

Cuntentraettemsldbaf 89317ce2deu iceNaneRart the rnone terproduc t Ke ya1 jAqFa0Zngt ines MCp9F358Fhame

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秒发布一次消息

运行效果-应用服务器侧(用户修改温度报警阈值)

image.png

运行效果-节点端串口打印(温度阈值被改变,触发节点端报警行为)

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

相关实践学习
快速体验阿里云云消息队列RocketMQ版
本实验将带您快速体验使用云消息队列RocketMQ版Serverless系列实例进行获取接入点、创建Topic、创建订阅组、收发消息、查看消息轨迹和仪表盘。
消息队列 MNS 入门课程
1、消息队列MNS简介 本节课介绍消息队列的MNS的基础概念 2、消息队列MNS特性 本节课介绍消息队列的MNS的主要特性 3、MNS的最佳实践及场景应用 本节课介绍消息队列的MNS的最佳实践及场景应用案例 4、手把手系列:消息队列MNS实操讲 本节课介绍消息队列的MNS的实际操作演示 5、动手实验:基于MNS,0基础轻松构建 Web Client 本节课带您一起基于MNS,0基础轻松构建 Web Client
相关文章
|
存储 SQL druid
什么是Druid
什么是Druid
5801 1
什么是Druid
|
物联网
通过微信小程序体验阿里云IoT物联网平台
通过微信小程序体验阿里云IoT物联网平台
10235 0
|
传感器 IDE 物联网
ESP8266接入阿里云物联网平台上传温湿度数据
本文章使用NodeMCU(ESP8266)开发板和SHTC3温湿度传感器接入阿里云物联网(IoT)平台,并上传读取到的温湿度数据。
23354 6
ESP8266接入阿里云物联网平台上传温湿度数据
|
存储 编译器 程序员
【C语言】内存布局大揭秘 ! -《堆、栈和你从未听说过的内存角落》
在C语言中,内存布局是程序运行时非常重要的概念。内存布局直接影响程序的性能、稳定性和安全性。理解C程序的内存布局,有助于编写更高效和可靠的代码。本文将详细介绍C程序的内存布局,包括代码段、数据段、堆、栈等部分,并提供相关的示例和应用。
804 5
【C语言】内存布局大揭秘 ! -《堆、栈和你从未听说过的内存角落》
|
前端开发 JavaScript 开发者
掌握 CSS 弹性布局(Flexbox):构建复杂页面布局的高效秘籍与实战案例
CSS弹性布局(Flexbox)是现代网页设计中构建复杂页面布局的高效工具。本文将深入浅出地介绍Flexbox的核心概念、使用技巧及实际应用案例,帮助读者快速掌握这一强大布局方法。
在Gazebo中添加悬浮模型后,利用键盘控制其移动方法
今天讲一下如何通过键盘来控制其移动:监听键盘输入并根据按键调整模型的位置,然后通过调用set_model_state函数来更新模型在Gazebo中的状态
952 0
|
NoSQL Redis 数据安全/隐私保护
macos系统中redis如何设置密码
以上步骤应该可以帮助你在macOS系统的Redis服务中设置密码,确保你的数据存储更加安全。此外,确保你定期检查Redis安全性相关的最佳实践和更新,以保持你的服务安全可靠。
1198 3
|
监控 网络协议 Linux
彻底解密:select,poll底层系统调用的核心思想原理
彻底解密:select,poll底层系统调用的核心思想原理
|
算法 安全 物联网
使用Paho-MQTT集成ID²,实现数据安全上云
IoT设备身份认证(IoT Device ID,ID²)是物联网设备接入到系统时的设备身份标识和设备认证系统,通过可信计算和密码技术为物联网系统提供设备认证、传输通道加密、业务数据加密等端到端的可信接入能力。 MQTT是一种基于发布/订阅模式的轻量级消息传输协议,专门针对低带宽和不稳定网络环境的物联网应用而设计,可以用极少的代码为联网设备提供实时可靠的消息服务。Eclipse Paho提供许多不同版本的MQTT Client以供不同平台使用,其中Paho Embedded-C是为嵌入式平台提供的MQTT开源实现。

相关产品

  • 物联网平台