当前位置:网站首页>STM32 uses esp01s to go to the cloud, mqtt FX debugging
STM32 uses esp01s to go to the cloud, mqtt FX debugging
2022-07-01 07:46:00 【Taochengyi 2.0】
List of articles
Last year, I did a little cloud practice , Now record it , I don't know much about the agreement , I don't study the Internet , Just as a record
1、mqtt Basic concepts of agreement
MQTT The agreement is based on the release / subscribe (publish/subscribe) Mode " Lightweight " Communication protocol , Is built on TCP/IP Agreement on , The biggest advantage is , With very little code and limited bandwidth , Provide real-time and reliable message services for connecting remote devices . As a low cost 、 Low bandwidth instant messaging protocol , Make it in the Internet of things 、 Small equipment 、 Mobile applications are widely used .
The block diagram is shown below :
The main concern here is :A Subscribed to the theme 1,B Subscribed to the theme 1, If A To the subject 1 Released information 1, that A and B You'll get messages 1
2、mqtt Agreement to use
This up The speaker was very good , Let me summarize how to use , And avoid some mistakes ( Mining pit )
https://www.bilibili.com/video/BV1fu411y77M?spm_id_from=333.999.0.0
The first is the tools used , Actually called esp8266, But this module is the cheapest , Basically 4 You can do it for a dollar , Recommended selection 01s, It seems that the pins are pulled up , Actually, too. 16 Years old version 
Download firmware , The firmware of anxinco is used here , In fact, there will be a default firmware when you buy it , That's the firmware we used , So if it's a new one, don't worry , Of course, if you want to learn how to download firmware, you can also try , Firmware address :https://docs.ai-thinker.com/esp8266/sdk

There is also a description of this module , It's also very detailed , I put it in gitee Inside the https://gitee.com/lx2035/data-manual/tree/master/ESP
The article explains how he downloads firmware 
Later, I checked the official information. He has three modes to choose from , You can choose the mode of downloading firmware according to this connection :
| Pattern | EN | RST | GPIOO | GPIO2 |
|---|---|---|---|---|
| UART Pattern | high | high | low | low |
| flash Operation mode | high | high | high | low |
Of course, if you are lazy , You can buy downloaders directly , The essence is also usb-ttl Tools , It is he who has connected these pins to you 
Connect the line and you can download , The firmware selected is as follows
The official website also provides download tools , Pay attention here , It is recommended to click erase first , Click download again , If the download process occurs Prompt to reset such information , Then wait there and don't panic , This is normal , Don't take him from USB Pull out the mouth and insert it , It's no use , Just connect RST Unplug this wire of , Connect GND, Just pick it up , After that, I downloaded it smoothly 
Then pull out the others , You can use AT Instructions , About AT Instructions recommend this article , The summary is in place
https://blog.csdn.net/csdnhuaong/article/details/67011585
Here is a summary , Use AT At the time of instruction , You need to check send new line , Just send more \r\n, Then the default baud rate is 115200

Here are some important ones to say , send out AT There will be OK Respond 
send out AT+GMR Print version information

If the baud rate has been set before , You can use this command to change the baud rate
AT+UART=115200,8,1,0,0
Now try to connect MQTT The server , Using this server
test.mosquitto.org
The computer opens the command line ping once , You can see the normal connection 
First use the following command to configure ESP01S
AT+CWMODE_DEF=3 // Set to STA+AT Pattern
AT+CWJAP_DEF="ZTE-tbua","88888888" // Connect WIFI
AT+SAVETRANSLINK=1,"test.mosquitto.org",1883,"TCP" // Enter transparent mode , Connect MQTT The server
Let's start the connection MQTT The server , It is in use here mqttfx Connect the tool to him 
The new connection is shown below 
Familiar with the common functions of this software are as follows 
Now let's edit the message , They are connection message and subscription message
The connection message is as follows , If you don't write the user name and key, you just 00 00, Special attention should be paid here to the user name I use and if the theme changes, the other two lengths should be changed accordingly , So here I'm going to use theta lx
| 10 | 12 | 00 04 | 4D 51 54 54 | 04 C2 | 00 78 | 00 02 | 6C 78 | 00 00 | 00 00 |
|---|---|---|---|---|---|---|---|---|---|
| agreement | Back length | Length of agreement | MQTT | edition | 120( heartbeat ) | client id( length ) | lx | user name id( length ) | The key ( length ) |
Subscription message
| 82 | 07 | 00 02 | 00 02 | 6C 78 | 00 |
|---|---|---|---|---|---|
| Headlines | length | Unknown | Theme length | lx | Unknown |
Here I put hex Put on
10 12 00 04 4D 51 54 54 04 C2 00 78 00 02 6C 78 00 00 00 00
82 07 00 02 00 02 6C 78 00
C0 00 // Keep alive according to the heartbeat , It is to send a command to tell the server that I am still connected within the heartbeat time
The requirement here is to disconnect and reconnect after the transparent transmission mode is set , It seems that I don't need , Anyway, if it doesn't work, you can try to disconnect and reconnect after setting it to transparent transmission mode .
Another thing to note is that after the transparent mode is set ,AT And the command fails , If you want to close , send out +++ This command is enough , Do not click send new line , Wait a minute and you'll see CLOSE This character , Is to turn off transparent transmission , At this time, you are sending AT It works
Send connection command , Note that 16 Base send , See the return and finally 00
Send subscription , Also return to the end 00
To see better , I switched to VOFA+ This serial port assistant is used to test , You can see that he returned the name and subject 
Then we use the previous mqtt.fx Subscribe to the topic and send a try , You can see the smooth reception 
3、 Use MQTT.fx Connect
The software is shown below

It can be used as a very convenient debugging tool , It can be used to chain and connect devices , Then receive the distributed data , Connection and subscription , It's more convenient , It is a good testing tool : Download link
http://www.mqttfx.jensd.de/index.php/download
Now start trying to connect onenet,onenet There seems to be a new version , I haven't tried yet , Later, I tried to record , Here is the idea of the old version , Then everything related to our cloud is in the console 
3.1、 Connect MQTT Internet of things Suite - Use MQTTS agreement
Get into MQTT Internet of things Suite 
After adding products, follow the prompts to create devices , The whole process is relatively simple , I won't elaborate here 
Click on the device to view the device 
The official documents contain details about this device ; Detailed description of the connection , As shown below , Links are as follows
https://open.iot.10086.cn/doc/mqtt/
Let me pick the key points and say , If you don't want to read official documents , You can look directly at what I said below
Generally, every cloud needs an account and password , Generally, some strings are added and changed , The government also generally provides some tools , here onenet The tools provided are as follows , Just go to download 
Let's use this tool first , Do what we need , I have filled in all the details below 
About unix Time stamp , It is a time conversion tool , The use here is once the time exceeds this time , The server will kick out the connected devices , The tool that generates the timestamp can use the following URL
http://www.usey.cn/timestamp
Edit below MQTT.fx Tools 
Let's connect 
The viewing device has also become online 
Now try uploading data , The documents are as follows , You can see that you can upload both data points and data commands 
Write and subscribe as required , You can see that the subscription is successful 
Subscribe to news , The data format is officially provided , As shown below
{
"id": 123,
"dp": {
"temperatrue": [{
"v": 30,
"t": 1552289676
}],
"power": [{
"v": 4.5,
"t": 1552289676
}],
"status": [{
"v": {
"color": "blue"
},
"t": 1552289677
},
{
"v": {
"color": "red"
},
"t": 1552289678
}
]
}
}

Enter the cloud platform and refresh to view 
Let's try to issue a command , The official description is as follows 
Subscribe as follows 
Enter the distribution page 
Edit command send 
After entering the software, you can see that the command issued has been received 
Now let's reply to the order 
It is to send the data immediately after the command cmdid Get it and paste it on the publish page to publish it , You can see that the reception is successful , already OK 了 
The information used above
product ID 489122
equipment ID 893388762
Equipment name lx2035
$sys/{
pid}/{
device-name}/dp/post/json Data point upload format
$sys/{
pid}/{
device-name}/cmd/request/{
cmdid} Equipment distribution format
$sys/{
pid}/{
device-name}/cmd/response/{
cmdid} The equipment sends the response format
$sys/489122/lx2035/dp/post/json/+
$sys/489122/lx2035/cmd/request/+
$sys/489122/lx2035/cmd/response/23e0bd09-e385-4a64-8fd4-4fe955fa25ba
3.2、 Use multi protocol access - Use MQTT agreement
Choose multi protocol access , This seems to be the most information I can find , Many choose this method to access , Routines are also very rich
notes : I use this mqttfx Failed to connect , The reason is unknown , Wait until you succeed in updating this article , Using official tools
Official document address :
https://open.iot.10086.cn/doc/multiprotocol/book/develop/mqtt/device/doc-tool.html
Create products and devices 
Then download the required tools in the official documents 
Edit to connect 
Go to the device page , You can see that the connection is successful

Next, we will test the data transmission , Subscribe to a topic , The name is arbitrary 
Edit data last 
data json The format is as follows :
{
"datastreams": [
{
"id": "temp",
"datapoints": [
{
"value": 36.5
}
]
}
]
}
You can see that the data has been received 
Let's test the data distribution , Enter and issue the command 
Successfully received 
3.3、 Access Tencent cloud console
Address the following , This often needs to log in , It has a lot to do with wechat , If not , Please log in with your mobile phone , His cloud is a big one , We use only a small part of it
https://console.cloud.tencent.com/iotexplorer
Then enter the public instance , And then create the project 
Then enter product creation , It's a series of processes 
Here we build two custom functions , Standard functions are those that everyone has . A normal variable and then a Boolean value 
As shown below 
Let's see to the rest , I don't know , Just set it up 
In the end, all of them are ticked OK 了 
good , Now let's go to the document time , After reading this document, you will know how to access the cloud
https://cloud.tencent.com/document/product/1081/46507
Here he also provides a distribution network tool to help us access 
Download is a compressed package , Then you just need to pay attention to a page in it 
The required data is obtained from here 
And then in MQTTfx Fill in , If you don't understand it, you can see the data length , It almost means that you have filled it in correctly 
Parameter descriptions are also in the document 
Click Connect to see the device online 
Equipment downlink data . The official documents are described as follows , Be sure to read my scarlet letter 
After subscription, it is shown as follows 
Publish a visible data 
MQTT The end is as follows , Receiving data is normal

Next, report the equipment attributes , The document is described as follows 
What needs to be added is in the object model protocol , The following is the sample I used , Because I used two variables
{
"method":"report",
"clientToken":"123",
"timestamp":1628646783,
"params":{
"data1":20.5,
"data2":1
}
}

The effect is as follows , You can see that the command was successfully sent 
3.4、 Access Alibaba cloud console
website :https://iot.console.aliyun.com/lk/summary/new
Let's start with the location , Or try searching directly : Internet of things platform 
Create a device under the public instance 
Just like Tencent cloud , Add two parameters , Start reporting 
Alibaba cloud is doing very well here , Direct copy , Click on MQTT Connection parameters 
You can see , You don't need any tools , Direct copy 
One to one paste 
Then the connection will show that it is online 
The following is the data distribution of the equipment , The format is explained in the product
/a1xZ1EhVjDH/${
deviceName}/user/get Template
/a1xZ1EhVjDH/test1/user/get

Click publish 
You can see that the message was successfully received 
Here is the upload data , Use this to customize topic
The template is as follows
/a1xZ1EhVjDH/${
deviceName}/user/update
/a1xZ1EhVjDH/test1/user/update
send out 
Because it is not the template of the object model , You can see our message in the log 
Let's try with the official order , Or two orders 
Equipment distribution 
You can see that the data is successfully received 
Now send it locally to the cloud , The data template is as follows
{
"method": "thing.service.property.set",
"id": "1469549558",
"params": {
"led": 0,
"temp": 36.5
},
"version": "1.0.0"
}
Switch to the publishing page , Published as follows 
Enter the view , You can see that the modification was successful !
then stm32 In fact, this is how you subscribe to and send these template data for updating , Write next time. , Wait for me to optimize the code .
4、onenet actual combat
5、 Tencent cloud actual combat
6、 Alibaba cloud actual combat
边栏推荐
- PWN attack and defense world int_ overflow
- Reply and explanation on issues related to "online training of network security education in 2022"
- 华为ModelArts训练Alexnet模型
- atguigu----脚手架--02-使用脚手架(2)
- [MySQL learning notes 26] view
- Cadence OrCAD Capture “网络名”相同,但是未连接或连接错误的解放方案之nodename的用法
- 1286_ Implementation analysis of task priority setting in FreeRTOS
- [recommendation system] breakthrough and imagination of deep location interactive network dpin for meituan takeout recommendation scenario
- redisson使用全解——redisson官方文档+注释(下篇)
- [programming training 2] sorting subsequence + inverted string
猜你喜欢

The programmer of Beipiao posted a post for help late at night: I am lonely when my girlfriend is gone

redisson使用全解——redisson官方文档+注释(中篇)

ctfshow-web351(SSRF)

Mysql与Redis一致性解决方案

2022 electrician (intermediate) recurrent training question bank and answers

I bet on performance and won the CTO of the company. I want to build Devops platform!

熱烈祝賀五行和合酒成功掛牌
![[programming training 2] sorting subsequence + inverted string](/img/96/87750c5d3954ef6c39cce073e8b9ae.png)
[programming training 2] sorting subsequence + inverted string

论文学习——水文时间序列相似性查询的分析与研究

三极管是一项伟大的发明
随机推荐
iNFTnews | 从《雪崩》到百度“希壤”,元宇宙30年的16件大事
【微服务|openfeign】Feign的日志记录
华为ModelArts训练Alexnet模型
十大劵商如何开户?另外,手机开户安全么?
weback5基础配置详解
Alibaba OSS postman invalid according to policy: policy condition failed: ["starts with", "key", "test/"]
I bet on performance and won the CTO of the company. I want to build Devops platform!
2022年茶艺师(中级)复训题库及答案
PWN attack and defense world int_ overflow
[kv260] generate chip temperature curve with xadc
Sorting out tcp/udp communication problems
Array: question brushing record
Todolist classic case ①
赌上了绩效,赢了公司CTO,我要搭DevOps平台!
三极管是一项伟大的发明
Oracle创建自增id
Atguigu---- scaffold --02- use scaffold (2)
[R language] age sex frequency matching select samples for case-control study, and perform frequency matching on age and sex
The H5 page has set the font thickness style, but the wechat access style in Huawei mobile phone doesn't take effect?
C# Newtonsoft.Json中JObject的使用