Create a script to switch wifi off when nobody connected - I have an old script

I've tried this:

Every time I check the log with "cat /tmp/autowifi.log", it says "Wifi is already OFF" even when it's ON.

This is the script taken from that thread:


SW=$(iwinfo 2>/dev/null | grep wlan0-1)

echo $(date) >> ${LOG}

if [ -z "$SW" ] # check if wifi is on
  echo "Wifi is already OFF" >> ${LOG}
  echo "Wifi is ON" >> ${LOG}
  if [ -z "$(iw dev wlan0-1 station dump | tr -d '\n')" ] # Check if anyone is connected
    echo "No-one is connected" >> ${LOG}
    case "$(cat /var/autowifi)" in # check if anyone was connected xx mins ago (defined in cron)
        echo "No-one is connected since some time, so turning wireless OFF" >> ${LOG}
    uci set wireless.@wifi-iface[1].disabled=1
    uci commit wireless
        /sbin/wifi 2>/dev/null
        cat </dev/null > /var/autowifi
        echo "Someone was connected some time ago, so leaving wireless ON for now" >> ${LOG}
        echo 1 > /var/autowifi
    echo "Someone is connected to wlan1" >> ${LOG}
    cat </dev/null > /var/autowifi

It supposedly worked with 14.07, but it's not working with 17.01.4.

Any ideas? What do I need to change?
Thank you,

Without knowing where SW comes from, it's a complete guess.

It appears that it is populated by the command:

iwinfo 2>/dev/null | grep wlan0-1

This command determines if there are SSIDs at wlan0-1...

Try changing this to wlan0 instead, perhaps you don't have a AP at location wlan0-1.

Consider, as well (as iw has big warnings about not "screen scraping" its output)

ubus call network.wireless status {}

which returns things like

	"radio24": {
		"up": true,
		"pending": false,
		"autostart": true,
		"disabled": false,
		"retry_setup_failed": false,
	"radio5": {
		"up": true,
		"pending": false,
		"autostart": true,
		"disabled": false,
		"retry_setup_failed": false,

Thanks for helping, guys.

I have an interface called wlan0, not wlan0-1, that's right. Improved.

The ubus call.... it would be something like...

if (network.wireless.radio24 = "up") /sbin/woggle

Now I'm trying to do things easy and simple. I've taken the "wifi toggle" script from
and realised it has changed, so the code I pasted was based on the old wifitoggle script.

But I have troubles with the wifi toggle script, even changing from device="wl0" to device="wlan0"

Checking the terminals from the command-line.

root@LEDE:/sbin# uci get wireless.wlan0.disabled
uci: Entry not found

The following lines have /proc/diag/led/ folder and files... I don't have any "diag" directory under /proc/, so where are the leds?
It seems I have all meesed up.
I'm using a TP-LINK WR-843N router, v9 firmware, LEDE 17.01.4 fresh installed.

Something as simple as...

root@LEDE:~# wifi down wlan0
Command failed: Not found
wlan0(): Interface type not supported

although ifconfig says I have a wlan0 interface.