FloFaber.com

OpenWRT: Disable WiFi at a given time

This information always takes me too much time to find so here I wrote it down myself.

The goal

We have a couple WiFi SSIDs configured. In this example I named them 'Home' and 'HomeChilds'. We want to disable the one named 'HomeChilds' everyday at 08:00PM and enable it again at 07:00AM so our childs don't stay up all night watching stuff on the internet.

First steps

First of all you will need to SSH into your OpenWRT box.

Disabling a specific SSID

To print out all the wireless information you can use the following command:

uci show wireless


The output will look something like this:

wireless.radio0=wifi-device
wireless.radio0.type='mac80211'
wireless.radio0.channel='36'
wireless.radio0.hwmode='11a'
wireless.radio0.path='pci0000:00/0000:00:00.0'
wireless.radio0.htmode='VHT80'
wireless.radio0.disabled='1'
wireless.radio1=wifi-device
wireless.radio1.type='mac80211'
wireless.radio1.hwmode='11g'
wireless.radio1.path='platform/ahb/18100000.wmac'
wireless.radio1.htmode='HT20'
wireless.radio1.country='AT'
wireless.radio1.channel='8'
wireless.default_radio1=wifi-iface
wireless.default_radio1.device='radio1'
wireless.default_radio1.network='lan'
wireless.default_radio1.mode='ap'
wireless.default_radio1.key='12345678'
wireless.default_radio1.ssid='Home'
wireless.default_radio1.encryption='psk2'
wireless.default_radio1.disabled='0'
wireless.default_radio1.hidden='1'
wireless.wifinet2=wifi-iface
wireless.wifinet2.network='lan'
wireless.wifinet2.ssid='HomeChilds'
wireless.wifinet2.encryption='psk2'
wireless.wifinet2.device='radio1'
wireless.wifinet2.mode='ap'
wireless.wifinet2.hidden='0'
wireless.wifinet2.key='12345678'

Notice the lines wireless.wifinet2.ssid='HomeChilds' and wireless.default_radio1.ssid='Home'.

Because we want to disable our 'HomeChilds' AP we need to write down the string before .ssid: wireless.wifinet2. If we wanted to disable the 'Home' AP, we would write down wireless.default_radio1.

Cron

Now we need to tell OpenWRT when to do what. This is done using the crontab file. Open it up using the crontab -e command. By default it's opened with the VI editor so you might want to watch a quick tutorial on that.

In case you don't know the crontab format here is a quick example:

# m h dom mon dow user  command
30 23 * * * wifi down >/dev/null 2>&1

This line will turn off all wireless interfaces everyday at 23:30 and write the output to /dev/null. You can use crontab-generator.org to generate your crontab line.


The command used to disable out 'HomeChilds'-AP. It disables the AP, saves the information and applies it.

uci set wireless.@wifinet2.disabled=1 && uci commit wireless && wifi reload


Now we just need to put this into the crontab file accordingly:

0 20 * * * uci set wireless.@wifinet2.disabled=1 && uci commit wireless && wifi reload >/dev/null 2>&1
0 7  * * * uci set wireless.@wifinet2.disabled=0 && uci commit wireless && wifi reload >/dev/null 2>&1

The first line will disable the Wifi at 08:00PM and the second one will enable it again at 07:00AM.

Disabling all WiFi interfaces

In case you want to disable all the WiFi interfaces I've got you covered as well. You can turn off the wifi with wifi down and turn it on with wifi up. Pretty simple.

The following crontab lines will disable the wifi at 11:00PM and enable it again at 08:00AM:

0 23 * * * wifi down >/dev/null 2>&1
0 8  * * * wifi up   >/dev/null 2>&1