Wifi schedule After reboot system

I didn't follow through the entire script, but it looks to be as though it works by setting up state changes in the future, to be triggered by cron.

The recheck command appeared to me to be part of a "don't drop wireless if anyone is connected" policy, not "what time is it now, and completely understand all the rules and determine the desired state". Doing the latter in the general case is nearly impossible.

If you have a simple set of rules, you could write your own script that checks date and then choose the desired wireless state.

Thank you Jeff for your answer but I am not able to write any script.
I'm a newbie in OpenWRT and his language.
Can you give me more explanations or examples?

If I understand the "recheck" function is not a good idea? If I understand correctly I should give up?

Regards.

https://openwrt.org/docs/guide-developer/write-shell-script

I don't think the recheck function does what you want.

Perhaps something like this (untested) as a starting point

#!/bin/sh

now=$(printf "%d" $(date +%H%M))    # remove leading 0 or 0600 (octal) becomes 384
if [ "$now" -lt 600 ] ; then        # don't use the leading zero here
    wifi down
elif [ "$now" -lt 2230 ] ; then
    wifi up
else
    wifi down
fi

Edit: Reading through man date suggests that the first line could be the simpler

now=$(date +%_HM)

or

now=$(date +%kM)

from

       %k     hour, space padded ( 0..23); same as %_H

I will read documentation about scripts. I will try to understand something and will try to decrypt your script.

Regards an good night (I'm living in France).

1 Like

I was curious, so I installed WiFi Schedule on mine to see how it behaved.

@jeff is correct; the service logic is very rudimentary and assumes that the router will never be rebooted. It merely sets up cron jobs to switch the WiFi on or off depending on the rules you set up in the service; it has no more intelligence than that.

If you want the router to be able to determine intelligently whether or not the WiFi should be on or off (e.g. after rebooting), this package won't do it in its current form.

If you feel like cutting your teeth on shell scripting, an interesting exercise might be to work out how to identify a window of time and take one action (e.g. switch the WiFi on) if the current time is inside that window and take another action (e.g. switch the WiFi off) if the current time is outside that window.

You scare me.
I think I will be not able to do this kind of job.
Can you help me if it's not too complicated for you?
Do you know if there is another way to schedule the WiFi in a better way, even the router is re-booted?
Regards.

There's only one way to find out. Everyone has to start somewhere; no-one knows everything straight away. It's all a matter of time and experience. The more you do, the more you learn.

If by "help" you mean "offer suggestions and guidance and links to relevant information to direct my learning", then yes, of course. If by "help" you mean "write it for me", then no. However, @jeff's post above, which shows a sample of some code to detect dates and times, is a good place to start. Some online or printed material about shell scripting would also be useful reading.

I don't know if there is. However, if you write one, then there will be. :smiley:

If other solutions are too scary or over your head, the simplest solution is: don't turn your router off.

2 Likes

Well, if you don't turn the router off/on often them out shouldn't be a big issue. If you Halen to do it while WiFi is supposed to be off then the it will stay on, yes, but next time the script will be triggered and it will work normally. So not the end of the world.

I see what @jeff wrote as easy solution, but probably is best to have something using tessting the user entered already (i.e. an extra function in the same .sh file that when called will read user settings and use them to turn off wifi if required. (And this should be called upon reboot as I was thinking recheck would do.

I understand this is a community project, so ideally if I propose it I should do it, but I come from Windows background so Linux scripting isn't my strong point.

Anyway, it's an idea if the package maintainer could spare a few minutes to look at it, though not really the end of the world if user have to turn the wifi off manully if they hapoen to reboot.

No fancy LuCI GUI, but I use this script here: Scheduling on/off wifi

It doesn't solve the issue of not checking for scheduled state upon booting, but it sure is easier to handle here in this script since you have ask days treated the same, so am you need is to compare time.

Hello all,

I want to switch OFF the Wifi for 2 reasons:

  • No more Wifi waves in my house.
  • Stop internet activity of my children.

My children have discovered that if they make a OFF-ON on the router the Wifi come back. And I don't want this.
But it seems to be too complicated for me. I think I will give up.
Thank you all for your support.

Regards.

The easier solution is to change the script to set the disable flag on each radio and then call wifi to reload the radio instead of explicitly calling wifi down/up.
This will then prevent it coming online after a reboot if it is in the correct time period.

1 Like

I like that approach. Assume the WiFi should always be off, unless the time is within a certain window. Neat!