Copyright 2009-2012 by djg. All Rights Reserved.

Wonky Gibbon Ramblings


Raspbery Pi: Copying SD card image to a smaller SD 0

Posted on January 19, 2014 by danny

Aaargh! So one of my Pi’s running AirPlay died. Or rather the SD card did. I bought a replacement and attempted to write the SD image to it in the usual way using Win32DiskImager. However it refused to write to it, saying that the image was bigger than the SD card.

Turns out that due to manufacturing errors, SD cards vary a little bit in capacity with dead bits hidden away. The new card had less capacity front than the old one.

So – I needed to find some way to burn the image to this card that was just a smidgen too small. This post was useful http://www.raspberrypi.org/phpBB3/viewtopic.php?t=19468&f=26

In the post some people talk about having to shrink the linux filesystem a little before cloning the card however, it turned out I’d never resized my partion up from 2GB to 4GB so I didn’t have this problem. The easiest solution in the end, proved to be to fix the problem using an Ubuntu install rather than Windows. The nice thing about Ubuntu is that like many linux distro’s it can be run direct from the install media without actually having to install it, either DVD or memory stick.

The steps to resolve the problem were as follows:
1) In Windows, download Ubuntu from http://www.ubuntu.com/download/desktop and burn to DVD (just to big to fit on a CD).

2) Then restart the laptop and let it boot the Ubuntu OS from the DVD.

3) Click on the dash icon and start typing the word “Terminal” so that it finds the terminal program. Double click and you get a command line.

4) Place the source SD card into the card reader slot and let Ubuntu mount it.

5) Type:

cd Desktop

6) Then type this command to make an image file on the desktop:

sudo dd if=/dev/sdb of=sdimage.img bs=4M

‘sudo’ gives root priveleges. ‘dd’ is a copying program, ‘if’ is the input file which is the sd card reader device, ‘of’ is the output image on the desktop and ‘bs’ is the block size.

This gives this output:

ubuntu@ubuntu:~/Desktop$ sudo dd if=/dev/sdb of=sdimage.img bs=4M
953+1 records in
953+1 records out
3998220288 bytes (4.0 GB) copied, 211.068 s, 18.9 MB/s

With 8GB of RAM on the laptop I was able to use the desktop effectively as a RAM disk. If you have less than this – you could try saving to your windows hard drive which Ubuntu will have mounted.

7) Take out the source SD card and replace it with the target one (which is a bit smaller) and execute this command:

sudo dd if=sdimage.img of=/dev/sdb bs=4M conv=notrunc,noerror

The aditional parameters at the end tell it to write the full size and allow it to continue when it runs out of space.

This gives this output:

ubuntu@ubuntu:~/Desktop$ sudo dd if=sdimage.img of=/dev/sdb bs=4M conv=notrunc,noerror
dd: writing `/dev/sdb': No space left on device
932+0 records in
931+0 records out
3904897024 bytes (3.9 GB) copied, 482.878 s, 8.1 MB/s

The 3.9GB at the end tells you that a little bit of the image was lost. Happily it is of course blank.

All of which results in a working SD card that the Raspberry Pi can boot. Sorted!

Raspberry Pi Does Sonos – Part 2 – Transmitting on AirPlay 2

Posted on December 30, 2013 by danny

In the first part, I talked a bit about setting up the Raspberry Pi as an AirPlay receiver; something that can receive audio streamed over a home’s wifi connection and play it.

Transmitting from Apple

Apple Devices already support AirPlay by default (not a shock – it’s an Apple invention). So to connect an ipad, iphone, itouch etc… is straightforward. You simply double swipe up in IOS7 and enable AirPlay in the control panel. Job done.

Transmitting from Windows

Windows can be made to talk to the Pi using a program called Tuneblade. This is an application (that if you’re streaming to Shairport as described in Part 1, is free) and can be downloaded from http://tuneblade.com/.

Once launched, Tuneblade can be accessed from your system tray and includes a volume control, so remember to turn it up! It streams the audio even if you mute the local audio output – which is handy if you don’t want to listen to your tiny PC speakers.

Transmitting from Android

On Android, some app’s (such as Streambels) support direct streaming to AirPlay – but many popular apps do not, for example, Spotify does not. Similarly, TuneIn the radio app doesn’t. So another solution is required, similar to that used on Apple devices. ie: redirect the entire audio stream of the device.

There are a number of Apps for Android that will stream the entire sound output of the phone to the Pi. For example, one called AirAudio and another called AirStream. Both of these have demonstration versions to allow you to test. However you will have to buy a licence for around £4 to get a permanent solution (ie: one that doesn’t switch itself off after 10 mins). I didn’t find a totally free alternative (and I’m not anti paying software developers in any case!!).

Whilst apps like Streambels that only stream their own audio channel don’t need root privileges, these other applications that give the greater flexibility of sending any audio on the device (such as that coming out of Spotify) by effectively snooping on other applications audio output – do require root access / super user privileges.

This gets you into the exciting area of device rooting. The process for this can be complicated and in many cases results in the device being wiped as one of the steps to do it. This was certainly the case for the house Nexus 7 though happily not my Motorola Atrix phone. Doing so, however gets this solution to work. In addition it also provides access to a variety of other very useful apps including backup tools that can backup application data as well as the install apk’s and much more. Rooting an android device is not for the feint hearted and comes with associated risks of bricking the device and invalidating your warranty. So something you do, at your own risk.

Transmitting to Multiple Zones

By setting up multiple Raspberry Pi’s around the house with different device names you can effectively zone the house into different audio areas. In addition many of these transmitting programs can broadcast to more than one AirPlay receiver at once. In our house, with our network setup, solely using Raspberry Pi’s, they seem somehow to sycnhronise which is very cool for parties!!!

Raspberry Pi Does Sonos – Part 1 – Making an AirPlay Receiver 0

Posted on December 30, 2013 by danny

Overview

So … I want Sonos. I want the ability to be able to select tunes from Spotify, my NAS drive, the radio, whatever – on a tablet and have it come out of my hifi without the tablet physically attached to it.

I could use Bluetooth. But the range is poor and the sound quality questionable.

But what if a Raspberry Pi could do the same thing? What if it could receive audio streamed over Wifi, from a tablet, or my phone, or a laptop etc?… turns out it can.

Apple’s AirPlay protocol is usually used by iTunes to allow it to communicate with Apple TV and is the backbone of the project. However as luck would have it, going beyond Apple and iTunes it is possible for other devices to use Airplay including a variety of Android apps and a few windows apps. There is also a linux project, shairport that allows linux devices to receive Airplay streams and play them.

This is the point I have to fess up and say that I should have written up the Raspberry Pi part of this as I was doing it – but hey ho, it’ a month later so this will lack detail but at least give a general overview.

The challenge with the Pi is simple enough: Get it running headless with shairport (which provides the audio listening service and outputs the audio through the Pi’s 3.5mm jack) running as a service from startup. And in fact, using the raspbian distribution this is relatively easy. However there were some issues: First, I quickly discovered that the Edimax micro USB wifi adapter I had, didn’t have the range to reach my router through a couple of walls. So I swapped it for a Ralink wifi usb adapter with a proper stick aerial I had lying around – but could I get the drivers to work? Could I hell!! Additionally, even without this problem and without launching a GUI, raspbian isn’t that quick to boot and I like quick booting!

For that reason I decided to do it again, using ArchLinux. ArchLinux boots fast and I knew from a previous project that the Ralink wifi adapter could be made to work.

Steps to Setup the Pi

So the steps to success on the Pi

  1. Install Archlinux
  2. Get Wifi Working
  3. Get a build environment working
  4. Download shairport package
  5. Compile
  6. Configure to get it working

To Install ArchLinux you can download an sd card image from here. And then bring the packages up to date using the instructions here. The most important section is that about updating the system. Don’t worry about installing additional software or a desktop environment.

Next – get the wifi working.
This page provides a guide to setting up wifi on ArchLinux. Personally I found the wpa_supplicant approach a real arse – in fact I didn’t get it working. By comparison the automatic Netctl approach mentioned, is very straightforward.

Now that the wifi is working, check that it can get a wifi signal from wherever in the house you tend to position the Pi. If you can’t and you’re using a micro adapter, you may need to change to an adapter with a larger / proper aerial.

Next, some development tools are required. The first command below installs gcc, make etc… the second provides support for git, which is where the shairport source repository is stored.

# sudo pacman -Sy base-devel
# sudo pacman git

My own efforts from this point got a certain distance, including a lot of mucking around with perl packages and cpan, but I was unable to unravel is completely. However, this blog post by Orson Tyrell – works extremely well.

At the end of this, you should have shairport installed and set to automatically startup at system boot.

You may well find that when you send a test signal it is very quiet.

If so, launch

# alsamixer

Set the volume to 100% or close and exit.
If you then call

# alsactl store

(you may need to use sudo) then this volume will be stored away and reused after a reboot.

In Part 2 – I’ll talk a bit about broadcasting to the Pi from other devices.

There were quite a lot of pages used in doing this, but the key ones were:
http://orsontyrell.blogspot.co.uk/2013/11/airplay-to-arch-linux-raspberry-pi-via.html
http://engineer.john-whittington.co.uk/2013/05/airpi-diy-airplay-speakers-using-shairport-and-a-raspberry-pi-updated/
And on raspbian
http://trouch.com/2012/08/03/airpi-airplay-audio-with-raspberry/
https://github.com/abrasive/shairport
… thanks to all.

Migrating Windows 7 on an ASUS N56VM Laptop to an SSD 1

Posted on October 13, 2013 by danny

That’s it! I can’t stand it any longer! My beautiful ASUS N56VM laptop – a mere year old, has slowed to the pace of an arthritic snail. Despite having 8GB of RAM and a 2.something GHz i7, it’s as wheezy as hell.

It’s time to move from spin disk to SSD, a 500GB Samsung 840 SD. Not least as I’d discovered that the existing disk was spinning at 5700rpm. I mean what is the point of selling a system with an i7 and 8GB of RAM and then equipping it with an ageing gerbil on a wheel to spin the disk. No wonder it had slowed to a heap of crap.

SO – how to copy the system from the existing spin disk to the SSD? Well first, I bought a disk big enough to take all my data. I can’t be doing with deleting stuff or moving onto external disk drives. Boring, boring, boring! I placed it temporarily into an external enclosure and used the free “EaseUS Partition Master” software to clone the disk from the internal spin disk to the external ssd.

There are two main advantages to cloning the existing spin disk. The first is that you don’t have to re-install all your software and setup all those little machine tweaks you like, second, if like this ASUS the windows installation software is all on a hidden recovery partition, it’s the only way to continue using the Windows 7 OEM licence that came with the machine.

So with the disk cloned – I took the ssd out of the external enclosure and swapped out the spin disk, turn on the machine and kapow lightening fast boot speeds, straight into windows – easy peasy.

Errr… No.

What I actually got was a boot failure and this error message screen:
– Status: 0xc0000225
– Info: The boot selection failed because a required device is inaccessible.

Hmmm…

A bit of investigation revealed that the original disk and the clone were both using GPT rather that the older MBR partition table of yesteryear. GPT is a newer type of partition table that uses 64bit addresses rather than 32bit allowing for greater disk capacities and other good things. It forms part of the UEFI standard and indeed the ASUS uses UEFI for basic system configuration rather than the older BIOS system. UEFI was expecting an ID relating to the old spin disk and instead was getting one relating to the new SSD. So it stalled.

Pressing ESC when the ASUS symbol appears at boot brings up the boot selector, but even selecting the ssd there doesn’t help. A Windows Repair Disk is needed to fix the startup process. Type “Repair” in the start menu search area, will bring up “Create a System Repair Disk”. Unfortunately doing this on an OEM Windows 7 (as installed on the ASUS) creates a less useful repair disk that only allows you to re-install the operating system. You need a proper repair disk as would be created by a vanilla Windows 7 installation. Hope you’ve got one of those to hand!

With a vanilla Windows 7 Repair Disk in the DVD drive, reboot the machine and let it boot the DVD. Once booted, it will ask you to select a language and will then display a list of all the Windows 7 installations it has detected. There may well be none in the list as happened with me. Click “Next” in any case and let it attempt to repair the system. This will end up with a reboot.

Let it boot the repair disk again. It will probably find your Windows 7 installation this time. You will probably have to do this cycle of repair and reboot a few times.

Eventually – you will need to help it fix the boot record. Select the command prompt from the repair menu:
– work out which drive letter your DVD drive is mounted to (select each drive in turn, type DIR, repeat etc…) – let’s say it’s G: then type the following:

G:
cd boot
bootrec /fixboot

This command can be used to recrete a Windows 7 boot loader too:

bootsect /nt60 SYS all

This fixes the boot record.

Then run the repair system again, just kind of… because.

At the very least you will now be able to boot your system from the ESC boot menu – if you’re lucky it may even boot without ESC key intervention at all!

Thanks to the following sites and References:
http://forums.macrumors.com/showthread.php?t=696523&page=4
http://www.howtogeek.com/howto/32523/how-to-manually-repair-windows-7-boot-loader-problems/
http://support.microsoft.com/kb/927392/en-gb
http://www.sevenforums.com/general-discussion/252790-error-0xc0000225-windows-boot.html
http://www.sevenforums.com/tutorials/20864-mbr-restore-windows-7-master-boot-record.html

DNS-320: Access Denied from User Nobody 0

Posted on June 15, 2013 by danny

Just had a bit of a hair pulling moment with my DNS-320.

Despite having given myself write privileges to a shared drive, I couldn’t write to it from windows, only read. Every time I tried to do any writing activity, Windows 7 would say “Access Denied” and indicate that I had to get permissions from the Unix user “Nobody”.

I logged into my Debian Squeeze installation to check the permissions on the directory – they all looked fine.

Mad.

Or not so mad.

It seems that the only way to reliably maintain the mapping between the windows user on my laptop and the unix user on the DNS-320 is using the utility that came with the NAS drive, a simple mapping of the network drive in Windows is not sufficient.

So if you run into this problem. Unmap the drive in windows and then recreate the mapping using the D-Link utility.

Raspberry Pi Wireless Radio – Part 2 0

Posted on March 25, 2013 by danny

To control the Raspberry Pi radio, you’re going to need to connect a bunch of switches to the GPIO header block. How many switches and the functions they perform is up to you. For example you could use them as presets, or channel up/down. And don’t forget you’ll need something to control volume.

I purchased some ribbon cable, veroboard, tactile switches, an IDC connector and a bunch of resistors to make my control board (see pic below) but you could go a breadboard route at least initially to get something working. This post is an excellent introduction to the wiring required: http://www.cl.cam.ac.uk/projects/raspberrypi/tutorials/robot/buttons_and_switches/

To interface with my external switch board (via the GPIO header block), I’m going to use Python.

Installing Python

Although installing python in itself was straightforward, finding information on how to install the gpio library was more challenging, most users having used it with raspbian or debian. In the case of archlinux it was clearly going to have to be compiled from scratch which given I haven’t compiled anything from scratch, was a bit daunting.

However, whilst standing on my own shoelaces and generally face planting, I stumbled across this post on the subject http://archlinuxarm.org/forum/viewtopic.php?f=31&t=4654 which outlines everything needed to install both python and the gpio library as well as a host of other development tools required along the way such as gcc and so forth.

First install the development tools you’re going to need (including things like gcc)

$ sudo pacman -Sy file base-devel abs git

Next download the gpio source code and unpack it

$ wget https://aur.archlinux.org/packages/ra/raspberry-gpio-python/raspberry-gpio-python.tar.gz
$ tar xf raspberry-gpio-python.tar.gz

Now run the make process that will create a package that can be imported by pacman, and import it

$ cd raspberry-gpio-python
$ makepkg -Acs --asroot
$ sudo pacman -U raspberry-gpio-python

By this point you now have Python 2 and 3 installed, plus a variety of other development tools and the gpio library.

NB: If at any point you see error message that look a bit like this:
error: failed retrieving file ‘libpulse-2.0-2-arm.pkg.tar.xz’ from mirror.archlinuxarm.org : The requested URL returned error: 404
the chances are that the package database in pacman is out of sync with what’s out on the internet. The following command will resync the database:

$ sudo pacman -Syy

If that doesn’t work try changing the download mirror

$ cd /etc/pacman.d
$ nano mirrorlist

Comment out the original mirror and remove a comment from one of the others, then save and update http://www.raspberrypi.org/phpBB3/viewtopic.php?f=28&t=12840

A Simple Python Radio Control Program

This simple program has three radio stations and two mp3s assigned to various input buttons, plus a volume up and a volume down.

#!/usr/bin/python
import RPi.GPIO as GPIO
import time
import os

def PlayRadio(station_url):
    os.system("mpc stop")
    os.system("mpc clear")
    os.system("mpc add " + station_url)
    os.system("mpc play")

def PlayMp3(mp3_file):
    os.system("mpc stop")
    os.system("mpc clear")
    os.system("mpc add " + mp3_file)
    os.system("mpc play")

def VolumeUp():
    os.system("mpc volume +2")

def VolumeDown():
    os.system("mpc volume -2")

def mainProg():
    # to use Raspberry Pi board pin numbers
    GPIO.setmode(GPIO.BCM)

    # set up unused GPIO as output channels and 0V
    # set up GPIO input with pull-down control
    #   (pull_up_down be PUD_OFF, PUD_UP or PUD_DOWN, default PUD_OFF)
    GPIO.setup(14, GPIO.OUT)
    GPIO.setup(15, GPIO.OUT)
    GPIO.setup(18, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
    GPIO.setup(23, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
    GPIO.setup(24, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
    GPIO.setup(25, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
    GPIO.setup(8, GPIO.OUT)
    GPIO.setup(7, GPIO.OUT)

    GPIO.setup(2, GPIO.OUT)
    GPIO.setup(3, GPIO.OUT)
    GPIO.setup(4, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
    GPIO.setup(17, GPIO.OUT)
    GPIO.setup(27, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
    GPIO.setup(22, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
    GPIO.setup(10, GPIO.OUT)
    GPIO.setup(9, GPIO.OUT)
    GPIO.setup(11, GPIO.OUT)

    # set RPi GPIO output pins low
    GPIO.output(14, GPIO.LOW)
    GPIO.output(15, GPIO.LOW)
    GPIO.output(8, GPIO.LOW)
    GPIO.output(7, GPIO.LOW)

    GPIO.output(2, GPIO.LOW)
    GPIO.output(3, GPIO.LOW)
    GPIO.output(17, GPIO.LOW)
    GPIO.output(10, GPIO.LOW)
    GPIO.output(9, GPIO.LOW)
    GPIO.output(11, GPIO.LOW)

    # look for inputs on RPi board pins
    prev_input = 0
    while True:
        #take readings
        this_cycle = 0
        input = GPIO.input(25)
        if ((prev_input == 0) and input):
            print ("Button 1 pressed")
            this_cycle = 25
            # ISA FM
            PlayRadio("http://80.13.146.243:8000/")
        input = GPIO.input(24)
        if ((prev_input == 0) and input):
            print ("Button 2 pressed")
            this_cycle = 24
            # LBC
            PlayRadio("http://ice-the.musicradio.com:80/LBC1152MP3Low")
        input = GPIO.input(23)
        if ((prev_input == 0) and input):
            print ("Button 3 pressed")
            this_cycle = 23
            # Fun Kids
            PlayRadio("http://icy-e-04.sharp-stream.com/funkids.mp3")
        input = GPIO.input(22)
        if ((prev_input == 0) and input):
            print ("Button 4 pressed")
            this_cycle = 22
            # Rock Lobster mp3 Test
            PlayMp3("LobsterTest.mp3")
        input = GPIO.input(27)
        if ((prev_input == 0) and input):
            print ("Button 5 pressed")
            # Beethoven mp3 Test
            PlayMp3("ClassicalTest.mp3")
            this_cycle = 27
        input = GPIO.input(18)
        if ((prev_input == 0) and input):
            print ("Button 6 pressed")
            VolumeUp()
            this_cycle = 18
        input = GPIO.input(4)
        if ((prev_input == 0) and input):
            print ("Buttpon 7 pressed")
            VolumeDown()
            this_cycle = 4

        prev_input = 0
        if (this_cycle > 0):
            prev_input = 1

        # software switch debounce
        time.sleep(0.05)
	
def main():
    mainProg()

if __name__ == "__main__":
    main()

From here you can really go to town. I followed this up with a web interface coded in Python and Django to allow button configuration and all sorts. Far to long to blog about here. But plenty of fun to be had!

References:
http://www.instructables.com/id/Pandoras-Box-An-Internet-Radio-player-made-with/step2/Setting-up-the-Pi/
http://www.instructables.com/id/Pandoras-Box-An-Internet-Radio-player-made-with/step7/Connecting-the-Pushbuttons/
http://www.cl.cam.ac.uk/projects/raspberrypi/tutorials/robot/buttons_and_switches/ describes wiring
http://lwk.mjhosting.co.uk/?p=343 describes GPIO
http://elinux.org/RPi_Low-level_peripherals describes GPIO
http://pypi.python.org/pypi/RPi.GPIO/0.3.1a describes python programming with GPIO
http://docs.python.org/2/tutorial/index.html python for newbies
http://www.xatworld.com/radio-search/ for finding IP URLs for radio stations
http://www.codedefied.co.uk/2011/12/24/playing-bbc-radio-streams-with-mpd/ how to unpack BBC tokenised streams

Raspberry Pi Wireless Radio – Part 1 0

Posted on December 27, 2012 by danny

As with many such posts, this one is primarily a reminder to myself, should I need to repeat my steps at a later date. However, I hope they are of use to someone also as it was a number of days work.

You will need one raspberry pi and a wireless USB adapter based on the Realtek RTL8188CUS chipset such as the Edimax EW-7811Un micro-usb adapter (cheap as chips and available from Amazon).

Basic Setup

Download the Arch Linux ARM install (because it is very lightweight and boots in under 10 seconds), burn to an SD card and plugin to the Pi as per the instructions on the download page here.

Boot it up. If you don’t have a screen and usb keyboard available just plug it into a wired network. ssh is enabled by default so you can connect using Putty immediately, instead.

Follow the update instructions here (http://elinux.org/ArchLinux_Install_Guide) to bring it up to the most recent distribution.
Early on it talks about rc.conf which doesn’t exist in this distribution, there’s probably an alternative but as I didn’t need to change timezones, I wasn’t concerned.
The command pacman-key –init, does take A LONG time (like 10 minutes with no onscreeen feedback).

Wireless Networking

Plug in the Edimax EW-7811Un micro wireless USB adapter and reboot. Support for the Realtek RTL8188CUS chipset this is based on is built into the current distributions of Arch Linux for the Pi.
Install the netcfg package so that wireless can be configured from the command line

 # pacman -S netcfg

Then follow these instructions to configure wireless: https://wiki.archlinux.org/index.php/Netcfg
Use the example wireless-wpa script as the starting point.
After issuing this instruction in that post: # netcfg mynetwork you will see this error nl80211: ‘nl80211’ generic netlink not found. This isn’t actually a problem, this post describes why https://bbs.archlinux.org/viewtopic.php?pid=940669
To ensure wireless is restarted after a reboot of the Pi, the following command in that post must be executed

# systemctl enable netcfg@myprofile

Reboot and check that you can putty to the Pi over wifi.

In the event, that the wireless hardware doesn’t initialise fast enough (can happen), you may get an error like ‘wlan0 does not exist’. See the entry in this post https://wiki.archlinux.org/index.php/Netcfg_Troubleshooting to resolve.

You may find that a few days after doing this, the IP lease for the Pi expires on the router causing it to assign a new IP address to it. This can cause the Pi to no longer be able to connect to the router because it’s own expectation of what the IP lease should be, aren’t being met. This post https://bbs.archlinux.org/viewtopic.php?id=120230 should troubleshoot this.

Install and Configure Media Player

Now install mpd & mpc:

# pacman -S mpd mpc alsa-utils

Sound itself needs enabling at boot up. To do this you need to create a script in the directory called /etc/modules-load.d called snd_bcm2835.conf which looks like this:

# Load snd_bcm2835 at boot
snd_bcm2835

You also need to install initscripts:

# pacman -S initscripts

A lot of the challenge is in getting mpd configured correctly, when stuff doesn’t work, it’s usually due to this file not being setup quite right. Also the errors reported to the command prompt are often less than helpful so don’t forget to check the mpd.log file, sometimes that actually provides useful help. In general it is recommended you don’t run it as root but rather as a user with less all-encompassing rights.

Here’s my /etc/mpd.conf file:

music_directory		"~/music"
playlist_directory "~/mpd/playlists"
db_file "~/mpd/mpd.db"
log_file "~/mpd/mpd.log"
pid_file "~/mpd/mpd.pid"
state_file "~/mpd/mpdstate"
user "wonkygibbon"
bind_to_address		"127.0.0.1"
port				"6600"
input {
        plugin "curl"
}
audio_output {
	type		"alsa"
	name		"My ALSA Device"
	device		"hw:0,0"	# optional
}

The default input plugin is called “curl” and can be used to pick up streaming audio over the web.

For this to work, I needed to create the various files and directories that these point at. Hence, login as your user (in my case wonkygibbon), then do the following:

$ mkdir music
$ mkdir mpd
$ cd mpd
$ mkdir playlists
$ touch mpd.log mpd.pid mpdstate

Finally, start mpd, connect to a radio stream, and play it:

$ mpd
$ mpc add http://80.13.146.243:8000/
$ mpc play

The IP address is that of one of my favourite french stations – replace with whatever you want to listen to.

If you wish to test using mp3 files – you can copy them to the Pi using WinSCP (provides an ftp type interface from windows to the Pi using ssh – meaning you don’t need the Pi to be running an ftp server).

They need to be placed in the “music” folder you created earlier. Then update mpd’s music database using:

$ mpc update

Thanks primarily to the following sites as well as others to numerous to mention:
http://miro.oorganica.com/raspberry-pi-mpd/
https://wiki.archlinux.org/index.php/Music_Player_Daemon#Starting_mpd_as_a_user
http://crunchbang.org/forums/viewtopic.php?pid=182574
https://wiki.archlinux.org/index.php/Netcfg_Troubleshooting
https://bbs.archlinux.org/viewtopic.php?id=120230
Part 2 if/when it follows will focus on how to to add external switches to select channels and the bits of scripting required to respond to them.

D-Link DNS-320 NAS, DebianSqueeze and Twonky Media Server 7

Posted on November 28, 2012 by danny

I gave myself a bit of a shock today by working out something in Linux that actually worked, all by mself! Obviously to any proper linux person it’s little more than a child’s first steps – but it was quite satisfying!

So …

Having got the NAS loaded with all my media files, I enabled the UPnP MediaServer that came with it – to discover it was total crap. And promptly disabled it again.

But the word on the street, is that the Twonky Media Server is good, so I thought, put that on it.

And indeed people have put it on the DNS-320. This post covers much of what needs to be done, providing a link to a build of Twonky for the ARM processor and instructions on how to configure.

The only problem, is that all the instructions are for the lightweight ffp Linux install – rather than debiansqueeze which I’m using (because of the subversion project posted about previously).

Nevertheless – I followed the instructions, and with a few variations … got it to work … which surprised me!

The main thing I did was to strip off every occurrence of /ffp wherever I saw it in a path eg: /ffp/opt/twonky/ became /opt/twonky/
I did this both with the instructions in the blog post and with the content of the two scripts downloaded by those instructions ‘twonky.sh’ and ‘twonkyserver-default.ini’
Note: Two things to be aware of here: 1) Don’t edit these files with Windows Notepad, it messes up the line feeds at the end of each line such that linux doesn’t like the result! The free editor Notepad++ can probably handle it. 2) The debiansqueeze equivalent of the /ffp/start directory is /etc/inet.d so drop the twonky.sh file in there.

twonky.sh
#!/bin/sh

# PROVIDE: twonky
# REQUIRE: LOGIN

. /etc/ffp.subr
name="twonky"
start_cmd="twonky_start"
stop_cmd="twonky_stop"

twonky_start()
{
# Add a route for twonky to be published via UPNP
route add -net 224.0.0.0 netmask 240.0.0.0 dev egiga0 >/dev/null 2>/dev/null </dev/null &
cd /opt/twonky
mkdir -p /opt/twonky/data/ &
# Twonky requires one handle per monitored filesystem if inotify is
# used. On many devices, this is set to 8192, which might be too low
# if music or photos are scanned. Therefor this value is raised to
# the doubled amount. If more is required, change the value below.
# Thanks Michael for reporting this!
/sbin/sysctl fs.inotify.max_user_watches=16384 >/dev/null 2>/dev/null </dev/null &
# The line below is without logging (logs are written to /dev/null).
# If you want logging, exchange it with the line below the current one.
/opt/twonky/twonkystarter -logfile /dev/null -appdata /opt/twonky/data/ >/dev/null 2>/dev/null </dev/null &
# /opt/twonky/twonkystarter -logfile /opt/twonky/data/TwonkyMediaServer-log.txt -appdata /opt/twonky/data/ >/dev/null 2>/dev/null </dev/null &
}

twonky_stop()
{
# Kill Twonky
if [ -n "`pidof twonkyserver`" -o -n "`pidof twonkystarter`" ]; then
echo "Stopping twonkyserver"
kill -9 `pidof twonkyserver` `pidof twonkystarter`
fi

if [ -n "`pidof twonkyproxy`" ]; then
echo "Stopping twonkyproxy"
kill -9 `pidof twonkyproxy`
fi

if [ -n "`pidof twonkywebdav`" ]; then
echo "Stopping twonkywebdav"
kill -9 `pidof twonkywebdav`
fi
# Remove the route
route del -net 224.0.0.0 netmask 240.0.0.0 dev egiga0 >/dev/null 2>/dev/null </dev/null &
}

run_rc_command "$1"
twonkyserver-default.ini
#!/bin/sh

# PROVIDE: twonky
# REQUIRE: LOGIN

. /etc/ffp.subr
name="twonky"
start_cmd="twonky_start"
stop_cmd="twonky_stop"

twonky_start()
{
# Add a route for twonky to be published via UPNP
route add -net 224.0.0.0 netmask 240.0.0.0 dev egiga0 >/dev/null 2>/dev/null </dev/null &
cd /opt/twonky
mkdir -p /opt/twonky/data/ &
# Twonky requires one handle per monitored filesystem if inotify is
# used. On many devices, this is set to 8192, which might be too low
# if music or photos are scanned. Therefor this value is raised to
# the doubled amount. If more is required, change the value below.
# Thanks Michael for reporting this!
/sbin/sysctl fs.inotify.max_user_watches=16384 >/dev/null 2>/dev/null </dev/null &
# The line below is without logging (logs are written to /dev/null).
# If you want logging, exchange it with the line below the current one.
/opt/twonky/twonkystarter -logfile /dev/null -appdata /opt/twonky/data/ >/dev/null 2>/dev/null </dev/null &
# /opt/twonky/twonkystarter -logfile /opt/twonky/data/TwonkyMediaServer-log.txt -appdata /opt/twonky/data/ >/dev/null 2>/dev/null </dev/null &
}

twonky_stop()
{
# Kill Twonky
if [ -n "`pidof twonkyserver`" -o -n "`pidof twonkystarter`" ]; then
echo "Stopping twonkyserver"
kill -9 `pidof twonkyserver` `pidof twonkystarter`
fi

if [ -n "`pidof twonkyproxy`" ]; then
echo "Stopping twonkyproxy"
kill -9 `pidof twonkyproxy`
fi

if [ -n "`pidof twonkywebdav`" ]; then
echo "Stopping twonkywebdav"
kill -9 `pidof twonkywebdav`
fi
# Remove the route
route del -net 224.0.0.0 netmask 240.0.0.0 dev egiga0 >/dev/null 2>/dev/null </dev/null &
}

run_rc_command "$1"

NB: These scripts are provided for reference only – more current versions may vary.

Also – I didn’t bother with this line [[ $(ls -1 /mnt|grep -c HD_a2) -eq 0 ]] && sed -i -e ‘s!/HD_a2!/HD/HD_a2!g’ -e ‘s!/HD_b2!/HD/HD_b2!g’ /ffp/opt/twonky/twonkyserver-default.ini
in the instructions – it does a search and replace – but it doesn’t seem necessary.

Finally the ‘twonky.sh’ script makes use of a script called ‘ffp.subr’ which I think is used to start and stop the twonky service. This doesn’t exist in Debiansqueeze. There is probably some native way of achieving the same thing – but I don’t know what it is so instead, I went and found the download for ffp – unpacked it, and retrieved the script. There’s nothing specific to ffp in it so I dropped it into the /etc directory. You do need to go through the file and remove /ffp off the start of any paths that it appears in.

Then as instructed, I ran the twonky,sh script to start the service and connected via a web browser – and OMG!!!! IT WORKED!!!! First time too, which usually only happens to people who are either (a) lucky or (b) liars.

Once I had configured the server through the web page, I left it to get on with the job of indexing my media collection. This was a task that UPnP service that came with the NAS had taken all night to do. Twonky seemed to do it in minutes. Not only that, connecting using Windows Media Player, it downloads the metadata from Twonky so much more rapidly. Streaming of both audio and video is very rapid and smooth as is seeking to a certain spot in the video. All in all – very impressed with Twonky. It’s good.

There are three reasons, changing all this stuff worked:
1) All the scripts use the sh shell which is of course available in both ffp and debiansqueeze (ie the syntax was the same)
2) The folder structures of ffp and debiansqueeze are very similar.
3) Can’t remember – it’ll come back to me.

The only reference for this post, is to thank (again) Uli author of the http://nas-tweaks.net site
for this page http://nas-tweaks.net/384/installation-of-twonky-server-7-on-nas-devices/

Configuring the D-Link DNS-320 NAS as an SVN Subversion server and connecting with VisualStudio 2010 4

Posted on November 23, 2012 by danny

Introduction

I recently found myself wanting to work on a programming project at home, using C# and VisualStudio 2010, and like any good developer realised I needed source control. Yes of course I could use Microsoft Sourcesafe, it does integrate nicely with VisualStudio. But lets be honest, it is a pile of crap, I’m used to TFS at work, I can’t be doing with Sourcesafe. Running my own TFS server is probably a bit over the top, I’m not sure I have the spare change in my back pocket for the licencing.

At the same time I was aware I wanted to move my RAID’ed storage / backup solution out of the media system under the telly where it currently lives, to a dedicated NAS device.

Two birds? One stone?

Being a tight arse I went over to Ebuyer and looked up the cheapest unit that supported RAID1 (mirroring) and gigabit transfer rates and found the D-Link DNS320 for £53 inc VAT without disks, it can take up to two 2TB drives. Thinking of my old Linksys router and remembering appliances often run linux under the hood, I had a bit of a google and found this page. Someone had got subversion running on it. Very cool!!

So I ordered one, waited a few days and once it arrived shoved a drive in it. Getting the device up and running was the job of a few minutes work. Getting subversion working – rather longer. Nevertheless – success was ultimately had. For reference, I am not a linux expert – in fact it would be fair to say, I know to next to nothing about it. But I like a challenge…

What will I end up with?

Whilst the DNS-320 ships with its own version of Linux in the firmware, we aren’t going to be able to bolt directly onto that. However there is an undocumented hook (called ‘fun_plug’ which I guess stands for functionality plugin) that is checked on startup and can be used to add additional functionality stored on the hard drive.

To get subversion running on the DNS-320 you need a linux installation that runs alongside the one in the firmware, in this case DebianSqueeze. Installing this does not affect the rest of the NAS and you wont see any impact on the web interface. Once you have DebianSqueeze installed and running, you install and configure the subversion package and away you go.

So what you end up with, is a NAS running linux, that runs DebianSqueeze linux as a plugin that hosts subversion.

Installation

Unfortunately it’s not that simple. To configure DebianSqueeze requires Telnet to be running on the NAS and unfortunately out of the box, this is not the case. Luckily there is a (convoluted) way to get a very thin linux install (ffp) with Telnet onto the box first and then use that to configure DebianSqueeze. Once that is done, the ffp install is not used any further.

This exceptionally well written blog post describes how to install ffp, the “Fonz fun_plug 0.5 for CH3SNAS, CH3MNAS, DNS-323”
Follow it all the way down to the section headed “Logging in using SSH”, but don’t disable Telnet in the last step, as you’re going to need it.

Next, download DebianSqueeze from here
Open the zip file. Inside is a “how to” and two other files. Follow the instructions in the file from Step 2 (you have in effect already done Step 1).
The very last step of renaming fun_plug.debian to fun_plug effectively discards ffp that we installed earlier, it having served it’s purpose.

Now that you have DebianSqueeze running you can install subversion.
This blog post here provides a step by step guide to do this.
Half way down he mentions the command:
# svnadmin create /var/svn/projectalpha
‘projectalpha’ should be replaced by whatever you want to call your repository.
Other than that, follow the blog exactly, all the way down to the point where it starts talking about running an ssh server on a custom port. You probably don’t need to do that so can stop there.

You now have subversion running on your NAS. Excellent!!

Connecting VisualStudio 2010

Although subversion is usually used with an Apache web server this is not actually necessary. The author of the previous post has avoided doing this opting to instead use the ssh server and communication protocol already installed with DebianSqueeze. This makes it more lightweight and conserves the limited RAM available on the box.

To get VisualStudio 2010 to work with subversion you need a plugin. A popular one is AnkhSVN which can be downloaded for free.

Once installed, assuming you don’t have the Tortoise SVN client installed then you need to help the plugin understand the ssh protocol before you can use it in VisualStudio.
This blog post describes how.
NB: The configuration file mentioned in the post is described as being in your My Documents\Application Data\subversion directory, this is in XP. In Windows 7, this folder now maps to here: c:\Users\<USERNAME>\AppData\Roaming\Subversion. You may need to set the Windows Explorer “Folder and Search Options” to “Show hidden files, folders, and drives” to be able to see the AppData folder.

Now restart VisualStudio.

First you need to enable Subversion as the source control plugin for VisualStudio. Go to “Tools->Options” and in the dialog go to the subsection “Source Control” and edit the “Plug-in Selection” to be AnkhSVN.

Now, you can connect to your Subversion repository using “File->Subversion->Open From Subversion.

In the dialog that pops up enter the URL of the subversion repository on your NAS box, which will look like this: svn+ssh://<NASBOX>/var/svn/<SvnRepositoryYouCreatedEarlier>
and you’re in!!!

So now you’ve got it all working. The only thing is this irritating “Plink.exe” window that keeps popping up. It has to go – it just has to.

Download TortoiseSVN from here, install it, find the file tortoiseplink.exe, rename it to plink.exe and replace your plink.exe with it. You can then uninstall TortoiseSVN again.

Hope this has been of help.

Now some thanks and references:
First and foremost Murzal Arsya who made it clear that this project could be done on the DNS-320, outlined the need for DebianSqueeze and provided the step by step instructions for setting up subversion on the NAS.
Next http://nas-tweaks.net which is a great resource for people wanting to use their NAS for more than just NAS and provided the amazing ffp stuff.
Then Shaunc for guidance on svn+ssh, cheers geeza!!
Finally Hao Chen for for the tip to get rid of the plink pop-up window http://haochen.wordpress.com/2011/02/22/hiding-the-plink-pop-up-window-in-netbeans-ide-using-svnssh/

NVIDIA Graphics Driver Installer Fails: The system cannot write to the specified device. 2

Posted on July 03, 2012 by danny

Just in case anyone runs into this problem and starts losing the plot!!

I was trying to install an earlier version of the NVIDIA display drivers for my graphics card today on Windows 7. Ones that MediaCentre would play nicely with.

Boy did I have to jump through some hoops!

Had to delete the version that Windows Update had downloaded otherwise it kept reinstalling them after the reboot – which was really annoying. Not trivial – you have to remove them from here:

C:\Windows\System32\DriverStore\FileRepository\nvdsp something something something. To delete them, you first need to take ownership of them (google that) and then once you have ownership set the permissions to provide full control. THEN you can remove them.

Then when I ran the NVIDIA installer it failed whilst trying to install the graphics driver component. Grrrr!

Then I tried installing it from Device Manager using “Update Driver” – and got this error message: “The system cannot write to the specified device.” – which lead me to believe that it couldn’t write to the card, or something in the windows directory – probably due to more bloody file permissions or whatever. And then I realised … that it wasn’t NVIDIA’s fault at all. My “Temp” folder was on a partition that was practically full. The installer couldn’t unpack the files. I cleaned out the temp folder – and hey presto – the drivers updated very happily indeed.

Net result – my kids can now watch “Peppa Pig” when they get up in the morning and I can sleep in. Praise your deity du jour!



↑ Top