is it possible to use (reprogram) the reset button for another use?
connect with for example a script ...
(Last edited by thierry69 on 19 Mar 2013, 18:51)
The content of this topic has been archived on 11 Apr 2018. There are no obvious gaps in this topic, but there may still be some posts missing at the end.
is it possible to use (reprogram) the reset button for another use?
connect with for example a script ...
(Last edited by thierry69 on 19 Mar 2013, 18:51)
The reset button is handled by the button_hotplug kernel driver, so whenever the reset button is pressed or released, a hotplug event is generated by the kernel.
A simplistic way to get these events is to create a subdirectory "/etc/hotplug.d/button" if not already present and create with vi a file named whatever you want (let's call it "buttons") with the following contents:
root@OpenWrt:/root# mkdir -p /etc/hotplug.d/button
root@OpenWrt:/root# cd /etc/hotplug.d/button
root@OpenWrt:/etc/hotplug.d/button# vi buttons
#!/bin/sh
logger $BUTTON $ACTION
... then do a:
root@OpenWrt:/etc/hotplug.d/button# chmod +x /etc/hotplug.d/button/buttons
... to make it executable.
Now, if you press/release the reset button, you should get lines added to the system log, you can observe them in real time using:
root@OpenWrt:/etc/hotplug.d/button# logread -f
Sep 8 16:22:43 OpenWrt user.notice root: reset pressed
Sep 8 16:22:44 OpenWrt user.notice root: reset released
Sep 8 16:22:45 OpenWrt user.notice root: reset pressed
Sep 8 16:22:46 OpenWrt user.notice root: reset released
Sep 8 16:22:47 OpenWrt user.notice root: reset pressed
Sep 8 16:22:47 OpenWrt user.notice root: reset released
For a more complete example, install package "restorefactory", and check the corresponding script "/etc/hotplug.d/button/50-restorefactory"
(Last edited by Squonk on 19 Mar 2013, 22:58)
Thank you . I try it
With this i can for exemple turn on and turn off wifi. Or start application?
(Last edited by thierry69 on 20 Mar 2013, 06:37)
The "/etc/hotplug.d/button/buttons" file above is a Shell script, so you do whatever you want in it!
ok, thank you. I'll do some tests, I think adding a new button on the top of
tplink.
If you want to add another button (using a gpio), take a look here:
https://forum.openwrt.org/viewtopic.php?id=39811
The reset button is handled by the button_hotplug kernel driver, so whenever the reset button is pressed or released, a hotplug event is generated by the kernel.
A simplistic way to get these events is to create a subdirectory "/etc/hotplug.d/button" if not already present and create with vi a file named whatever you want (let's call it "buttons") with the following contents:
root@OpenWrt:/root# mkdir -p /etc/hotplug.d/button root@OpenWrt:/root# cd /etc/hotplug.d/button root@OpenWrt:/etc/hotplug.d/button# vi buttons
#!/bin/sh logger $BUTTON $ACTION
... then do a:
root@OpenWrt:/etc/hotplug.d/button# chmod +x /etc/hotplug.d/button/buttons
... to make it executable.
Now, if you press/release the reset button, you should get lines added to the system log, you can observe them in real time using:
root@OpenWrt:/etc/hotplug.d/button# logread -f Sep 8 16:22:43 OpenWrt user.notice root: reset pressed Sep 8 16:22:44 OpenWrt user.notice root: reset released Sep 8 16:22:45 OpenWrt user.notice root: reset pressed Sep 8 16:22:46 OpenWrt user.notice root: reset released Sep 8 16:22:47 OpenWrt user.notice root: reset pressed Sep 8 16:22:47 OpenWrt user.notice root: reset released
For a more complete example, install package "restorefactory", and check the corresponding script "/etc/hotplug.d/button/50-restorefactory"
ok , first i do this it's works good :-) i look for gpio now
If you are using the gpios as buttons, you don't need to remove the resistor. I think (from memory) most are pull-down resistors, so if you connect a button between the gpio side of the resistor and 3v3 you will get a button that goes high when pressed.
See:
http://www.scriptoriumdesigns.com/embedded/gpio_in.php
in fact , i want to change a command with this button ,
i use madplay for listen the radio by the internet ,
i put my command madplay in etc/local.rc to start the radio when i turn on the router.
with the "reset button" i want to change the http flux adresse .
i imagine have a file who contain this (french radio) :
wget -O - http://mp3.live.tv-radio.com/franceinfo … ceinfo.mp3 | madplay -
wget -O -http://www.tv-radio.com/station/france_inter_mp3/france_inter_mp3-128k.m3u | madplay -
wget -O -http://www.tv-radio.com/station/france_culture_mp3/france_culture_mp3-128k.m3u | madplay -
wget -O -http://www.tv-radio.com/station/france_musique_mp3/france_musique_mp3-128k.m3u | madplay -
wget -O -http://www.tv-radio.com/station/le_mouv_mp3/le_mouv_mp3-128k.m3u | madplay -
wget -O -http://www.tv-radio.com/station/fip_mp3/fip_mp3-128k.m3u | madplay -
and every time i push the "reset button" i select a new line .
but i understand nothing to script shell under "linux" i go to try to look on the internet
some examples to do something who works ...
i must say linux is very interesting !
(Last edited by thierry69 on 20 Mar 2013, 18:39)
in pseudo-code, something like this
do
do while button is off [wait for a button press]
increment counter
if counter > 5 then counter = 0
case $counter in
"0") wget -O - http://mp3.live.tv-radio.com/franceinfo/all/franceinfo.mp3 | madplay -
"1") wget -O -http://www.tv-radio.com/station/france_inter_mp3/france_inter_mp3-128k.m3u | madplay -
esac
do while button is on [wait until button is released]
loop
(Last edited by lizby on 20 Mar 2013, 15:58)
That is CPU intensive (which is already being used by mad play)
Using hotplug would be less intrusive on user cpu/ram.
I haven't thought about how to get a single button to select via hotplug though.
in pseudo-code, something like this
do do while button is off [wait for a button press] increment counter if counter > 5 then counter = 0 case $counter in "0") wget -O - http://mp3.live.tv-radio.com/franceinfo/all/franceinfo.mp3 | madplay - "1") wget -O -http://www.tv-radio.com/station/france_inter_mp3/france_inter_mp3-128k.m3u | madplay - esac do while button is on [wait until button is released] loop
yes i think about something like that ,
i try to change it in a right code for linux , but i am afraid for the cpu usage !?
That is CPU intensive (which is already being used by mad play)
Using hotplug would be less intrusive on user cpu/ram.
I haven't thought about how to get a single button to select via hotplug though.
i look for hotplug (fonction ? )
(Last edited by thierry69 on 20 Mar 2013, 18:46)
You would need to recompile an image,
but I gave an example in this link:
http://www.scriptoriumdesigns.com/embedded/gpio_in.php
>i am afraid for the cpu usage
It may use a lot of cycles, but if it's not depriving your other tasks, would it matter?
A hotplug/interrupt solution would be more elegant.
Here is a commented "/etc/hotplug.d/button/buttons" script that should do more or less what you want (change station on reset button press):
#!/bin/sh
# Uncomment the following line to activate debug
#set -xv
# File that holds the current station number
STATION_NUMBER=/tmp/.station_number
# File that holds the station url list, one per line
STATION_LIST=/root/stations
if [ $BUTTON = reset -a $ACTION = pressed ]; then
# If button pressed event received
if [ -e $STATION_NUMBER ]; then
# Get the current station number from file
n=$(cat $STATION_NUMBER)
else
# No file, initialize station number to 1
n=1
fi
# Count the number of lines in the station list
last=$(wc -l $STATION_LIST | cut -d ' ' -f 1)
if [ $n -ge $last ]; then
# If current station number larger than last station, wrap
n=1
fi
# Extract the url line from the station list file
url=$(sed -n "${n}p" $STATION_LIST)
# Stop previous station performance and start new one
killall madplay; killall wget; wget -O - $url | madplay - &
# Increment current station number
n=$(($n + 1))
# Write it back to file for next event
echo $n > $STATION_NUMBER
fi
Just put the station url into the file specified by STATION_LIST, one per line.
To simulate a button press:
export BUTTON=reset;export ACTION=pressed
Then:
/etc/hotplug.d/button/buttons
I strongly recommend you to learn Bash scripting
http://tldp.org/HOWTO/Bash-Prog-Intro-HOWTO.html
(Last edited by Squonk on 20 Mar 2013, 22:54)
Squonk ; thanks for the code with the descrip , it's more clear for me...
i try tonight.
i look the "http://tldp.org/HOWTO/Bash-Prog-Intro-HOWTO.html" for learn a little the code Bash.
You would need to recompile an image,
but I gave an example in this link:
http://www.scriptoriumdesigns.com/embedded/gpio_in.php
this way for me is more simple , i am not obliged to change hardware inside the router ,
but it is interesting to know this is possible to add more buttons with gpio...
I order another wr703n to play with
(Last edited by thierry69 on 21 Mar 2013, 10:47)
its works very good , many thanks !!
it's very fast to change station , now i must put a nice button on the top !
now i must write in code " By Squonk from forum.openwrt.org "
thank to forum.openwrt.org
(Last edited by thierry69 on 21 Mar 2013, 13:24)
thierry69,
since you want to add a physical button (which requires some soldering), why not add a couple connected to some gpios.
Then you can have a station-up and station-down, or even (get those bash scripts running!) a "tune" button and a memory button.
Or more: only your imagination will limit it.
Good luck and have fun.... oh and photo documentation would be great! I bet others would love this.
thierry69,
since you want to add a physical button (which requires some soldering), why not add a couple connected to some gpios.
Then you can have a station-up and station-down, or even (get those bash scripts running!) a "tune" button and a memory button.
Or more: only your imagination will limit it.
Good luck and have fun.... oh and photo documentation would be great! I bet others would love this.
I see what you mean about soldering ,...
i have buy another wr703n ( I'm waiting for delivery) after i can mod this one !
i make some pictures and why not a video ...
Here i got a problem:
after i did what @Squonk suggested to monitor the button action, i do trigger the button event and run the shell file, but the system still reboots, seem like some system service or something hooked up to the button too, don't know which. is there any way to unhook that?
here's the console log (using Aug 28's trunk, commend ll='ls -alF')
BusyBox v1.19.4 (2013-08-28 00:08:22 PDT) built-in shell (ash)
Enter 'help' for a list of built-in commands.
_______ ________ __
| |.-----.-----.-----.| | | |.----.| |_
| - || _ | -__| || | | || _|| _|
|_______|| __|_____|__|__||________||__| |____|
|__| W I R E L E S S F R E E D O M
-----------------------------------------------------
BARRIER BREAKER (Bleeding Edge, r37849)
-----------------------------------------------------
* 1/2 oz Galliano Pour all ingredients into
* 4 oz cold Coffee an irish coffee mug filled
* 1 1/2 oz Dark Rum with crushed ice. Stir.
* 2 tsp. Creme de Cacao
-----------------------------------------------------
root@OpenWrt:~# ll /etc/hotplug.d/button/
drwxr-xr-x 2 root root 0 Aug 29 19:52 ./
drwxr-xr-x 1 root root 0 Aug 28 12:53 ../
-rwxr-xr-x 1 root root 33 Aug 29 17:25 buttons*
root@OpenWrt:~#
root@OpenWrt:~#
root@OpenWrt:~#
root@OpenWrt:~# cat /etc/hotplug.d/button/buttons
#!/bin/sh
logger $BUTTON $ACTION
root@OpenWrt:~#
root@OpenWrt:~#
root@OpenWrt:~#
root@OpenWrt:~# logread -f
Fri Aug 30 08:45:12 2013 authpriv.error root: reset pressed
Fri Aug 30 08:45:13 2013 authpriv.error root: reset pressed for 0 seconds
Fri Aug 30 08:45:13 2013 daemon.info sysinit: - shutdown -
Fri Aug 30 08:45:13 2013 authpriv.error root: reset released
Fri Aug 30 08:45:13 2013 security.info dropbear[962]: Premature exit: Terminated by signal
Fri Aug 30 08:45:13 2013 daemon.error netifd: Interface 'lan' is now down
Fri Aug 30 08:45:13 2013 auth.info kernel: [ 167.930000] IPv6: ADDRCONF(NETDEV_UP): eth0: link is not ready
Fri Aug 30 08:45:13 2013 auth.info kernel: [ 167.950000] device eth0 left promiscuous mode
Fri Aug 30 08:45:13 2013 auth.info kernel: [ 167.950000] br-lan: port 1(eth0) entered disabled state
Fri Aug 30 08:45:13 2013 daemon.error netifd: Interface 'loopback' is now down
Fri Aug 30 08:45:13 2013 daemon.info dnsmasq[1049]: read /etc/hosts - 1 addresses
Fri Aug 30 08:45:13 2013 daemon.info dnsmasq[1049]: read /tmp/hosts/6relayd - 0 addresses
Fri Aug 30 08:45:13 2013 daemon.info dnsmasq-dhcp[1049]: read /etc/ethers - 0 addresses
Fri Aug 30 08:45:13 2013 daemon.error netifd: wan (906): Received SIGTERM
The discussion might have continued from here.