ESP32 WiFi example


In preparation for uploading sketches to a microcontroller, I installed the ESP32 board infromations and a USB to UART Bridge driver, see: Preparations for Programming an ESP32.

Once the ESP32 is connected to the ArduinoIDE, the existing examples can be customized and uploaded to the ESP32. To use the integrated WiFi module, the ESP32 can connect as a client in a WLAN as follows:

WiFi Client

The WiFiClient example connects the ESP32 to the specified WLAN:

After selecting the example, the variables for the WLAN can be specified:
SSID: variable "ssid" and password "password" is clear, but what are the following variables: host, streamID and privateKey?

A look into the source code clarifies: The host is a web server with which the ESP establishes a connection after starting and the streamId, as well as the privateKey are transmitted to the server. To test only the WLAN connection, we can write anything here for now:

Then click on "Save",

"Verify and Upload"

After I selected the correct hardware and COM port in the Arduino IDE, the upload worked, see Programming ESP32, Installing Arduino - Prerequisites.

Then one more upload of the sketch and the ESP32 boots and executes it: The ESP connects to the WLAN and tries to contact the specified host, transmitting the specified "streamId" and the "privateKey" to the specified host. As host a server is necessary for the connection establishment, which accepts this. Since I don't have a server prepared for this, I'm content for now with being able to see the WLAN connection on my router:

A look into the "Serial Monitor" shows me the text output of the sketch:

Mirrored question marks ⸮ in the "Serial Monitor".

If the speed (baud rate) of the sketch does not match the baud rate of the Serial Monitor, nothing reasonable is output, in my case lots of "⸮'.

If the rate is correct, the output is also correct:

As already described, I didn't set up a web server as a remote station for the example, so the Serial Monitor shows me "connection failed".

Example HelloServer

Another example to test the WLAN is a simple webserver, the HelloServer example. For this example it is enough to enter the SSID (ssid) and the WLAN password (password):

After the upload and the boot process it is possible to retrieve the following web page in the browser from the ESP32:

positive Bewertung({{pro_count}})
Rate Post:
{{percentage}} % positive
negative Bewertung({{con_count}})

THANK YOU for your review!

Publication: 2022-11-04 from Bernhard 🔔


Top articles in this section


ESP32 Flowmeter - RS485 Modbus
As described in the first article of this series, my first goal was to read out a TUF-2000M Ultrasonic Flow Meter via an ESP32. For this purpose I found an example for an ESP8266 on the internet: Reading a TUF-2000M Ultrasonic Flow Meter with an Arduino or ESP8266 and https://forum.arduino.cc/t/comunicacion-rs485/698786/2. I described the setup of the TUF-2000M in the following article: Field Report: Ultrasonic Flow Meter TUF-2000M. To be able to read the TUF-2000M via RS485, it must first be c...

ESP32 MQTT - Send data
To be able to receive data from an ESP32, I have prepared an MQTT broker as a Docker container. The container can be integrated into Home-Assistant and thus forward the data from the ESP32 to Home-Assistant via MQTT. On the part of ESP32, I tested sending with the following sketch and later integrated the relevant parts into another sketch.

DS18B20 Temperature Sensors ESP32, MQTT and WiFi - HowTo
In addition to connecting a flow meter via RS485, I plugged 5-piece DS18B20 temperature sensors to the ESP32 so that their values are also transmitted to HomeAssistant via MQTT.

Questions / Comments