wpa-connect communicates with WPA supplicant over D-Bus (linux message bus system).
This package was developed as part of IoT project in order to add Wi-Fi connectivity to headless Raspberry Pi like devices. No need for connman or Network Manager be installed.
On Linux:
wpa_supplicant service should run with -u flag in order to enable DBus interface. Run it as Linux service before first call to wpa_supplicant. Otherwise system will start it automatically without -u flag.
Systemd service configuration file - /etc/systemd/system/wpa_supplicant@wlan0.service
[Unit]
Description=WPA supplicant for %i
[Service]
ExecStart=/usr/sbin/wpa_supplicant -u -i%i -c/etc/wpa_supplicant.conf -Dwext
[Install]
WantedBy=multi-user.target
On Raspberry PI OS (Debian Buster):
Raspbery PI OS (formerely known as Raspbian) uses dhcpd-run-hooks to setup and invoke the wpa_supplicant daemon.
- Disable the systemd managed wpa_supplicant located under
/etc/systemd/dbus-fi.w1.wpa_supplicant1.service
by runningsudo systemctl disable wpa_supplicant
- Modify the existing wpa_supplicant dhcpd-run-hook available under
/lib/dhcpcd/dhcpcd-hooks/10-wpa_supplicant
by adding the-u
flag to the invocation of the wpa_supplicant daemon in thewpa_supplicant_start()
function. - Alternatively run
sudo sed -i 's/wpa_supplicant -B/wpa_supplicant -u -B/g' /lib/dhcpcd/dhcpcd-hooks/10-wpa_supplicant
to modify the hook in place.
On Project:
go get github.com/mark2b/wpa-connect
Please see godoc.org for documentation. (Not ready yet)
import wifi "wpa-connect"
if conn, err := wifi.ConnectManager.Connect(ssid, password, time.Second * 60); err == nil {
fmt.Println("Connected", conn.NetInterface, conn.SSID, conn.IP4.String(), conn.IP6.String())
} else {
fmt.Println(err)
}
import wifi "wpa-connect"
if bssList, err := wifi.ScanManager.Scan(); err == nil {
for _, bss := range bssList {
print(bss.SSID, bss.Signal, bss.KeyMgmt)
}
}
Package release under a MIT license.