I use ESP32s while traveling or at home. Different approaches to connecting the ESP32's WiFi are possible. At home I have a router that I can connect to. But this is not the case in nomadic use. I use then the possibility of configuring the ESP32 in "Access Point" mode.
Every sketch I write, I have to reconfigure the section concerning the WiFi connection. This is not practical and is prone to errors. This little module uses conditional compilation in the Arduino IDE. It allows you to configure all the parameters in a small “wifi_cfg.h” file which can be pre-filled. All you have to do is modify the operating mode and possibly an IP address to have a functional WiFi connection.
The configuration file "wifi_cfg.h"Only this file need to be edited for changing anything in your WiFi configuration. This file can contain pre-filled, the settings for your WiFi configuration. The hostname can also be set, but I did not notice any changes...
Note that there are also the credentials to connect to your WiFi network in "station mode" and the credentials (ssid and password) of the access point that you can create. So be carefull with this file if you pass the files to somebody.
- Selection of Station mode is done by Commenting Out "#define AP".If "#define AP" is not Commented Out the ESP32 will work as Access Point. The IP parameters defined in section "// IP parameters for Access Point" are used.
- If "#define STATIC_IP" is Commented Out dhcp is used.If "#define STATIC_IP" is not Commented Out, static IP with the parameters defined in section "// IP parameters for Station mode with fixed IP" are used.
This procedure uses conditional compilation so that the generated code agrees with the parameters you defined in the "wifi_cfg.h" file.
There is no need to modify this file unless you want to remove the "Serial.print()" feature.
You no longer have to rack your brains, search for the parameters of your WiFi network, or do research when you want to switch from dhcp to fixed IP, or even use the ESP32 as an "Access Point".
How to use it- Place the files "wifi_cfg.h" and "ESP32_WiFi.h" in the the same directory as your sketch.
- Edit "wifi_cfg.h" for your settings.
- In your sketch ad a line: #include "ESP32_WiFi.h"
- and in the setup, call the procedure: WiFi_setup();
See the "Example_WiFi.ino".
There may be other ways to do this, but I don't have enough programming knowledge to go further.
Comments
Please log in or sign up to comment.