Normally if we look for tests with the ESP32 module and the MQTT protocol, they mainly use Arduino IDE for ESP32, there is no problem, but this time we will use espressif development environment “ESP-IDF” or “Espressif IoT Development Framework” for the ESP32 which has more advantages and features for more robust applications.
The ESP32 modules have more features than the ESP8266 as we already know, but these resources can not be fully exploited with the Arduino IDE, but ESP-IDF has all the features to create more professional applications.
Materials and where to buy
Video: MQTT in ESP32 with ESP-IDF ESP-MQTT
Espressif IoT Development Framework
Some time ago I indicated how to install and configure ESP-IDF for linux, in my case Lubuntu a variant of Ubuntu, if you are a Windows user, you can also mount Virtualbox and create a Lubuntu virtual machine and install ESP-IDF without problems, then some recommended tutorials.
Lubuntu in Virtual Machine (Vitualbox) in Windows
Complete and permanent installation of Lubuntu, I use it and it is excellent!!!.
ESP-MQTT sobre TCP/IP
We will use the example of ESP32 for MQTT.
Edit Compile and Download
Since a very simple process is required to download and compile the code to our ESP32, this process will be explained step by step in our Video tutorial:MQTT in ESP32 with ESP-IDF ESP-MQTT : PDAControl .
by default these modules in my case use the USB/Serial “/dev/ttyUSB0” in case of using another change in “make menuconfig”.
Downloading code to ESP32.
In any of the 3 versions previously seen should run without problems, but I will use the ESP32-PICO-D4 version, I was presented with a contest, I arrived 3 months late had already finished the contest, but ELEKTOR thank you very much for the module.
Code in execution.
- Topic subscription: /topic/qos1.
- Topic of publication: /topic/qos0.
Subscribe to the topic “/topic/qos0”.
Well this tutorial, is nothing new but it will work if you want to start in MQTT for ESP32 with ESP-IDF.
Maybe ESP-IDF seems very complex but clearly is not for novices, but they have a great documentation and its difficulty is rewarded with its robustness.
Again if you want to make a robust application in ESP32, I recommend using ESP-IDF, I have nothing against Arduino IDE I use it a lot, but if at any time you want to create a solution based on ESP32, the Espressif development environment is your best bet and will take better advantage of the ESP32 features.
Advantages of ESP-IDF
- Debugging processes and subprocesses.
- Code Structuring
- Control of execution of routine tasks and functions.
- Detailed documentation
- Control and better management of MQTT and Wifi example events.
- FreeRTOS is migrable to any other hardware platform without major compatibility problems or large modifications in code.