wifi-station.sh
NetworkManager is the standard tool of modern board distributions: two commands are enough to join a WPA2 access point and check the obtained IP. The script also lists visible networks with their security.
Hardware
A Raspberry Pi Zero W (BCM2835, 512 MB) running Raspberry Pi OS, with 2.4 GHz Wi-Fi and Bluetooth. None: the radio is built into the board.
Wiring
No wiring. Antenna: keep the board in its case or fit the external antenna when the signal is weak.
How it works
nmcli detects the wireless interface, triggers a rescan, connects with the credentials then prints active connections and the IPv4 address.
Running it
Copy the script (scp), chmod +x, run. Recent Raspberry Pi OS: GPIO access works without sudo (gpio group).
Variants
Create an offline profile (nmcli connection add ... wifi-sec.pri-key ...), or chain with the web server to check connectivity remotely.
wifi-station.sh
#!/bin/bash
# Connexion Wi-Fi station via nmcli (NetworkManager, standard des OS carte).
# Usage : ./wifi-station.sh "MonSSID" "cle-de-securite"
set -e
SSID="${1:?Usage: $0 SSID CLE}"
CLE="${2:?Usage: $0 SSID CLE}"
echo "== Interfaces reseau =="
ip -brief link
DEV=$(nmcli -t -f DEVICE,TYPE device | awk -F: '$2=="wifi"{print $1; exit}')
[ -n "$DEV" ] || { echo "aucune interface wifi trouvee"; exit 1; }
echo "== Scan (peut etre vide en mode AP masque) =="
sudo nmcli device wifi rescan 2>/dev/null || true
nmcli -f SSID,SIGNAL,SECURITY device wifi list | head -15
echo "== Connexion a "$SSID" via $DEV =="
nmcli device wifi connect "$SSID" password "$CLE" ifname "$DEV"
echo "== Etat =="
nmcli -f NAME,DEVICE,STATE connection show --active
ip -4 -brief addr show "$DEV"