MQTT in ESP32 with ESP-IDF – ESP-MQTT & Node-RED

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.

ESP32 Module

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

 
 

Tests Performed

In this opportunity we will test the example of MQTT using TCP / IP available in ESP-IDF Github.

For the test our ESP32 will use the public broker test.mosquitto.org through port 1883 and we will use another MQTT client with the help of Node-RED.

Recommendation: For a more detailed explanation step by step I recommend watching the full video MQTT in ESP32 with ESP-IDF ESP-MQTT & Node-RED available on our  Youtube channel PDAControl.

ESP-IDF

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”.

Recommendation: For a more detailed explanation step by step I recommend watching the full video MQTT in ESP32 with ESP-IDF ESP-MQTT & Node-RED available on our  Youtube channel PDAControl.

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.

 

Recommendation: For a more detailed explanation step by step I recommend watching the full video MQTT in ESP32 with ESP-IDF ESP-MQTT & Node-RED available on our  Youtube channel PDAControl.

Code in execution.

 

Node-RED

For this test we will use Node-RED, using the MQTT publication and subscription nodes.

  • Topic subscription: /topic/qos1.
  • Topic of publication: /topic/qos0.

Recommendation: For a more detailed explanation step by step I recommend watching the full video MQTT in ESP32 with ESP-IDF ESP-MQTT & Node-RED available on our  Youtube channel PDAControl.

Results

When starting or restarting ESP32, the MQTT event handler publishes “data_3” from the topic, “/topic/qos1”.

Subscribe to the topic “/topic/qos0”.

From Node-RED we send the datetime in Unix format and the ESP32 receives it instantly.

 

Conclusions

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.

Personally I have not thoroughly tested ESP-IDF but I know its scope when reading the documentation, maybe I will do an endeavor for an industrial solution and I will use ESP-IDF.

Recommendation: For a more detailed explanation step by step I recommend watching the full video MQTT in ESP32 with ESP-IDF ESP-MQTT & Node-RED available on our  Youtube channel PDAControl.

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.
 

Downloads

References

Leave a Reply