基于阿里云STM32L4R5ZI端到端物联网全栈开发学习笔记(2)2020/1/29

课时5:Paho MQTT客户端接入阿里云物联网平台

一、产品与设备的关系

在这里插入图片描述

二、物联网平台、网关和设备的关系的关系

在这里插入图片描述

三、在阿里云控制台注册一个产品与其设备

1.进入阿里云控制台:https://homenew.console.aliyun.com/

在这里插入图片描述

2.进入阿里云物联网平台创建产品

在这里插入图片描述

3.三元组概念:

在这里插入图片描述

4.创建设备

设备创建后,会生成唯一属于设备的三元组信息
在这里插入图片描述

5.为产品定义Topic类

Topic类会在后面讲MQTT协议时详细介绍,暂时理解为一个能传递信息的黑匣子
在这里插入图片描述
注册格式:
操作权限可选为发布订阅(都是以设备端为第一人称视角)
发布:设备端 向 阿里云平台 发送Topic类信息
订阅:阿里云平台 向 设备端 发送Topic类信息
在这里插入图片描述
本历程共需定义4个Topic类:
两个订阅:
clearAlarm:清除报警
tempThresholdSet:设置温度阈值
两个发布:
tempHumUpload:当前温度值
tempAlarm:温度报警
在这里插入图片描述

6.为产品创建服务端订阅

此功能是为了将云端数据通过HTTP发送到应用端(后端)
在这里插入图片描述
完成以上操作后,历程中所对应的云端部署已经完成
可以在设备平台查看三元组信息

四、将三元组信息,通过串口写入STM32的FLASH中,即完成设备端部署

串口工具:
在这里插入图片描述

Tera Term使用说明:https://blog.csdn.net/qq_38688850/article/details/104112323

串口打印信息如下:
有//的行是需要我们输入的WIFI和三元组信息,后面是备注,原程序中没有

**************************************************************************
***                   STM32 based AliIoT Client Demo                   ***
***                            Without TLS                             ***
***              FW version 1.1.1 - Nov  4 2019, 10:16:27              ***
**************************************************************************

Application parameter init. Send alarm when temprature>= 22 degrees Celsius,turn off Red LED when temprature<21 degrees Celsius

*** WIFI connection ***

Push the User button (Blue) within the next 5 seconds if you want to update the WiFi network configuration.  
  //按下蓝色按钮修改WIFI信息

Your WiFi parameters need to be entered to proceed.

Enter SSID: aliyun        //WIFI用户名
You have entered aliyun as the ssid.

Enter Security Mode (0 - Open, 1 - WEP, 2 - WPA, 3 - WPA2):3           //大多都是3 - WPA2,建议开热点,可以自己选择安全模式
You have entered 3 as the security mode.

Enter password: 123456789   //WIFI密码

Initializing the WiFi module
firmware version is : basic_AT_v2.1.2     //WIFI固件版本号
OK

> WiFi module MAC address is: 3C:91:80:F1:AD:18


Connecting to AP: aliyun  Attempt 1/3 ...
Connected to AP aliyun
Retrieving the IP address.
IP address: 192.168.43.3
Push the User button (Blue) within the next 5 seconds if you want to update the device security parameters or credentials.
  //按下蓝色按钮修改三元组和域名信息

Start to enter Ali Device Parameters: Region ID,Product Key,Device Name and Device Secret

Enter Region ID: (example: cn-shanghai)
cn-shanghai         //输入域名,似乎大陆只有这一个
read: --->
cn-shanghai  
<---

Enter Product Key: (example: a1b05Uexxxx)
a1h2u5rMFUn         //输入Product Key
read: --->
a1h2u5rMFUn
<---

Enter device name: (example: mydevicename)
smartthermometer     //输入device name
read: --->
smartthermometer
<---

Enter device secret: (example: 7o7GJ3odUE7pPnie07dzxxxxxxxxxxxx)
****************    //输入device secret,哈哈,此处保密,不过你足够牛批是可以算出来的,不过到时候这个设备应该被我删除啦!!!
read: --->
****************
<---
MQTT server address is :a1h2u5rMFUn.iot-as-mqtt.cn-shanghai.aliyuncs.com

*** Start connecting to MQTT server ***
Server address: a1h2u5rMFUn.iot-as-mqtt.cn-shanghai.aliyuncs.com : 1883

TCP Connection in progress:   Attempt 1/3 ...     //先建立TCP链接,因为MQTT协议是建立于TCP链接之上的

connected to server

Processing MQTT Connection

MQTT Client ID is :***************************************  //保密,嘻嘻
MQTT Username is :***************************************  //保密,嘻嘻
content:clientId3c9180f1ad18deviceNamesmartthermometerproductKeya1h2u5rMFUntimestamp85543
key: ***************************************  //保密,嘻嘻
MQTT password generated successfully:***************************************  //保密,嘻嘻
MQTT Connection Attempt 1/3 ...
subscribe to topic: /a1h2u5rMFUn/smartthermometer/user/tempThresholdSet        //订阅温度设置主题
subscribe to topic: /a1h2u5rMFUn/smartthermometer/user/clearAlarm              //订阅清除警报主题
publish device status successfully : temprature = 13, humidity = 48

publish device status successfully : temprature = 13, humidity = 48

publish device status successfully : temprature = 13, humidity = 48            //成功上报温度数据到阿里云平台啦!!!

五、平台显示上线

至此,设备端到阿里云的链路打通
在这里插入图片描述

六、建立感性认知后,我打算花半个月从以下几个方向,详解从设备到云

设备端:

1.WIFI和三元组信息如何通过串口保存至FLASH,详细到FLASH寄存器和时序操作
2.温度信号如何采集,X-NUCLEO-IKS01A2传感器模到STM32–NUCLEO-L4R5ZI开发板的IIC通讯详解
3.对庆科EXT-AT3080的WIFI模块驱动的理解
4.阿里云协议栈应用流程
5.PC键盘输入字符,如何通过串口输入到STM32,以及如何回显
6. tera term串口工具配置推荐

网络协议:

1.TCP链接详解
2.MQTT协议
3.TLS
4.调用了哪些阿里云的API

七、总结:

今天完成了:
1.tera term串口工具安装
2.了解了产品,设备,网关,子设备的关系
3.了解了三元组的获取和配置使用设备端的方式,建立了设备到云的基础认知
4.掌握了阿里云平台物联网产品与注册流程
5.阿里云大学,基于STM32的端到端物联网全栈开发课程,学到第5课

补充:阿里云大学的视频讲的很简洁,很多需要自己上网找资料去学习。这正是锻炼我们学习能力的好机会!也希望我能坚持下去!!!
共同进步交流群:697226678
————————————————
版权声明:本文为CSDN博主「这么帅气的小机灵」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/qq_38688850/article/details/104095679

发布了4 篇原创文章 · 获赞 5 · 访问量 452

猜你喜欢

转载自blog.csdn.net/qq_38688850/article/details/104101899