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.

Hinweis: Alternativ zur Arduino IDE kann für den Einsatz in Home Assistant ESP-Home verwendet werden. ESP-Home kümmert sich um die Kommunikation mit Home-Assistant inklusive WLAN-Verbindung, siehe:  Home-Assistant + DIY Mikrocontroller + ESP Home (Docker)

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!

Questions / Comments

By continuing to browse the site, you agree to our use of cookies. More Details