Static IP address on OSMC

The standard place on Linux for the network configuration is /etc/network/interfaces , but OSMC uses connman which is a lightweight network controller designed for embedded devices. Connman uses different files to the traditional Linux network configuration files. To define a static IP address one should create a config file in the /var/lib/connman directory with a filename ending with .config.

In my case I created a file: /var/lib/connman/ethernet.config

Type = ethernet
IPv4 =
Nameservers =

This uses my local network settings (IP address/subnet mask/default gateway) and I’ve set the dns entry to one of Googles public DNS servers.
If you need something a bit more advanced (perhaps wifi with encryption) then more examples are available in the config-format.txt file on git.

I then rebooted the Raspberry Pi and it came up with the new IP address (the changes can be applied dynamically, but I prefer to reboot whenever making network changes to make sure that they come up correctly at start-up).

From –

Email my public address

Email my public address

As by now you would have known that I have a RaspberryPI connected to my TV running OSMC. I recently had to need to connect to this RPI remotely. So as we all do I punched a hole in my router to the device on the ssh port. I also signed up for DynDNS so I can access the Pi from a URL. But being the tinkerer I am I decided, why not let the Pi tell me it’s public IP address. And just like that a new tinkering project was born! I first created a small php script on my server which returns the IP address of the connecting party, you can check it out here.
php script


Now I had to find a way to get the Pi to connect to this site, collect the returned ip address and check it with some previously stored address for change, and of course email me ONLY when there’s a change. So I created a quick python script to do just that:

import requests
import datetime
import smtplib
from email.mime.text import MIMEText

url = ""
    response = requests.get(url)
    pipaddr = response.text
    f = open('ipadddress','rw+')
    ipaddr = f.readline()
    pipaddr = ''

if(ipaddr <> pipaddr):
    f = open('ipadddress','w')
    print, ipaddr, "=>", response.text
    today =
    to = ''
    gmail_user = ''
    gmail_password = ''
    smtpserver = smtplib.SMTP('', 587)
    smtpserver.login(gmail_user, gmail_password)
    msg = MIMEText(pipaddr)
    msg['Subject'] = 'IP For RPI on %s' % today.strftime('%b %d %Y')
    msg['From'] = gmail_user
    msg['To'] = to
    smtpserver.sendmail(gmail_user, [to] ,msg.as_string())

And this is not all, now this script must be scheduled so it checks the ip then emails me if need be. I did this via good ole cron. There’s a small caveat though with the cron, I had to first change into the directory of the script then run the script or else it would look for the ipaddress file in the current path.

* * * * * cd ~/Scripts/;./ >> log.txt

Make your Raspberry Pi speak!

I found an article online once that taught me the “say” command on OSX – which i think was pretty cool! The command line function allows you to activate the speech to text feature of OSX and can be used for a variety of fun project. You can try it by firing up terminal (Applications > Utilities > Terminal) in OSX and typing

Say "hello world"

I embarked on an audacious project to teach my son programming over the holiday and thought this feature would be a really cool addition to one of the lessons. The idea is to teach him programming in python on the raspberry pi so he learn basic programming structures and also the hardware that it runs on. Natively the RPI does not have this (say) function built in but lucky I found a way to get it done. Here follows the instructions to get the RPI to speak.

The Raspberry Pi needs mplayer and internet access to make this work. By default it does not have mplayer installed by default.

sudo apt-get update
sudo apt-get install mplayer

Now you can create a command out of it by creating a /usr/bin/say file

mplayer "$1";

Depending what speaker setup you have, you may need to adjust some settings. In particular, you can try telling the Pi what audio interface to use with the command

amixer cset numid=2

numbid can be any of

On a side note, if you get this error from amixer:

amixer: Mixer attach default error: No such file or directory

The fix for this is to run this command

sudo modprobe snd-bcm2835

That command will create the necessary device directories in /dev/snd/

To actually run the file as a command or program it has to be executable, and in linux that means changing the permission attribute on the file:

chmod +x /usr/bin/say

And that’s it, you can now get the RPI to speak by typing the say “hello world” like on OSX.

Flexget for Movies and TV Shows

Flexget for Movies and TV Shows

Here’s the list of instructions I used to setup flexget on my Raspberry Pi. One day I believe i will automate this.

0. Setup Raspbmc
Download the appropriate  for your system and execute it. Remember system here is the computer     you’re using to prepare the sd card, not the Pi itself.

1. Change password for SSH
2. Login to ssh
3. To make sure everything is up to date
sudo apt-get update

4. Create home directories
mkdir /home/pi/flexget
mkdir /home/pi/incomplete
mkdir /home/pi/torrent
mkdir /home/pi/TVShows
mkdir /home/pi/Movies
mkdir /home/pi/Music

5. Install transmission daemon –
sudo apt-get install transmission-daemon
after install, the daemon is started automagically. We don’t want that, because we want to tweak the config.
Stop the daemon:
sudo /etc/init.d/transmission-daemon stop
Now we want to change the config of the daemon:
sudo nano /etc/transmission-daemon/settings.json

6. copy/paste and run this command: sudo nano /etc/transmission-daemon/settings.json

7. Change
“alt-speed-down”: 400,
“download-dir”: “/home/pi/TVShows”,
“download-queue-size”: 2,
“incomplete-dir”: “/home/pi/incomplete”,
“incomplete-dir-enabled”: true,
“ratio-limit”: 0.2,
“ratio-limit-enabled”: true,
“rpc-password”: “YOURDESIREDPW”,
“rpc-username”: “YOURDESIREDUSERNAME”,
“rpc-whitelist”: “,192.168.*.*”,
“script-torrent-done-filename”: “/etc/transmission-daemon/”,
“seed-queue-enabled”: false,
“seed-queue-size”: 1,
“speed-limit-down”: 2000,
“speed-limit-down-enabled”: true,
“speed-limit-up”: 90,
“speed-limit-up-enabled”: true,
“watch-dir”: “/home/pi/torrent”

press CTRL+X to exit the settings file, then Y to save.

8. You can change the daemon to run as pi,
sudo nano /etc/init.d/transmission-daemon
change “USER=debian-transmission” to “USER=pi”
Now, because we changed the user, we also have to change ownership of the folders used by Transmission
sudo chown pi:pi /etc/transmission-daemon/settings.json
sudo chown pi:pi /etc/init.d/transmission-daemon
sudo chown -R pi:pi /var/lib/transmission-daemon/info

9. sudo /etc/init.d/transmission-daemon start

10. Install flexget
sudo apt-get -y install python-pip
sudo pip install flexget
sudo pip install transmissionrpc
sudo easy_install subliminal

11. Create an account:
Create a list “Following”. If you are like me and you follow most tv shows in normal quality and some in high 720p quality, create two lists (“Following” and “Following in HD”). I consider normal quality to be hdtv but not 720p rips.
add all tv shows you like watch in XBMC to this list by going to TV Shows and scroll through the shows or search the shows. You can do this by selecting “Add to Custom List” for every tv show.
for Movies: simply select “add to Watchlist”. A movie will automatically be removed from this Watchlist once you have watched it in XBMC.

12. copy the text of this file and save as config.yml (you will need it later) –
Open in text editor and modify the things in CAPITALS to your personal accounts

13. Change to /home/pi/flexget
cd /home/pi/flexget/
nano config.yml
Paste contents of config.yml from above into this file

14. Trigger XBMC to update library on finished downloads
sudo nano /etc/transmission-daemon/
Now copy this and save it with CTRL+X Y:
/usr/bin/wget –header=’Content-Type:application/json’ –post-data='{“jsonrpc”: “2.0”, “method”: “VideoLibrary.Scan”, “id”: “pi”, “params”: {“directory”:”‘”$TR_TORRENT_DIR”‘/”}}’ “http://localhost:80/jsonrpc”

give the file execution permission: sudo chmod +x /etc/transmission-daemon/

15. Make sure flex get and it’s configuration is working fine
flexget -c /home/pi/flexget/config.yml check

16. Schedule flexget in crontab
crontab -e
0 3,6,9,12,15,17 * * * nice -n 4 /usr/local/bin/flexget -c /home/pi/flexget/config.yml execute

17. Add user pi to samba
sudo smbpasswd -a pi

18. Add your sources! Go to Videos and choose Add Source. Go to ROOT, then media>usb>TV Shows and select this folder. Then select This folder contains TV Shows and save it. Do the same for Movies but select it contains Movies.