Cron Job for Reboot Router if not on Defined "DFS Channel"

Cron Job for Reboot Router if not on Defined "DFS Channel"

I want to create a cron job that does this for my Flint 2 Router .....

  1. Get "5GHz Wi-Fi " Channel as you have defined "GL-iNet Admin Panel"
    If defined "5GHz Wi-Fi " Channel is not a "DFS Channel" then Abort the cron job

  2. If root/DFSReboot.txt File exist with todays date then Abort the cron job (Note the cron job has allready ran today)

  3. (At this point cron job has determined it has not ran today and defined "5GHz Wi-Fi " Channel is a "DFS Channel")
    Note: Somehow get current "DFS Channel" and if it's not the define "5GHz Wi-Fi " Channel in the "GL-iNet Admin Panel"

    Create root/DFSReboot.txt File (with todays date)
    If the current "DFS Channel" is the define "5GHz Wi-Fi " Channel in the "GL-iNet Admin Panel" then No Router Reboot is needed Abort Cron Job

    Force Reboot of router now

--- end of Cron Job. ---

I haven't written any Cron jobs before, I wrote Batch files for windows command line.

any help would be appreciated. not sure where to start.

During severe weather I get kicked on the DFS Channel even thou I'm 60 miles from Major airport (ICT Wichita,Ks) I would like to run a cron job in the morning say around 7am to check to see if I'm still on the DFS Channel I have selected, I See in "Luci" "Channel Analysis" I don't know if I could use that information in the cron job.

Thank you

This doesn't make really sense, imho.

DFS will fail as soon as radar is detected. No matter if you reboot or not. So what is the goal?

The goal is if radar is not detected to put me back on the DFS channel I selected in Admin Panel. when you have a very crowded "5GHz Wi-Fi " on other channels in my area my wireless range is very poor.

If I go into "GL-iNet Admin Panel" and select and "apply" my "DFS Channel" that doesn't work, but a reboot the router does everytime.

I guess you must never have that problem (maybe your neighbors are miles apart)

Sounds more like an bug to me.

@bruce Can you check if the DFS channel will switch back when radar detection does not detect radar anymore? Should work like this, imho.

1 Like

Hi,

This cron job requires you to add/edit, as this is the customize rule of the cron, by SSH to read the /etc/config/wireless or command 'iwinfo' to get Wi-Fi configuration.

Before that, as my understanding by your post, can I confirm these following info with you:

  1. Do you want to force 5GHz Wi-Fi to work on the DFS channel? (like keeping use the channel 60 you choose manually all the time)

  2. If 5GHz Wi-Fi (as Q.1) does not work on the DFS channel, does the router require to reboot? And only reboot once time on everyday?

Note: If you choose a DFS channel manually, the router will detect the radar signal first. If the channel you choose is used by the radar, the router will still auto switch to another available channel to continue working (this for ensure that the router Wi-Fi can work normally). Even if reboot the router, also detects the radar DFS signal to avoid them. If the work channel of the radar has always been occupied, so that the router cannot choose DFS channel to work. It does make sense.

Had a little rain storm north of me in ICT area last night and got switched from my DFS channel down to Channel 52 and it hasn't switched back yet this morning. "Luci" "Channel Analysis" shows it's on Wifi Channel 52 and my phone app "WiFiman" shows it's on Channel 52 also.

This promising that I can see it changed in "Luci" "Channel Analysis" now if I can figure how to write some code.

I will not do a reboot just yet this morning, and see if will change back, but in the past it has not changed automatically on any of the firmware versions I have tried, right now I am on " openwrt-mt6000-4.6.0-0615-1718389581 Snapshot"

(insert scratch my head here) :face_with_monocle:

I'm Trying to Keep it on DFS channel 116 (also tried 110,112,114 in the past)

and yes if I reboot it does check for "radar" signal before applying a channel change that works like it should, and if choose a DFS channel manually to a new DFS channel it does check for "radar" signal before applying a channel change.

If it's supposed to switch back automatically it does not do it on my Flint 2 or even on my GL-AXT1800 Slate AX.

So this why I'm wanting to write some code to do what I want.

The scanned channel will occupy a 5G WiFi hardware interface, which will cause the terminal device to be connected to WIFI to disconnect (why it is disconnected WIFI for DFS channel scanning, the principle can be Google).

If the router DFS scan frequently, such as 30 mins per once, this will cause the WiFi terminal to experience a poor experience, as the WiFi lost connectivity every 30 mins.

I think this is go crazy for users. If you do require this job, can try to make a sh or script in the router to loop it. And actually it does not require to reboot the router, only restart the
whole network interface: /etc/init.d/network restart

There's a command "/etc/init.d/network restart" that serves my purpose without a reboot and I just tried it and it works as you described, after running "/etc/init.d/network restart" it put me back on my DFS Channel 116

Now if i can figure how to get "5GHz Wi-Fi " current channel like "Luci" "Channel Analysis" shows maybe I can get somewhere.

Note: I only would run this once per day if it's not on my DFS channel I choose

When I use this command "/etc/init.d/network restart" it takes All network connections down. ( All Wired and Wireless ports)

After Googling and searching my Log file is there a way to call "RadarStateCheck()" from the command line that way It could scan for radar and only shut down the "5GHz Wi-Fi " network?

Sounds more like some driver command than a shell command. Since the DFS detection is built-in into the driver itself, I highly doubt you can call it manually.

On Flint 2 this should work to just restart the 5 GHz interface:

ifconfig rax0 down && ifconfig rax0 up

this command does not return a command line error so you would think if I ran just "ifconfig rax0 down" and look at my "5GHz Wi-Fi " network on my phone the network in my wifiman app would show "5GHz Wi-Fi" to be down but it's still up :worried:

(Bang Head here)

On my system it did the job. Are you sure you wait long enough for the phone to see the 5 GHz is going down?

When I run ifconfig rax0 down only the internet Traffic is shut off, wifiman app on my phones Show "5GHz Wi-Fi" to be still up.

When I connect with another phone to my "5GHz Wi-Fi" network I can connect to network but it shows no internet available. So this command this command must shutdown the "5GHz Wi-Fi" port only and not actually shutting down the "5GHz Wi-Fi" Wireless Network.

Now this Shuts down the WiFi Networks completely
"wifi down" and "wifi up" turns it back on, but this is both the 2.4 & 5 ghz Wireless Networks.

Looks like we getting closer. Now to figure how to shut down only "5GHz Wi-Fi" wireless network :nerd_face:

closer I think,

since I have "5GHz Wi-Fi" & "5GHz Guest Wi-Fi" I have to run both
ifconfig rax0 down
ifconfig rax1 down
to completely shut down the "5GHz Wi-Fi" wireless network

and
ifconfig rax0 up
ifconfig rax1 up
to turn back on the "5GHz Wi-Fi" wireless network

I think with this or
"wifi down" and "wifi up" this will fit most of my needs

my head hurts :dizzy_face:

1 Like

Ok I think I got it a cron job figured out, I just tell cron job to shut down the "5GHz Wi-Fi" wireless network at 7:05 every morning then wait 60 seconds and bring the "5GHz Wi-Fi" wireless network back up. Cron job does not check what channel the "5GHz Wi-Fi" wireless network is on, it just turns it off and then back on to the channel you had set in Admin Panel.

in Luci
go to "system tab"
and select "scheduled Tasks"
(This is the system crontab in which scheduled tasks can be defined.)

"enter" - Start of code

"# Turn off and then backup "5GHz Wi-Fi" wireless network only
"# - Put it back on the Channel you selected in case you had it on a DFS Channel and it detected weather radar and changed to non DFS Channel
"# At 7:05 AM every day
05 7 * * * ifconfig rax0 down && ifconfig rax1 down && sleep 60 && ifconfig rax0 up && ifconfig rax1 up

  • End of code

now Click "save"

Note: this Cron job will show up in \etc\crontabs\ Folder (root is the name of the file)

This solves my problem when weather radar changes my channel on the "5GHz Wi-Fi" wireless network and puts it back on the channel I had selected in Admin Panel every morning at 7:05 am if weather radar is not detected.

Thanks for getting my mind headed in a direction I could understand cron jobs :sunglasses:

Note for some reason the only way I could get cron job comment to display in this forum was start the comment with a qoute, replace "# with #
in the code shown