2

I have a Raspberry without screen/keyboard/mouse that does nothing else than launching a radio stream at startup :

mplayer http://95.81.146.2/fip/all/fiphautdebit.mp3

I have put this command at the end of /etc/rc.local. Unfortunately, 50% of the time, the playing doesn't start (maybe because the WIFI wasn't properly connected yet?) and I have to reboot to make the sound playing start.

How can I check what happened during rc.local startup, later, with a SSH connexion ? I tried with dmesg, but couldn't see the result of mplayer. Which is the most appropriated script to put such a command ? (rc.local, /etc/profiles ?)

  • You want to redirect the output of mplayer? mplayer http:// >/tmp/out 2>&1 Then look in /tmp/out? – Marki Feb 9 '14 at 23:41
  • Should I put this command in the rc.local ? – Basj Feb 9 '14 at 23:45
  • Looks like the correct place to me. – Marki Feb 9 '14 at 23:47
  • What distribution are you running on the Pi? With what init system, if not the default? – Gilles 'SO- stop being evil' Feb 9 '14 at 23:54
  • I use the default Raspbian @Gilles – Basj Feb 9 '14 at 23:56
2

Instead of running mplayer directly from your start up, I would write a script and run that instead.

Your script would eventually just run the same mplayer command you have given, but before hand you could check that your wifi connection is up and working (maybe by pinging your router), this gives your script control. It could wait until the connection comes up, and then start mplayer.

If you put start the script in something like rc.local, then it will start once on start-up. if you start it from your profile, then it will be started when you login.

Here's an example script which waits until it successfully pings an IP address before starting mplayer.

#!/bin/bash

RouterIP="128.0.0.1"
TimeOut=2
WaitTime=8


echo "Waiting for network connection"
while ! ping -q -c 1 -w $TimeOut $RouterIP > /dev/null
do
  echo Timeout, waiting $WaitTime seconds
  sleep $WaitTime
  echo "Waiting for network connection"
done

mplayer blah blah

You can change the ip address to your routers internal port and correct the mplayer line.

Name it startRadio and make it executable then test it.

`./startRadio

Add it to whichever startup script you want, but redirect stdout and stderr to /dev/null and start it as a background process.

eg.

/path/to/your/script/startRadio >/dev/null 2>&1 &
  • Interesting indeed ! Could you give an example of such script (check wifi connection is up), and where to call this script from ? (still from rc.local ?). I'm really new to that, so I even don't exactly know what's the best way to call a script from another... – Basj Feb 10 '14 at 0:55
  • There's no best way. There's only one way. – Marki Feb 10 '14 at 1:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.