Turn off the 2.4 GHz Wi-Fi overnight

Hello,

I would like to disable the 2.4 GHz Wi-Fi overnight.

Then I entered the following under System > Scheduled Tasks:

#Start Wi-Fi
00 08 * * 1-5 uci set wireless.radio1.disabled=0; uci commit wireless; wifi

00 10 * * 6-7 uci set wireless.radio1.disabled=0; uci commit wireless; wifi

#Stop Wi-Fi
00 23 * * * uci set wireless.radio1.disabled=1; uci commit wireless; wifi

wireless.@wifi-device[!].disabled=0 also did not result in the Wi-Fi being turned off at night.

I also tried wireless.@wifi-iface without success.

What did I misunderstand?
Have a nice day.
Bebbi

Suggest you start with 1st party documentation wiki? Your links are anachronisms.

I couldn't find an answer to my question at https://openwrt.org/docs.

I couldn't find an answer to my question at https://openwrt.org/docs.

I found the information on the linked pages in a similar form on other sites. However, I didn't find anything to suggest that this is no longer up to date.

6-7 is invalid. Allowed values=0 thru 6

See: https://openwrt.org/docs/guide-user/base-system/cron

so it should be:

00 08 * * 1-5 uci set wireless.radio1.disabled=0; uci commit wireless; wifi

00 10 * * 0,6 uci set wireless.radio1.disabled=0; uci commit wireless; wifi

Yes. At 10:00 on sundays and saturdays.

Thanks for the clarification. I have now tried it with a different time for “Stop,” so it should be disabled now. But even after rebooting, the Wi-Fi is still active.

wifi --help
Usage: /sbin/wifi [config|up|down|reconf|reload|status|isup]
enables (default), disables or configures devices not yet  configured

Issuing wifi with No arguments : effectively takes down the wireless interfaces and then enables them again.

Try it from cli: uci set wireless.radio1.disabled=1; uci commit wireless; uci show wireless.radio1.disabled

The output is then:

wireless.radio1.disabled=‘1’

Under Network > Wi-Fi, it is also displayed as disabled. However, an existing connection to the smartphone is displayed there. The smartphone also indicates that it s connected to the network. When I disconnect there, it can no longer be re-established from the smartphone, but the network is still detected. After a while, the connection is re-established.

I've been wondering all this time whether I can leave out the ‘wifi’.

Just use wifi reload to re-read the wireless config.

uci set wireless.radio1.disabled=1; uci commit wireless; uci show wireless.radio1.disabled; wifi reload; wifi status
wireless.radio1.disabled='1'
{
        "radio0": {
                "up": true,
                "pending": false,
                "autostart": true,
                "disabled": false,
                "retry_setup_failed": false,
                "config": {
                        "channel": "36",
                        "hwmode": "11a",
                        "path": "pci0000:00/0000:00:00.0",
                        "htmode": "VHT80",
                        "cell_density": 0,
                        "txpower": 20,
                        "disabled": false
                },
                "interfaces": [
                        {
                                "section": "default_radio0",
                                "ifname": "phy0-ap0",
                                "config": {
                                        "mode": "ap",
                                        "key": "[…]",
                                        "ssid": "[…]",
                                        "encryption": "psk2",
                                        "network": [
                                                "lan"
                                        ],
                                        "mode": "ap"
                                },
                                "vlans": [

                                ],
                                "stations": [

                                ]
                        }
                ]
        },
        "radio1": {
                "up": false,
                "pending": true,
                "autostart": true,
                "disabled": true,
                "retry_setup_failed": false,
                "config": {
                        "channel": "11",
                        "hwmode": "11g",
                        "path": "platform/ahb/18100000.wmac",
                        "htmode": "HT20",
                        "country": "DE",
                        "cell_density": 0,
                        "disabled": true
                },
                "interfaces": [
                        {
                                "section": "default_radio1",
                                "ifname": "phy1-ap0",
                                "config": {
                                        "mode": "ap",
                                        "ssid": "[…]",
                                        "encryption": "psk2",
                                        "key": "[…]",
                                        "network": [
                                                "lan"
                                        ],
                                        "mode": "ap"
                                },
                                "vlans": [

                                ],
                                "stations": [

                                ]
                        }
                ]
        }
}

Thank you for your support.

If your problem is solved, please consider marking this topic as [Solved]. See How to mark a topic as [Solved] for a short how-to.
Thanks! :slight_smile:

Does OpenWrt need time for the changes to take effect?

What I understand:

- The “wifi” at the end of the lines is superfluous.

- Sunday is indicated with “0”.

- If I have changed something under System > Scheduled Tasks and clicked on “Save,” I have to enter “wifi reload” in the console.

Unfortunately, I don't understand why Network > WLAN is shown as disabled, but a connection via WLAN is possible and “uci show wireless.radio1.disabled” outputs “wireless.radio1.disabled=‘0’”.

What I expected:

- Between 11 p.m. and 8 or 10 a.m., I cannot find this Wi-Fi with my smartphone, and at 11 p.m., the connection is interrupted.

- If I set “00 18 * * * uci set wireless.radio1.disabled=1;” at 6:25 p.m. uci commit wireless“ at 6:25 p.m. and enter ”wifi reboot,“ the Wi-Fi is turned off. If I then set it to ”00 19 * * * uci set wireless.radio1.disabled=1; uci commit wireless," it is reactivated.

However, neither of these both things seems to be the case.

When you make changes to the wireless configuration using uci set and uci commit, the changes are not applied immediately. The uci commit command saves the changes, but you still need to apply them to take effect. This is true for any uci capable configuration.

Therefore, after running the command: uci set wireless.radio1.disabled=1; uci commit wireless; you still need to use wifi reload to apply the changes

This command tells the wireless subsystem to reload the configuration and apply the changes you made. In summary, both uci commit and wifi reload are necessary for the changes to take effect.

No.
Here you are modifying the cron application, NOT anything to do with /etc/config/wireless config.

Using your initial example 00 08 * * 1-5 uci set wireless.radio1.disabled=0; uci commit wireless; wifi, cron monitors this portion “00 08 * * 1-5” to determine when it should execute this portion uci set wireless.radio1.disabled=0; uci commit wireless; wifi reload

Bottom line, anytime you change/commit a uci capable configuration, you need to reload the configuration to apply the changes.

However, adding this to /etc/config/wireless does not seem to be correct either.

root@OpenWrt:~# wifi reload
root@OpenWrt:~# uci show wireless.radio1.disabled
uci: Parse error (invalid command) at line 40, byte 0

My definition begins in line 40.

If I enter a time in a few minutes in the cron job an press “save” the Wi-Fi is turned off.

30 00 * * * uci set wireless.radio1.disabled=1; uci commit wireless; wifi

If the router is restarted within the next 24 hours, this will have no effect, as far as I understand. This is not ideal, but it works.

How is OpenWRT supposed to recognize whether it is offline time or not when specified in /etc/config/wireless? Separate entries must be combined for this. No time period is defined in a command.

I really don’t follow you on this. Most isn’t of relevance to the issue.

You said you changed the times when you want to disable/enable from your original post. If that is what you want long term, then please tell me:

  • What days and hours do you want Radio0 to become disabled/un-available.
  • What days and hours do you want Radio0 to become enabled/available.

Take note that the command will not run if the router is down during the cron run time. Probably is better to build an idempotent script that when run check the clock and set the wifi state. Put that on the cron and on the startup list, and you should be fine.

1 Like

That goes without saying. Obviously if the router is off/down, nothing runs.

Lets's take a look at the scenario based on the OP's initial post:

  • If router is down prior to 23:00 and recovers after 8:00 or 10:00 nothing changes - wifi radio0 will be up.
  • If router is down prior to 23:00 and recovers before 8:00 or 10:00 then no harm done - wifi radio0 remains up. Cron still runs and sets enable which does not induce any harm.
  • If router is down after 23:00 wifi radio0 will be down and if router recovers prior to 8:00 or 10:00 cron runs and brings wifi radio0 up.
  • If router is down after 23:00 wifi radio0 will be down and if router remains down after 8:00 or 10:00 then this is the only scenario that would need manual intervention that could be rectified by issuing this one line in a terminal: uci set wireless.radio0.disabled=0; uci commit; wifi reload

It is unlikely the OP would be able to independantly craft said script given the logic required.

Cron runs on system time which, by default, will be established by ntp typically much less than a minute after init brings up the router.

Try the app wifischedule?

That’s an option, though I believe this takes down all radios, not just Radio0, and it’s subject to the same issues as above. You can’t get around unplanned outages.

This works as cron entries:

Cron
#Start Wi-Fi Weekday
00 08 \* \* 1-5 uci set wireless.radio0.disabled='0'; uci commit wireless; wifi reload; logger -s "WIFI ON" "Radio0 enabled"
#Start Wi-Fi Saturday, Sunday
00 10 \* \* 6,0 uci set wireless.radio0.disabled='0'; uci commit wireless; wifi reload; logger -s "WIFI ON" "Radio0 enabled"
#Stop Wi-Fi Daily
00 23 \* \* \* uci set wireless.radio0.disabled='1'; uci commit wireless; wifi reload; logger -s "WIFI OFF" "Radio0 disabled"