This is a version of python-wifi-connect that uses the more recent sdbus-networkmanager library
Inspired by the wifi-connect project written by balena.io.
It has been tested on Raspbery Pi 4 running Debian GNU/Linux 12 (bookworm), Kernel 6.6.31+rpt-rpi-v8 and Python 3.11.2
For your particular application, replace the logo.svg and favicon.ico files in the ui/img folder. If you only have a png of your logo, place it in the above folder and modify line 38 of the index.html file accordingly.
Please read the INSTALL.md then the RUN.md files. Also seee below in Additions
WiFi Connect interacts with NetworkManager, which should be the active network manager on the device's host OS.
Wifi Connect looks to see if it can access the internet when it starts. If it can, it shuts itself down. This can be overridden for test purposes (see Additions)
WiFi Connect detects available WiFi networks and opens an access point with a captive portal. Connecting to this access point with a mobile phone or laptop allows new WiFi credentials to be configured.
Connect to the opened access point on the device from your mobile phone or laptop. The access point SSID is, by default, <name>
where name is something random like "shy-lake" or "green-frog" or "dawnlite" (what is currently in the codebase).
After connecting to the access point from a mobile phone, it will detect the captive portal and open its web page. Opening any web page will redirect to the captive portal as well.
The captive portal provides the option to select a WiFi SSID from a list with detected WiFi networks and enter a passphrase for the desired network.
When the network credentials have been entered, WiFi Connect will disable the access point and try to connect to the network. If the connection fails, it will enable the access point for another attempt. If it succeeds, the configuration will be saved by NetworkManager.
- Video demo of the application.
- These are the geeky development details and background on this application.
-
The files in the nm_scripts directory are standalone and can be used to manipulate connections
-
The run.sh script executes the primary program: http_server.py.
-
The install.sh script creates a virtual environment and loads all needed modules.
-
To allow for other services to recognize the state of the Raspberry Pi, in hotspot mode, the file:
/etc/wifi_state/hotspot
- exists. Otherwise, the file
/etc/wifi_state/client
-
exists. This can be used in conjuction with other programs, for instance a service that launches at startup if the device is hotspot mode and flashes an LED to indicate that state. The service could monitor the existance of the hostpost file and shut down when it disapears. Also, using systemd, you can control a service starting using the existance of one or the other file. For examples see.
-
Added the -i option to the http_server.py program to allow the user to ignore a eth0 connection while doing development work. The program will still manipulate the wlan0 connections.
-
net_man_utlites.py has been removed as all of its functions can be accomplished with nmcli