Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 7503

Networking and servers • Python utility code to connect a headless pi to WiFi

$
0
0
I built a couple of projects using python on a headless pi-zero and wanted to make it possible for an end user to connect them to their home WiFi using a web page in hotspot mode. I wrote some code for this and have published it on github.
https://github.com/st739/Wifind-pi
I've tested on Bookworm and Trixie (delays due to various issues with Trixie).
The objective of the code is to allow a headless pi to configure and connect to a WiFi network at installation time.
There's a Systemd service that configures and starts a hotspot on first boot then passes control to python code that displays a web page allowing network choice. Once a network is chosen and successfully accessed, a NetworkManager entry is created and an arbitrary application started. Subsequent boots connect to the NeworkManager network and start the application.
I'm trying to avoid features that are already in sdm or other SD card management tools.
The code should work on an sdm customized SD card but I haven't tested it.
Configuration code runs on a linux pc and writes to an onboard SD card reader. (I don't have a Windows PC, but code should work in Cygwin). Code is written to /usr/local/Wifind on the SD card (but this path can be changed).
If the network fails, a script is triggered by NetworkManager events (Bookworm) or cron (Trixie) that attempts to reconnect to the ssid.
If the ssid is removed or the password changed, the pi can be reset by power cycling 3 times (allowing sufficient time for the boot to complete)
on the fourth boot the pi will start in hotspot configuration mode.
Simon

Statistics: Posted by Simon739 — Thu Feb 12, 2026 3:12 pm — Replies 0 — Views 51



Viewing all articles
Browse latest Browse all 7503

Trending Articles