The ability to connect to a known set of APs automatically and to make sure the device is available has been a problem under OpenWrt which pains those with travel routers. This post discusses mods to a tool set written by dabyd64 and posted here. Howto Automated Wifi network change if the current fails
The tool set was written to allow a fixed device to cycle through a set of known APs and select one when the signal from the current disappears. Similar but different requirement for a Travel Router. The basic function works well to store and automatically connect to one of the predefined AP(STAtions) in the “config” file. The tool set as written does not address the issue of accessing the device when no AP(STAtion) is available. I have attempted to make some changes to the function, and for the most part these work. There are some issues noted below, and hoping that someone smarter than I may be able to help.
The original tool would ping Google and if a response was received sleep for a period defined in the config file (default 60 sec). When no ping is received it begins to test the AP(STAtions) in the config, in order, until one is found which works and then updates the config to the iface, restarts the wireless and again confirms the operation.
This version of the tool will set the AP(STAtion) to disabled when no ping is received. It also will address an issue which is caused by manually adding an unlisted AP(STAtion), which is to remove the BSSID entry, as the original code as written does not consider this.
The original function added a file to init.d to start the function, however I find that the function starts before the wireless is fully up and will set the AP(STAtion) to disabled on boot. I have moved this to a local startup entry and added a 40 second sleep time (May vary be device what you want here) before starting the wifiMgr. Not really sure this is better than the init.d method.
I have changed the reference to the specific iface, moving it from the (default) first to the second, as when one removes a AP(STAtion) manually, the LAN/WLAN is moved up. I am assuming the LAN/WLAN will always be the same. This is needed to support using a non-listed AP (one off) connection.
I have made some minor changes to the messages inside the wifiMgr.sh file, mostly converting them to English.
Please see the readme.txt for installation instructions.
Other notes:
I have tested this on both AR9331 (AR-150) and a Mediatek MT7620N (similar to the MT300N). Both seem to work the same.
The check runs on start and then every “ConnCheckTimer” period. While I had hoped to set this for a long period, not really expecting to need this to run more than on boot, if the wifi is not up before the check runs, you will have to wait for the defined period until it finds an AP(STAtion).
On occasion there will be a UCI: Not found message in the log. I believe this relates to the tool trying to delete a non-exsistant BSSID.
There is a shell command option to run the wifiMgr to scan all or for a specific AP(STAtion). With the package luci-app-commands you can configure buttons to run the manual force (wifiMgr.sh --force X, where X is a number for a config) to select a specific entry or run through the list. Note that it always reports an error on execution, but does seem to work. It is easier and faster to use preconfigured items from here than using the Netowrk=>Wifi=>Scan to change stations. There is NO data entry.
There is no way, other than manual editing, to move a AP(STAtion) to the config file.
Untested: SSIDs with other than A-Z, 0-9.
The known issues are as follows.
1 - Currently the wifi is bounced at the “ConnCheckTimer” period for about 5-6 seconds when there is no available AP. There is no check to address the situation where no AP(STAtion) is available and the current STA iface is already disabled. The code disables the iface every time. Only an issue if one has no connection and say streaming media (like in a car).
2 - The tool is some how impacting reboot from LuCi. I have to reboot -f from a console. It looks like it reboots, but you will notice that it does not take one back to the login, and if one checks the logs they go back before the reboot.
3 - Somehow starting from rc.local has corrupted the LEDs. I believe it has to do with the parameters related to the rc.local string, as the LEDs operate fine when the wifiMgr init.d script is used. Functionality seems not to be impacted.
4 - If using the init.d wifiMgr script, I am of the opinion that Start and Restart are not working correctly.
Nice to have mods
1 - Add a check for the condition when the existing AP is set to disabled and the no AP found scenario sets the value again and cycles the wifi.
2 - I would like to be able to write the logger messages out to a log file. I can then use this screen mod to put them in a new log tab. OpenWrt Forum Archive