当前位置:网站首页>ESP8266_ Connect to Alibaba cloud through mqtt protocol
ESP8266_ Connect to Alibaba cloud through mqtt protocol
2022-06-11 09:37:00 【Little tiger_ IOT】
1、 Alibaba cloud operations
1.1、 Get ready
Log on the official website of aliyun , Registered account , Real name authentication ;
Find the product → The Internet of things IoT→ Enterprise Internet of things platform → Access control → Public examples ;
1.2、 Create a product and two devices under the product
Create products , For example, a ESP8266 Control lamp products ;
This product requires two cloud devices ,ESP8266 Itself and the client , The client sends control instructions to Alibaba cloud , The instructions are forwarded to through the cloud ESP8266 equipment ;


1.3、 see MQTT Connection parameters , use mqtt.fx Test whether it can be connected to the cloud
Selected device , In the device information , I circled it out “MQTT Connection parameters ”, Click on “ see ” And then there is , Copy this information to mqtt.fx Configuration file for , Can successfully connect ;

1.4、 Create rules , Realize data transmission between devices
First, understand the topic name of the subscription publication , In the product of Topic There are... In the class list ;
- The topic name of the default subscription :/ProductKey/DeviceName/user/get
- The default published topic name :/ProductKey/DeviceName/user/update
And then in “ Rules engine ”、“ Cloud product flow ”、 Old edition , Add two rules , among mqttfx Forward data to esp8266 The rules are as follows ;

After creating the rule , Start these two rules , Open two mqttfx Client to test , success ;

2、 Code and phenomenon
2.1、esp8266 Code
want modify mqtt_config.h Server domain name in 、 port 、ClientID、MQTT user name 、 password 、 Holder identification ;
also user_main.c Subscription topic name in 、 Publish topic name 、 received PUBLISH Message subject name ;
ClientID I can see it at a glance , How long is it spicy , It must be more than 64 Yes. , therefore hold config.h Medium “device_id” Changed to 128 position , It is also confirmed that there is no problem when using this parameter ;
download 、 function , The following information is returned :

Look for what you have written MQTT That article ESP8266_MQTT agreement _ Little tiger _IOT The blog of -CSDN Blog , have a look CONNACK The message 32,2,0,4 What does it represent , good heavens , Invalid user name or password ;

Is the user name and password invalid ? Like Baidu cloud last time ?
Go to the equipment details “MQTT Connection parameters ” Copied the new user name 、 password 、 client ID, Then burn and run , Not yet. ;
emmm, I just forgot to change the holder logo , Change and try again , It's another meal, but it still doesn't work ;
Then I counted the length of the password , just 64 position ,emmm, Not at all. OK , Remember the password array in the code 64 position , The string has another '\0' Well , So we need to hold config.h Medium “mqtt_pass” Change to 128 position , Again , It is also confirmed that there is no problem when using this parameter , Sure enough ;
// system parameter
//-------------------------------------------------------------------------------------
typedef struct{
uint32_t cfg_holder; // Holder identification ( Only update this value , System parameters will be updated )
uint8_t device_id[128]; // client ID[128]
uint8_t sta_ssid[64]; // WIFI name [64]
uint8_t sta_pwd[64]; // WIFI password [64]
uint32_t sta_type; // STA type
uint8_t mqtt_host[64]; // MQTT Server domain name [64]
uint32_t mqtt_port; // MQTT port
uint8_t mqtt_user[64]; // MQTT user name [64]
uint8_t mqtt_pass[128]; // MQTT password [128]
uint32_t mqtt_keepalive; // Stay connected for
uint8_t security; // Security type
} SYSCFG;2.2、 The phenomenon

Make complaints : I regret mosaic the key from the first picture , Then we have to play mosaic , Whenever I advise you to send a few, don't call , No problem , It seems that we all hear another voice , no way , The front has been mosaic , And if you don't fight now, you will seem to forget , It's stupid fufu Of , No matter what I say about the other one, I won't listen , Even control my hands , This is the so-called internal friction , I split ;
边栏推荐
- 制作业信息化为什么难施行?
- document对象
- Simulation of map and set
- Day41 process pool and thread pool
- Pytorch installation for getting started with deep learning
- 服装ERP:企业如何进行施行规划?
- Analysis of Kube scheduler disk scheduling source code
- Console you don't know
- [software] ten skills to maximize the value of ERP system
- Openstack explanation (24) -- registration of neutron service
猜你喜欢

Résumé de la méthode d'examen des mathématiques

Output image is bigger (1228800b) than maximum frame size specified in properties (1048576b)

Exclusive interview with PMC member Liu Yu: female leadership in Apache pulsar community

Opencv image basic operation (III) -- image feature extraction (corner detection)

Identifier keyword literal data type base conversion character encoding variable data type explanation operator

Console you don't know

document对象

OpenCV OAK相机对比及介绍

Openstack explanation (24) -- registration of neutron service

Video review pulsar summit Asia 2021, cases, operation and maintenance, ecological dry goods
随机推荐
Talk about how to customize data desensitization
Where is it safer to open an account for soda ash futures? How much does it cost to buy at least one hand?
affair
Interview question 17.10 Main elements
Before applying data warehouse ODBC, you need to understand these problems first
P1169 "chessboard making"
Package details
Opencv image basic operation (IV) -- image feature extraction (corner detection)
Clothing ERP: how do enterprises carry out implementation planning?
Talk about reading the source code
The difference and relation between machine learning and statistics
ERP体系能帮忙企业处理哪些难题?
[scheme design] scheme of household oximeter based on single chip microcomputer
我们是如何连上WiFi的?
ArcGIS 10.9.1 geological and meteorological volume metadata processing and service publishing and calling
远程办公最佳实践及策略
[TiO websocket] v. TiO websocket server counts the number of online people
Technical practice of dolphin dispatching in kubernetes system
Sword finger offer II 041 Average value of sliding window
Flask (VI) - template