[Secondary development and application] Anxin can ESP32/ESP8266 module access the Ali Life IoT platform

foreword

Before, we have pushed how to access the Ali IoT platform (or Ali Life IoT platform) through AT commands. Today we will teach you how to access the Alibaba Life IoT platform through secondary development to realize cloud smart APP or Tmall Genie to control the ESP32 module. Group\Development Board, ESP-12S Module\Development Board.

1. Preparation

1.1. Hardware preparation

  1. ESP-12S development board x 1 + data cable x 1
    insert image description here

  2. ESP32-S development board x 1 + data cable x 1

insert image description here

1.2, software preparation

  1. VMware® Workstation 16 Pro, software acquisition link: https://www.vmware.com/cn/products/workstation-pro.html
  2. Linux (Ubuntu) system image, image acquisition link: https://ubuntu.com/download
  3. ESP8266, ESP32, ESP32S2 chips are connected to the SDK package of Ali Life IoT platform: https://github.com/espressif/esp-ali-smartliving.git

2. Engineering construction

Platform settings

  1. Create a new project
    Create a new project, the project name is random, the project type selects the Tmall Elf ecological project, check the I agree with the Tmall Elf option, and click OK to create a successful project.
    insert image description here

  2. Create a product:

  • Fill in the product name randomly
  • Select the category of electrical lighting –> lamp
  • Node type selection device
  • Choose whether to access the gateway or not;
  • Select wifi as the networking method;
    insert image description here
  1. Product Management Configuration
  • The function definition part can be deleted according to personal needs, and the default settings are maintained here;
  • In the human-computer interaction part, click on the QR code to scan the code to download the Tmall Genie APP. Users can adjust the APP configuration interface according to their personal needs, and the default settings are also maintained here;
  • In the device debugging section, select Uncertified for Device Information, click Add Test Device, and set the device name randomly.

4. Save the quadruple
After the device is created successfully, click View to copy the device triplet: ProductKey, DeviceName and DeviceSecret parameters:
insert image description here

Go back to the product and click to copy the parameters of the Product Secret:
insert image description here
save the above parameters for later use.

Partial software operation of ESP-12S development board

  1. Clone the Alibaba Life IoT Network Access SDK to the specified directory of Linux. The instructions are as follows:
git clone --recursive https://github.com/espressif/esp-ali-smartliving.git
  1. Pull the ESP8266_RTOS_SDK package to the same directory, clone successfully and switch the branch to release/v3.3, enter the SDK directory, run the two commands ./install.sh and ../export.sh to build the translation environment:
git clone --recursive  https://github.com/espressif/ESP8266_RTOS_SDK.git
cd ESP8266_RTOS_SDK
git checkout release/v3.3
git pull
./install.sh
. ./export.sh
  1. Execute in the esp-ali-smartliving directory:
cd ali-smartliving-device-sdk-c
make reconfig (选择SDK平台,这里选择config.freertos.esp8266)
make menuconfig (选择相关功能配置,默认不需要修改,该步骤可以省略)
make (生成相关头文件和库文件)
  1. Compile the demo example and generate the final bin:
cd examples/solutions/smart_light
make defconfig
make menuconfig		//配置模组flash大小为4M
make -j8
  1. To erase the original firmware and burn the new firmware, the command operation is as follows:
make erase_flash   //擦除开发板中的原有固件
make flash
  1. Burn the quad to the NVS partition
    There is a reference configuration file in the esp-ali-smartliving/config/mass_mfg directory, single_mfg_config.csv, we copy the file to the project and modify it:
key,type,encoding,value
aliyun-key,namespace,,
DeviceName,data,string,config
DeviceSecret,data,string,dsj3RuY74pgCBJ3zczKz1LaLK7RGApqh
ProductKey,data,string,a10BnLLzGv4
ProductSecret,data,string,pVfLpS1u3A9JM0go

Paste the quadruple of the device you just created into the specified location and save it. Run the command in the directory ESP8266_RTOS_SDK/components/nvs_flash/nvs_partition_generator to generate the quadruple bin file:

$IDF_PATH/components/nvs_flash/nvs_partition_generator/nvs_partition_gen.py --input UserPath/single_mfg_config.csv --output UserPath/single_mfg.bin --size 0x4000

Finally, add a quaternion to burn into the development board:

$IDF_PATH/components/esptool_py/esptool/esptool.py --port /dev/ttyUSB0 write_flash 0x100000 my_single_mfg.bin

Partial software operation of ESP32-S development board

  1. Clone the Alibaba Life IoT Network Access SDK to the specified directory of Linux. The instructions are as follows:
git clone --recursive https://github.com/espressif/esp-ali-smartliving.git
  1. Pull the esp-idf package to the same directory, clone successfully and switch the branch to release/v4.3, enter the SDK open directory, and run the two commands ./install.sh and ../export.sh to build the translation environment:
git clone --recursive  https://github.com/espressif/esp-idf.git
cd esp-idf
git checkout release/v4.3
git pull
./install.sh
. ./export.sh
  1. Execute in the esp-ali-smartliving directory:
cd ali-smartliving-device-sdk-c
make reconfig (选择SDK平台,这里选择config.esp32.aos)
make menuconfig (选择相关功能配置,默认不需要修改,该步骤可以省略)
make (生成相关头文件和库文件)
  1. Compile the demo example and generate the final bin:
cd examples/solutions/smart_light
make defconfig
make menuconfig		//配置模组flash大小为4M
make -j8
  1. To erase the original firmware and burn the new firmware, the command operation is as follows:
make erase_flash   //擦除开发板中的原有固件
make flash
  1. Burn the quad to the NVS partition
    There is a reference configuration file in the esp-ali-smartliving/config/mass_mfg directory, single_mfg_config.csv, we copy the file to the project and modify it:
key,type,encoding,value
aliyun-key,namespace,,
DeviceName,data,string,config
DeviceSecret,data,string,dsj3RuY74pgCBJ3zczKz1LaLK7RGApqh
ProductKey,data,string,a10BnLLzGv4
ProductSecret,data,string,pVfLpS1u3A9JM0go

Paste the quadruple of the device you just created into the specified location and save it. Run the command in the directory $IDF_PATH/components/nvs_flash/nvs_partition_generator to generate a quadruple bin file (note: the ESP32-S module and the ESP-12S module have different command formats for generating a quadruple bin file):

$IDF_PATH/components/nvs_flash/nvs_partition_generator/nvs_partition_gen.py UserPath/single_mfg_config.csv UserPath/single_mfg.bin --size 0x4000

Finally, burn the quad to the development board:

$IDF_PATH/components/esptool_py/esptool/esptool.py write_flash 0x210000 single_mfg.bin

3. Effect demonstration

3.1. Tmall Genie finds teammates to test

After completing the above configuration and restarting the device, the device will enter the one-click network configuration state. At this time, give the Tmall Genie the command "Find Device", and the daymall Genie will reply that there is a new device. When it is connected, press the "Connect" command, and finally wait. Network distribution is successful.

3.2. APP distribution network test

Open the "Tmall Genie APP", click the "+" button in the upper right corner, select Scan, scan the QR code of the device's network configuration, enter the account password, and finally wait for the network to be successfully connected.

more info

The above is the content shared in this issue. The purpose is to allow everyone to quickly adapt to the development of new product solutions. The driver source code provided above can be provided free of charge by contacting us.

Official website: https://www.ai-thinker.com
Development information: https://docs.ai-thinker.com/
Official forum: http://bbs.ai-thinker.com
Company address: Bao'an District, Shenzhen Xixiang Gushu Huafeng Smart Innovation Port Building C 410

Guess you like

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