OpenWrt Forum Archive

Topic: [Howto](AAP) Automated Wifi network change if the current fails

The content of this topic has been archived between 1 Sep 2014 and 5 May 2018. There are no obvious gaps in this topic, but there may still be some posts missing at the end.

Not sure if this is still active but....
I'm looking for a script I can drop on a N600 OpenWRT box that scans, and then connects, to multiple SSID's in a round robin fashion. So AP1,AP2,AP3 etc etc.I "own" the AP's, each SSID is unique, and I have the passwords/keys. Its simply to check that
a) the SSID is still broadcasting
b) when connected to the SSID, there is a route out to the Internet (so ping 8.8.8.8)

I'm not 100% that this script will do it, or maybe it just needs a tweak (rather than me re-inventing the wheel). Could some good soul advise?

cheers

cabs

Yes, it could be tweaked to do that, but why?
It's much better by trying them only if the connection fails.
Doing so when it's working makes no sense, it will be constantly dropping the connecting, everytime it connects and checks the APs.

If you just want to use that box as a watchdog instead giving internet to other devices, and want to do something like logging the faults or rebooting the unresponsive APs, then yes, it makes sense.

(Last edited by dabyd64 on 3 Sep 2015, 22:50)

dabyd64 wrote:

Yes, it could be tweaked to do that, but why?
It's much better by trying them only if the connection fails.
Doing so when it's working makes no sense, it will be constantly dropping the connecting, everytime it connects and checks the APs


Maybe I didn't explain it as well as I should :-) This box is simply a monitor OPENWRT box, its not there to provide access to clients. So it runs silently in the background , "seeing" all the proper AP's. As th AP's are remote to me, I'd like this box to simply go round all those other ones, connect to each unique SSID, get an IP, ping, and repeat-whilsT writing to syslogs the results

Cheers

cabs

Yes, that can be done.
So, let's say that you only want it to constantly scan and log the status to the syslog, and then you remotely connect by SSH to that box from time to time to check how it's been going?
You want to log only the failing APs?
Also, it be saved to a text file on the flash, as the syslog is lost after a reboot.
It will use very little space, unless the APs fail constantly and you never delete the file.
It may also stress a bit the flash endurance, but I think it would only fail after few years.
Just tell me and I'll kindly help on this, if I know how to do so!

dabyd64 wrote:

Yes, that can be done.
So, let's say that you only want it to constantly scan and log the status to the syslog, and then you remotely connect by SSH to that box from time to time to check how it's been going?
You want to log only the failing APs?
Also, it be saved to a text file on the flash, as the syslog is lost after a reboot.
It will use very little space, unless the APs fail constantly and you never delete the file.
It may also stress a bit the flash endurance, but I think it would only fail after few years.
Just tell me and I'll kindly help on this, if I know how to do so!

The box has an 8GB flash drive mounted as ext4,it performs as root, and additional storage http://en.code-bude.net/2013/02/16/how- … h-extroot/ So loads of space! :-)
Yep-say, run a scan of ALL knowsn SSID's every 30 minutes,connect, get IP via DHCP, ping 8.8.8.8-and move on.Write to syslog-and then SSH in, now and again, to see how its going. Would prefer to see the successful AND unsuccessful attempts, just so I know its working!

cheers mucho

cabs

Okay, but, the box should only have internet from the wifi side, otherwise it will may ping 8.8.8.8 from lan side.
Also, how will you connect by SSH if the box is scanning?(I guess you'll have to wait a bit when this happens, until it finishes)
Do you have a default wifi network to set when it's not performing the scan?

(Last edited by dabyd64 on 3 Sep 2015, 23:56)

This is an early work but it works well.
ApScan v.01
This the output, from a real test:

logread | grep ApScan

Sun Feb 23 03:55:17 2014 user.notice root: ApScan: Scanning started
Sun Feb 23 03:55:18 2014 user.notice root: ApScan: Network Wifi_8a65 not found
Sun Feb 23 03:55:41 2014 user.notice root: ApScan: Network Cofee found, but ping failed
Sun Feb 23 03:56:08 2014 user.notice root: ApScan: Network MyWifi OK
Sun Feb 23 03:56:08 2014 user.notice root: ApScan: End of Wlan scan

However, you still need to tell me what to do when the scan ends,and how are you going to setup the internet connection when it isn't scanning.

I see that your native language could be Spanish? That's mine too, so if it's better for you to explain in Spanish it will be okay, but I prefer english, because here there's a lot of non-hispanic people.
Regards

(Last edited by dabyd64 on 4 Sep 2015, 02:02)

dabyd64 wrote:

This is an early work but it works well.
ApScan v.01
This the output, from a real test:

logread | grep ApScan

Sun Feb 23 03:55:17 2014 user.notice root: ApScan: Scanning started
Sun Feb 23 03:55:18 2014 user.notice root: ApScan: Network Wifi_8a65 not found
Sun Feb 23 03:55:41 2014 user.notice root: ApScan: Network Cofee found, but ping failed
Sun Feb 23 03:56:08 2014 user.notice root: ApScan: Network MyWifi OK
Sun Feb 23 03:56:08 2014 user.notice root: ApScan: End of Wlan scan

However, you still need to tell me what to do when the scan ends,and how are you going to setup the internet connection when it isn't scanning.
I see that your native language could be Spanish? That's mine too, so if it's better for you to explain in Spanish it will be okay, but I prefer english, because here there's a lot of non-hispanic people.
Regards

Lol-I'm Scottish, not Spanish-so English is fine :-)

So its a N600 OpenWRT-your right-the "main" WAN connection is through a cable modem via Ethernet/wired-the N600 receives a public IP on its WAN side. The N600 is dual radio, so both I would like to be able to connect to known AP's in its radio range. I can see how when it connects, it may use the wired WAN side for the ping-but one of the curious things I have seen before, is that when you have dual WAN connectivity (so wired and wireless-to a secondary AP), the device always seems to pick the wireless (wlan0) as the default route! Not sure why but I suppose putting something like

 curl ipecho.net/plain 

in the script, would let you know what WAN connection is being used?

For when the scan ends, would a sleep function, or just running it as a cronjob not do the trick?

Oh, it's fine then smile,
The script runs as daemon at system startup, it sleeps during the specified waiting time.
I guess the easiest way would be to disable the wired wan during the  scan.
The dual band could make it harder, do you want to scan both 2.4 and 5GHz bands?

dabyd64 wrote:

Oh, it's fine then smile,
The script runs as daemon at system startup, it sleeps during the specified waiting time.
I guess the easiest way would be to disable the wired wan during the  scan.
The dual band could make it harder, do you want to scan both 2.4 and 5GHz bands?

In terms of both bands, then it would be a nice to have, but not essential. So disable the eth0 during the scan, and then bring it back up on completion?-cool!

There may be better ways, but for the typical half-brained chimp like me it's the fastest and easiest way wink
What do we do with WiFi after the scan? Keep it disabled?
Please put the contents of
/etc/config/network
/etc/config/firewall
/etc/config/wireless

(Last edited by dabyd64 on 4 Sep 2015, 23:41)

Sorry and apologies for not getting back to the thread-been mad busy at work, and not had a chance to try it out. It looks good, and keeps it simple.Discovered if the device under test, if in AP mode, runs the script, it will change the SSID to the last one successfully scanned-so am going to get a few dedicated units. Going to try it out on some small TP-703's, and see how they cope.

But looking good so far :-)

Hi, yeah I was already thinking on 2016! big_smile
It won't work in AP mode, wifi must be configured in client mode to scan and connect!

What do we do with wifi when the device is not scanning? AP mode? Connect to a trusted wifi ? Disable wifi?
And what about dual band? It will be harder but it can be done. The WR703N is 2.4G only, so we can forget about it.

I need to know the device exactly, depending on it, the wifi interface may be called different, and has to be changed on the script.
Think on it, put it clear over the paper, and we'll end in a hurry!
Cheers

dabyd64 wrote:

Hi, yeah I was already thinking on 2016! big_smile
It won't work in AP mode, wifi must be configured in client mode to scan and connect!

What do we do with wifi when the device is not scanning? AP mode? Connect to a trusted wifi ? Disable wifi?
And what about dual band? It will be harder but it can be done. The WR703N is 2.4G only, so we can forget about it.

I need to know the device exactly, depending on it, the wifi interface may be called different, and has to be changed on the script.
Think on it, put it clear over the paper, and we'll end in a hurry!
Cheers

So the main unit is a TP-Link TL-WDR3600 v1 -simultaneous dual band. wlan0 for the 2.4Ghz, wlan1 for the 5Ghz
If it can be done, then once the scan is finished, the device comes back out of client mode, and back into AP mode, using the original SSID before the scan started (this would be a bonus as I can take the unit "offline" for the period of the scan, and dont have to put in a seperate one).
I'll still use the original version of the script for the TP-703, as it is a handy little device, and can run for days on battery back up :-)

cheers my man

cabs

Been looking for something like this. Tried it with a WNDR3700v1 and could not get it to work. I have used DD-WRT, but I am new to OpenWRT. I used dabyd64's instructions right after the OpenWRT flash. Does it require more config than that? It seems to loop and find the ssids, but never successfully connects to one. Which routers has this been verified on? Thanks in advance if anyone listening.

(Last edited by ewpro98 on 5 Oct 2015, 21:45)

You need to enable wireless first, and then configure it as client.

Edit /etc/config/wireless with "vi" (vi /etc/config/wireless). If you need more help, check THIS

Change    " option disabled '1' "
to            " option disabled '0' "


Also, make sure that this two options are set like this

config wifi-iface
    ..
    option device 'radio0'
    ..
    option mode 'sta'            <---------- 
    option network 'wan'       <----------

Reboot and should work now

@cabsandy
I've been lot of busy lately, I hope to finish it soon!

(Last edited by dabyd64 on 6 Oct 2015, 20:30)

Back to the original design please....

I am dealing with the Portable/Travel router issue of lost WWAN connection leads the WLAN to be come unavailable.  I have found a few other options which either rely on a button or just kill the WWAN on every boot (see below).  This looks like a much better solution as if I understand every time it boots it will scan my list of connection and continue until it finds one. 

Will this make the WLAN available even if it can not connect to a AP?

I do not understand the random mac issue can you please explain why I want or may not want to set this?  Do i need to load something for this function?

Has this been tried on CC RC or final?

What are the known good or bad chipsets?  I have a TooToo TM02 => Ralink RT5350F

Reference posts for other solutions
Button Event - relies on knowledge of the devices button functionality
https://forum.openwrt.org/viewtopic.php … 25#p188725
https://forum.openwrt.org/viewtopic.php … 22#p262622
Kill WWAN on Reboot
https://forum.openwrt.org/viewtopic.php … 18#p272018
https://forum.openwrt.org/viewtopic.php … 30#p278230

(Last edited by RangerZ on 7 Oct 2015, 21:44)

The random mac was a request from a user, some people connect to a public hotspot that limit the time or data, so a random mac will overrun this limit. In home use it's useless.

About the AP wlan going down if the client mode wlan, aka "wwan",  it's a limitation of that mode (repeater, also called ap+sta mode), and nothing can be done to fix that.

The only way is to mod the script, so in case that all networks were checked and none could be reached, disable the client network and just enable the AP, then it'll keep the wlan, although without internet connection

(Last edited by dabyd64 on 21 Oct 2015, 02:34)

cabsandy wrote:

So the main unit is a TP-Link TL-WDR3600 v1 -simultaneous dual band. wlan0 for the 2.4Ghz, wlan1 for the 5Ghz
If it can be done, then once the scan is finished, the device comes back out of client mode, and back into AP mode, using the original SSID before the scan started (this would be a bonus as I can take the unit "offline" for the period of the scan, and dont have to put in a seperate one).
I'll still use the original version of the script for the TP-703, as it is a handy little device, and can run for days on battery back up :-)

cheers my man

cabs

OK man! I've finished it, really sorry for the long time, I've been working too hard on that damn computer shop, lots of troubles, so you can imagine that when I came home I wanted to do rest and don't even think on computers!
Here you have!
ApScan v1.0
It's working perfect on my WDR4900, both bands.
It disables wireless APs and wired WAN before testing, makes the test, the it restores the default wireless and wan settings.
You can set everything on the config file.
This was the output of my test (logread | grep ApScan)

Wed Oct 21 00:31:06 2015 user.notice root: ApScan:         Starting
Wed Oct 21 00:31:23 2015 user.notice root: ApScan  (2.4G)  Network HOME_2G OK
Wed Oct 21 00:31:34 2015 user.notice root: ApScan  (2.4G)  Network wifi33 found, but ping failed
Wed Oct 21 00:31:34 2015 user.notice root: ApScan  (2.4G)  Network whatever_2G not found
Wed Oct 21 00:31:51 2015 user.notice root: ApScan  (5G)    Network HOME_5G OK
Wed Oct 21 00:31:51 2015 user.notice root: ApScan  (5G)    Network wifi55 found, but ping failed
Wed Oct 21 00:31:51 2015 user.notice root: ApScan  (5G)    Network whatever_5G not found
Wed Oct 21 00:31:53 2015 user.notice root: ApScan:         Finished

It looks pretty good. Let me know how it went wink
Cheers

(Last edited by dabyd64 on 21 Oct 2015, 02:38)

Hell there

Been playing with this-could I ask for some things to be considered?

wlan0 on here looks to be 5G-is it possible for wlan0 to be the 2.4G radio and wlan1 for 5G radio-as this is how Openwrt sees it on my device?
I know this shouldn't make a difference on a dual radio device but I was trying it on a single (2.4g) device, and couldn't work out why I was getting errors :-)
Which leads me to my 2nd ask-is it possible to make the latest script (v1.0) have the option to use it on a single and/or dual radio? This way, I can use the same script on a "working" AP, regardless if its single or dual. When I started out on this, a standalone device looked the way ahead, but as you adapted the script to take a working AP "down", and then back "up" , it got me thinking i could run this as a cronjob on a working device, and run it at 4am in the morning (or maybe twice a day), thereby not interfering with many customers?

Thoughts?

cheers

cabs

No problem chaging that. I thought it would be the same as my wdr4900.
About the cronjob, it's easier that the current method, easy fix.
About the dual/single band compatibility, not that easy.
First, usually Broadcom and Ralink chipset give too many headaches, so this will be Atheros only...
Second, WiFi devices can have different names, ex.: wlan0 ath0 wlan1..I have to investigate how to detect this.
Let me check it out,
Cheers

dabyd64 wrote:

No problem chaging that. I thought it would be the same as my wdr4900.
About the cronjob, it's easier that the current method, easy fix.
About the dual/single band compatibility, not that easy.
First, usually Broadcom and Ralink chipset give too many headaches, so this will be Atheros only...
Second, WiFi devices can have different names, ex.: wlan0 ath0 wlan1..I have to investigate how to detect this.
Let me check it out,
Cheers

Thanks for that-I think the 3600 is Ralink-I think! Dont give yourself too much hassle, can always go back to a standalone unit! :-)

cabsandy wrote:
dabyd64 wrote:

No problem chaging that. I thought it would be the same as my wdr4900.
About the cronjob, it's easier that the current method, easy fix.
About the dual/single band compatibility, not that easy.
First, usually Broadcom and Ralink chipset give too many headaches, so this will be Atheros only...
Second, WiFi devices can have different names, ex.: wlan0 ath0 wlan1..I have to investigate how to detect this.
Let me check it out,
Cheers

Thanks for that-I think the 3600 is Ralink-I think! Dont give yourself too much hassle, can always go back to a standalone unit! :-)


Nope, it has Atheros AR9344! wink
http://wiki.openwrt.org/toh/tp-link/tl-wdr3600

Ok, I've done it different.
Just "config" and "ApScan.sh". Edit the config file and run ApScan.sh everytime you want to perform a scan, from cronjob or any other method you want to use.

I gave up on trying to detect the device, it probably would cause problems and give a lot of work.
So, different scripts for 2.4G only and dual band.
For 2.4G only devices, wlan0 is used.
For dual band WDR3600, wlan0 for 2.4G and wlan1 for 5G.
For dual band WDR4900, wlan1 for 2.4G and wlan0 for 5G.

ApScan 1.0b

Regards wink

(Last edited by dabyd64 on 29 Oct 2015, 15:33)

hi @dabyd64...very thank for your works, it's work well!
but i want to auto connect SSID1 again if it up, Suppose SSID1 is best connecting!

(Last edited by phantnang on 5 Nov 2015, 16:28)

Reboot and it will check again, or mod the script as you like.
It won't check the wifi while being connected because it will break internet everytime.
It only checks when it fails, then if WiFi1 is found it will connected to it.