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 required
A Compute Module 3+ (BCM2837B0, 1 GB LPDDR4) on a Compute Module IO Board v3, powered at 5 V, running Raspberry Pi OS (Bullseye). 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. On Bullseye: sudo apt install python3-gpiozero then python3 your_script.py. The CM3+ behaves like a Pi 3 B+; IO Board pins follow the BCM numbering.
Going further
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"