Skip to content

Instantly share code, notes, and snippets.

@NghiaMaster
Last active October 20, 2019 05:33
Show Gist options
  • Save NghiaMaster/d7f2469a5d22b78785d7ad875d465f52 to your computer and use it in GitHub Desktop.
Save NghiaMaster/d7f2469a5d22b78785d7ad875d465f52 to your computer and use it in GitHub Desktop.
Check Wifi And AUTO Connect
#!/system/bin/sh
# source configuration
log=/data/local/wifi.log
check_interval=10
#
exec 1> /dev/null
exec 2>> $log
echo $(date) > $log
# without check_interval set, we risk a 0 sleep = busy loop
if [ ! "$check_interval" ]; then
echo "No check interval set!" >> $log
exit 1
fi
startWifi () {
wpa_cli -iwlan0 -p/data/misc/wifi/sockets/ reconnect
}
startWifi
while true; do
ONL=$(wpa_cli -iwlan0 -p/data/misc/wifi/sockets/ status | grep -c "ssid=VIETTEL - SLHNB");
if [ "$ONL" = 0 ]; then
echo $(date) " Attempting reconnect..." >> $log
echo 1 >/sys/class/leds/button-backlight/brightness
startWifi
sleep 3
else
echo 0 >/sys/class/leds/button-backlight/brightness
sleep $check_interval
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment