Written in : MicroPython
Tested on : ESP32
Description : WiFi Manager to find, connect and save wifi credentials
Main features :
- Web based connection manager
- save known Networks, IP settings and passwords in "profiles.json" (JSON-Format)
- Easy to include in your projects
- Adapts to many cases
Planned features:
-
Update website design
-
Network IP setup
- add IP config into HTML webpage
- merge new form data into ESP programm
- DHCP
- Static IP configuration
- save ip setup into profiles.json
-
Captive portal for AP
-
Manage (delete) saved Networks
-
More to come
Usage :
-
copy the wifiManager.py in your project folder
-
import the wifiManager in your boot.py (recommended) or main.py
import wifiManager
-
Run the
getConnection()
methodwlan = wifiManager.getConnection() if wlan is None: print("[WifiMgr] Could not initialize the network connection.") while True: pass # you shall not pass :D
The
getMethod()
method will return a workingWLAN(STA_IF)
interface orNone
-
Run your main code afterwards
Logic:
Diagramm:
graph TD;
subgraph main.py;
A[[main.py]] --> B{function<br>check_connection};
B-- CONNECTED -->C[Your Code];
B -- False --> D[Something is Wrong];
B--Regular Intervall-->B
end;
graph TD;
subgraph check_connection;
E[[fuction <br>check_connection]] --> F[check connection];
F--Connected--> G>Return TRUE];
F--not Connected--> H(open known profiles);
H-->I(Scan WiFis);
I-- Found known WiFi --> J(Try to connect);
I-- no known WiFi found --> K(Start webserver);
J--Connected--> L>Return True];
J--not Connected-->K;
K--Connected-->L;
end;
graph TD;
subgraph webserver;
N[[Webserver]]-->M(Open Access Point);
M-->O(Webserver Listen<br>192.168.4.1:80)
O-->P[User connect to webpage<br>and submitt data]
P-->Q(Try to connect<br>to new network)
Q--cannot connect-->O
Q--Connected-->R(Save network Infos<br>in JSON)
R-->S(Close Access Point)
S-->T>Return TRUE]
end;
-
step: check if "profiles.json" contains any reachable networks
-
step: open a web server to configure a new wifi
-
step: save the ssid / password from the configuration to "profiles.json"
-
After successful connection the
wifiAP
gets closed.The connection sould be checked in regular intervals to prevent unwanted behaviour!
-
step: run user code
How to setup wifi configuration:
-
Connect to the AP opened by the ESP
- default SSID:
PA0DEV-ESP
- default pass:
12345678
- default SSID:
-
Open the page
192.168.4.1
-
With dynamic IP-settings:
- Leave the DHCP on "ON"
- Select your network and enter the password
- hit the "Submit" button
-
With static IP-settings:
- Select DHCP to be "Off"
- Enter the IP-configuration you want to use
- Select your network and enter the password
- hit the "Submit" button
-
If you entered everything correctly you will get a message "ESP successfully connected to WiFi network [ YOUR_SSID ]."
If not, you will get "ESP could not connect to WiFi network [ YOUR_SSID ]
snippets of the code are inpired by https://github.com/tayfunulu/WiFiManager