Installing SABnzbd on a Raspberry Pi running OSMC

For quite some time I’ve been running SABnzbd on a PC, downloading files, and then transferring them over the local network to a USB drive attached to a Raspberry Pi which is running OSMC. There’s a Linux version of SABnzbd which means I can cut out the PC and have the Pi handle the downloads. It’ll mean I can queue up the downloads from a web interface running on whatever device I have to hand, like an iPad.

First Try

The initial installation of SABnzbd was quite easy;

sudo apt-get install python-openssl unrar par2

sudo apt-get install sabnzbdplus

Edit the settings so that the web client starts up on port 8085..

sudo nano /etc/default/sabnzbdplus

USER=osmc
HOST=0.0.0.0
PORT=8085

sudo service sabnzbdplus restart

This then allowed me to connect to SABnzbd and transfer over all my settings that I was using on my PC.

Delayed Start

What I found was that SABnzbd started before the USB drive was properly mounted by OSMC, so I disabled the main service from starting up, and added a script to wait for the USB drive to get mounted at a particular path.

There was a good forum post here that pointed me in the right direction.

Disable the default service…

sudo update-rc.d sabnzbdplus disable

Write a quick shell script to wait for the directory/USB drive to be mounted…

nano /home/osmc/startsabnzb.sh

#!/bin/sh

# Wait for this folder to be mounted...
DIR=/media/Elements

while [ ! -d "$DIR" ]; do
sleep 120
done

/etc/init.d/sabnzbdplus start

chmod a+x /home/osmc/startsabnzb

Add the script to system startup…

sudo nano /etc/rc.local

/home/osmc/startsabnzb.sh

Upgrading

The version of SABnzbd that installed above was very dated. That repo doesn’t get updated very often. Here’s how I updated it to the latest version.

sudo su root

echo "deb http://ppa.launchpad.net/jcfp/nobetas/ubuntu xenial main" | tee -a /etc/apt/sources.list
echo "deb http://ppa.launchpad.net/jcfp/sab-addons/ubuntu xenial main" | tee -a /etc/apt/sources.list

apt-key adv --keyserver hkp://pool.sks-keyservers.net:11371 --recv-keys 0x98703123E0F52B2BE16D586EF13930B14BB9F05F

sudo apt-get update

Upgrading sabyenc

This solved the issue where SABnzbd was complaining that sabyenc wasn’t the right version. It uses the 2nd repo (sab-addons) we added in the steps above.

sudo apt-get install python-sabyenc

Final thoughts

SABnzbd runs quite well on the Pi. It is a lot slower than it was on a PC.. it only manages about 3 MB/s on the download on a wired connection (compared to 6 MB/s on a Wifi connection on a laptop), and unpacking is slow.

However, the files are unpacked onto the device which I was manually copying the files to anyway, so that saves time.

Sharing attached USB storage in OSMC using NFS

As well as being attached to the living room TV for use as a media centre, I also wanted to be able to use my Raspberry Pi 3 B+ as a simple NAS for other TVs in the house to stream from.

The Pi I’m using has a 1Tb desktop hard drive attached to it over USB, and I wanted a way to easily share the contents. It was actually relatively easy to set up… this is how to do it in OSMC;

  1. Install SSH to OSMC via the Store
  2. Now you can remote shell into the Pi to set up the network share
  3. Install NFS services using the following command;
    sudo apt-get install nfs-kernel-server
  4. Edit the file shares;
    sudo nano /etc/exports

    Add a share like this;

    /media 192.168.1.0/255.255.255.0(rw,fsid=0,insecure,no_subtree_check,async,crossmnt)

    (crossmnt fixed an issue where I could see the folders but no files)

  5. Restart the NFS service;
    sudo /etc/init.d/nfs-kernel-server restart

That’s it.. you should now be able connect to the Raspberry Pi and see the files on any of the USB drives you’ve got attached.

Automated mains socket power-off for OSMC on a Raspberry Pi

I’ve chosen to replace an ageing mini-PC which I’ve used since 2010 with a new Raspberry Pi 3 B+ running OSMC. It makes for a really capable media centre which can playback newer h.265 HEVC video files at 1080p without any problems, or it can serve 4K files over NFS to a box with a hardware h.265 chip like the Fire TV Box.

This form factor is easy to take on holiday and you can use an old infrared remote control (or Harmony learning remote) with it too.

However, the one thing I’ve struggled with is how to make it easy for my family to use in regard to switching it on and off. The Pi doesn’t have a power button. Some power supplies have an inline rocker switch, which almost fits the bill. I wanted something more automated.

Fortunately I had a spare Energenie power socket from a previous project where I use one to turn off our bass speaker when the TV isn’t on. These power sockets are controlled remotely (over RF) from a Pi which you attach an Energenie control board/shield to.

What I’ve done with the Pi 3 is have it powered through an Energenie socket, and set up a service that executes when it detects OSMC is shutting down. That service will make a quick HTTP call to the Pi with the Energenie controller shield, which will in turn send an RF signal to turn the mains socket off.

 

osmcshutdown

 

Here’s how you can set it up like I have…

Scripts for the Pi running OSMC

First, add a new service script.. create a new file in this folder;

/etc/systemd/system/callenergenie.service


[Unit]
Description=Energenie Remote Call to Secondary Pi
Before=multi-user.target
After=network.target
Conflicts=shutdown.target
[Service]
ExecStart=/bin/true
ExecStop=/bin/sh /home/osmc/callenergenie.sh
Type=oneshot
RemainAfterExit=yes
[Install]
WantedBy=multi-user.target

Then enable it with;

sudo systemctl enable callenergenie.service

There are a couple of useful things happening in this service, the After parameter makes sure the code runs before the network code is shut down, and Conflicts parameter is looking for OSMC shutting down.

Now add a helper script… this will make the webserver call as a background task, so control will be given back to the service immediately, rather than it waiting for the wget to complete.

/home/osmc/callenergenie.sh


echo Calling energenie socket…
wget –quiet –background –output-document="callenergenie.log" "http://192.168.1.99/callenergenie.php?delay=10&switch=2&state=off"
echo Sleeping for 2 seconds
sleep 2
echo Done.
exit 0

This calls the PHP script, telling it which socket to turn off, and how long to delay before sending the command, which we’re doing so that the Pi has time to shut down before the power is cut.

Scripts for the Pi with the Energenie shield

This is the PHP script I added to the other Pi which was already configured to be a PHP web server.

/var/www/html/callenergenie.php


<?php
/* MattC – Call this with various parameters..
callenergenie.php?
delay = time in seconds to sleep before calling Energenie
switch = which socket to talk to
state = turn socket on/off
e.g. callenergenie.php?delay=5&switch=2&state=off
*/
print ("Waiting ".$_GET['delay']." seconds");
sleep($_GET['delay']);
print ("Switching socket ".$_GET['switch']." ".$_GET['state']);
exec("sudo python /var/www/callenergenie.py ".$_GET['state']." ".$_GET['switch']);
?>

To allow PHP to run the script as root, I needed to add the Apache user to the list of sudo-ers.. not that secure tho :( I’d be interested in anyone who knows how to run the Energenie scripts a regular user.. their Python doesn’t like it when it’s not root.

nano /etc/sudoers

www-data ALL=(ALL) NOPASSWD:ALL

The nice thing about the PHP script is that we can actually call it to turn the Pi on remotely too.. so you could configure that into a widget on your phone, or add it to Alexa.

Adding IR Remote Control Support to the Raspberry Pi

In my last post I took you through how I created a small portable media centre that I can easily take on holiday to hook up to the hotel TV.

To reduce the amount space it took up, I used a cheap USB keypad which could be used to control the media center. It worked really well & having something hard-wired meant I didn’t have to worry about a Bluetooth-paired device needing re-pairing.

However, what I then realised was it would be good to be able to use a spare remote control instead. I was using the OpenElec distribution and looked through their documentation for how to do this, but only found references to version 3 of the software (it’s on version 7) and how to get LIRC working with it. There were plenty of blog posts on hooking up IR support, but a lot of them were written 2-3 years ago, and the software has moved on somewhat.

Hardware Setup

What I did first was buy a suitable IR receiver. I chose the Vishay TSOP4838 (which costs less than £1) because of the voltage range (2.5-5.5v) and receiver frequency (38KHz). If you look at the datasheet for the product, you’ll see which pins should get wired up to the Pi;

Simply wire pin 1 to GPIO 18, pin 2 to GND, and pin 3 to a 3.3v power pin, e.g.

By using some short F-F jumper wires and a small cut in the side of the case, I was able to position the reciever neatly(ish) on the side.. it’s still easily removable, but you could integrate it into the case a bit more seamlessly than this ;)

Software Setup

Before this project I was using OpenElec, but had limited success getting the IR support working properly. I switched to OSMC which I’d read had better IR support through the main UI. I think I was actually on the right track with OpenElec, but I realised later that the old vintage Xbox remote I was trying to use wasn’t 100% working.

If you’re going to use a remote control that’s officially recognised, then you can jump this part about learning IR remote control codes.

Learning IR remote commands

The remote I found in the loft was an old DVD player remote which (unsurprisingly) wasn’t in the list of pre-recognised remotes in the OSMC installation. I needed to get the Pi to learn the IR pulses being sent out by the remote and map them to the Kodi functions.

1. First off, you need to telnet to the Pi. Username: osmc, Password: osmc.

2. Next you need to stop the LIRC service which is being locked/used by Kodi

sudo systemctl stop lircd_helper@lirc0

3. Now you can run the IR learn mode.. this will record what it finds to the config file you specify;

irrecord -d /dev/lirc0 /home/osmc/lircd.conf

4. Follow the on-screen instructions which will recognise your remote.

One observation I had was that this only worked properly if I stopped after the first prompt to press lots of keys on the remote.. if I completed the second stage, the key mapping didn’t work, e.g.

If I ignored the second phase & let it abort, the learn process worked

When it’s working, you’ll be able to enter the Kodi function (like KEY_UP, KEY_DOWN, etc) & map it to a key press on your remote;

Once you’ve mapped all the functions you want, we then need to move back to OSMC and tell it to use that config file we’ve just written.

OSMC Settings

In OSMC you need to do the following;

1. Disable the CEC service (via System Settings > Input > Peripherals > CEC Adapter), which seems to be needed for LIRC to work.

2. Now go into OSMC settings and pick the Raspberry Pi icon

3. Go into Hardware Support and enabled LIRC GPIO Support. You shouldn’t need to change anything if you connected the sensor to GPIO 18.

4. Now go back and select the Remote Control option.

5. Ignore the list of pre-installed remotes and select Browse;

6. Navigate to the folder where LIRC wrote your config file;

7. Confirm the change & reboot the box;

That should be it.. your remote should be able to control everything in Kodi.

Portable Raspberry Pi Media Center

We recently went on holiday and I took my laptop & VGA cable with me. It was my intention to hook it up to the TV and play some media on it to keep the kids happy on rainy days. However, It turned out the TV had the VGA port covered up by the wall mounting bracket, and my laptop doesn’t have HDMI.. so we ended up putting the laptop on a chair and watching videos from there; it did the job, but wasn’t ideal.

At home we have a Fire TV Stick that could run Kodi, but the problem with Fire TV is that it has to have an internet connection, otherwise it doesn’t work (you can’t even get to Kodi!). Tethering it to my phone isn’t an option, since there are poor mobile signals in a lot of the places we visit.

Next time I’m going to be more prepared, with a more compact and flexible setup consisting of a Raspberry Pi 2 running OpenElec (and Kodi) together with a set of cables allowing me to hook it up to pretty much any TV. The Pi 2 runs Kodi really well, and the OpenElec distribution boots really quickly & has good Wifi and BlueTooth support. I initially chose a compact/travel USB-based keyboard instead of Bluetooth in case OpenElec ‘forgot’ the keyboard and I’d have nothing to navigate the menus to re-pair it.

Cable-wise, I’ve got a 1m standard HDMI cable, which will be fine in most situations.. with a 2m HDMI extension lead if I can’t get the Pi near enough to the TV (some accomodation doesn’t have power sockets where you’d expect them). I’ve also got a RCA lead, with a SCART adapter as well.. so that helps if we get stuck with an older TV.

For media storage I’ve gone with a USB3 Flash Drive with a capacity of 64Gb, which gives us more to play with than the microSD card, and it’s super-fast for copying media from a PC. As soon as you plug in the flash drive, Kodi will show it in the menus.

So that’s it.. nothing groundbreaking or overly difficult to put together. The whole system is small enough to fit in a small travel bag & gives us a lot of flexibility when dealing with different hotels/accommodation. You may just find the TV accepts the USB flash drive and can play back whatever is on it.. but at least you’ll have all the gear you need if it doesn’t ;)

After I made the video, I bought a USB numeric keyboard from eBay for a paltry £2.. that’s compacted the kit even further, allowing it to fit in an old camera bag.

The keypad isn’t instantly recognised by Kodi, but an easy way to get it up and running is to use the Keymap Add-on. Attach a normal USB keyboard and the keypad at the same time.. start the add-on and use the keyboard to activate the remap process. From there, it’s dead simple to map the keypad to the different Kodi functions.

Here’s the full kit list;

1 x Raspberry Pi 2
1 x 8Gb MicroSD card
1 x 2m HDMI extension cable
1 x 1m HDMI cable
1 x USB numeric keypad
1 x RCA to SCART adapter
1 x 3.5mm plug to RCA lead
1 x 64Gb USB3 Flash Drive
1 x USB power supply + cable

Update 1:

Just got back from a week at Center Parcs (Woburn) and was really pleased to find a HDMI socket on the wall, and a power socket.. it made it super easy to hook up the Pi to the TV :)

Update 2:

We spent a week near Blackpool, and the accommodation we stayed in had a patch panel as well! Seems like they’re quite common these days :)

 

Streaming video from the Humax HDR-Fox T2 to Android and Blackberry Playbook

One of the nice features of the Humax HDR-Fox T2 is that it’ll stream your standard definition recordings over your network to DLNA clients. I’ve had a it streaming video onto a PC running XBMC, but wanted something more portable for catching up with some TV whilst I’m getting ready in the morning.

As long as your Android phone is relatively recent, there are a bunch of DLNA clients.. the one I’ve had the best results with is Skifta. Then I’ve got MX Player installed which will handle video playback. The thing I like about MX Player is the gesture control for skipping through the program (swipe across), and adjusting volume (swipe up/down).

I’m running that on a Samsung Galaxy S3, and it works really well. It’s just slightly too small when it’s across the room. It would be better on a tablet, and I have a Blackberry Playbook (from their developer programme).. the only problem has been the lack of a DLNA client.. until just recently, when I found KalemSoft Media Player.

The app is currently being sold at £5, which was a bit more than I’m used to paying.. but the reviews were almost all really good, so I gave it a go. Here’s the app running with my Humax HDR-Fox T2;

As you can see, it’s really fast to browse the folders and start playing back video. It even manages HD if you’re running the auto-decode package, although I had buffering issues when trying to play it back over my network.

KalemSoft do a PC service which will share all your video from there too; I’ve found it works really well.. better than TVersity, and the built-in Windows media sharing stuff, both of which seemed to take ages to index my stuff, and then didn’t even work well after that. Apparently it can be configured to share stuff out over the Internet (password protected too), but I don’t need that feature. It can also stream live TV if you’ve got a TV card.

NZB-to-Server Automation

The HTPC I’m using is also my download box. It started to get really tedious to VNC onto it & surf for NZB files, and manage things that way. Now I do it all from my laptop and use a relatively simple batch script to get the NZB files onto the server.

Here’s what’s involved;

Automatic Save Folder – Firefox Add-On

This useful Firefox add-on is used to save the NZB files to a specific folder without even prompting me where to put it. Saves a few clicks and having to re-select the same folder all the time.

Batch Script

One I’m done with the NZB files I then use this simple batch script to map a network drive to the server & move them into a specific folder. This script is then pinned into my Windows 7 Programs folder so that it’s simple to run with a few keystrokes.

Rem EXTRACT ALL ZIP FILES

c:\progra~1\7-zip\7z x "C:\Users\blah\Documents\_altbinz\nzbs\*.zip" -o"C:\Users\blah\Documents\_altbinz\nzbs"

Rem DELETE ZIP FILES

del "C:\Users\blah\Documents\_altbinz\nzbs\*.zip"
del "C:\Users\blah\Documents\_altbinz\nzbs\*.nfo"

Rem MAP NETWORK DRIVE (TEMPORARY)

NET USE T: \\192.168.1.10\htpc /Persistent:No

Rem MOVE ALL FILES TO SERVER

move "C:\Users\blah\Documents\_altbinz\nzbs\*.nzb" "t:\usenet\nzbs-import\"

Rem UNMAP NETWORK DRIVE

NET USE T: /DELETE

pause

Alt.Binz Auto-Import Feature

The alt.binz client allows you to automatically import NZB files from a speified folder. It does this automatically & can delete the NZBs after it’s done. This is perfect for what I’m attempting to do here.

Harmony 600 Replacement

Due to a clash with a toddler and my Harmony 555 all-in-one remote I bought a Harmony 600 in September last year. In the last month it’s been repeatedly rebooting/restarting. A new set of batteries sorts the issue out, but only for a couple of weeks, and then it starts happening again. There’s a thread on Logitech’s support site which talks about the problem, so it’s not an isolated issue.

The good thing is, that after raising a support ticket on Sunday, it only took a couple of message exchanges before they said it was faulty & shipped a new remote. They don’t even ask for the old one back, since they can de-activate it on their servers so that it can never be updated online.. pretty much rendering it useless, because there’s no way to update it without using their online app.

Kudos to Logitech for sorting this out so quickly! Really impressive.

Building a Zotac ION-based HTPC

I’ve been looking to replace my ageing Xbox which has reliably run XBMC for over 7 years with a box that can handle HD content, as well as acting as a NAS & download server. The Zotac ION box caught my eye, since the latest media center apps now support hardware acceleration for video playback & the nVidia ION GPU is supported.

Components

I bought the kit as a bundle from Mini-ITX.com and fitted a 32Gb SSD for the operating system, and a 1TB Western Digital Essentials HDD which would be attached via USB & powers down when not in use. The shopping list looks like this;

– Zotac ION-ITX-A Motherboard with Dual Core 1.6GHz Atom N330
– 2GB or 4GB DDR2 800 RAM included
– M350 Universal Mini-ITX Enclosure
(bundle costing £233 from Mini-ITX)

– OCZ Onyx 32GB SATA II 2.5in Solid State Disk
(about £50 from Amazon)

– 1TB Western Digital Essentials
(about £45 from Amazon)

OS

For the OS I wanted to use Windows 7; that’s what I’m most comfortable writing scripts + code for. The Linux distros for XBMC Live look pretty good, but there was too much of a learning curve involved for adding in the extra features I wanted.

Installing OS From USB

Since there’s no optical drive, I opted to install Windows 7 from a USB key. I actually used a 4Gb SD card from my camera & a SD card reader, and followed these instructions to make it bootable & have the Windows 7 installation on it. Installation went without a hitch.

Media Player

After installing the OS, I updated with the latest nVidia drivers, and started installing apps like XBMC. The latest Dharma release of XBMC supports hardware acceleration using DXVA2, however I was unable to get it working with 1080p content & gave up after a couple of hours. I then tried Media Portal which worked perfectly with whatever I threw at it. There’s a brilliant guide on how to configure Windows 7 and MediaPortal by Rhys Jones, which is useful to follow if you want to optimise your HTPC setup.

Remote Control

Next up was getting the remote control working correctly. I had a cheapo CyberLink remote, plus a Harmony 600.. I used the Cyberlink IR Reciever & mapped up keys into the Harmony 600. Some of the buttons worked, some didn’t. I ended up re-mapping the numeric keys to certain MediaPortal features using one of the plugins. I also re-mapped the MCE Green Button so that it runs MediaPortal (see this guide.. scroll to the Green Button heading).

Scripts

The HTPC also acts as a NAS + handles any downloads, so I’ve written a bunch of scripts to handle certain situtations.

– Timed execution of certain download tasks using Windows Scheduler. Making sure that the tasks don’t bring the HTPC out of sleep.
– Execution of scripts when the HTPC is brought out of sleep (like making sure MediaPortal is running)

Keyboard + Mouse Control

For times when I need a keyboard, I’m running Unified Remote on the HTPC and the client on my Android phone. This allows me to control most aspects of the HTPC via my phone, without having to buy extra hardware like a wireless mouse/keyboard.