Wlan scheduled crontab

Hi, i need a scheduled task to activate and stop the wireless lan.

The name of the wireless lan is = wlan0
Check here:

Can i add these command to the crontab ?

# start wlan0 each day at 06:30 am
00 06 * * * uci set wireless.@wifi-device[0].disabled=0; uci set wireless.@wifi-device[0].txpower=20; uci set wireless.@wifi-device[1].disabled=0; uci set wireless.@wifi-device[1].txpower=20; uci commit wireless; wifi
# stop wlan0 each day at 05:00 am
30 23 * * * uci set wireless.@wifi-device[0].disabled=1; uci set wireless.@wifi-device[1].disabled=1; uci commit wireless; wifi

Check here:

Is now the configuration complete, is that all correct ?
Thanks for your help!

# wifi --help
Usage: /sbin/wifi [config|down|reload|status]
# wifi down
# wifi

should i add the additional ?

The point is you can do it simpler with just wifi down and wifi.

Than i should only add thi command in the crontab,
but how i must also add the time ?
Stop: 5:00am
Activate: 06:30am

See examples:

1 Like

Well, this doesn't fit to my personal usecase ... where a 17 year old boy simply powercycle the router and the WLAN is back again ... :wink:

Therefore I use this snippet successfully for a couple of years:

# ap-toggle script
# written by Dirk Brenken (dev@brenken.org)
# usage:
#   ap-toggle.sh on <radio>  => switch the AP on all radios "on", you can limit this with the optional <radio>-parm
#   ap-toggle.sh off <radio> => switch the AP on all radios "off", you can limit this with the optional <radio>-parm
# reference this script in /etc/crontabs/root and restart cron service afterwards, e.g.:
#   0 00 * * *    /usr/bin/ap-toggle.sh off
#   0 06 * * *    /usr/bin/ap-toggle.sh on

# This is free software, licensed under the GNU General Public License v3.
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

# set initial defaults
apt_sysver="$(ubus -S call system board | jsonfilter -e '@.release.description')"

. "/lib/functions.sh"

# f_prepare: gather wireless information & enable/disable AP interfaces
    local config="${1}"
    local mode="$(uci -q get wireless."${config}".mode)"
    local radio="$(uci -q get wireless."${config}".device)"
    local disabled="$(uci -q get wireless."${config}".disabled)"

    if [ "${mode}" = "ap" ] && ([ -z "${apt_radio}" ] || [ "${apt_radio}" = "${radio}" ])
        if [ "${apt_action}" = "on" ] && ([ -z "${disabled}" ] || [ "${disabled}" = "1" ])
            uci -q set wireless."${config}".disabled=0
        elif [ "${apt_action}" = "off" ] && ([ -z "${disabled}" ] || [ "${disabled}" = "0" ])
            uci -q set wireless."${config}".disabled=1
config_load wireless
config_foreach f_prepare wifi-iface

# commit & reload all changes, write final log message
if [ -n "$(uci -q changes wireless)" ]
    uci -q commit wireless
    ubus call network reload
    apt_radio="${apt_radio:="all radios"}"
    logger -t "ap-toggle-[${apt_ver}] info " "AP on ${apt_radio} has been switched '${apt_action}' (${apt_sysver})"

Any way to do the scheduling just with a single SSID? I don't want to turn off the radio complete just one of the two SSIDs on it..

Yes, you should just use 'disabled' option of interface.

its working from command line but not from cron:

uci set wireless.wifinet3.disabled="1"; uci commit; wifi reload wifinet3

Try initially to use full paths:
/sbin/uci /sbin/wifi

Activating cron

Cron is not enabled by default, so your jobs won't be run. To activate cron:

/etc/init.d/cron start /etc/init.d/cron enable

:!: If there is no crontab defined (i.e. /etc/crontabs/ is empty), then cron won't start! Make sure you already defined cron jobs before trying to start cron.

Good suggestion, but didn't work either. Is here a log file for cron? I could not find anything in the /var/log...

edit ok let me try the above and reboot

Works for me, at least:

*/5 * * * * /sbin/uci show wireless > /tmp/cronwireless
Wed Dec 11 10:48:16 2019 cron.info crond[2568]: crond (busybox 1.28.4) started, log level 5
Wed Dec 11 10:50:00 2019 cron.info crond[2568]: USER root pid 2583 cmd /sbin/uci show wireless > /tmp/cronwireless

its the time - I can't get UTC to work correctly somehow. I sync with browser, reboot and then its back to some random time. I see these in the logs:

cron.err crond[1219]: time disparity of 1260 minutes detected

What about NTP, is it failing or something?