Skip to content

Latest commit

 

History

History
86 lines (62 loc) · 3.29 KB

README.md

File metadata and controls

86 lines (62 loc) · 3.29 KB

Arduino WiFiManager Library for ESP32

This Arduino library is improving the usage ESP32 WiFi module. The change log of this library can be found in CHANGELOG.md.

Purpose

The library provides simple WiFi connection management. On the first launch, WiFiManager creates a Wi-Fi Access Point to setup a future connection to an existing Wi-Fi network. After checking connection, WiFiManager will save this configutation and restart the CPU. Next, WiFiManager will automatically connect to the saved Wi-Fi network, as well as periodically check the connection with the gateway (router). If the ping fails, a reconnect should occur.

States diagram

diagram.drawio.png

Configuration Access Point

To get the setup web page after connecting to the configuration Access Point, use http://192.168.4.1 in a browser. If DNS is enabled (default), it is also possible to redirect any http://xxx.xxx (httpS doesn't redirect!) address to the configuration portal.

config_portal.jpg

On the configuration web page, you can select the Wi-Fi networks that were found.

Design

In order to use memory efficiently WiFiManager uses some low-level ESP32 API calls (nvs, ping, httpd_server). WiFiManagerClass is only used as a wrapper for user-friendly interface, making it easy to access c-callback API functions.
Many ideas are used from the project s60sc/ESP32-CAM_MJPEG2SD.

Getting Started

Copy the files src/WiFiManager.cpp and src/WiFiManager.h to your project directory.

#include <Arduino.h>
#include "WiFiManager.h"

Some features can be configured with the -Dxxx compiler option (see platformio.ini)

#define WFM_ST_MDNS_ENABLE 1 // station mDNS service "http://%HOSTNAME%.local" - DISABLED BY DEFAULT
#define WFM_AP_DNS_ENABLE  1 // access point DNS service - ENABLED BY DEFAULT
#define WFM_SHOW_LOG         // show debug messages over serial port - DISABLED BY DEFAULT

Configutation before start

Set a static IP address to call your device if necessary.
// default ip = "192.168.0.200"
// subnet = "255.255.255.0"
// gateway = router ip
// dns1 = router ip
WiFiManager.setStaticIP();

// or set the desired parameters
WiFiManager.setStaticIP("192.168.0.123");

If setStaticIP() is not called, the IP address set by the router DHCP.

Set a configuration Access Point if necessary.
WiFiManager.configAP("my_ap_ssid", "123456789");

If configAP() is not called, the default access point name "ESP-XXXX" is used, where XXXX is the end MAC address of the device, with an empty password (open).

Start WiFiManager

WiFiManager.start(); // start with default Hostname = Access Point name
WiFiManager.start("esp_hostname"); // or set Hostname and start

Check WiFi-connection

WiFiManager.isConnected(); // if true - connection OK

Clean stored WiFi settings

WiFiManager.cleanWiFiAuthData();

Print memory usage statistics

WiFiManager.debugMemory("debugMemory");

Example

This repository made as a Platformio project. See src/main.cpp for an example of usage.