“ This article will run the FreeRTOS operating system on ESP32 and send MQTT messages to the AWS IoT Core platform.”
FreeRTOS is commonly used in Cortex M3/M4 core microcontrollers and simplifies embedded device development, avoiding the need to write complex bare-metal pure C code directly, as well as simplifying the differences between different microcontrollers and directly managing memory space.
The microcontroller used in this article is still the ESP32.
In our previous practice, we used Arduino C code to program the ESP32, which is relatively simple, while FreeRTOS is much more complex. So why use FreeRTOS for embedded device development?
1. FreeRTOS or similar RTOS operating systems can provide more fine-grained device control, making it simpler for developers to manage device control than pure C code when designing production-grade products;
2. Compared to other high-level programming languages, FreeRTOS development based on C has higher efficiency and a smaller code footprint;
3. In the face of production-grade product development, it offers higher efficiency and shorter development cycles;
4. Compared to other high-level programming languages, FreeRTOS development based on C requires lower power consumption.
01
—
Setting up the ESP32 Development Environment
Setting up the FreeRTOS development environment for ESP32 requires configuring the ToolChain required by the ESP32 BoardManager, connecting the device’s serial conversion software, and downloading the FreeRTOS software package.
The setup process mainly refers to:
https://docs.aws.amazon.com/freertos/latest/userguide/getting_started_espressif.html
——
Setting up the local computer development environment
Setting up ToolChain
The ToolChain is used for communication with the ESP32 device, developed by the board’s provider, and is compatible with the FreeRTOS operating system (can you imagine what this means? ><)
Installing the ToolChain is straightforward; just follow the steps in the documentation link.
https://docs.espressif.com/projects/esp-idf/en/v3.3/get-started-cmake/macos-setup.html
pip install --user pyserial
brew install cmake ninja
Downloading the software package
https://dl.espressif.com/dl/xtensa-esp32-elf-osx-1.22.0-80-g6c4433a-5.2.0.tar.gz
Unzip and set environment variables:
mkdir -p ~/espcd ~/esptar -xzf ~/Downloads/xtensa-esp32-elf-osx-1.22.0-80-g6c4433a-5.2.0.tar.gz
export PATH=$HOME/esp/xtensa-esp32-elf/bin:$PATH
printenv PATH
Installing CMake
https://cmake.org/download/
CMake is used to build demo ESP32 applications based on FreeRTOS.
——
Local development environment and device serial connection
The local laptop needs to communicate with the ESP32 DevKitC board and requires the installation of the USB-to-UART conversion driver. Install it through the following link.
https://www.silabs.com/products/development-tools/software/usb-to-uart-bridge-vcp-drivers
——
02
—
Downloading and configuring FreeRTOS
Download FreeRTOS for ESP32. Visit the following link to download the appropriate software package for the development board. If you don’t have hardware, you should be able to download the Windows Simulator (I haven’t tried it).
https://console.aws.amazon.com/iot/home?region=us-east-1#/software/freertos
Configuring AWS CLI
aws configure
Installing AWS Python SDK (for running configuration scripts)
pip install tornado nose --user
pip install boto3 --user
Run the configuration script, first modify the configuration filefreertos
/tools/aws_config_quick_start/configure.json:
{ "afr_source_dir":"/Users/jianhong/Downloads/FreeRTOS", "thing_name":"myESP32", "wifi_ssid":"712", "wifi_password":"92861899", "wifi_security":"eWiFiSecurityWPA2"}
Run freertos
/tools/aws_config_quick_start/SetupAWS.py
python SetupAWS.py setup.
AWS IoT automatically configures Things, Certificates, and Policies, as well as WiFi SSID. (To understand AWS IoT’s Certificates, Policies, etc., refer to Using MQTT and AWS IoT Core for communication. In our previous implementation without pure C code, we had to manually handle certificate issues in our C code after creating a certificate on AWS IoT. Zenryth and MongooseOS automatically helped us handle certificate issues.)
By checking the following files, you can see that the script has already helped us handle the WiFi, Endpoint, and certificate issues required to connect to AWS IoT.
FreeRTOS/demos/include/aws_clientcredential.h
/* * FreeRTOS V201906.00 Major * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of * the Software, and to permit persons to whom the Software is furnished to do so, * subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * * http://aws.amazon.com/freertos * http://www.FreeRTOS.org */
#ifndef __AWS_CLIENTCREDENTIAL__H__
#define __AWS_CLIENTCREDENTIAL__H__
/* * Include for device certificate and private key */#include "aws_clientcredential_keys.h"
/* * MQTT Broker endpoint. */#define clientcredentialMQTT_BROKER_ENDPOINT "a36swrxk5hxfjq-ats.iot.us-east-1.amazonaws.com"
/* Use of a "define" and not a "static const" here to be able to* use pre-compile concatenation on the string. */#define clientcredentialIOT_THING_NAME "myESP32"
/* * Port number the MQTT broker is using. */#define clientcredentialMQTT_BROKER_PORT 8883
/* * Port number the Green Grass Discovery use for JSON retrieval from cloud is * using. */#define clientcredentialGREENGRASS_DISCOVERY_PORT 8443
/* * Wi-Fi network to join. */#define clientcredentialWIFI_SSID "712"
/* * Password needed to join Wi-Fi network. */#define clientcredentialWIFI_PASSWORD "92861899"
/** * @brief Security type * WPA2 Security, @see WIFISecurity_t * Possible values are - eWiFiSecurityOpen, eWiFiSecurityWEP, eWiFiSecurityWPA, * eWiFiSecurityWPA2 */#define clientcredentialWIFI_SECURITY eWiFiSecurityWPA2
#endif
03
—
Build and Flash FreeRTOS
After setting up the local development environment and the AWS IoT related parameters for the ESP32 Package, you can start flashing FreeRTOS onto the ESP32 hardware.
You can either use the cmake command to flash or use a Python script to build and flash.
cmake -DVENDOR=espressif -DBOARD=esp32_wrover_kit -DCOMPILER=xtensa-esp32 -S . -B build
Erase the Flash of the ESP32 development board
./vendors/espressif/esp-idf/tools/idf.py erase_flash -B build
Flash the development board
./vendors/espressif/esp-idf/tools/idf.py flash -B build
Flash result:
This process takes some time, and here is the entire process.
Setting IDF_PATH environment variable: /Users/jianhong/Downloads/FreeRTOS/vendors/espressif/esp-idf
Checking Python dependencies...Python requirements from /Users/jianhong/Downloads/FreeRTOS/vendors/espressif/esp-idf/requirements.txt are satisfied.
Running make in directory /Users/jianhong/Downloads/FreeRTOS/build
Executing "make -j 6 all"...
[ 1%] Built target partition_table
[ 1%] Built target gen_secure_boot_signing_key
[ 2%] Built target afr_3rdparty_tinycbor
[ 3%] Built target afr_kernel
[ 4%] Built target idf_component_espcoredump
[ 6%] Built target idf_component_soc
[ 7%] Built target idf_component_heap
[ 7%] Built target idf_component_log
[ 9%] Built target idf_component_freertos
[ 9%] Built target idf_component_vfs
[ 9%] Built target idf_component_esp_ringbuf
[ 9%] Built target idf_component_tcpip_adapter
[ 10%] Built target idf_component_newlib
[ 11%] Built target idf_component_esp_event
[ 11%] Built target idf_component_app_update
[ 11%] Built target idf_component_micro-ecc
[ 12%] Built target idf_component_spi_flash
[ 15%] Built target idf_component_driver
[ 17%] Built target idf_component_bootloader_support
[ 18%] Built target idf_component_efuse
[ 19%] Built target idf_component_app_trace
[ 19%] Built target idf_component_ethernet
[ 19%] Built target idf_component_xtensa-debug-module
[ 19%] Built target esp32_linker_script
[ 20%] Built target idf_component_smartconfig_ack
[ 20%] Built target idf_component_pthread
[ 21%] Built target idf_component_nvs_flash
[ 21%] Built target idf_component_cxx
[ 21%] Built target idf_component_console
[ 21%] Built target idf_component_esp_adc_cal
[ 22%] Built target idf_component_expat
[ 23%] Built target idf_component_bt
[ 25%] Built target idf_component_wear_levelling
[ 26%] Built target idf_component_openssl
[ 31%] Built target idf_component_fatfs
[ 31%] Built target idf_component_sdmmc
[ 31%] Built target idf_component_nghttp
[ 33%] Built target idf_component_freemodbus
[ 34%] Built target idf_component_ulp
[ 34%] Built target blank_ota_data
[ 35%] Built target idf_component_spiffs
[ 35%] Performing build step for 'bootloader'
[ 35%] Built target idf_component_espcoredump_sections_info
[ 37%] Built target afr_freertos_plus_tcp
[ 37%] Built target idf_component_soc_sections_info
[ 38%] Built target idf_component_log_sections_info
[ 48%] Built target idf_component_wpa_supplicant
[ 48%] Built target idf_component_heap_sections_info
[ 3%] Built target idf_component_main
[ 5%] Built target dummy_main_src
[ 8%] Built target idf_component_spi_flash
[ 12%] Built target idf_component_log
[ 41%] Built target idf_component_soc
[ 44%] Built target idf_component_micro-ecc
[ 53%] Built target idf_component_efuse
[ 55%] Built target idf_component_main_sections_info
[ 82%] Built target idf_component_bootloader_support
[ 83%] Built target idf_component_soc_sections_info
[ 85%] Built target idf_component_spi_flash_sections_info
[ 87%] Built target idf_component_log_sections_info
[ 89%] Built target idf_component_efuse_sections_info
[ 91%] Built target idf_component_micro-ecc_sections_info
[ 92%] Built target idf_component_bootloader_support_sections_info
[ 48%] Built target idf_component_freertos_sections_info
[ 58%] Built target afr_3rdparty_mbedtls
[ 59%] Built target idf_component_newlib_sections_info
[ 59%] Built target idf_component_vfs_sections_info
[ 92%] Built target ldgen_section_infos
[ 59%] Built target idf_component_esp_ringbuf_sections_info
[ 59%] Built target idf_component_driver_sections_info
[ 59%] Built target idf_component_tcpip_adapter_sections_info
[ 59%] Built target idf_component_esp_event_sections_info
[ 92%] Built target ldgen
[ 59%] Built target idf_component_spi_flash_sections_info
[ 59%] Built target idf_component_app_update_sections_info
[ 59%] Built target idf_component_bootloader_support_sections_info
[ 59%] Built target idf_component_micro-ecc_sections_info
[ 98%] Built target bootloader.elf
[ 59%] Built target idf_component_efuse_sections_info
[ 59%] Built target idf_component_xtensa-debug-module_sections_info
[ 59%] Built target idf_component_app_trace_sections_info
[ 59%] Built target idf_component_ethernet_sections_info
[100%] Built target bootloader
[ 59%] Built target idf_component_nimble
[ 68%] Built target idf_component_cxx_sections_info
[ 68%] Built target idf_component_bt_sections_info
[ 69%] Built target idf_component_console_sections_info
[ 69%] Completed 'bootloader'
[ 69%] Built target idf_component_esp_adc_cal_sections_info
[ 70%] Built target idf_component_expat_sections_info
[ 70%] Built target idf_component_wear_levelling_sections_info
[ 70%] Built target idf_component_sdmmc_sections_info
[ 71%] Built target bootloader
[ 71%] Built target idf_component_fatfs_sections_info
[ 72%] Built target idf_component_freemodbus_sections_info
[ 72%] Built target idf_component_nghttp_sections_info
[ 79%] Built target idf_component_esp32[ 73%] Built target idf_component_openssl_sections_info
[ 79%] Built target idf_component_spiffs_sections_info
[ 79%] Built target idf_component_wpa_supplicant_sections_info
[ 79%] Built target idf_component_ulp_sections_info
[ 80%] Built target idf_component_esp32_sections_info
[ 80%] Built target afr_wifi[ 80%] Built target idf_component_nimble_sections_info[ 82%] Built target afr_crypto[ 82%] Built target ldgen_section_infos[ 83%] Built target afr_secure_sockets[ 83%] Built target ldgen_esp32.project.ld_script[ 84%] Built target afr_tls[ 84%] Built target afr_pkcs11_implementation[ 86%] Built target afr_pkcs11[ 87%] Built target afr_common[ 88%] Built target afr_dev_mode_key_provisioning[ 88%] Built target afr_platform[ 90%] Built target afr_serializer[ 92%] Built target afr_ble[ 93%] Built target afr_ble_hal[ 94%] Built target afr_ble_wifi_provisioning[ 96%] Built target afr_mqtt[100%] Built target aws_demos[100%] Built target app
Choosing default port /dev/cu.SLAB_USBtoUART (use '-p PORT' option to set a specific serial port)
Running esptool.py in directory /Users/jianhong/Downloads/FreeRTOS/build
Executing "/usr/bin/python /Users/jianhong/Downloads/FreeRTOS/vendors/espressif/esp-idf/components/esptool_py/esptool/esptool.py -p /dev/cu.SLAB_USBtoUART -b 460800 --after hard_reset write_flash @flash_project_args"...
esptool.py -p /dev/cu.SLAB_USBtoUART -b 460800 --after hard_reset write_flash --flash_mode dio --flash_freq 40m --flash_size 4MB 0x1000 bootloader/bootloader.bin 0x8000 partition_table/partition-table.bin 0x16000 ota_data_initial.bin 0x20000 aws_demos.binesptool.py v2.8-dev
Serial port /dev/cu.SLAB_USBtoUART
Connecting....
Detecting chip type... ESP32
Chip is ESP32D0WDQ6 (revision 1)
Features: WiFi, BT, Dual Core, 240MHz, VRef calibration in efuse, Coding Scheme None
Crystal is 40MHz
MAC: 24:0a:c4:c6:76:a4
Uploading stub...
Running stub...
Stub running...
Changing baud rate to 460800
Changed.Configuring flash size...
Compressed 26592 bytes to 15831...
Wrote 26592 bytes (15831 compressed) at 0x00001000 in 0.4 seconds (effective 576.6 kbit/s)...Hash of data verified.
Compressed 3072 bytes to 118...
Wrote 3072 bytes (118 compressed) at 0x00008000 in 0.0 seconds (effective 1751.3 kbit/s)...Hash of data verified.
Compressed 8192 bytes to 31...
Wrote 8192 bytes (31 compressed) at 0x00016000 in 0.0 seconds (effective 5023.8 kbit/s)...Hash of data verified.
Compressed 932544 bytes to 580234...
Wrote 932544 bytes (580234 compressed) at 0x00020000 in 13.7 seconds (effective 544.6 kbit/s)...Hash of data verified.
Leaving...Hard resetting via RTS pin...Done
After flashing, we log into AWS IoT Core and can find that the platform has received MQTT messages sent from the ESP32/FreeRTOS.
If you want to obtain the standard output information from the development board’s serial port, you can use the following command to build and flash.
./vendors/espressif/esp-idf/tools/idf.py erase_flash flash monitor -p /dev/cu.SLAB_USBtoUART -B build
Here is the entire process:
I (72) boot: Chip Revision: 1
I (72) boot_comm: chip revision: 1, min. bootloader chip revision: 0
I (39) boot: ESP-IDF v3.3-163-g601a03e 2nd stage bootloader
I (39) boot: compile time 22:20:19
I (39) boot: Enabling RNG early entropy source...
I (44) boot: SPI Speed : 40MHz
I (48) boot: SPI Mode : DIO
I (52) boot: SPI Flash Size : 4MB
I (56) boot: Partition Table:
I (60) boot: ## Label Usage Type ST Offset Length
I (67) boot: 0 nvs WiFi data 01 02 00010000 00006000
I (75) boot: 1 otadata OTA data 01 00 00016000 00002000
I (82) boot: 2 phy_init RF data 01 01 00018000 00001000
I (90) boot: 3 ota_0 OTA app 00 10 00020000 00177000
I (97) boot: 4 ota_1 OTA app 00 11 001a0000 00177000
I (105) boot: 5 storage WiFi data 01 02 00317000 00010000
I (112) boot: End of partition table
I (117) boot: No factory image, trying OTA 0
I (121) boot_comm: chip revision: 1, min. application chip revision: 0
I (129) esp_image: segment 0: paddr=0x00020020 vaddr=0x3f400020 size=0x2304c (143436) map
I (188) esp_image: segment 1: paddr=0x00043074 vaddr=0x3ffbdb60 size=0x030d4 ( 12500) load
I (193) esp_image: segment 2: paddr=0x00046150 vaddr=0x40080000 size=0x00400 ( 1024) load
0x40080000: _WindowOverflow4 at /Users/jianhong/Downloads/FreeRTOS/freertos_kernel/portable/ThirdParty/GCC/Xtensa_ESP32/xtensa_vectors.S:1713
I (195) esp_image: segment 3: paddr=0x00046558 vaddr=0x40080400 size=0x09ab8 ( 39608) load
I (220) esp_image: segment 4: paddr=0x00050018 vaddr=0x400d0018 size=0xa70cc (684236) map
0x400d0018: _flash_cache_start at ??:?
I (461) esp_image: segment 5: paddr=0x000f70ec vaddr=0x40089eb8 size=0x0c9ac ( 51628) load
0x40089eb8: r_rwbt_isr at ??:?
I (495) boot: Loaded app from partition at offset 0x20000
I (531) boot: Set actual ota_seq=1 in otadata[0]
I (531) boot: Disabling RNG early entropy source...
I (532) cpu_start: Pro cpu up.
I (535) cpu_start: Application information:
I (539) cpu_start: Project name: esp-idf
I (544) cpu_start: App version: 1
I (549) cpu_start: Compile time: Jun 30 2020 22:19:48
I (555) cpu_start: ELF file SHA256: ca03371377ab875e...
I (561) cpu_start: ESP-IDF: v3.3-163-g601a03e
I (567) cpu_start: Single core mode
I (571) heap_init: Initializing. RAM available for dynamic allocation:
I (578) heap_init: At 3FFAFF10 len 000000F0 (0 KiB): DRAM
I (584) heap_init: At 3FFB6388 len 00001C78 (7 KiB): DRAM
I (590) heap_init: At 3FFB9A20 len 00004108 (16 KiB): DRAM
I (596) heap_init: At 3FFBDB5C len 00000004 (0 KiB): DRAM
I (603) heap_init: At 3FFCCC60 len 000133A0 (76 KiB): DRAM
I (609) heap_init: At 3FFE0440 len 0001FBC0 (126 KiB): D/RAM
I (615) heap_init: At 40078000 len 00008000 (32 KiB): IRAM
I (621) heap_init: At 40096864 len 0000979C (37 KiB): IRAM
I (627) cpu_start: Pro cpu start user code
I (310) cpu_start: Starting scheduler on PRO CPU.
I (317) uart: queue free spaces: 100 0 [main] Initializing FreeRTOS TCP stack
I (317) PKCS11: Initializing NVS partition: "storage"
1 0 [main] Write certificate...
2 14 [iot_thread] [INFO ][DEMO][140] ---------STARTING DEMO---------
I (457) BTDM_INIT: BT controller compile version [9891bc6]
3 14 [iot_thread] [INFO ][INIT][140] SDK successfully initialized.
I (457) system_api: Base MAC address is not set, read default base MAC address from BLK0 of EFUSE
W (477) phy_init: failed to load RF calibration data (0x1102), falling back to full calibration
I (617) phy: phy_version: 4102, 2fa7a43, Jul 15 2019, 13:06:06, 0, 2
GAP procedure initiated: stop advertising.
GAP procedure initiated: advertise; disc_mode=2 adv_channel_map=0 own_addr_type=0 adv_filter_policy=0 adv_itvl_min=480 adv_itvl_max=960
I (927) wifi: wifi driver task: 3ffd8af8, prio:23, stack:3584, core=0
I (927) system_api: Base MAC address is not set, read default base MAC address from BLK0 of EFUSE
I (927) system_api: Base MAC address is not set, read default base MAC address from BLK0 of EFUSE
I (957) wifi: wifi firmware version: c94f3e6
I (957) wifi: config NVS flash: enabled
I (957) wifi: config nano formating: disabled
I (957) wifi: Init dynamic tx buffer num: 32
I (957) wifi: Init data frame dynamic rx buffer num: 32
I (957) wifi: Init management frame dynamic rx buffer num: 32
I (967) wifi: Init management short buffer num: 32
I (977) wifi: Init static rx buffer size: 1600
I (977) wifi: Init static rx buffer num: 10
I (977) wifi: Init dynamic rx buffer num: 32
I (987) wifi: mode : sta (24:0a:c4:c6:76:a4)
I (997) WIFI: SYSTEM_EVENT_STA_START
I (1837) wifi: new:<7,0>, old:<1,0>, ap:<255,255>, sta:<7,0>, prof:1
I (2827) wifi: state: init -> auth (b0)
I (2827) wifi: state: auth -> assoc (0)
I (2837) wifi: state: assoc -> run (10)
I (3117) wifi: connected with 712, channel 7, BW20, bssid = 64:9a:08:0e:48:8c
I (3117) wifi: pm start, type: 1
I (3117) WIFI: SYSTEM_EVENT_STA_CONNECTED
4 301 [IP-task] vDHCPProcess: offer c0a87d6d
I (3347) event: sta ip: 192.168.125.109, mask: 255.255.255.0, gw: 192.168.125.1
I (3347) WIFI: SYSTEM_EVENT_STA_GOT_IP
5 303 [IP-task] vDHCPProcess: offer c0a87d6d
I (3367) [iot_thread] [INFO ][MQTT][9480] Establishing new MQTT connection.
11 948 [iot_thread] [INFO ][MQTT][9480] Anonymous metrics (SDK language, SDK version) will be provided to AWS IoT. Recompile with AWS_IOT_MQTT_ENABLE_METRICS set to 0 to disable.
12 948 [iot_thread] [INFO ][MQTT][9480] (MQTT connection 0x3ffde3a8, CONNECT operation 0x3ffdfe1c) Waiting for operation completion.
13 1050 [iot_thread] [INFO ][MQTT][10500] (MQTT connection 0x3ffde3a8, CONNECT operation 0x3ffdfe1c) Wait complete with result SUCCESS.
14 1050 [iot_thread] [INFO ][MQTT][10500] New MQTT connection 0x3ffd2340 established.
15 1050 [iot_thread] [INFO ][MQTT][10500] (MQTT connection 0x3ffde3a8) SUBSCRIBE operation scheduled.
16 1050 [iot_thread] [INFO ][MQTT][10500] (MQTT connection 0x3ffde3a8, SUBSCRIBE operation 0x3ffdfd88) Waiting for operation completion.
17 1152 [iot_thread] [INFO ][MQTT][11520] (MQTT connection 0x3ffde3a8, SUBSCRIBE operation 0x3ffdfd88) Wait complete with result SUCCESS.
18 1152 [iot_thread] [INFO ][DEMO][11520] All demo topic filter subscriptions accepted.
19 1152 [iot_thread] [INFO ][DEMO][11520] Publishing messages 0 to 1.
20 1154 [iot_thread] [INFO ][MQTT][11540] (MQTT connection 0x3ffde3a8) MQTT PUBLISH operation queued.
21 1155 [iot_thread] [INFO ][MQTT][11550] (MQTT connection 0x3ffde3a8) MQTT PUBLISH operation queued.
22 1155 [iot_thread] [INFO ][DEMO][11550] Waiting for 2 publishes to be received.
23 1184 [iot_thread] [INFO ][DEMO][11840] MQTT PUBLISH 0 successfully sent.
24 1184 [iot_thread] [INFO ][DEMO][11840] MQTT PUBLISH 1 successfully sent.
25 1214 [iot_thread] [INFO ][DEMO][12140] Incoming PUBLISH received:Subscription topic filter: iotdemo/topic/1Publish topic name: iotdemo/topic/1Publish retain flag: 0Publish QoS: 126 1214 [iot_thread] [INFO ][MQTT][12140] (MQTT connection 0x3ffde3a8) MQTT PUBLISH operation queued.
27 1214 [iot_thread] [INFO ][DEMO][12140] Acknowledgment message for PUBLISH 0 will be sent.
28 1217 [iot_thread] [INFO ][DEMO][12170] Incoming PUBLISH received:Subscription topic filter: iotdemo/topic/2Publish topic name: iotdemo/topic/2Publish retain flag: 0Publish QoS: 129 1217 [iot_thread] [INFO ][MQTT][12170] (MQTT connection 0x3ffde3a8) MQTT PUBLISH operation queued.
30 1217 [iot_thread] [INFO ][DEMO][12170] Acknowledgment message for PUBLISH 1 will be sent.
31 1218 [iot_thread] [INFO ][DEMO][12170] 2 publishes received.
32 1218 [iot_thread] [INFO ][DEMO][12180] Publishing messages 2 to 3.
33 1218 [iot_thread] [INFO ][MQTT][12180] (MQTT connection 0x3ffde3a8) MQTT PUBLISH operation queued.
34 1218 [iot_thread] [INFO ][MQTT][12180] (MQTT connection 0x3ffde3a8) MQTT PUBLISH operation queued.
35 1218 [iot_thread] [INFO ][DEMO][12180] Waiting for 2 publishes to be received.
36 1368 [iot_thread] [INFO ][DEMO][13680] Incoming PUBLISH received:Subscription topic filter: iotdemo/topic/3Publish topic name: iotdemo/topic/3Publish retain flag: 0Publish QoS: 137 1368 [iot_thread] [INFO ][MQTT][13680] (MQTT connection 0x3ffde3a8) MQTT PUBLISH operation queued.
38 1368 [iot_thread] [INFO ][DEMO][13680] Acknowledgment message for PUBLISH 2 will be sent.
39 1371 [iot_thread] [INFO ][DEMO][13710] Incoming PUBLISH received:Subscription topic filter: iotdemo/topic/4Publish topic name: iotdemo/topic/4Publish retain flag: 0Publish QoS: 140 1371 [iot_thread] [INFO ][MQTT][13710] (MQTT connection 0x3ffde3a8) MQTT PUBLISH operation queued.
41 1371 [iot_thread] [INFO ][DEMO][13710] Acknowledgment message for PUBLISH 3 will be sent.
42 1371 [iot_thread] [INFO ][DEMO][13710] 2 publishes received.
43 1371 [iot_thread] [INFO ][DEMO][13710] Publishing messages 4 to 5.
44 1371 [iot_thread] [INFO ][MQTT][13710] (MQTT connection 0x3ffde3a8) MQTT PUBLISH operation queued.
45 1371 [iot_thread] [INFO ][MQTT][13710] (MQTT connection 0x3ffde3a8) MQTT PUBLISH operation queued.
46 1371 [iot_thread] [INFO ][DEMO][13710] Waiting for 2 publishes to be received.
47 1398 [iot_thread] [INFO ][DEMO][13980] MQTT PUBLISH 2 successfully sent.
48 1470 [iot_thread] [INFO ][DEMO][14700] MQTT PUBLISH 3 successfully sent.
49 1470 [iot_thread] [INFO ][DEMO][14700] Incoming PUBLISH received:Subscription topic filter: iotdemo/topic/3Publish topic name: iotdemo/topic/3Publish retain flag: 0Publish QoS: 150 1471 [iot_thread] [INFO ][MQTT][14710] (MQTT connection 0x3ffde3a8) MQTT PUBLISH operation queued.
51 1471 [iot_thread] [INFO ][DEMO][14710] Acknowledgment message for PUBLISH 2 will be sent.
52 1474 [iot_thread] [INFO ][DEMO][14730] Incoming PUBLISH received:Subscription topic filter: iotdemo/topic/4Publish topic name: iotdemo/topic/4Publish retain flag: 0Publish QoS: 153 1474 [iot_thread] [INFO ][MQTT][14740] (MQTT connection 0x3ffde3a8) MQTT PUBLISH operation queued.
54 1474 [iot_thread] [INFO ][DEMO][14740] Acknowledgment message for PUBLISH 3 will be sent.
55 1474 [iot_thread] [INFO ][DEMO][14740] 2 publishes received.
56 1474 [iot_thread] [INFO ][DEMO][14740] Publishing messages 6 to 7.
57 1474 [iot_thread] [INFO ][MQTT][14740] (MQTT connection 0x3ffde3a8) MQTT PUBLISH operation queued.
58 1474 [iot_thread] [INFO ][MQTT][14740] (MQTT connection 0x3ffde3a8) MQTT PUBLISH operation queued.
59 1474 [iot_thread] [INFO ][DEMO][14740] Waiting for 2 publishes to be received.
60 1481 [iot_thread] [INFO ][DEMO][14810] Incoming PUBLISH received:Subscription topic filter: iotdemo/topic/1Publish topic name: iotdemo/topic/1Publish retain flag: 0Publish QoS: 161 1481 [iot_thread] [INFO ][MQTT][14810] (MQTT connection 0x3ffde3a8) MQTT PUBLISH operation queued.
62 1481 [iot_thread] [INFO ][DEMO][14810] Acknowledgment message for PUBLISH 4 will be sent.
63 1484 [iot_thread] [INFO ][DEMO][14840] Incoming PUBLISH received:Subscription topic filter: iotdemo/topic/2Publish topic name: iotdemo/topic/2Publish retain flag: 0Publish QoS: 164 1484 [iot_thread] [INFO ][MQTT][14840] (MQTT connection 0x3ffde3a8) MQTT PUBLISH operation queued.
65 1484 [iot_thread] [INFO ][DEMO][14840] Acknowledgment message for PUBLISH 5 will be sent.
66 1484 [iot_thread] [INFO ][DEMO][14840] 2 publishes received.
67 1484 [iot_thread] [INFO ][DEMO][14840] Publishing messages 8 to 9.
68 1484 [iot_thread] [INFO ][MQTT][14840] (MQTT connection 0x3ffde3a8) MQTT PUBLISH operation queued.
69 1485 [iot_thread] [INFO ][MQTT][14850] (MQTT connection 0x3ffde3a8) MQTT PUBLISH operation queued.
70 1485 [iot_thread] [INFO ][DEMO][14850] Waiting for 2 publishes to be received.
71 1501 [iot_thread] [INFO ][DEMO][15010] MQTT PUBLISH 4 successfully sent.
72 1737 [iot_thread] [INFO ][DEMO][17370] Incoming PUBLISH received:Subscription topic filter: iotdemo/topic/1Publish topic name: iotdemo/topic/1Publish retain flag: 0Publish QoS: 173 1737 [iot_thread] [INFO ][MQTT][17370] (MQTT connection 0x3ffde3a8) MQTT PUBLISH operation queued.
74 1737 [iot_thread] [INFO ][DEMO][17370] Acknowledgment message for PUBLISH 4 will be sent.
75 1740 [iot_thread] [INFO ][DEMO][17400] Incoming PUBLISH received:Subscription topic filter: iotdemo/topic/2Publish topic name: iotdemo/topic/2Publish retain flag: 0Publish QoS: 176 1740 [iot_thread] [INFO ][MQTT][17400] (MQTT connection 0x3ffde3a8) MQTT PUBLISH operation queued.
77 1740 [iot_thread] [INFO ][DEMO][17400] Acknowledgment message for PUBLISH 5 will be sent.
78 1740 [iot_thread] [INFO ][DEMO][17400] 2 publishes received.
79 1741 [iot_thread] [INFO ][DEMO][17400] Publishing messages 10 to 11.
80 1741 [iot_thread] [INFO ][MQTT][17410] (MQTT connection 0x3ffde3a8) MQTT PUBLISH operation queued.
81 1741 [iot_thread] [INFO ][MQTT][17410] (MQTT connection 0x3ffde3a8) MQTT PUBLISH operation queued.
82 1741 [iot_thread] [INFO ][DEMO][17410] Waiting for 2 publishes to be received.
83 1747 [iot_thread] [INFO ][DEMO][17470] Incoming PUBLISH received:Subscription topic filter: iotdemo/topic/3Publish topic name: iotdemo/topic/3Publish retain flag: 0Publish QoS: 184 1747 [iot_thread] [INFO ][MQTT][17470] (MQTT connection 0x3ffde3a8) MQTT PUBLISH operation queued.
85 1747 [iot_thread] [INFO ][DEMO][17470] Acknowledgment message for PUBLISH 6 will be sent.
86 1751 [iot_thread] [INFO ][DEMO][17510] Incoming PUBLISH received:Subscription topic filter: iotdemo/topic/4Publish topic name: iotdemo/topic/4Publish retain flag: 0Publish QoS: 187 1751 [iot_thread] [INFO ][MQTT][17510] (MQTT connection 0x3ffde3a8) MQTT PUBLISH operation queued.
88 1751 [iot_thread] [INFO ][DEMO][17510] Acknowledgment message for PUBLISH 7 will be sent.
89 1752 [iot_thread] [INFO ][DEMO][17520] 2 publishes received.
90 1752 [iot_thread] [INFO ][DEMO][17520] Publishing messages 12 to 13.
91 1753 [iot_thread] [INFO ][MQTT][17530] (MQTT connection 0x3ffde3a8) MQTT PUBLISH operation queued.
92 1753 [iot_thread] [INFO ][MQTT][17530] (MQTT connection 0x3ffde3a8) MQTT PUBLISH operation queued.
93 1753 [iot_thread] [INFO ][DEMO][17530] Waiting for 2 publishes to be received.
94 1758 [iot_thread] [INFO ][DEMO][17580] Incoming PUBLISH received:Subscription topic filter: iotdemo/topic/2Publish topic name: iotdemo/topic/2Publish retain flag: 0Publish QoS: 195 1758 [iot_thread] [INFO ][MQTT][17580] (MQTT connection 0x3ffde3a8) MQTT PUBLISH operation queued.
96 1758 [iot_thread] [INFO ][DEMO][17580] Acknowledgment message for PUBLISH 9 will be sent.
97 1761 [iot_thread] [INFO ][DEMO][17610] Incoming PUBLISH received:Subscription topic filter: iotdemo/topic/1Publish topic name: iotdemo/topic/1Publish retain flag: 0Publish QoS: 198 1761 [iot_thread] [INFO ][MQTT][17610] (MQTT connection 0x3ffde3a8) MQTT PUBLISH operation queued.
99 1761 [iot_thread] [INFO ][DEMO][17610] Acknowledgment message for PUBLISH 8 will be sent.
100 1763 [iot_thread] [INFO ][DEMO][17630] 2 publishes received.
101 1763 [iot_thread] [INFO ][DEMO][17630] Publishing messages 14 to 15.
102 1763 [iot_thread] [INFO ][MQTT][17630] (MQTT connection 0x3ffde3a8) MQTT PUBLISH operation queued.
103 1763 [iot_thread] [INFO ][MQTT][17630] (MQTT connection 0x3ffde3a8) MQTT PUBLISH operation queued.
104 1763 [iot_thread] [INFO ][DEMO][17630] Waiting for 2 publishes to be received.
105 1768 [iot_thread] [INFO ][DEMO][17680] MQTT PUBLISH 6 successfully sent.
106 1769 [iot_thread] [INFO ][DEMO][17690] Incoming PUBLISH received:Subscription topic filter: iotdemo/topic/3Publish topic name: iotdemo/topic/3Publish retain flag: 0Publish QoS: 173 1769 [iot_thread] [INFO ][MQTT][17690] (MQTT connection 0x3ffde3a8) MQTT PUBLISH operation queued.
108 1769 [iot_thread] [INFO ][DEMO][17690] Acknowledgment message for PUBLISH 6 will be sent.
109 1772 [iot_thread] [INFO ][DEMO][17720] MQTT PUBLISH 7 successfully sent.
110 1773 [iot_thread] [INFO ][DEMO][17730] Incoming PUBLISH received:Subscription topic filter: iotdemo/topic/4Publish topic name: iotdemo/topic/4Publish retain flag: 0Publish QoS: 173 1773 [iot_thread] [INFO ][MQTT][17730] (MQTT connection 0x3ffde3a8) MQTT PUBLISH operation queued.
112 1773 [iot_thread] [INFO ][DEMO][17730] Acknowledgment message for PUBLISH 7 will be sent.
113 1774 [iot_thread] [INFO ][DEMO][17740] 2 publishes received.
114 1776 [iot_thread] [INFO ][DEMO][17760] Publishing messages 16 to 17.
115 1776 [iot_thread] [INFO ][MQTT][17760] (MQTT connection 0x3ffde3a8) MQTT PUBLISH operation queued.
116 1776 [iot_thread] [INFO ][MQTT][17760] (MQTT connection 0x3ffde3a8) MQTT PUBLISH operation queued.
117 1776 [iot_thread] [INFO ][DEMO][17760] Waiting for 2 publishes to be received.
118 1780 [iot_thread] [INFO ][DEMO][17800] MQTT PUBLISH 9 successfully sent.
119 1781 [iot_thread] [INFO ][DEMO][17810] MQTT PUBLISH 8 successfully sent.
120 1782 [iot_thread] [INFO ][DEMO][17820] Incoming PUBLISH received:Subscription topic filter: iotdemo/topic/2Publish topic name: iotdemo/topic/2Publish retain flag: 0Publish QoS: 195 1782 [iot_thread] [INFO ][MQTT][17820] (MQTT connection 0x3ffde3a8) MQTT PUBLISH operation queued.
122 1782 [iot_thread] [INFO ][DEMO][17820] Acknowledgment message for PUBLISH 9 will be sent.
123 1785 [iot_thread] [INFO ][DEMO][17850] Incoming PUBLISH received:Subscription topic filter: iotdemo/topic/1Publish topic name: iotdemo/topic/1Publish retain flag: 0Publish QoS: 198 1785 [iot_thread] [INFO ][MQTT][17850] (MQTT connection 0x3ffde3a8) MQTT PUBLISH operation queued.
125 1785 [iot_thread] [INFO ][DEMO][17850] Acknowledgment message for PUBLISH 8 will be sent.
126 1786 [iot_thread] [INFO ][DEMO][17860] 2 publishes received.
127 1786 [iot_thread] [INFO ][DEMO][17860] Publishing messages 18 to 19.
128 1787 [iot_thread] [INFO ][MQTT][17870] (MQTT connection 0x3ffde3a8) MQTT PUBLISH operation queued.
129 1787 [iot_thread] [INFO ][MQTT][17870] (MQTT connection 0x3ffde3a8) MQTT PUBLISH operation queued.
130 1787 [iot_thread] [INFO ][DEMO][17870] Waiting for 2 publishes to be received.
131 1792 [iot_thread] [INFO ][DEMO][17920] MQTT PUBLISH 5 successfully sent.
132 1793 [iot_thread] [INFO ][DEMO][17930] MQTT PUBLISH 11 successfully sent.
133 1794 [iot_thread] [INFO ][DEMO][17940] Incoming PUBLISH received:Subscription topic filter: iotdemo/topic/4Publish topic name: iotdemo/topic/4Publish retain flag: 0Publish QoS: 173 1794 [iot_thread] [INFO ][MQTT][17940] (MQTT connection 0x3ffde3a8) MQTT PUBLISH operation queued.
135 1794 [iot_thread] [INFO ][DEMO][17940] Acknowledgment message for PUBLISH 11 will be sent.
136 1799 [iot_thread] [INFO ][DEMO][17990] 2 publishes received.
137 1799 [iot_thread] [INFO ][DEMO][17990] (MQTT connection 0x3ffde3a8) UNSUBSCRIBE operation scheduled.
138 1799 [iot_thread] [INFO ][DEMO][17990] (MQTT connection 0x3ffde3a8, UNSUBSCRIBE operation 0x3ffdf478) Waiting for operation completion.
139 1804 [iot_thread] [INFO ][DEMO][18040] MQTT PUBLISH 12 successfully sent.
140 1805 [iot_thread] [INFO ][DEMO][18050] MQTT PUBLISH 13 successfully sent.
141 1879 [iot_thread] [INFO ][DEMO][18790] MQTT PUBLISH 18 successfully sent.
142 1880 [iot_thread] [INFO ][DEMO][18800] MQTT PUBLISH 19 successfully sent.
143 1881 [iot_thread] [INFO ][MQTT][18810] (MQTT connection 0x3ffde3a8, UNSUBSCRIBE operation 0x3ffdf478) Wait complete with result SUCCESS.
144 1881 [iot_thread] [INFO ][MQTT][18810] (MQTT connection 0x3ffde3a8) Disconnecting connection.
145 1881 [iot_thread] [INFO ][MQTT][18810] (MQTT connection 0x3ffde3a8, DISCONNECT operation 0x3ffdef44) Waiting for operation completion.
146 1883 [iot_thread] [INFO ][MQTT][18830] (MQTT connection 0x3ffde3a8, DISCONNECT operation 0x3ffdef44) Wait complete with result SUCCESS.
147 1883 [iot_thread] [INFO ][MQTT][18830] (MQTT connection 0x3ffde3a8) Connection disconnected.
148 1884 [iot_thread] [INFO ][MQTT][18840] (MQTT connection 0x3ffde3a8) Network connection closed.
I (20137) wifi: state: run -> init (0)
I (20137) wifi: pm stop, total sleep time: 11989936 us / 17021033 us
I (20137) wifi: new:<7,0>, old:<7,0>, ap:<255,255>, sta:<7,0>, prof:1
I (20147) WIFI: SYSTEM_EVENT_STA_DISCONNECTED: 8153 1982 [iot_thread] [INFO ][MQTT][19820] (MQTT connection 0x3ffde3a8) Network connection destroyed.
154 1982 [iot_thread] [INFO ][MQTT][19820] MQTT library cleanup done.
155 1982 [iot_thread] [INFO ][DEMO][19820] memory_metrics::freertos_heap::before::bytes::184768
156 1982 [iot_thread] [INFO ][DEMO][19820] memory_metrics::freertos_heap::after::bytes::59988
157 1982 [iot_thread] [INFO ][DEMO][19820] memory_metrics::demo_task_stack::before::bytes::56961
158 1982 [iot_thread] [INFO ][DEMO][19820] memory_metrics::demo_task_stack::after::bytes::18881
159 1982 [iot_thread] [INFO ][DEMO][19820] Demo completed successfully.
160 1985 [iot_thread] [INFO ][INIT][19850] SDK cleanup done.
161 1985 [iot_thread] [INFO ][DEMO][19850] -------DEMO FINISHED-------
From the above Monitor results, we can see that the ESP32 running FreeRTOS continuously sends messages via MQTT to the AWS IoT platform.
The above is a very simple practice of FreeRTOS and Cloud; real-world development will be far more complex than the above practice. In fact, when I tried to change the MQTT messages sent by FreeRTOS to the JSON format data for Temperature and Humidity from the previous article, I needed to use more FreeRTOS functions to handle it.
Finished.