2
0
mirror of https://github.com/koreader/koreader synced 2024-11-18 03:25:46 +00:00
koreader/platform/kobo/restore-wifi-async.sh
NiLuJe e9eca55d90
Minor auto_restore_wifi tweaks (#5143)
* Try to make sure restoreWifiAsync eventually sends a NetworkConnected
event...

re: #5109

* Take a page from @shermp's book, and make sure wpa_supplicant managed to
connect to the AP before acquiring an IP.
Tear down WiFi modules in case of failure.
c.f., https://github.com/shermp/Kobo-UNCaGED/pull/21

* Don't let restore-wifi-async.sh enable WiFi behind our back when we're
killing it to start Nickel...

* Don't even call ping if there's no default gw
2019-07-31 01:00:51 +02:00

28 lines
815 B
Bash
Executable File

#!/bin/sh
RestoreWifi() {
echo "[$(date)] restore-wifi-async.sh: Restarting WiFi"
./enable-wifi.sh
# Much like we do in the UI, ensure wpa_supplicant did its job properly, first.
# Pilfered from https://github.com/shermp/Kobo-UNCaGED/pull/21 ;)
wpac_timeout=0
while ! wpa_cli status | grep -q "wpa_state=COMPLETED"; do
# If wpa_supplicant hasn't connected within 10 seconds, assume it never will, and tear down WiFi
if [ ${wpac_timeout} -ge 40 ]; then
echo "[$(date)] restore-wifi-async.sh: Failed to connect to preferred AP!"
./disable-wifi.sh
return 1
fi
usleep 250000
wpac_timeout=$((wpac_timeout + 1))
done
./obtain-ip.sh
echo "[$(date)] restore-wifi-async.sh: Restarted WiFi"
}
RestoreWifi &