Cron task to restart wlan0 when it disconnects. Needed

i have a client mode setup but due to ambient factors sometimes the wireless interface will need to be restarted to reconnect.

i need a script that will restart the (wlan0) when RX Rate will hang on 1 Mbit/s for more than 10 seconds.

as when i get 1 Mbit/s there is no connection unless i manually restart wlan0

You can't, the minstrel rate control algorithm will always revert back to 1 MBit/s on an idle link.

I ran into something like this as well on my Relay it would just stop working. not sure why? I thought it was just my IPV6 going stale but my ipv4 didn't work either, so I used the crontab to run a script every minute that sends one ping to my gateway to ensure connectivity or Restart the network services. which then fixes the connection.
Here's the script below.

ping -c4 > /dev/null
if [ $? -eq 0 ]
    exit 0
        /etc/init.d/network restart

Just replace the with your address and setup the Cron on the Luci System>Scheduled Tasks.
Just a Note I googled this script a while back and edited it a bit so if any of you can make it better, do it; no balls.

i pasted it all, from " #! to restart " , my openwrt buffalo g450h is so i left it as it is. is that correct ?

its a bug as from client side when openwrt is idle it will show 1 MBit/s permanently, it gets fixed by restarting wlan0 on the same client and varies between 39-104 MBit/s when active

That is not a bug, but working as designed.

Sounds like a driver problem. Which wireless device do u use? I would suggest to write a bug report.

@slh designed to disconnect and stay disconnected till i reset the wireless interface manually ...everytime ?

i have no idea about the driver but it did the same on an old asus, buffalo and netgear wireless adapters. my theory is that passing cars between ap and client will corrupt at a certain point the signal requiring new reset, handshake or whatever...

unfortunately the script did not help

Designed to fall down to 1 MBit/s on an idle link, but to ramp up to maximum speed when needed; I'm just saying that seeing 1 MBit/s bitrates (whenever your wifi is idle) is expected and normal behaviour.

@slh as said, my problem is that when i get 1 MBit/s it remains permanent at 1 and idle till i reset it and that's a bug at least in my opinion !
no one said it wont rise to higher speeds in other cases .

Uh....In order for the script to work you need to create a file on your device example like "/etc/" that holds the code inside the Code Tags above. And in some cases you may need to "chmod +x /etc/" in order to get it to execute.

and Another note. I realized that my script was incorrect cause I left in "BASH" instead of "ASH" haha woops. I edited it to just work I would imagine.

Here is documentation on utilizing the CronTab just for reference also

complicated ... you don't think i can do that from the scheduled tasks from openwrt

You know I never really thought about it but try putting this in your CronTab

* * * * * if [ $? -eq 0 ] | ping -c4 > /dev/null; then exit 0; else /etc/init.d/network restart; fi

This runs the script every minute you could probably change that as necessary.