Raspberry Roller

30 12 2012

I got a Raspberry Pi a while ago (well, two actually) and have finally finished my first project with it, to make a portable music streaming device.

This would have been pretty easy, but I decided to put it in an old retro 80s ghetto blaster case, namely this one, a Phillips Roller radio cassette player. My parents had one when I was a kid and I came across one on eBay and thought it would be perfect.

roller01scaled

So, I ripped out the guts, including the rather measly speakers and cut out loads of the inner plastic that was supporting the amp, radio and cassette parts and went to work to put in my own contents.

This took quite a while and the added difficulty of a young baby and a two year old who needs constant entertainment only added to the challenge (using a dremel when the wife has put your 6 month old son to sleep doesn’t go down too well ;)).

Once all the insides had been cleaned out, I then went to work to put my own contents inside. Alongside the Raspberry Pi, I also put in:

USB WiFi dongle with external aerial (so I can replace the one on the radio)

USB WiFi dongle with external aerial (so I can replace the one you see from the outside)

Amp from Sure Electronics (I wanted a tripath, but this seemed the easiest)

Amp from Sure Electronics (I wanted a tripath, but this seemed the easiest)

Kenwood Car Speakers

Car Speakers (3-way speakers for better range, but at 5 1/4″ these aren’t gonna rock the house too much)

Simple USB soundcard

Simple USB sound card (I’d read the internal sound chip in the Pi is a bit basic if you are using the 3.5mm output, hence this)

The car speakers were chosen since the old ones were really small and not capable of any bass or offering high power output, the amp because i thought it had a volume control – but to get it to work needed some ninja soldering skills that I don’t have, the sound card I believe is an improvement on the in-built chip (but I might be wrong) and finally the WiFi dongle uses an external antennae, so I’ll still get a good service with all the different devices crammed inside the stereo.

The next step was getting the Pi to play music. Luckily, I tend to listen to all my music from a central server running the rather awesome MPD to stream my music out to as many connected MPD clients as I want. So, all I had to do was install MPD on to a fresh version of the latest Raspbian and I was almost ready to go. I wrote a small script which, on boot, checks to see if my MPD server is available, if so it starts the MPD daemon on the server playing the stream, then starts the MPD client on the Pi playing the stream from the server. If it doesn’t find the server, it adds music from the small local library stored on the SD card and plays that instead., via MPD.

Here’s the inside of the Roller, with the Pi, amp, soundcard and speakers in place:

A view inside the Raspberry Roller.

A view inside the Raspberry Roller.

I stuffed the whole thing with cotton wool, to help boost the bass (but I know next to nothing about proper speaker design, it is one of those things I plan to do in my retirement – build massive bass-thundering speakers).

The Pi is at the bottom, the amp in the middle (you can see the amp’s fan sticking out) and the sound card is at the top.

The finished Roller in all it's red raspberry goodness.

The finished Roller in all it’s red raspberry goodness.

And here is the finished article (playing at the time, but you can’t tell when it is on apart from the music playing).

 

It sounds pretty good considering. The bass could be better, but you can’t expect much from such relatively small speakers. However, it does go pretty loud for something so small and it sounds really clean and crisp, so I am happy with it.

For the other Pi I have lying around, I plan to use it (when Piface comes out) to control the lights in the dolls house we got my daughter this Christmas. Eventually she will hopefully get in to using Scratch herself to control the lights in her dolls house (and maybe some other things like a little mini stereo or even a small screen in her dolls house). I would imagine when she sees that we can plug her dolls house into the TV and it is a computer, she will be a little excited and intrigued!





What A Crazy 48 Hours

11 11 2012

Well, that was fun. Interviewed by the BBC, got featured on BBC One (though crazy early at around 7am) and then on BBC News 24 twice. In-depth article on the BBC news website which makes the front of the Technology section (as a feature on the side) and then it makes the Home page as the most shared article and the second most read! Then get interviewed live on local radio and finally have a news agency come and take some photos and do another interview. Madness! All because of a blog post I wrote two years ago.

Many people have said I should try to cash in on this, but as others have pointed out, what I have done here isn’t rocket science, it isn’t complex, but I guess what is different is that I took the time to write about it and I plan to explain how to do it in non-techy speak. I also hope to write up a more detailed version, which will take time and I might charge a tiny amount for it, but that would simply be due to the time taken to write it up and because it would contains some code and scripts that I have created myself.

Kudos to WordPress for handling the server load. I use to host this site on my own sever at home, which would have melted by now!

I guess normality will resume tomorrow, but it was fun whilst it lasted. 





Build your own baby monitor revisited

8 11 2012

(Quite) a while ago I wrote about my attempts to make my own video baby monitor. I had also written about a few other approaches as well, but they were pretty involved and complex and tended to break after a few days.

Wanting to simplify the approach and make it easier to set up, I came up with a slightly more refined solution that works much better. I’ve been using it successfully for about a year and it works with multiple cameras and screens. Now I have a second bundle of terror it has proved very useful.

Rather than trying to reinvent the wheel I decided to use products already out there, but ones that aren’t actually designed to monitor babies with and thus don’t have the crazy high price tags. I use an IP webcam, that connects to a WiFi network, this can then be viewed on any laptop or android device you have. It should also work with the iPhone as well, but not being a fan of Apple’s walled garden, I haven’t yet investigated this in any great detail.

The most important part of all this is the camera and I’ve stuck with the same camera I used last time, the IP Night Vision webcam. These can be found all over eBay, or there are also variants available on places like ebuyer.com and dabs.com. It has a WiFi and an ethernet network connection, night vision up to a couple of meters, two-way audio (so you can both listen to and talk to your baby – though I don’t suggest the latter, that is one big brother step too far) and it can be panned and tilted around so you can ensure the baby stays in view even if it moves. Most of these cameras are made by Chinese manufacturers, but some are of better quality than others. Foscam is a really good brand it seems, I have two and they have been running non-stop for the last year with no problems what so ever. The model I have used and would recommend is the Foscam FI8918W.

Foscam FI8918w

Foscam FI8918w

It is relatively simple to set up, you just need to connect it to your wireless network following the instructions included in the box. Once this is done you can then view the camera in many different ways. There is an internal web address that you can use to view it from any laptop connected to your wireless network using a web browser. You can also use the free media software VLC to view the video feed, the advantage being this approach also gives you sound and will work on pretty much all platforms supported by VLC (so Windows, Linux and Mac OS). I have written a number of scripts that can be run on Linux (Ubuntu) and Windows that launches the necessary video feeds and restarts the video every hour, since the audio can sometimes get out of sync with the video.

However, the best way to view the video feed I have found is via an Android app, called IP Cam Viewer. There is a free version which works perfectly for my needs, but if you want to say thanks to the developer, you can get the Pro version which is only a few pounds and gives you a few more features. I run this app on my Android tablet, an Android set top box and my Android phone. It allows me to view the the video feed of the two sleeping terrors on a TV in the kitchen using the Android set top box, anywhere in the house on my Android tablet or whilst out and about pretty much anywhere in the world (with a mobile data connection) on my Android phone. The app allows you to move the camera around if you need to and you can put widgets on your home screen that update as fast as once every second, so you don’t even need to run the app to see what is happening.

IP Cam Viewer in action

IP Cam Viewer in action

There is some technical cleverness that needs to be carried out to allow you to view the web cam outside of your wireless network on your phone, but this is very simple to set up and can be done for free.

All in all, this set-up works really well. So much so that the BBC just interviewed me about it! It is certainly a much cheaper and more flexible approach than the dedicated solutions on the market currently and rather than only being able to view the video feed on one tiny screen, you can view it on pretty much any screen you wish pretty much anywhere you want.

If you want to do this yourself, do get in contact via the Contact page. I might put together some more detailed information into a PDF, maybe with a “Pro” version that contains simple step-by-step instructions for a small fee or something. It seems all the rage these days ;)

UPDATE: Gosh, so the story has got a bit of traction on BBC News and I’ve got quite a few comments and emails to read through. I’ll read and respond to all your comments over the weekend and I am sure I can produce a PDF with instructions.

Glad other people are keen on this idea!





How to backup and sync your rooted Android phone automatically

1 03 2012

I have for a while now been working on a custom automatic sync solution for my HTC Hero running Froyo (Froydvillain ROM). As I am a Linux junkie and love scripts and hacks I wanted to do it all via cunning hacks and I’ve finally got it nailed.

This solution uses Scripting Layer 4 Android (SL4A) and Tasker alongside a custom ROM with rsync (any ROM should do so long as it has rsync). For those that don’t know, rsync is an awesome application that allows for remote backup and sync across machines. It turns out you don’t even need a ROM with rsync built in, as you can install an app that provides rsync, the app is called rsync backup for android and can be found here: https://market.android.com/details?id=eu.kowalczuk.rsync4android&hl=en

The only issue is you can’t call rsync from the command line using simply “rsync” since it isn’t in your systems path. However, if you use the following string instead,replacing calls to “rsync” with the following, the scripts still work: /data/data/eu.kowalczuk.rsync4android/files/rsync

SL4A is used to set out what to do via a script. You can write scripts in various languages in SL4A but I am using Bash as I am familiar with it. Rsync is used to actually handle the sync / backup and Tasker is used to launch the scripts when certain conditions are met.

I have created two scripts in SL4A, one backups my photos folder to my main photo folder on my server. The server runs the rsync daemon which rsync on the phone connects to. The other script does the reverse and copies a remote folder in my server that contains a bunch of music to my phone.

Tasker is set up with a profile that activates when my phone is plugged in and it’s between midnight and 7.00 am. This then connects to my WiFi network and then runs the two scripts via the SL4A plugin. Since I charge my phone each night this is effectively automatic.

The key here is getting permissions correct with rsync during the file transfer, as the memory card uses fat32 it hasn’t got any permissions. The rsync daemon doesn’t like this and errors out, hence the need for various settings. The second key here is exporting your password as an environmental variable. This is inherently insecure but since my server has multiple redundant backups and is only locally accessible I don’t care much. I could use trusted keys but I’m too lazy.

Here are the two scripts. First the music script that syncs from server to phone:

#rsync sync
export RSYNC_PASSWORD=password
DATE=$(date)
LOG=/mnt/sdcard/rsyncmusic.txt
echo rsync started $DATE > $LOG
TRY=1
rsync_com ()
{
DATE=$(date)
if [ $TRY = 15 ]; then
echo rsync failed, quitting on $DATE >> $LOG
exit
fi
sleep 10
echo rsync attempt $TRY started $DATE >> $LOG
rsync --progress -vHrltD --chmod=Du+rwx,go-rwx,Fu+rw,go-rw --no-perms --stats --password-file=/mnt/sdcard/scrt prupert@prupert::amusic /mnt/sdcard/amusic >> $LOG 2>&1
EXIT=$?
TRY=`expr $TRY + 1`
echo exit code is $EXIT >> $LOG
echo "********************" >> $LOG
}
rsync_com
while [ $EXIT != 0 ]; do
rsync_com
done
echo rsync finished $DATE >> $LOG
exit

The second script syncs the phones photos folder to my server:

#rsync sync photo
export RSYNC_PASSWORD=password
DATE=$(date)
LOG=/mnt/sdcard/rsyncphoto.txt
echo rsyncphoto started $DATE > $LOG
TRY=1
rsync_com ()
{
DATE=$(date)
if [ $TRY = 15 ]; then
echo rsync failed, quitting on $DATE >> $LOG
exit
fi
sleep 10
echo rsync attempt $TRY started $DATE >> $LOG
rsync -vHrltD --chmod=Du+rwx,go-rwx,Fu+rw,go-rw --no-perms --stats --password-file /mnt/sdcard/scrt /mnt/sdcard/DCIM prupert@prupert::apics >> $LOG 2>&1
EXIT=$?
TRY=`expr $TRY + 1`
echo exit code is $EXIT >> $LOG
echo "********************" >> $LOG
}
rsync_com
while [ $EXIT != 0 ]; do
rsync_com
done
echo rsync finished $DATE >> $LOG
exit

I have put some logging in to check progress and also some retry code that retries the sync if it timesout. It seems my HTC Hero’s WiFi connection claps out after a while so the script retries up to 15 times to run successfully based on the rsync exit code.





get_iplayer startup script

19 02 2012

For funsies I am looking to create a web pvr, using get_iplayer, sickbeard and sabnzbd+ (though I am planning to stay on the legal side and only download what I can watch for free anyway).

Since there is no startup script for the get_iplayer web pvr program, I created one. You can find it here:

https://github.com/pruperting/code_snippets/blob/master/get_iplayer





Not so long and thanks for all the clicks

4 02 2012

Edit, I’ve transferred over to wordpress.com, so the site stays, it’ll just stagnate for a while….

So, clearly, I have let this blog fall by the wayside. I haven’t written a new post since April 2011. Bad bad me.

As it’s time to renew my hosting, I have decided not to renew and to let this blog expire, rather than just let it attrite, as so many sites do. I use to have a lot more time, but now as I have a reasonably secure job (that I really enjoy), a wife, a lovely 2 year old and another on the way, I have no time to wax lyrical on tech any more.

You will be able to find me here:

http://www.rupert-plumridge.co.uk/

and my tech writings / scripts will move over to here: http://github.com/pruperting

So, it leaves to me say thanks to everyone who read and commented, it’s been fun.





A Better FFmpeg Progress Script

7 04 2011

So, a while ago I wrote an FFmpeg progress script. It worked, but it wasn’t brilliant and it fell apart on occassion.

After getting so annoyed by trying to get it work, I gave up. However, having a need to encode some stuff with FFmpeg again, I decided to return to the script. In the interveening period, my post on the Ubuntu forums, apart from getting one of the best response ever (see the matrix comment) had also encouraged others to give their solutions.

I thus used a combination of these ideas to create my updated version, which is below. It seems to be slightly more robust and still give the same useful info. I will be using this version for now, so I  hope it is of use for others ;)

Creative Commons License
YAFF by Rupert Plumridge is licensed under a Creative Commons Attribution-Non-Commercial-Share Alike 2.0 UK: England & Wales License








Follow

Get every new post delivered to your Inbox.