Essence Share | Essence's Wi-Fi module connection guide for HUAWEI CLOUD IoT platform. (with source code)

Guide for Anxinke Wi-Fi Module to Connect to HUAWEI CLOUD IoT Platform

content

0. Introduction

Essence is a design expert in IoT wireless, focusing on designing simple and flexible solutions that are easy to manufacture and deploy. Essence can develop and design wireless system-on-module products with integrated SoC, stable performance and low power consumption in the IoT industry, so it has powerful Wi-Fi and Bluetooth functions, as well as excellent RF performance.

The HUAWEI CLOUD IoT platform (IoT device access cloud service) provides access and management capabilities for a large number of devices. It can connect your IoT devices to HUAWEI CLOUD, support device data collection on the cloud, and issue commands from the cloud to devices for remote control. , cooperate with other HUAWEI CLOUD products to help you quickly build IoT solutions.

Using the IoT platform to build a complete IoT solution mainly includes 3 parts: IoT platform, business applications and devices.

  • As the middle layer connecting business applications and devices, the IoT platform shields various complex device interfaces and realizes rapid access to devices; at the same time, it provides powerful open capabilities to support industry users to quickly build various IoT business applications.
  • The device can access the IoT platform through fixed network, 2G/3G/4G/5G, NB-IoT, Wifi and other networks, and use the LWM2M/CoAP or MQTT protocol to report business data to the platform, and the platform can also send control commands delivered to the device.
  • Business applications implement business scenarios such as device data collection, command issuance, and device management by calling the API provided by the IoT platform.

1. Purpose

Based on the Linux environment, this article introduces the specific process of connecting the Anxinke Wi-Fi module to the HUAWEI CLOUD IoT platform for readers' reference.

Anxin can sell modules support
ESP8266 series modules, including ESP-12F/12S/12E/12L Currently not supported, adapting...
ESP32 series modules, including ESP32-S, ESP32-SU support
ESP32S2 series modules, including ESP-12K, ESP-12H support
ESP32S3 series modules, including ESP-S3-12K, ESP-S3-12F Currently not supported, adapting...
ESP32C3 series modules, including ESP-C3-32S, ESP-C3-12F support

2. Hardware Preparation

  • linux environment
    The necessary environment for compiling & programming & running.

Windows users can install a virtual machine and install linux in the virtual machine.

  • Equipment
    Go to Anxin to get it officially.

  • USB cable
    Connect PC and ESP device, used to burn/download programs, view logs, etc.

3. HUAWEI CLOUD PLATFORM PREPARATION

According to the official documentation of HUAWEI CLOUD IoT platform access , creating products on HUAWEI IoT cloud platform, creating devices, and automatic generation will be used in Section 6.2.3.

4. Environment construction

If you are familiar with the ESP development environment, you can easily understand the following steps; if you are not familiar with a certain part, such as compiling and burning, you need to understand it in conjunction with the official related documents. If you need to read the ESP-IDF programming guide document, etc.

4.1 Build the compiler environment

  • ESP32/s2/c3 : Download the toolchain according to the toolchain settings in the official link

Toolchain settings refer to ESP-IDF Programming Guide .

4.2 Obtaining the burning tool/downloading tool

  • ESP32/s2/c3 platform: The burning tool is located under esp-idf./components/esptool_py/esptool/esptool.py

esptool function reference:

$ ./components/esptool_py/esptool/esptool.py --help

5. SDK preparation

  • esp-huawei SDK , through which the MQTT protocol can be used to connect ESP devices to the HUAWEI CLOUD IoT platform.
  • Espressif SDK

After the Espressif SDK is downloaded:
ESP-IDF: Please switch to the v4.3 branch:git checkout v4.3

6. Compile & program & run

6.1 Compiling

6.1.1 Exporting the compiler

Reference Toolchain Settings

6.1.2 Compile the demo example

idf.py set-target esp32/s2/c3
idf.py menuconfig

insert image description here

  • Configure programming serial port
  • Configure the triplet obtained from Huawei IoT.
  • Compile, open the Anxin WeChat official account to configure wireless access to the network, that is, the WeChat airkiss distribution network protocol.

2. Generate the final bin

idf.py build

6.2 Erase & Compile & Burn & Download Firmware & View Log

Connect the USB cable to the device and PC, and make sure the programming port is correct.

6.2.1 [Optional] Erase flash

idf.py -p (PORT) erase_flash

Note: No need to erase every time, you need to redo 6.2.3 after erasing.

6.2.2 Burn Program

idf.py -p (PORT) _flash

6.2.3 Mass production burning triple information

  • Instructions to be completed. .

6.2.4 Operation

make monitor

If you turn the ESP32 to the running state, you can see the following log:
The log shows that the ESP32 has established a secure connection path with the Huawei IoT cloud platform based on TLS, and then subscribes and publishes messages through the MQTT protocol. You can see the MQTT messages pushed by the ESP32.

I (798) wifi:enable tsf
I (808) wifi_init: rx ba win: 6
I (808) wifi_init: tcpip mbox: 32
I (808) wifi_init: udp mbox: 6
I (808) wifi_init: tcp mbox: 6
I (808) wifi_init: tcp tx win: 5744
I (808) wifi_init: tcp rx win: 5744
I (818) wifi_init: tcp mss: 1440
I (818) wifi_init: WiFi IRAM OP enabled
I (818) wifi_init: WiFi RX IRAM OP enabled
I (828) router: -- get ssid: aiot@xuhongv
I (828) router: -- get password: xuhong12345678
I (838) aithinker-debugLog::: Next connectting router.
I (838) wifi:new:<1,0>, old:<1,0>, ap:<255,255>, sta:<1,0>, prof:1
I (848) wifi:state: init -> auth (b0)
I (898) wifi:state: auth -> assoc (0)
I (938) wifi:state: assoc -> run (10)
I (958) wifi:connected with aiot@xuhongv, aid = 3, channel 1, BW20, bssid = 9c:9d:7e:40:e8:10
I (958) wifi:security: WPA2-PSK, phy: bgn, rssi: -21
I (968) wifi:pm start, type: 1

W (968) wifi:<ba-add>idx:0 (ifx:0, 9c:9d:7e:40:e8:10), tid:6, ssn:2, winSize:64
I (988) wifi:AP's beacon interval = 102400 us, DTIM period = 1
I (2088) esp_netif_handlers: sta ip: 192.168.31.228, mask: 255.255.255.0, gw: 192.168.31.1
I (2088) aithinker-debugLog::: WiFi Connected to ap
I (2088) aithinker-debugLog::: Free memory: 229384 bytes
I (2088) aithinker-debugLog::: MQTT xTaskCreate OK

I (2098) aithinker-debugLog::: port 8883
I (2098) aithinker-debugLog::: host  a1621cfafc.iot-mqtts.cn-north-4.myhuaweicloud.com
I (2108) aithinker-debugLog::: client_id aithinker_F4CFA25BB155_0_0_2022032704
I (2118) aithinker-debugLog::: username aithinker_F4CFA25BB155
I (2118) aithinker-debugLog::: password3e7bbb8fba3161685348d96434bb43fb450f39d765232ffbcd8ecb35df2be35b
I (2128) aithinker-debugLog::: Other event id:7
W (2148) wifi:<ba-add>idx:1 (ifx:0, 9c:9d:7e:40:e8:10), tid:0, ssn:0, winSize:64
I (3458) aithinker-debugLog::: MQTT_EVENT_CONNECTED
I (3458) aithinker-debugLog::: sent subscribe successful=$oc/devices/aithinker_F4CFA25BB195/sys/events/down
I (3468) aithinker-debugLog::: sent subscribe successful=$oc/devices/aithinker_F4CFA25BB195/sys/messages/dowm
I (3558) aithinker-debugLog::: MQTT_EVENT_SUBSCRIBED, msg_id=60971
I (3618) aithinker-debugLog::: MQTT_EVENT_SUBSCRIBED, msg_id=21864
I (3558) aithinker-debugLog::: MQTT_EVENT_SUBSCRIBED, msg_id=60971
I (3618) aithinker-debugLog::: MQTT_EVENT_SUBSCRIBED, msg_id=21864

This article is reproduced in the original CSDN blog of half a heart , and has been authorized.
Free access to the source code: https://github.com/xuhongv/esp-huawei

contact us

Official website: https://www.ai-thinker.com
Development of DOCS: https://docs.ai-thinker.com
Official forum: http://bbs.ai-thinker.com
Technical support: [email protected]

Guess you like

Origin blog.csdn.net/Boantong_/article/details/123786342