/etc/rc.button/reset updated script

This is an updated script for the reset button to allow recovery from non-functioning wifi due to using client mode (AP+STA) and the client network being unavailable or misconfigured.
A short press of reset will disable and enable wifi.
A long press (Between 2 and 4 seconds) will disable the client wifi network and restart wifi allowing AP use.
A press of 5 seconds or longer will default the router firmware to factory.


[ "${ACTION}" = "released" ] || exit 0

. /lib/functions.sh

logger "$BUTTON pressed for $SEEN seconds"

if [ "$SEEN" -lt 2 ]
elif [ "$SEEN" -ge 2 ] && [ "$SEEN" -lt 5 ]
logger "Disabling STA interface"
/sbin/uci set wireless.sta.disabled='1'
/sbin/uci commit
/sbin/wifi up
elif [ "$SEEN" -gt 5 ]
echo "FACTORY RESET" > /dev/console
/usr/bin/flashleds &
jffs2reset -y && reboot &

first, you need to name the STA configure in wireless as “sta” in /etc/config/wireless

Second, I suggest not to use continuous numbers in timing. For example, you can use a larger number than 5 to revert to factory settings. As you will have trouble to count the exact number of seconds and made some mistake.

I already experienced the timing issue alshao mentioned. Furtonately I edited the script in such a way that it didn’t reset the router to its default settings, but I discovered the timing is really difficult.

I can’t seem to get this working.

How do I ‘name the STA configure in wireless as “sta” in /etc/config/wireless’ as mentioned by alzhao?

I’ve checked my etc/congif/wireless and it has ’ config wifi-iface ‘sta’ ’ and option mode ‘sta’.

Am I missing something?

@alzaho - Not sure what you mean by “first, you need to name the STA configure in wireless as “sta” in /etc/config/wireless”

Using the default firmware on the router and connecting through an existing wifi network should create the ‘wireless.sta’ entries.

As for timing I never had any issue with it because 5 seconds is a pretty long time really but it’s easy enough to change to personal preference. I didn’t want to take away any functions and you’re pretty limited when it comes to buttons / switches so I went with this. I agree it’s not perfect more of a starting point that in a pinch gets you out of an annoying situation.

@gjames - If you’ve got client mode and AP set-up and working from the command line ‘uci show wireless’ should tell you more about what your interfaces are called. I’ve only used the firmware supplied on my router so if it differs to yours there could be naming differences that I’m unaware of but it should be easy enough to edit the script to make it do what you need. If you post any output from that command be careful as it may contain data you don’t want to post without obscuring first.

like this, text in bold.


config wifi-iface ‘sta’

option …

option …

Ahh okay I understand what you mean now. Your web front end takes care of that configuration when you use client mode, that said I did notice a small issue using disable which is that you then need to use LUCI to enable the interface again. With a UCI delete that doesn’t happen but I didn’t really want to post a script to help beginners that deleted stuff out of their config.

@illusion thanks, I’ll try that. Also with your last reply, is it only with the enable/disable wifi that you need to use LUCI to re-enable or is it also with AP+STA?

What would a UCI delete remove from config?