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!

Updated: 2023-08-19 von Bernhard | Übersetzung Deutsch |🔔 | Comments:0

ESP32 programming, Arduino - install requirements | ESP32 | ESP32 MQTT - Send data

Top articles in this section


ESP32 Flowmeter and RS485 Modbus

As described on the article ESP32 programming, Arduino - install requirements, my first goal was to read out a TUF-2000M Ultrasonic Flow Meter via an ESP32. 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 out the TUF-2000M via RS485, it...


DS18B20 - Temperature sensors in ESP-Home

Complementary to the article: DS18B20 Temperature Sensors ESP32, MQTT and WiFi - HowTo, I have meanwhile replaced the Arduino project with ESP-Home. Simple projects can be implemented much easier in ESPHome. As an example, in ESPHome these 2 lines are enough to address the temperature sensors:


Home Assistant + DIY Microcontroller + ESP Home (Docker)

With ESPHome it is very easy to program your own microcontroller for use in HomeAssistant. My first use for a self-programmed microcontroller was to record the water flow and temperature values of my heater, see: ESP32 programming, Arduino - install requirements.

Questions / Comments


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