Wifi continues to work after [Disable AP when no upstream connectivity]

Hi, I'm new here, greetings to everyone first,

I have a UBIQUITI AC-PRO antenna:

And a TP-LINK Archer C7 V2

The UBIQUITI AC-PRO antenna is installed outdoors and connected to a shared wifi that provides me with internet perfectly.
The AC-PRO is connected only by LAN to a 5-port switch, one of which I have connected the Archer C7 as a dumb AP.
The Archer C7 provides me with Wifi throughout my home and everything works perfectly.
But I have a problem: !!!

If the AC-PRO loses the connection of the external shared Wi-Fi, I stop surfing the LAN on my Notebook (obviously), instead the Archer C7 that gives me the Wi-Fi ... "It still has a Wifi signal" therefore all phones, printers or any device connected to my wifi have a Wi-Fi connection when it is not true.

My query is if there is a way via script, or another way, or a manual, or system, to be able to configure or tell the Archer C7 that when the LAN, internet, that comes from AC-PRO automatically cut off the Wifi signal and Stop providing a fake Wifi.

It is possible to create a process or configuration for it.
Thank you very much to all.

Yes, possible. How quickly does it need to shut off the wireless or restore it? Seconds? Or are once a minute checks OK?

Hi Jeff, thank you very much for answering,

The idea is that when the external AC-PRO Wi-Fi connection fails for whatever reason, the Archer C7 learns that the AC-PRO Wi-Fi no longer provides Internet output and runs for example a DOWN radio0 until the AC- fall. PRO resets again.
(Normally this is already done automatically, but sometimes it can take hours or minutes until AC-PRO is restored, and you have Wi-Fi on your mobile, yes, but you are disconnected from the internet world.)

Imagine doing a ping, or ping -t every X minutes, 15, 20, ... minutes and then generate a Wi-Fi UP radio0, for example, not being like controlling it right now, I keep reading through the forum .. .

I don't know if I've explained myself, and you've understood me, if we don't talk ...

Because this:
I can know if I go to Facebook, Instagram, etc., if I have dropped the Wifi or AC-PRO is disconnected (and I fix it), but there are people like my mother or grandparents who set up a Wi-Fi and if it stops working They do not find out or they do not activate 4G on the mobile phone when the wifi of the mobile does NOT disappear, then you try to contact them with a simple WhatsApp and they do not find out.
I believe that this problem if it could be solved would be very useful for everyone ...

Greetings jeff and thanks.

Ok, yes, the use case was clear from your first post. To confirm, a check once a minute is ok, it doesn’t have to be any faster, correct?

Correct if, but I don't know how to do it, automatically, from openwrt, a script, a process implemented in openwrt that I don't know, it's not like doing it,

Thank you and forgive my google translator english, I am writing from Catalonia,
Regards,

Joan.

Google Translator is working well enough to understand you very well.

I assume your setup looks like

                  wireless                   wireless
OpenWrt Archer C7 <~~~~~~> AC-PRO (OpenWrt?) <~~~~~~> WISP
          |
         /|\
   wireless clients

and you need to detect when the AC-PRO has / does not have connection to the WISP.

  • When connected, the Archer C7 wireless should be up
  • When not connected, the Archer C7 wireless should be down

This can be done with a "cron job"

In this example, it assumes that Google's DNS server cluster for 8.8.8.8 is always up and always responds to pings. This is probably "close enough" as I am reasonably certain that there is more than one machine for 8.8.8.8. There are fancier ways to do this, but this should work well enough.

Note: Typo in original version removed from below script

#!/bin/sh

wifi_is_up () {                     # Test to see if at least wireless is up
    ubus call network.wireless status | fgrep -q '"up": true,'
}

ping -c3 8.8.8.8 > /dev/null        # Try to see if 8.8.8.8 is reachable, three times. Discard output.
if [ "$?" ] ; then                  # Check to see if the ping failed
    wifi_is_up && wifi down         # ping failed, only change if needed 
else
    ! wifi_is_up && wifi up         # ping succeeded, only change if needed (or will reset wireless)
fi

(make sure that those are "plain" single and double quotes. Sometimes copy-paste changes them)

Save that as a file, for example, as /usr/libexec/check-and-set-wifi.sh and make it executable with chmod 755 /usr/libexec/check-and-set-wifi.sh

Then you can edit /etc/crontab (you may have to create it, it may be available in LuCI to edit) and add a line to run that script every minute

* * * * *     /usr/libexec/check-and-set-wifi.sh

If you wanted to run it every five minutes, that line would look like

*/5 * * * *     /usr/libexec/check-and-set-wifi.sh

Edit: I hope you don't mind that I added to your title so that others can easily find the thread.

2 Likes

:aplaudir::aplaudir:

Thank you very much jeff

I am going to implement it and I confirm how it works, which is going to cost me a lot, but don't worry, I follow your instructions, or I read through the Forum.

Regards, and thanks.

Joan.

P.D.
You can change what you need.
(Google Translator is working well enough to understand you very well)
Sorry if I offended you, but it's hard to move to understand me through this forum...

1 Like

You did not offend me!

I only wanted to say that I understand the words well and that I appreciate you taking the time to translate your words to my language.

You should be able to quickly test it by unplugging the AC-PRO, seeing if the wireless APs go down, plugging it back in and seeing that they come back up.

2 Likes

Hi Jeff,

Indeed, your process works correctly, if you unplug the AC-PRO PoE, the Archer C7 stops providing Wi-Fi to Clients, on the iPhone try to connect but does not provide IP.

If I plug in AC-PRO again, the Wi-Fi connection is restored and the operation is normal.
But:
Without bothering to bother you anymore, the idea was that when AC-PRO loses the shared external Wi-Fi connection

Run the same process as when you unplug it from the PoE, which I have verified that it does not work the same, the Archer C7 Wifi is still active and is not operational, do not connect to the Internet.

well if you can get it by changing some parameter of wifi_is_up (), ok, but if I am going to bother you a lot with this quiet I will continue investigating the forum until you find the solution, you have helped me with your knowledge, there is no hurry, there is time and eager to learn...

Thanks jeff

Have you waited at least a minute after disconnecting the AC-PRO?

The cron job only runs at the start of every minute, then probably takes ~5 seconds to turn off/on the Archer C7 wireless.

I will look at the script again. It works by seeing if the Archer C7 can connect to the "outside world". It surprises me that the way that you break that connection changes how the script behaves.

You can also run the script from the command line, if you don't want to wait!

Hi Jeff, good morning, 09:00 here,

First of all I understand that the script is configured in Archer C7, since it gives Wi-Fi to Clients.... no?.
I give you images of how I have managed everything so far and you better understand the scenario.

***Lan Archer C7 o TP-LINK_BLACK ***
Tareas%20Programadas

Lan AC-PRO

***Lan Archer C7 o TP-LINK_BLACK ***

Well as I told you, if I unplug the AC-PRO


The process works correctly both when disconnecting and reconnecting the AC-PRO.

I have tried to deactivate the incoming Wifi in AC-PRO, and wait almost 5 minutes and the Archer C7 continues to give false Wifi, the Mobile has Wifi and is separated from the Internet.


Well, at this point the Archer C7 does not disconnect the Wifi waiting more than 5 minutes, and continues to give false wifi signal,

I hope I have helped you, if you see that what I am asking for is abnormal or annoying, leave it ..., I will continue reading through the forum, I may contact you with any doubts or advances that may occur,

Thanks for everything jeff.

Thanks, it sounds like something is not quite right with the script. Yes, it should be running on the Archer C7.

Let's look through it step by step.

I'm pretty sure that wifi up and wifi down work, as many people would complain if that was broken!

Where could it be broken? The steps are:

  1. cron runs the script
  2. The script creates a helper function, wifi_is_up()
  3. Check to see if 8.8.8.8 is reachable
  4. Based on the result, check the current wifi status and change it, if needed

So I started checking things step-by-step here and found that I made a mistake in my typing

jeff@office:~$ wifi_is_up () {                     # Test to see if at least wireless is up
>     ubus call network.wireless status | fgrep -q '"up": true,' 2>dev/null
> }
jeff@office:~$ wifi_is_up && echo UP || echo down
-ash: can't create dev/null: nonexistent directory
Command failed: Not found
down

This should have been 2>/dev/null which means "send any error messages to the bit bucket (black hole, trash can, ...)". Looking at it again, where that is doesn't do much since fgrep isn't likely to return an error message reading its input from the output of the ubus command. Might as well remove it so that part can read

wifi_is_up () {                     # Test to see if at least wireless is up
    ubus call network.wireless status | fgrep -q '"up": true,'
}

If not, the next step I would take is to "watch" the script run. sh -x /some/script will show each line executed. The function definition isn't "executed" so it isn't there.

I edited the script to not actually change the wireless and tried it here

#!/bin/sh

wifi_is_up () {                     # Test to see if at least wireless is up
    ubus call network.wireless status | fgrep -q '"up": true,'
}

ping -c3 8.8.8.8 > /dev/null        # Try to see if 8.8.8.8 is reachable, three times. Discard output.
if [ "$?" ] ; then                  # Check to see if the ping failed
    wifi_is_up && echo "set wifi down"         # ping failed, only change if needed 
else
    ! wifi_is_up && echo "set wifi up"         # ping succeeded, only change if needed (or will reset wireless)
fi

with the output when the wireless is running

root@office:/home/jeff# sh -x ./test-script.sh 
+ ping -c3 8.8.8.8
+ '[' 0 ]
+ wifi_is_up
+ ubus call network.wireless status
+ fgrep -q '"up": true,'
+ echo 'set wifi down'
set wifi down

Hi Jeff,

Congratulations, now it works perfect, both by cable and Internet fall in AC-PRO, I have made a small change in the (if ["$?"]; Then), I have searched the Internet for what it meant and it has not clarified much , so choose to switch to:

         if [$? -eq 0]; then
        # 0 indicates success, others indicates error.

It helped me more to understand.

In the end the code has been like this, tested 100 times... both in PoE drops, changing the password in external Wifi to cause disconnection, as well as disconnections of the Wifi by hand from LuCi.

<----!
#!/bin/sh

wifi_is_up () {
ubus call network.wireless status | fgrep -q '"up": true,'
}
ping -c3 8.8.8.8 > /dev/null
if [ $? -eq 0 ]; then
! wifi_is_up && wifi up
else
wifi_is_up && wifi down
fi
<-----!

Just to tell you how you see increasing the time of checking pings to 15 minutes, so as not to overload the Router Archer C7, I don't think this process is a lot of effort for the router, no, what do you think ... it would be something like that ... , do not?:
* / 15 * * * * /usr/libexec/check-exit-and-set-wifi.sh

Well, just thank you for your help, I will continue researching the forum although I can't find where to see examples of * .sh or similar files in Openwrt, if you know any site, thanks,

Regards,

Joan.

1 Like

Glad you found my error and that things are running.

There isn't a lot of load associated with running the ping, at least in my opinion. If you do want to test at a lower rate, whitespace is the separator, so the line would read

*/15 * * * * /usr/libexec/check-exit-and-set-wifi.sh

(For "code", you can use the preformatted button </> in the editor toolbar.)

1 Like

OK, Gracias, Thanks

ok yes it's better

xao

1 Like

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.