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

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

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
6077 1
什么是Druid
|
数据采集 存储 传感器
IoT物联网设备端硬件上云技术方案详解
IoT物联网设备端硬件上云技术方案详解
9617 15
|
8月前
|
人工智能 自然语言处理 安全
Claude Code 全攻略:命令大全 + 实战工作流(建议收藏)
本文介绍了Claude Code终端AI助手的使用指南,主要内容包括:1)常用命令如版本查看、项目启动和更新;2)三种工作模式切换及界面说明;3)核心功能指令速查表,包含初始化、压缩对话、清除历史等操作;4)详细解析了/init、/help、/clear、/compact、/memory等关键命令的使用场景和语法。文章通过丰富的界面截图和场景示例,帮助开发者快速掌握如何通过命令行和交互界面高效使用Claude Code进行项目开发,特别强调了CLAUDE.md文件作为项目知识库的核心作用。
52877 73
Claude Code 全攻略:命令大全 + 实战工作流(建议收藏)
|
人工智能 缓存 安全
Claude Code 深度拆解:一个顶级AI编程工具的核心架构
Claude Code是由Anthropic开发的AI编程工具,集成于终端环境,支持代码编写、调试与项目管理。其核心功能包括自然语言交互、代码生成与优化、工具调用、上下文管理及安全控制。Claude Code通过智能处理用户指令,大幅提升开发效率,具备多模型协作与上下文压缩能力,适用于复杂项目场景。
35619 2
|
存储 网络协议 Nacos
高效搭建Nacos:实现微服务的服务注册与配置中心
Nacos(Dynamic Naming and Configuration Service)是阿里巴巴开源的一款动态服务发现、配置管理和服务管理平台。它旨在帮助开发者更轻松地构建、部署和管理分布式系统,特别是在微服务架构中。
3543 81
高效搭建Nacos:实现微服务的服务注册与配置中心
|
NoSQL Redis 数据安全/隐私保护
macos系统中redis如何设置密码
以上步骤应该可以帮助你在macOS系统的Redis服务中设置密码,确保你的数据存储更加安全。此外,确保你定期检查Redis安全性相关的最佳实践和更新,以保持你的服务安全可靠。
1464 3
|
人工智能 JavaScript 前端开发
字节最新AI 版IDE:用Trae开发网站打包信息追踪插件,国产版Cursor表现如何?
本文介绍了如何使用字节最新推出的AI编程工具Trae,通过零代码方式快速开发一款名为`dist-info`的前端插件。该插件能够将Git信息或自定义内容注入HTML文件中,兼容Webpack和Vite项目。开发者只需在浏览器控制台输入`info`,即可轻松查看代码的相关信息。文章详细描述了插件的背景、开发流程、核心代码实现以及优化建议,并展示了如何借助Trae高效完成项目搭建和代码编写。
3880 0
字节最新AI 版IDE:用Trae开发网站打包信息追踪插件,国产版Cursor表现如何?
|
传感器 消息中间件 网络协议
Paho MQTT 客户端接入阿里云物联网平台(2)| 学习笔记
快速学习 Paho MQTT 客户端接入阿里云物联网平台(2)
1773 1
Paho MQTT 客户端接入阿里云物联网平台(2)| 学习笔记

相关产品

  • 物联网平台