Fix flaky hotspot->home WiFi reconnect in netwatch
Real-hardware finding: netwatch repeatedly reported 'home WiFi not found' 4 times over 13min while sitting right next to the router. Root cause: a plain 'nmcli con up home-wifi' straight out of AP mode relies on NM's scan cache for wlan0, which is stale/empty coming out of AP mode (the radio can't scan while acting as an AP). A single con-up attempt didn't wait for a fresh scan to land before giving up. Fix: explicitly drop the AP connection first to free the radio, force a fresh scan with a settle delay, and retry the connect attempt (longer 30s timeout) up to 2 times before conceding and restoring the hotspot. Bumped the systemd unit's TimeoutStartSec to 180s to give the retry loop enough headroom (was defaulting to 90s). Co-authored-by: Copilot <[email protected]>
This commit is contained in:
@@ -5,4 +5,7 @@ Wants=NetworkManager.service
|
|||||||
|
|
||||||
[Service]
|
[Service]
|
||||||
Type=oneshot
|
Type=oneshot
|
||||||
|
# Retry loop (down AP, rescan, retry connect up to 2x) can take ~80s worst
|
||||||
|
# case - default 90s systemd start timeout was too tight a margin.
|
||||||
|
TimeoutStartSec=180
|
||||||
ExecStart=/usr/local/bin/yaris-netwatch.sh
|
ExecStart=/usr/local/bin/yaris-netwatch.sh
|
||||||
|
|||||||
@@ -39,9 +39,32 @@ fi
|
|||||||
|
|
||||||
logger -t "$LOG_TAG" "wlan0 is on hotspot, checking for home WiFi ($HOME_CON)..."
|
logger -t "$LOG_TAG" "wlan0 is on hotspot, checking for home WiFi ($HOME_CON)..."
|
||||||
|
|
||||||
if nmcli --wait 20 con up "$HOME_CON" >"$LAST_LOG" 2>&1; then
|
# Real-hardware finding: a plain "nmcli con up home-wifi" straight out of AP
|
||||||
|
# mode reliably reports "not found" even when actually in range, repeatedly
|
||||||
|
# (confirmed: 4 failures in a row over 13min while sitting right next to the
|
||||||
|
# router). NM's scan cache for wlan0 is stale/empty coming out of AP mode
|
||||||
|
# (the radio literally can't scan while acting as an AP - see comment above),
|
||||||
|
# and a single con-up attempt doesn't wait for a fresh scan to land before
|
||||||
|
# giving up. Fix: explicitly drop the AP connection first to free the radio,
|
||||||
|
# force a fresh scan and give it a few seconds to populate, then retry the
|
||||||
|
# connect attempt with a longer timeout up to 2 times before conceding and
|
||||||
|
# restoring the hotspot.
|
||||||
|
nmcli con down "$AP_CON" >"$LAST_LOG" 2>&1
|
||||||
|
|
||||||
|
connected=false
|
||||||
|
for attempt in 1 2; do
|
||||||
|
nmcli device wifi rescan ifname "$IFACE" >>"$LAST_LOG" 2>&1
|
||||||
|
sleep 5
|
||||||
|
if nmcli --wait 30 con up "$HOME_CON" >>"$LAST_LOG" 2>&1; then
|
||||||
|
connected=true
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
logger -t "$LOG_TAG" "home WiFi attempt $attempt failed, retrying..."
|
||||||
|
done
|
||||||
|
|
||||||
|
if [ "$connected" = true ]; then
|
||||||
logger -t "$LOG_TAG" "home WiFi found, switched to '$HOME_CON'"
|
logger -t "$LOG_TAG" "home WiFi found, switched to '$HOME_CON'"
|
||||||
else
|
else
|
||||||
logger -t "$LOG_TAG" "home WiFi not found, restoring hotspot"
|
logger -t "$LOG_TAG" "home WiFi not found after retries, restoring hotspot"
|
||||||
nmcli con up "$AP_CON" >>"$LAST_LOG" 2>&1
|
nmcli con up "$AP_CON" >>"$LAST_LOG" 2>&1
|
||||||
fi
|
fi
|
||||||
|
|||||||
Reference in New Issue
Block a user