Raspberry Pi Streaming Radio Player: Room Customization

Sometimes you (well, I) want a bit of late-night music, which is now one button press away. However, I initially set things up so the Raspberry Pi’s startup code executed a Python script on a network share from the file server in the basement, which shuts down around midnight after the daily backup.

Keeping a local copy meant having to update that copy whenever I tweak the code, a nuisance not to be tolerated. This Bash (or whatever) code in /etc/rc.local figures out if the server is up and, if so, updates the local copy from the server. If the server isn’t up, then it just runs with what it has:

# was !/bin/sh -e

... snippage ...


ping -c 1 $server
if [ $? -eq 0 ]
  mount -o ro ${server}:/mnt/bulkdata/Project\ Files/Streaming\ Media\ Player/Firmware/ /mnt/part
  rsync -auv /mnt/part/Streamer.py /home/pi
  umount /mnt/part

sudo -u pi sh -c 'python /home/pi/Streamer.py any' &

N.B.: you must remove the -e from the shebang, because otherwise the script jams to a stop when the ping fails. Took me a while to figure that out, yup.

Use raspi-config to force the startup sequence to wait until the network is available. Turns out that the DHCP process can stall for half a minute, so fixed timeouts don’t work.

Hardcoding the server IP address eliminates a whole bunch of mysterious failures apparently due to whatever handles the translation from mollusk.local to the dotted quad. Maybe that’s not really a problem, but I’ll run with it.

Now the streamers fetch the Latest and Greatest version whenever they’re on during the day and run their local copy, with the room parameter telling it where it lives.

Life is good!

14 thoughts on “Raspberry Pi Streaming Radio Player: Room Customization

  1. You could add a “set -e” command after the ping if you want it to bail out on errors down the line.

    1. Mostly, I don’t care about errors; the whole rickety affair either runs or crashes and, in the latter situation, there’s not a lot I can do about it without firing up an SSH session (which isn’t going to happen in the dark).

      Shortly after I set up the ping-and-copy code, every stream began stuttering / buffer draining / general malfeasance. After two days of increasingly desperate debugging, every stream began working again (with no changes to my code!); apparently something throttled the incoming bitstream from all the streaming services to my router. I have no practical way to test an idea like that, but it’s been working fine ever since.

      Mysteries abound in the networking realm…

    1. The “server” stays awake a little longer than we do, wakes up a little earlier, and generally just loafs along. The poor thing is, after all, just an off-lease Optiplex 760 with delusions of grandeur.

      Opinions seem equally divided between “never spin down a hard drive” and “it doesn’t matter”; I tend toward the latter.

      Bonus: shutting down all the PCs for half a dozen hours reduces our power bill by a noticeable amount. The power company still tries to shame us by mentioning our power consumption ranks Number One amid a group of comparable homes, though.

      1. Guess I’m spoiled out here with (a) paying $0.071/kWh which puts the cost of keeping a 780 on all night at $1.16 a month, and/or (b) that $1.16 a month isn’t noticeable to me… :)

        1. The bottom line says 17.1 ¢/kWh, which explains why we’ve been gradually installing LED bulbs and suchlike. On the other paw, I don’t turn off the (mostly fluorescent) basement lights between trips when I’m tinkering and we let the PCs run all day with LCD monitors auto-powered-off as needed.

          The never-sufficiently-to-be-damned electric water heater and refrigerator most likely lie at the root of all evil; we’ll do those differently in The Next House, should the opportunity arise.

          1. Solar FTW, just have to pick the right house (or state) :)
            But with panel and storage prices coming down, it might make sense even in places that get snowy during winter.
            Also,ability to give the finger to utilities – priceless :)

            1. Solar doesn’t make much sense around here (*), as the weather gets in the way much too often. The last numbers I saw from a building-scale installation across the river suggested that it ran at 10% of the nameplate rating: you need a lot of panels to get much traction.

              (*) Subsidies have distorted the market enough to put panels atop nicely shaded houses = the triumph of marketing over good engineering.

              The concept of fly-by-night solar installers makes my head hurt.

            2. Those 10% seems awfully low but it depends on the metrics used. Having 10% of nameplate power in cloudy weather doesn’t sound too bad but I’d expect you can get at least 50-80% of theoretical maximum output during summer, and still considerably more then 10% in the winter.

              Couldn’t find much data from around you, but this guy seems to be doing fine (or at least he did during those two months in 2015)
              Even this guy in Minnesota averages 3kWh/kW efficiency and I’m guessing he must be worse off then you geographically, right?

              When TCO gets to where installation will pay itself off in ~20yrs (panel lifetime) it makes sense to install them whether it’s 10% or 90% output. Places with better insolation average will simply get there sooner.

            3. That was the grand average over the course of a year. For example, to get a 3 kW average load, they needed 30 kW peak of installed panel, plus battery hardware for daily averaging. That’s a lot of panel!

              Batteries are bad, that’s definite, but without storage you’re still dependent on utility power. I want a big array in the yard, enough storage for a couple of days, and … not renting them from some fly-by-night solar company that’s dependent on rebates to stay alive.

            4. With that metric, 10% is not all too bad. Look at it this way, on average you only get 12h/day of light, so 50% as the best case scenario. Sun travels east-west during the day which on average cuts output in half, landing you at 25% as the best case – and that’s in summer. This fits nicely with Dave Jones’s data (of EEVBlog fame) http://pvoutput.org/list.jsp?sid=20402.

              Winter without snow will probably cut the output in half, so 12.5% in winter or 18.75% average load out of your peak power is the best case scenario. When you add snow, clouds and what-not 10% is OK-ish.

              For the long time I was deluded about practical aspects of solar power, battery storage and electric cars. I admit I’m now pretty much in awe of anything and everything Elon Musk takes on, but the guy delivers on his promises and he is not alone in this. Batteries get better at stored kWh/kg about 8% yearly, and with Gigafactory going into production, I think it’s safe to say lithium is here to stay and probably only get cheaper. Solar is on a similar path, with panels getting cheaper every year.

              So I wouldn’t call batteries bad. Sure, they drop some efficiency (Tesla quotes 92.5% round trip efficiency in optimal conditions) but the way I look at it, they (powered by solar, hydro and wind) will probably save our ass in the next 50 years (or however long it takes for someone to make a practical fusion, thorium, arc, ZPM or other great-in-theory-but-nowhere-to-be-seen reactor).

              I don’t know how much energy you use, but I’m willing to bet at least 2/3 of it is in or could be shifted to daytime, cutting the batteries mostly out of the equation. Three day storage is somewhat worse (still possible though), but unless you want to regularly take the snow off the panels in the winter, you’ll still need grid for the backup and since it’s already in place, why not use it from time to time?

            5. Maybe by the time we need a new house, solar will be so cheap I can plant a big array on (what used to be) the lawn and solve two problems at once. I’m willing to own the panels, rather than rent them from somebody who intends to make money from me no matter what happens, but maybe I can even be talked out of that.

Comments are closed.