Original Openwrt thread: https://forum.openwrt.org/viewtopic.php?id=43352 This branch was pulled from https://www.gl-inet.com/forums/topic/wifimgr-tool-to-automaticaly-select-an-apstation-from-a-list-of-saved-aps/ Contributors, as far as I can tell, are (RangerZ, Mehdi Chaouch, dabyd64(originator), and Daniel Roseman (Whunder)). Updated by Daniel Roseman (Whunder) January 2017 This was a bastard for me to modify which means this must have been a monumental headache for the originators. Please give credit where credit is due. This script and associated files originally released as 'do as you please' (See https://forum.openwrt.org/viewtopic.php?id=43352&p=4). I restrict this branch of the script and associated files with GPL License. This does not apply to any previous version of the script and associated fies. ################## # INSTALLATION # ################## ================================================================== Copy the files as this: wifiMgrcfg /etc/config wifiMgr.sh /usr/bin wifiMgr /etc/init.d Then execute these commands: chmod 777 /etc/config/wifiMgrcfg chmod 777 /usr/bin/wifiMgr.sh chmod 777 /etc/init.d/wifiMgr /etc/init.d/wifiMgr enable /etc/init.d/wifiMgr start NOTE: Expect a connection bounce upon execution of start. DONE! ================================================================== ################## # USAGE # ################## The script will start at boot, and check the network availability every user specified interval, by issuing several pings to a DNS service. If all pings fail, it will trigger the network scan and reconfigure the network. You should edit the file /etc/config/wifiMgrcfg The order in that file makes a difference: The script will parse the file and configure the first network found. That means that "net1" has preference over "net2", and so on. The config file needs eight variables for each network: net1_ssid="WIFI1" net1_encrypt="psk2" net1_key="password" net1_bssid="AA:BB:CC:DD:EE:FF" net1_network="wwan" net1_device="radio0" net1_mode="sta" net1_channel="6" To create new networks, just create new "net2", "net3" and so on (Don't forget to add to the apNumber how many are in the list!): net2_ssid="WIFI2" net2_encrypt="psk" net2_key="Wifi2pass" net2_bssid="AA:BB:CC:DD:EE:FF" net2_network="wwan" net2_device="radio0" net2_mode="sta" net2_channel="6" net3_ssid="WIFI3" net3_encrypt="psk2" net3_key="qwerty1234" net3_bssid="AA:BB:CC:DD:EE:FF" net3_network="wwan" net3_device="radio0" net3_mode="sta" net3_channel="6" IMPORTANT NOTE: Remeber to PUT dashes ("") and DO NOT put spaces between the variable name, the "=" and the variable value. Examples of what not to do: net1_ssid=WIFI1 net1_ssid ="WIFI1" net1_ssid = "WIFI1" net1_ssid= "WIFI1" The script would work in an impredictable way if you don't respect the format. There is a limit of 99 networks, the script will stop searching if it reaches the "net99", then return to the network check loop. I don't think anybody has 99 wifi networks seen on his home! SOME NOTES: When the script finds a wireless network, it configures the interface and restarts the networking system. After the pingSleep timer expires, it checks for internet availability even if the network was found. If it fails, it discards the changes and continues searching from the point it left before. Example: It finds "net1", but "net1" has no internet. Then it returns to the networks search, but looking for "net2". In the case that a "netX" ssid variable is blank or doesn't exist, it assumes that it's the end of the file and the search is cancelled. However, the script will keep running, so after 60 seconds (pingSleep) it will check the network again. There is a variable (PingLocation) which lets you sepcify the location you want to have your router ping. Choose a location that is close to you with a fst response time. The default is the Level3 DNS server. Google "public dns servers" for morre choices. There is a variable called initialSleep which was added to allow the routers netork to come up before testing for a connection. This can save a minute on boot time. If you are not connecting to known good APs on boot, increase this time. Also check your syslog file and make sure that you see the first wifiMgr check starting after the first set of daemon.notice netifd messages. You can edit the checking intervals by editing the variables inside the config file: # Background internet connection checking interval pingSleep=60 # After new network is set, time to wait for network to establish, before checking if it's working pingSleep=60 # 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 Also, you can set a random wlan MAC on each boot by changing the line: randMac="0" to randMac="1" ================================================================== FORCE NETWORK SCAN At any moment, you can force a network scan (ex. your preferred network came back). Just type: wifiMgr.sh --force It will scan and search the available networks and put the first available that it finds inside of the config file. Also, you can force a scan and try to connect to a specific network: wifiMgr.sh --force 5 It will try to connect to the network correspoding to "net5_ssid" It will output the result: if it wasn't found, if it failed to connect, or it sucessfully connected. HINT If you load the package "luci-app-commands" you can use this to create buttons to execute various force commands and connect you quicly to a specific AP or to scan all the APs on demand. #################### # IS IT WORKING? # #################### ================================================================== Ensure that it's running in the background: Run "ps -aux". You should see the script running: 25718 root 1520 S {wifiMgr.sh} /bin/sh /usr/bin/wifiMgr.sh ================================================================== Run "logread -f" to see the script output. It should be like this: Sep 4 15:13:05 OpenWrt user.notice root: WifiMgr: Attempting to ping 209.244.0.3 now... Sep 4 15:13:12 OpenWrt user.notice root: WifiMgr: Got 5 out of 5 ping responses. Sep 4 15:13:12 OpenWrt user.notice root: WifiMgr: Network appears OK. Sep 4 15:13:13 OpenWrt user.notice root: WifiMgr: Waiting 60 seconds then checking the network again... Sep 4 15:14:13 OpenWrt user.notice root: WifiMgr: Attempting to ping 209.244.0.3 now... Sep 4 15:14:20 OpenWrt user.notice root: WifiMgr: Got 5 out of 5 ping responses. Sep 4 15:14:20 OpenWrt user.notice root: WifiMgr: Network appears OK. ================================================================== If the network came unavailable, it should output this: Sep 4 15:14:20 OpenWrt user.notice root: WifiMgr: Attempting to ping 209.244.0.3 now... Sep 4 15:14:31 OpenWrt user.notice root: WifiMgr: Got 0 out of 5 ping responses. Sep 4 15:14:32 OpenWrt user.notice root: WifiMgr: Network failed. Starting network change... Sep 4 15:14:33 OpenWrt user.notice root: WifiMgr: Performing network scan for available APs... ... (Various messages about network initialization / setup) ... Sep 4 15:14:33 OpenWrt user.notice root: WifiMgr: Performing network scan for available APs... Sep 4 15:14:42 OpenWrt user.notice root: WifiMgr: WLAN1662 network found. Applying settings... ... (Various messages about network initialization / setup) ... Sep 4 15:14:43 OpenWrt user.notice root: WifiMgr: Attempting connection to WLAN1662 now... Sep 4 15:14:48 OpenWrt user.notice root: WifiMgr: Waiting 60 seconds then checking the network again... Sep 4 15:15:48 OpenWrt user.notice root: WifiMgr: Attempting to ping 209.244.0.3 now... -------------------------------------- Send logs to a file logread | grep "WifiMgr" >/tmp/wifiMgr.log