Controlling mpd using the SES/AOSS/EZ-SETUP button

Discussion about my Wifi Radio project at http://mightyohm.com/wifiradio/ or my WL-520gU talk at NOTACON.
Tozmo
Posts: 7
Joined: Tue Sep 14, 2010 3:42 pm

Re: Controlling mpd using the SES/AOSS/EZ-SETUP button

Post by Tozmo »

I'm still a "script kiddie" and have been following the guides to get my radio working to the way I want it (streamed pls starting on router power-up).

I don't get how to really import scripts to get them to work, I figured I'd try a copy/paste, but that didn't seem to do what was needed. Anyone able to give a dummy's guide? Google/Wiki didn't really help from what I found.
User avatar
gerben
Posts: 164
Joined: Sat Oct 16, 2010 8:41 am
Location: Netherlands

Re: Controlling mpd using the SES/AOSS/EZ-SETUP button

Post by gerben »

Copy paste should work just fine. Just make sure you change the files permissions to allow it to be executed. Just use "chmod +x file-name-here", if I'm not mistaken.

To execute the script use "./filename.sh" (notice the './' in front).
mcc253
Posts: 10
Joined: Mon Mar 05, 2012 4:48 pm
Location: Portugal

Re: Controlling mpd using the SES/AOSS/EZ-SETUP button

Post by mcc253 »

Hi to all,

Today I've started trying to put this scripts working. I have some doubts regarding how can I start this scripts automatically on router power-up. Do I need to add some code on mpd or some other file that is read on power up (to the router be able to recognize this ez-setup button pressings and execute the scripts according to that)?

I would also like to ask help to make a change in one script. I would like to create a sleep timer of 30 minutes, pressing the button twice but holding the second time (the router would be playing for 30 minutes and then it would stop).

Many Thanks.

Miguel
User avatar
gerben
Posts: 164
Joined: Sat Oct 16, 2010 8:41 am
Location: Netherlands

Re: Controlling mpd using the SES/AOSS/EZ-SETUP button

Post by gerben »

The only script that needs to be started on startup is detect-ads.sh. For convienience I created the radio-init.sh. This script also starts detect-ads.sh. radio-init is run on startup by creating the file in /etc/init.d (which I named /etc/init.d/myradio). All the code is present in the post.

The ez-setup button is already supported by OpenWRT. To run script on button press and release you'll need to create a file in /etc/hotplug.d/button/ (I called it /etc/hotplug.d/button/01-radio-control). The script inside the file checkes if it is a press or release and calls /root/buttonpressed.sh of /root/buttonreleased.sh respectfully.
Please note that if you press and release a few times the order of the press and release is sometimes switched. E.g. you'll get press-release-release-press. The script already takes care of this.

For your sleep function you'll need to remove the first 3 lines from mympc.sh. Namingly:

Code: Select all

if [ "$1" != "stop" ];then
   touch /tmp/lastradioinput
fi
You'll might also want to change the cron settings so it will check every minute instead of 5minutes if the sleep period has passed. Just change '*/5' to '*'

Hope this is helpful. If you have any more questions, just let me know.

Next you'll need to to change button-pressed.sh, by adding

Code: Select all

if [ "$states" = "prp" -o "$states" = "ppr" ];then
   /root/mympc.sh play
   touch /tmp/lastradioinput
   exit
fi
Finally you'll need to change check-sleep.sh, to make it only stop playback the first time.
Change

Code: Select all

touch /tmp/lastradioinput
to

Code: Select all

rm /tmp/lastradioinput
mcc253
Posts: 10
Joined: Mon Mar 05, 2012 4:48 pm
Location: Portugal

Re: Controlling mpd using the SES/AOSS/EZ-SETUP button

Post by mcc253 »

Gerben,

I'm sorry to thank you only now, but I only have completed yesterday the implementation of the code created by you.

Unfortunately it's not working. The ez button don't react to any touch and I can't see the led blinking. I've already used the chmod 777 "filename" but still not working.

Do you have some idea to check if I've made any mistake copying the code to the scripts files?

Once more thank you very much for your help.
User avatar
gerben
Posts: 164
Joined: Sat Oct 16, 2010 8:41 am
Location: Netherlands

Re: Controlling mpd using the SES/AOSS/EZ-SETUP button

Post by gerben »

Try to run the individual script from the command line. Check if the you get any errors, and also check if anything happens, like flashing LEDs and music playing. (I'm assuming you have a WL-520GU)

Add some stations to the playlist. Then run "mpc play 2".

Run "/root/flash-led.sh 3" and see if the led blinks three times, and then after 2 second starts blinking repeatedly.

Next run "/root/show-preset.sh". The led should flash 2 times, and then after 2 second starts blinking repeatedly.

Next run "/root/mympc.sh stop". Music should stop and led should turn off.

Next run "/root/mympc.sh play". Music should continue and led should flash 2 times, and then after 2 second starts blinking repeatedly.

Next run "/root/buttonpressed.sh". Music should stop and led should turn off.


This should show which script is not working. Let me know what worked, what not, and what errors you received.
mcc253
Posts: 10
Joined: Mon Mar 05, 2012 4:48 pm
Location: Portugal

Re: Controlling mpd using the SES/AOSS/EZ-SETUP button

Post by mcc253 »

Once more thank you very much for your help.

The router is 520-GU

Before posting the results of the tests, just to tell you that at startup the router starts playing my favourite wifi radio (I have entered a code into /etc/init.d/mpd which starts automatically) with your help in post " viewtopic.php?f=2&t=579 ".

Now the results of the test:

Run "/root/flash-led.sh 3" and see if the led blinks three times, and then after 2 second starts blinking repeatedly. =-> Everything OK


Next run "/root/show-preset.sh". The led should flash 2 times, and then after 2 second starts blinking repeatedly. =->Nothing happends, the led continues blinking repeatedly and ERROR:

root@OpenWrt:/# sh show-preset.sh
3
show-preset.sh: line 11: /root/flash-led.sh: not found


Next run "/root/mympc.sh stop". Music should stop and led should turn off. =->The music stops but led don't turn off and continues blinking repeatedly and ERROR:
root@OpenWrt:/# sh mympc.sh stop
volume: 80% repeat: on random: off
root@OpenWrt:/# mympc.sh: line 15: /root/show-preset.sh: not found



Next run "/root/mympc.sh play". Music should continue and led should flash 2 times, and then after 2 second starts blinking repeatedly. =-> The music starts again but the led don't flash and continues blinking repeatedly and ERROR:
root@OpenWrt:/# sh mympc.sh play
Racoon - Took A Hit
[playing] #3/7 1:21/0:00 (100%)
volume: 80% repeat: on random: off
root@OpenWrt:/# mympc.sh: line 15: /root/show-preset.sh: not found



Next run "/root/buttonpressed.sh". Music should stop and led should turn off. =-> The led turn off but music continues playing blinking and ERROR:
root@OpenWrt:/# sh buttonpressed.sh
killall: sleep: no process killed
buttonpressed.sh: line 26: /root/mympc.sh: not found




Just 2 notes:
- I've checked the code of the scripts which are giving error, and they are exactly the same as in this topic (just without the first lines with comments or text). All my scripts starts with #!/bin/sh

- If when executing the sh command I enter for example: sh /root/file.sh, it will not found the script file. To work, I need to go to root and then enter sh file.sh . This way it will work.


Many thanks
Last edited by mcc253 on Fri May 04, 2012 2:34 am, edited 2 times in total.
User avatar
gerben
Posts: 164
Joined: Sat Oct 16, 2010 8:41 am
Location: Netherlands

Re: Controlling mpd using the SES/AOSS/EZ-SETUP button

Post by gerben »

It can't find the script-files. Very weird. Where did you place the files? Could you post the result of "ls /root"? What about "ls ~"
mcc253
Posts: 10
Joined: Mon Mar 05, 2012 4:48 pm
Location: Portugal

Re: Controlling mpd using the SES/AOSS/EZ-SETUP button

Post by mcc253 »

What an huge mistake I've done :)

The files were not in directory called "root" but in the root. I'm sorry Gerben.

I've made again the test you have recommended. I've run all the scripts you told me to run. The results were OK and that code which you gave me of sleep mode (when selected) it's also working.

Now I just want to test if after 30 min of inactivity in the of radios changing (if the file is modified more than 30 minutes ago), If it stops playback. I would like the router to play continuous all the time without turning off the volume (except of course when I press the button to enable the sleep function of 30 min).

Once again Gerben, I'm really sorry for my stupid mistake of change the location of the script files.

Many thanks for your help.
Last edited by mcc253 on Sat May 05, 2012 5:28 am, edited 2 times in total.
User avatar
gerben
Posts: 164
Joined: Sat Oct 16, 2010 8:41 am
Location: Netherlands

Re: Controlling mpd using the SES/AOSS/EZ-SETUP button

Post by gerben »

No problem. It's how we learn, right.
Glad you got it working. If you have any more question feel free to ask.
Post Reply