Based on esp32-aliyun-demo, to reduce the binary size (i.e., libmain.a and main.bin), we extract the dependencies of mqtt-example from the library esp32-aliyun, compile them into a library, and then link the library to the demo program mqtt-example
.
https://esp-idf.readthedocs.io/zh_CN/latest/get-started/linux-setup.html
Assume that the toolchain archive is unpacked to $HOME/esp/xtensa-esp32-elf
.
Note that different from esp32-aliyun-demo, this repository has only one submodule esp-idf and it already contains the dependencies in esp32-aliyun.
$ git clone --recursive https://github.com/renweizhukov/esp32-aliyun-demo-mini.git
$ cd esp32-aliyun-demo-mini/
$ git submodule update --init --recursive
(1) Do it manually.
$ export IDF_PATH=$(pwd)/esp-idf
$ export PATH=$PATH:$HOME/esp/xtensa-esp32-elf/bin
(2) Use setup_env.sh
in this repository.
$ source setup_env.sh
You may export the environment variables in $HOME/.profile
so that their definitions are loaded every time you log in.
Set the following macro values according to your IoT product in main/src/mqtt_example.c
.
#define PRODUCT_KEY "xxxxxx"
#define DEVICE_NAME "yyyyyy"
#define DEVICE_SECRET "zzzzzzzzzzzz"
make menuconfig
-> choose demo
-> mqtt-example
.
Note that the other demo ota-mqtt-example
in esp32-aliyun-demo is not ported here.
make menuconfig
-> choose demo
-> Type the WiFi SSID and password.
(1) make menuconfig
-> Compiler options
-> Optimization Level
-> Select Release (-Os)
.
(2) make menuconfig
-> Compiler options
-> Assertion level
-> Select Disabled (sets -DNDEBUG)
.
(3) Disable debug logging in Makefile
by commenting out the following line.
#CFLAGS += -D IOTX_DEBUG
(4) After make
, strip the unneeded symbols from the library and then make
again.
$ make
$ xtensa-esp32-elf-strip --strip-unneeded build/main/libmain.a
$ xtensa-esp32-elf-strip --strip-unneeded build/esp32-aliyun-mini/libesp32-aliyun-mini.a
$ make
$ make
$ make flash monitor
Note that the above steps also work for Ubuntu on Windows 10, but you do need to associate the Windows serial port with Linux before you can flash the demo. For details, please refer to https://blog.csdn.net/xiaoyuluoke1/article/details/79111599.
If everything works as expected, you should see the following messages in the terminal:
I (3535) wifi: connected with XXXXXX, channel 1
iotx_mc_connect/1960: mqtt connect success!
************************ 174704 **********************
iotx_mc_cycle/1237: PUBACK
event_handle|084 :: publish success, packet-id=24
iotx_mc_cycle/1237: PUBACK
event_handle|084 :: publish success, packet-id=29