I am using a function to check for a wireless connection and update 'wireless' based on availability of a defined set of APs. While the function works as desired, it appears to somehow affect the routers ability to reboot using the LuCi Reboot function (System=>Reboot).
I am hoping that someone can identify the issue and suggest a remedy.
The code was written by dabyd64 and is published here.
https://forum.openwrt.org/viewtopic.php?id=43352
I have made some mods and republished it here.
http://www.gl-inet.com/forums/topic/wif … post-11953
I have tested the code on two devices and it seems to operate the same. Select the reboot function from LuCi and the page will sit for about 1 minute then return to the Status Overview Screen, not the Login. Logs confirm the system did not reboot. On occasion I will see "daemon.info procd: - shutdown -", but not every reboot attempt; otherwise nothing remarkable. The device will reboot with the reboot -f parameter.
There are 3 files. 1 in init.d, the main function in /user/bin/ and a config file in /etc/wifimgr. If i remove the file (wifiMgr) from init.d, the system reboots normally. Below is my modified version (wifiMgr.sh and config).
etc/init.d/wifiMgr
#!/bin/sh /etc/rc.common
START=99
APP=wifiMgr.sh
ARGS=--daemon
PID_FILE=/var/run/$APP.pid
start() {
start-stop-daemon -S -x $APP -- "$ARGS" -p $PID_FILE -m -b
}
stop() {
start-stop-daemon -K -n $APP -p $PID_FILE -s TERM
rm -rf $PID_FILE
}
There is no file in /var/run/wifiMgr.pid and start and restart return a web page saying "Connection was reset".
/usr/bin/wifiMgr.sh
#!/bin/sh
. /etc/wifiMgr/config
randMacAddr()
{
macaddr=$(dd if=/dev/urandom bs=1024 count=1 2>/dev/null|md5sum|sed 's/^\(..\)\(..\)\(..\)\(..\)\(..\)\(..\).*$/00:\2:\3:\4:\5:01/')
uci set wireless.@wifi-iface[1].macaddr="$macaddr"
uci commit wireless
/etc/init.d/network restart
}
NetStatus()
{
logger WifiMgr: Checking network...
# Sleep adjusts for network not up on boot
sleep $PingSleep
net=$(ping $PingLocation -c5 |grep "time=")
if [ "$net" ]; then
logger WifiMgr: Network OK
#got ping response!
return
else
logger WifiMgr: Network failed. Starting network change...
NetChange
fi
}
NetChange()
{
logger WifiMgr: Performing network scan...
scanres=
ifconfig wlan0 down
iw phy phy0 interface add scan0 type station
ifconfig scan0 up
while [ "$scanres" = "" ]; do
#Sometimes it shows nothing, so better to ensure we did a correct scan
scanres=$(iw scan0 scan|grep SSID)
done
iw dev scan0 del
ifconfig wlan0 up
killall -HUP hostapd
logger WifiMgr: WifiMgr: Searching available networks...
if [ "$1" ]; then
ssid=net"$1"_ssid
eval ssid=\$$ssid
echo Trying to connect to network "$1"": $ssid"
n=$(expr "$1" - "1")
else
n=0
fi
while [ "1" ]; do
n=$(expr "$n" + "1")
if [ "$n" = "99" ]; then
#too much counts. Crazy wireless count, breaking loop!
break
fi
ssid=net"$n"_ssid
encrypt=net"$n"_encrypt
key=net"$n"_key
eval ssid=\$$ssid
eval encrypt=\$$encrypt
eval key=\$$key
if [ "$ssid" = "" ]; then
#ssid not existing or empty. Assume it's the end of the wlist file
uci set wireless.@wifi-iface[1].disabled="1"
uci commit wireless
/etc/init.d/network restart
logger WifiMgr: No usable APs found, disabling the WWAN.
break
fi
echo SSID: $ssid
echo Password: $key
echo Encryption: $encrypt
active=$(echo $scanres | grep " $ssid ">&1 )
if [ "$active" ]; then
if [ "$1" ]; then
echo Network found. Connecting...
fi
logger WifiMgr: "$ssid" network found. Applying settings..
uci set wireless.@wifi-iface[1].ssid="$ssid"
uci set wireless.@wifi-iface[1].encryption="$encrypt"
uci set wireless.@wifi-iface[1].key="$key"
uci set wireless.@wifi-iface[1].disabled="0"
uci delete wireless.@wifi-iface[1].bssid
uci commit wireless
/etc/init.d/network restart
#wait some seconds for everything to connect and configure
sleep $NewConnCheckTimer
logger WifiMgr: Checking connectivity...
#check for internet connection, 5 ping sends
net=$(ping $PingLocation -c5 |grep "time=")
if [ "$net" ]; then
#got ping response!
logger WifiMgr: Internet working! Searching ended
if [ "$1" ]; then
echo Sucess!
fi
break
fi
if [ "$1" ]; then
echo Connection failed!
break
fi
logger WifiMgr: Failed! Searching next available network...
fi
done
}
if [ "$1" = "" ]; then
echo "No arguments supplied"
elif [ "$1" = "--force" ]; then
NetChange $2
elif [ "$1" = "--daemon" ]; then
if [ "$randMac" = "1" ]; then
randMacAddr
fi
NetChange
while [ "1" ]; do
sleep $ConnCheckTimer
NetStatus
done
else
echo "Wrong arguments"
fi
/etc/wifiMgr/config
# Background internet connection checking interval
ConnCheckTimer=60
# After new network is set, time to wait for network to establish, before checking if it's working
# If too low the router may be still waiting for the dhcp assignment from the main router, causing the script to discard the network
NewConnCheckTimer=25
# Set the loation you wish the program to use to ping for a connection.
# Choose a location with a low response time. Google public DNS Server.
# The default is Level 3's Public DNS server.
PingLocation=209.244.0.3
# Set a time delay for to wait for the network to come up on intial boot.
PingSleep=5
# Set a random MAC each boot
randMac="0"
net1_ssid="Dummy1"
net1_encrypt="psk2"
net1_key="dumbkey1"
net2_ssid="Dummy2"
net2_encrypt="psk2"
net2_key="dumbkey2"
net3_ssid="Dummy3"
net3_encrypt="psk2"
net3_key="dumbkey3"
net4_ssid="Dummy4"
net4_encrypt="psk2"
net4_key="dumbkey4"
net5_ssid="Dummy5"
net5_encrypt="psk2"
net5_key="dumbkey5"
net6_ssid=""
net6_encrypt=""
net6_key=""