BLOG developers portal FAQs

Connecting ESP32 to thethings.iO using MQTT

IoT

In this post we will explain how to connect and ESP-32 to thethings.iO platform through and ESP-32 from Espressif. Keep in mind that the project used as an example could be found in our 

repo:  https://github.com/theThings/ESP32_MQTT

Let’s go!

First of all, take a look on the requirements (for more explanations you can visit our previous blog post HERE https://blog.thethings.io/http-integration-with-esp32-s2/

  • Java SE (11 or higher) 
  • Python (3.5 or higher). Otherwise, install the most recent version by clicking on each of the links.
  • ESP-IDF Tools Installer 
  • Eclipse IDE for C / C ++ Developers package with the necessary plugin that can be found here.
  • Git version manager, install the most recent version by clicking on the link. Once installed, clone the ESP-IDF 4.2 repository where the ESP32-S2 module libraries are located (here).

With all the needed software installed we can start to play with the ESP-32 and thethings.io platform:

Take the ESP32-S2-Saola-1 kit from Espressif and connect it via USB to the terminal. From here, you can:

  1. Create a project.
  2. Create a project with a template.
  3. Open a project.

CREATE A PROJECT

Projects are easily created by selecting the File> New> Espressif IDF Project tab. Enter the name and click Finish.

CREATE A PROJECT WITH TEMPLATE

Template projects are the best option for both novice users, who want to discover first-hand the potential of the ESP32-S2, as well as experts or professionals, who appreciate having  parts of the code already made to quickly move to the testing phase.

CREATE A PROJECT WITH TEMPLATE

Template projects are the best option for both novice users, who want to discover first-hand the potential of the ESP32-S2, as well as experts or professionals, who appreciate having  parts of the code already made to quickly move to the testing phase.

 

Before compiling, the user needs to fill in three code definitions. From the project explorer window (located on the left of the screen) locate and open the main file, main.c. Definitions are at the beginning.

Write the identifier and password of the Wi-Fi from which you want to make the connection and the token number assigned to the thing, which will be responsible for storing the samples received by MQTT. Note: if the Wi-Fi does not have a password, leave the space empty (“”).

New users of the Thethings.io platform who need to create an account can do so at https://thethings.io and follow the steps. After registration is complete, create a new IoT product through the Things Manager screen and select JSON as the product type.

Once the main.c file has been modified, click on the hammer icon (above the project explorer) to compile. Verify that the process has finished without errors or warnings.

Next, start recording the kit by clicking on the play icon (located next to the hammer). Once completed, you can see from the Things Details screen how a temperature record has been created, which will be updated every 5 minutes.

 

Optionally, the application can be tracked via USB by opening the terminal window. Select the Window> Show View> Terminal. A new window will appear with various icons in the upper right. Click the first at all (the one that looks like a screen). A new configuration window will appear. Select the port to which the kit is connected and leave the rest of the default values. Click OK to start communication.

Use thethings.iO, the simplest enterprise IoT platform. If you have any doubts please contact us at hello@thethings.io