Python FreeDNS client (on Raspberry Pi)

I'm using FreeDNS - a dynamic DNS provider for my Raspberry Pi. If you sign up and follow the instructions on their site you can quickly have a nice name for your site like mine: Jerbly

To keep your external dynamic address updated with FreeDNS there are a number of clients (scripts) available. Since this is Raspberry Pi though I had to have one in Python.

import urllib2
import os.path

OLDIP_FILE = '/var/lib/misc/oldip'

def updatedns(ip):
    print urllib2.urlopen("http://freedns.afraid.org/dynamic/update.php?YOUR-SECRET-KEY-HERE").read().strip()
    f = open(OLDIP_FILE, 'w')

newip = urllib2.urlopen("http://ip.dnsexit.com/").read().strip()

if not os.path.exists(OLDIP_FILE):
    f = open(OLDIP_FILE, 'r')
    oldip = f.read()
    if oldip != newip:

NOTE: You will have to change the YOUR-SECRET-KEY-HERE to the one supplied by FreeDNS.

I've just put this script (called simply "freedns") in my /etc/cron.hourly directory which is good enough for my site.


Raspberry Pi webcam

*** UPDATE NOTE: I am now using Motion instead of ffserver see this new post: Battery powered, Wireless, Motion detecting Raspberry Pi ***

Here's a walk-through of the steps I took to get a webcam stream on the Internet from my Raspberry Pi.

 Raspberry Pi
 8G class 4 Sandisk SD card
 5V 1A MicroUSB power supply
 Ethernet cable
 HDMI cable
 USB keyboard
 Webcam (PS3 EyeToy)

Prepare the OS
 Arch Linux ARM - you can get the image file from the Raspberry Pi download page.
 Write the image to the SD card. (I use Win32DiskImager)
 Expand the main partition to fill the SD card. From my Windows laptop I booted to a GParted Live CD to do this.

Go headless
 Change the root password!

passwd root
 Set up a fixed IP address. (You may need to change your router settings to define a fixed IP address range) Edit /etc/rc.conf using nano:
nano /etc/rc.conf
 Follow the instructions to set up your fixed IP something like this:
 Also change resolv.conf to use your router for name resolution:
 Since this Pi is running headless we don't need so much RAM allocated to the GPU. So swap the default start.elf for the 224 version:
cd /boot
mv start.elf orig-start.elf
cp arm224_start.elf start.elf
 Unplug the keyboard and HDMI, reboot and then ssh to your Pi. (I use PuTTY)

Start streaming
 Update your packages and install mplayer and ffmpeg:

pacman -Syu
pacman -S mplayer
pacman -S ffmpeg
 Create an ffserver.conf configuration file in /root. Here's mine:
Port 8090 
MaxClients 4
MaxBandwidth 10000 

<Feed webcam.ffm> 
File /tmp/webcam.ffm 
FileMaxSize 5M 

<Stream webcam.asf> 
Feed webcam.ffm 
Format asf 
VideoCodec msmpeg4 
VideoFrameRate 2
VideoBufferSize 80000 
VideoBitRate 200 
VideoQMin 1 
VideoQMax 10 
VideoSize qvga
PreRoll 0 

<Stream webcam.mjpeg>
Feed webcam.ffm
Format mpjpeg
VideoSize qvga
VideoFrameRate 2
Strict -1
 Start the streaming server:
ffserver -f /root/ffserver.conf & ffmpeg -v 2 -r 5 -s 640x480 -f video4linux2 -i /dev/video0 http://localhost:8090/webcam.ffm
 You should now have two streams available from your Raspberry Pi. One is an asf stream which you can connect to from players like Windows Media Player or VLC. The other is an mjpeg stream which you can view from a web browser without requiring any plugins.
 The mjpeg URL is:
 The asf stream is:

Put it on the Internet
If you just want to see this on the Internet temporarily simply open up port 8090 on your home router firewall settings. Set up an Inbound Service on port 8090 to Now find your external ip address and you should be able to connect through that. Your external address will probably be shown somewhere in your router web interface or you can find it by going to here: http://ip.dnsexit.com/
Your external address will change occasionally unless you have a fixed IP address. In another post I'll show how to set up Dynamic DNS with an address updater so you can reach your Pi on the net through a name rather than address. The updater ensures that if your external address changes the Dynamic DNS provider is given the new one.

*** UPDATE NOTE: I am now using Motion instead of ffserver see this new post: Battery powered, Wireless, Motion detecting Raspberry Pi ***

My Raspberry Pi webcam stream is sometimes available here: http://jerbly.uk.to/picam
Please be gentle. If you don't see a stream try again another time!