IoT with ESP32 Board

Spread the word!

Motivation

The ESP-32 development board makes it possible to code in the Arduino IDE and does not need any external wireless connectivity. In this post you can find useful information about common procedures you can face during your development.

Before going on … You have the possibility to order the ESP-32 Kit containing

  • 2 x ESP-32  Development Board
  • 5 x 10 KOhm Resistor
  • 2 x Breadboard
  • 5 x Pushbutton
  • 2 x USB to Micro B Cable
  • 75 x Jumper Wire 3.0″

Note: the Kit contains more components than you need to perform a single test! If it’s too much, just order specific components from online shops (e.g. on Ebay ESP-32).

PS: If you want a standalone application, it could be useful to buy a power bank.


Used model: ESP32-WROOM-32

Preparation

Open Arduino IDE > File > Preferences > Additional Boards Manager URLs:

https://dl.espressif.com/dl/package_esp32_index.json, http://arduino.esp8266.com/stable/package_esp8266com_index.json

Go to Tools > Board > Boards Manager…, and install ESP32 by Espressif Systems.

If you have trouble, go here.

Board selection

Board: DOIT ESP32 DEVKIT V1
Upload Speed: 921600
Flash Frequency: 80 MHz
Port: COM… (depends to which port the ESP32 is connected)

Uploading 

Remember: during the program upload, you need to press the BOOT button on the ESP32 board (connected with USB to the corresponding COM port) when you see “Connecting…” in the  console. As soon as it goes on with uploading the program, you can release the BOOT button.

Examples

Go to file > Examples. Under “Examples for DOIT ESP32 DEVKIT V1” you should be able to see many kind of application example, for example Wifi, or HTTPClient.

These examples are very important, since they represent a working code you can embedd in your application.

Testing: how to access your local server remotely

Let’s assume you have written your nice backend application locally and now you want to test it by letting your IoT device to connect to your server. If you want to test a client-server communication and you prefer to keep your server local, you can tunnel your local port to a public addresses (e.g. tunnel 80) by using Tunnel (follow the given instructions).

Access to HTTPS servers

If you need to e.g. submit POST requests to a HTTPS page, you will also need to export their SSL certificates (as .crt file).

ssl_export_firefox

Just copy and paste the certificate in Arduino IDE and add the line deliminters. At the end, it should look like this:

If you need to vertically select, copy and paste characters from Notepad++ (or other advanced text editors), you can simply keep Alt pressed during the selection!

Test everything with a small project

The files mentioned in this section can be found here:
https://github.com/Pisciotta/button-state-detector

I didn’t dedicate lot of time for this project, and for this reason the code could not appear very fancy. I also didn’t go deeper about optimisation issues and code documentation, so if it looks too messy, just start from the given example and the other information presented previously. There could be also errors for the timestamp value of the measurement. I will update this section if I will come back to the same sample project.

Anyway, even if this is not a serious IoT application, I still want to share it here (possibly for future improvements), otherwise it would be completely lost somewhere in my laptop.

esp32-blog

The idea is very simple: it must be shown when a button is pressed or released. The button is connected to the ESP32 board. You can easily find sample wiring schemes online (like here). The developer writes the backend locally (see index.php), e.g. using XAMPP server and tunnel it to a public address as described previously. Since I have an account on GitHub, I just got the idea to write such public address in a txt file on GitHub servers. The raw version of this file is the one to which the ESP connects.

raw

Don’t forget to create a test table in your database. Do it manually or just import the test.sql file.

Note: it’s possible that the SSL certificates given in main.ino are old !

Be the first to comment

Leave a Reply

Your email address will not be published.


*