13. Networking and Communication
Hero shot

Materials used during the assignment
- ESP32 WROOM
- Button
- My "cat-controller"
- Neo pixel LED ring
- Cables

...And my cat... To supervise my work !

Installing the ESP32 Board
To use the ESP32 in Arduino IDE, you'll have to install it :
- In Arduino IDE, open the "File" menu and click on "Preferences"
- Go down to the “Additional Board Manager URLs” field and copy/paste the line below in it
https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json
- Press "ok" to close the window
- Open the Boards Manager by going in the "Tools" menu, then on "Board" and finally "Boards Manager…"
- Search for ESP32 in the search field and install the “ESP32 by Espressif Systems“ board
Testing the ESP32 - Without wifi
First let's check if the ESP32 is correctly working by following this ESP32 + button tutorial found on ESP32 I/O's website.
For that, connect a button on a GND (or VCC) pin and a digital pin of the ESP32.

Plug the ESP32 in your computer, open Arduino IDE and copy/paste this code :
#define BUTTON_PIN 21 // GIOP21 pin connected to button
void setup() {
Serial.begin(9600); // initialize serial communication at 9600 bits per second
// initialize the pushbutton pin as an pull-up input
// the pull-up input pin will be HIGH when the switch is open and LOW when the switch is closed.
pinMode(BUTTON_PIN, INPUT_PULLUP);
}
void loop() {
int buttonState = digitalRead(BUTTON_PIN); // read the state of the switch/button
Serial.println(buttonState); // print out the button's state
}
Upload the code on the ESP32 and open the serial monitor.
Eerytime you press the button, you'll see the number "1" change in "0".
"1" = High and "0" = Low
Personal issues
As I tried to upload the code on the ESP32, it didn't work at first.
The COM Port "wasn't connected".

I tried to select another one in the "Tools" menu but I couldn't. The option was blocked.
After several different attempts in Arduino IDE (like selecting all the different ESP32 boards or clicking on "debug". Why not?!), I did some research on internet and found the website Random Nerd Tutorials.

There is the "ESP32 Troubleshooting Guide" which sent me to install missing CP210X drivers that can be downloaded on the Silabs' website.

Once done, the ESP32 COM port appeard in Arduino IDE as I plugged it in the computer !
Testing the ESP32 - With wifi
The next step is to check that the ESP32 is connecting to the wifi.
To test the ESP32 with WiFi we need a broker to use the MQTT protocol.
Installing Mosquitto
Eclipse Mosquitto is an open source (EPL/EDL licensed) message broker that implements the MQTT protocol versions 5.0, 3.1.1 and 3.1.
Mosquitto is lightweight and is suitable for use on all devices from low power single board computers to full servers.
The MQTT protocol provides a lightweight method of carrying out messaging using a publish/subscribe model.
This makes it suitable for Internet of Things messaging such as with low power sensors or mobile devices such as phones, embedded computers or microcontrollers.

Files and resources
Files
Resources