Create scheduled task to automatically change wifi channel

Good day! Can anyone help me create a scheduled task to change the wifi channel (2.4g) every 2 hours. I want to automatically change channel from 1 to 11 and back for a specified period of time like every 2 hours. I'm new to openwrt and don't know how to create the script. tnx in advance.

Like this?

DEVICE="radio0"
CHANNELS="1 11"
DURATION=7200

while true; do
    for channel in $CHANNELS; do
        uci set "wireless.$DEVICE.channel"="$channel"
        uci commit wireless
        wifi up "$DEVICE"

        sleep $DURATION
    done
done

You might want to parse the result of iw scan to figure out which channel has the least interference from other APs.

1 Like