Sunday, December 22, 2024
ESPExplainerHow ToIoT HardwaresTutorials/DIY

Dynamic WLAN configuration for ESP32 Board | AutoConnect

Today i am telling to you about Dynamic WLAN configuration for ESP32 Board. An Arduino library available for ESP8266/ESP32 WLAN configuration at run time with web interface. It is no needed hard-coding in advance the SSID and Password into the sketch to connect between. ESP8266/ESP32 and WLAN. You can input SSID & Password from a smartphone via the web interface at runtime.

To the dynamic configuration for ESP32 for joining to WLAN with SSID and PSK accordingly. It an Arduino library united with ESP8266WebServer class of ESP8266 or WebServer class of ESP32. Easily implementing the Web interface constituting the WLAN for ESP8266/ESP32 WiFi connection. With this library to make a sketch easily which connects from ESP8266/ESP32 to the access point at runtime by the web interface without hard-coded SSID and password.

Autoconnect
source- https://github.com/Hieromon/AutoConnect

Key points

No need pre-coded SSID & password –

It is no needed hard-coding in advance the SSID and Password into the sketch to connect between ESP8266/ESP32 and WLAN. You can input SSID & Password from a smartphone via the web interface at runtime.

Simple usage – AutoConnect control screen will be displayed automatically for establishing new connections. It aids by the captive portal when vested the connection cannot be detected. By using the AutoConnect menu, to manage the connections convenient.

Store the established connection – The connection authentication data as credentials are saved automatically in EEPROM of ESP8266/ESP32 and You can select the past SSID from the AutoConnect menu.

Easy to embed in – AutoConnect can be embedded easily into your sketch, just “begin” and “handleClient“.

Lives with the your sketches – The sketches which provide the web page using ESP8266WebServer/WebServer there is, AutoConnect will not disturb it. AutoConnect can use an already instantiated ESP8266WebServer object(ESP8266) or WebServer object(ESP32), or itself can assign it.

Easily add user-owned web screen and parameters – You can easily add your own web screen that can consist of representative HTML elements as the styled TEXT, INPUT, BUTTON, CHECKBOX, RADIO, SELECT, SUBMIT into the menu. It can be invoked from the AutoConnect menu and parameters can be passed.


How to Use | How embed the AutoConnect to the sketches | Dynamic WLAN configuration for ESP32


Most simple approach to applying AutoConnect for the existing sketches, follow the below steps.

Required libraries

AutoConnect requires the following environment and libraries.

Arduino IDE

The current upstream at the 1.8 level or later is needed. Please install from the official Arduino IDE download page. This step is not required if you already have a modern version.

ESP8266 Arduino core

AutoConnect targets sketches made on the assumption of ESP8266 Community’s Arduino core. Stable 2.4.0 or higher required and the latest release is recommended.
Install third-party platform using the Boards Manager of Arduino IDE. Package URL is http://arduino.esp8266.com/stable/package_esp8266com_index.json

ESP32 Arduino core

Also, to apply AutoConnect to ESP32, the arduino-esp32 core provided by Espressif is needed. Stable 1.0.1 or required and the latest release is recommended.
Install third-party platform using the Boards Manager of Arduino IDE. You can add multiple URLs into Additional Board Manager URLs field, separating them with commas. Package URL is https://dl.espressif.com/dl/package_esp32_index.json for ESP32.

Additional library (Required)

The PageBuilder library to build HTML for ESP8266WebServer is needed.
To install the PageBuilder library into your Arduino IDE, you can use the Library Manager. Select the board of ESP8266 series in the Arduino IDE, open the library manager and search keyword ‘PageBuilder‘ with the topic ‘Communication‘, then you can see the PageBuilder. The latest version is required 1.3.2 later.

Additional library (Optional)

By adding the ArduinoJson library, AutoConnect will be able to handle the custom Web pages described with JSON.

Install the AutoConnect

Clone or download from the AutoConnect GitHub repository. hen in the Arduino IDE, navigate to “Sketch > Include Library”. At the top of the drop down list, select the option to “Add .ZIP Library…”.

How To use Autoconnect with ESP32 | Dynamic WLAN configuration for ESP32

Open the Arduino IDE, write the following sketch and upload it. The feature of this sketch is that the SSID and Password are not coded.

#include <ESP8266WiFi.h>          // Replace with WiFi.h for ESP32
#include <ESP8266WebServer.h>     // Replace with WebServer.h for ESP32
#include <AutoConnect.h>

ESP8266WebServer Server;          // Replace with WebServer for ESP32
AutoConnect      Portal(Server);

void rootPage() {
  char content[] = "Hello, world";
  Server.send(200, "text/plain", content);
}

void setup() {
  delay(1000);
  Serial.begin(115200);
  Serial.println();

  Server.on("/", rootPage);
  if (Portal.begin()) {
    Serial.println("WiFi connected: " + WiFi.localIP().toString());
  }
}

void loop() {
    Portal.handleClient();
}

The above code can be applied to ESP8266. To apply to ESP32, replace ESP8266WebServer class with WebServer and include WiFi.h and WebServer.h of arduino-esp32 appropriately.

After about 30 seconds, if the ESP8266 cannot connect to nearby Wi-Fi spot, you pull out your smartphone and open Wi-Fi settings from the Settings Apps. You can see the esp8266ap in the list of “CHOOSE A NETWORK…”. Then tap the esp8266ap and enter password 12345678.A something screen pops up automatically.

This screen displays the current status of the established connection, WiFi mode, IP address, free memory size, and etc. Also, the hamburger icon is the control menu of AutoConnect seems at the upper right. By tap the hamburger icon, the control menu appear.

Here, tap “Configure new AP” to connect the new access point then the SSID configuration screen would be shown. Enter the SSID and Passphrase and tap apply to start connecting the access point.

After connection established, the current status screen will appear. It is already connected to WLAN with WiFi mode as WIFI_AP_STA and the IP connection status is displayed there including the SSID.

For one, continues execution of the sketch while keeping this connection. You can access ESP8266 via browser through the established IP address after cancel to “Log in” by upper right on the screen.
Or, “RESET” can be selected. The ESP8266 resets and reboots. After that, immediately before the connection will be restored automatically with WIFI_STA mode.

The IP address of ESP8266 would be displayed on the serial monitor after connection restored. Please access its address from the browser. The “Hello, world” page will respond. It’s the page that was handled by in the sketch with “on” function of ESP8266WebServer.


Which are Board Supported ?


Generic ESP8266 modules (applying the ESP8266 Community’s Arduino core)

Adafruit HUZZAH ESP8266 (ESP-12)

ESP-WROOM-02

Heltec WiFi Kit 8

NodeMCU 0.9 (ESP-12) / NodeMCU 1.0 (ESP-12E)

Olimex MOD-WIFI-ESP8266

SparkFun Thing

SweetPea ESP-210

ESP32Dev Board (applying the Espressif’s arduino-esp32 core)

SparkFun ESP32 Thing

WEMOS LOLIN D32

Ai-Thinker NodeMCU-32S

Heltec WiFi Kit 32

M5Stack

And other ESP8266/ESP32 modules supported by the Additional Board Manager URLs of the Arduino-IDE.

 

I hope you like this post “Dynamic WLAN configuration for ESP32”. If have you any query please write in comment box. And you can share this post “Dynamic WLAN configuration for ESP32”.

POST Credit :  Umawati Nikam


You may like also:


 

Harshvardhan Mishra

Hi, I'm Harshvardhan Mishra. Tech enthusiast and IT professional with a B.Tech in IT, PG Diploma in IoT from CDAC, and 6 years of industry experience. Founder of HVM Smart Solutions, blending technology for real-world solutions. As a passionate technical author, I simplify complex concepts for diverse audiences. Let's connect and explore the tech world together! If you want to help support me on my journey, consider sharing my articles, or Buy me a Coffee! Thank you for reading my blog! Happy learning! Linkedin

45 thoughts on “Dynamic WLAN configuration for ESP32 Board | AutoConnect

Leave a Reply

Your email address will not be published. Required fields are marked *