Skip to content

PA0DEV/WifiManager

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

25 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

WifiManager

Version: 1.2.1

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 :

  1. copy the wifiManager.py in your project folder

  2. import the wifiManager in your boot.py (recommended) or main.py

    import wifiManager
  3. Run the getConnection() method

    wlan = 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 working WLAN(STA_IF) interface or None

  4. 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;
Loading
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;
Loading
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;
Loading
  1. step: check if "profiles.json" contains any reachable networks

  2. step: open a web server to configure a new wifi

  3. step: save the ssid / password from the configuration to "profiles.json"

  4. After successful connection the wifiAP gets closed.

    The connection sould be checked in regular intervals to prevent unwanted behaviour!

  5. step: run user code

How to setup wifi configuration:

  1. Connect to the AP opened by the ESP

    WiFi QR code
    • default SSID: PA0DEV-ESP
    • default pass: 12345678
  2. Open the page 192.168.4.1

  3. With dynamic IP-settings:

    DHCP active

    • Leave the DHCP on "ON"
    • Select your network and enter the password
    • hit the "Submit" button
  4. With static IP-settings:

    DHCP active

    • Select DHCP to be "Off"
    • Enter the IP-configuration you want to use
    • Select your network and enter the password
    • hit the "Submit" button
  5. If you entered everything correctly you will get a message "ESP successfully connected to WiFi network [ YOUR_SSID ]."

    ESP-Connected

    If not, you will get "ESP could not connect to WiFi network [ YOUR_SSID ]

    ESP-Failed

snippets of the code are inpired by https://github.com/tayfunulu/WiFiManager