I'm also including instructions on setting up a second Pi with Openelec as a client for this, but you can just as easily use XBMC installed on any computer.
NOTE: These instructions are for the terrestrial Freeview HD service, and assume you already KNOW that you have sufficient Freeview HD coverage at your house. All this tutorial is for is to distribute Freeview from a central location to places you don't have decent coverage, or (as in my case) don't have an aerial port where you want to put the TV, or if you don't have a TV, but want to use your PC instead.
For the record, this setup should work for Freeview satellite, if you replace the DVB-T tuner for a DVB-S tuner, but as I don't have a DVB-S tuner, I can't comment on that.
Related: If anyone can recommend a good, small, low-cost USB DVB-S tuner, please let me know. :-)
=======================
SERVER
=======================
What you need:
- Raspberry Pi (with SD card and power supply)
- DVB-T Tuner - I got three of these from TradeMe.
- Aerial Cable
Optional:
- USB HDD (for recording programmes)
- Multiple tuners (for watching channels on different multiplexes at the same time)
- Powered USB Hub (likely required if you want multiple tuners and a hard drive - this one works nicely)
1. Install Raspbian
The instructions on the site are better than any I would provide, so please refer to those. I would suggest you set Debian up with console access only. X Windows would simply add extra load to the Pi.
Once complete, SSH into your Pi (or login if you have a screen and keyboard) using the default "pi" user. The remaining steps all assume you're logged in as this user.
2. Setup the DVB-T Tuner(s)
Given the large number of possible DVB-T tuners out there, I can't provide instructions on how to get Linux drivers for all of them. However, a large number of the cheaper ones probably use the same chipset, which is the ITE9135 chipset. The drivers for that chipset (which includes the tuner linked above) can be downloaded from my Dropbox. If that link doesn't work, let me know.
You can download this file straight to the right location on your Pi with the following commands:
cd /lib/firmware
sudo wget https://dl.dropboxusercontent.com/u/6101726/Raspbian/dvb-usb-it9135-02.fw
Now plug in the USB DVB-T, and type:
dmesg
You're looking for a line that says something like:
usb 1-1.4.1: dvb_usb_v2: 'ITE 9135 Generic' successfully initialized and connected
If you see that, you're good to go. If not, feel free to reply below with the messages you do see, and I'm sure someone here will be able to help figure out why it's not working. :-)
Note, if you have multiple tuners of the same type, you only need to install the firmware once. They all use the same file.
At this point, make sure you've got everything plugged in. If you have an external USB drive, plug that in now, and the same with all the DVB-T devices you have.
You also want to connect the DVB-T tuners to an aerial. I have a UHF aerial on the roof, with an 8 way splitter in the cupboard under the stairs. Since that's where I've put the Pi, the tuners are all connected to this splitter with their own cables.
Depending on where you are, you may get away with an internal aerial. I tested my setup with the tiny aerial that came with the tuner, but I can see the Waiatarua tower from my office chair. It's more likely you'll need to hook it up to an aerial on your roof.
3. Install TVHeadend
The simplest way to do this is by installing from the TVHeadend Debian repository. To allow access to the repository, run the following commands:
curl http://apt.tvheadend.org/repo.gpg.key | sudo apt-key add -
sudo apt-add-repository http://apt.tvheadend.org/stable
This adds the repository to your server so you can install from it. Now you need to edit the /etc/apt/sources.list file, and add the following line (sorry, use of nano or vi is beyond the scope of this write up):
deb http://apt.tvheadend.org/stable wheezy main
Then finish the installation by running:
sudo apt-get update
sudo apt-get install tvheadend
And get a drink or three. That last one can take quite a while, especially if you've got a slower SD card. Once it's finished, it will automatically start the server for you, and also sets it up so it will start whenever the Pi restarts.
You will be asked to complete some information, such as providing an admin login username and password.
4 (optional). Set up the USB Hard Drive
If you want to add a USB hard drive for recording programmes, or for timeshift (live pause), then you will need to set it up first.
Plug the disk in, and run the following:
sudo fdisk -l
This will show you the connected disks. Assuming you've only got one USB disk installed, it should appear as /dev/sda, but make sure of that before you continue. Note if you have multiple disks, these instructions may not be the best to follow, as they really do assume you've only got one. You have been warned.
To prepare the disk for use, you will need to format it. THIS WILL DELETE EVERYTHING ON IT, so make sure it's a disk with nothing you care about on it.
sudo fdisk /dev/sda
Change as appropriate for your disk.
Delete all existing partitions by pressing d, and selecting each in turn. Then press c to create a new partition, and allow it to fill the disk. Save your changes by pressing w.
Now format the new partition:
sudo mkfs.ext4 /dev/sda1
Once formatted, mount the disk to make sure it's all working. I put my mount point into /media, but you can put it where you like.
cd /media
If the directory "usb" exists, great, if not, create it with:
sudo mkdir usb
Then mount the USB drive in that directory, and create a directory for TVHeadend to use:
sudo mount /dev/sda1 /media/usb
sudo mkdir /media/usb/data
sudo chmod 0777 /media/usb/data
Now you want to make sure your disk is loaded each time you restart the Pi. Edit /etc/fstab (again, I'm not going to tell you how to use vi), and add the following line at the end:
/dev/sda1 /media/usb ext4 defaults 0 0
Once done, I would suggest rebooting the Pi, then logging back in, and making sure you can still access the USB drive at /media/usb/, and that you can write to the /media/usb/data/ directory as the "pi" user (ie - without sudo).
5 (optional). Configure the EPG
The method Freeview uses to broadcast the EPG over-the-air is apparently a little difficult for TVHeadend to use. Thankfully there are some kind people that provide a download the the data in a convenient format. To use this, you'll need to add a script to your Pi.
cd /usr/bin
sudo wget https://dl.dropboxusercontent.com/u/6101726/Raspbian/tv_grab_nz-py
sudo chmod a+x tv_grab_nz-py
This provides the script that TVHeadend can use to download the data, but you do need to configure it first. Note that download is from my Dropbox account again, and I've made a small change to the script that is available elsewhere.
The script originally had an issue with the accented character in the word Maori, which caused the script to crash. This version just removes that character, so when you see "Mori Television", that's why.
sudo /usr/bin/tv_grab_nz-py --configure
Run through the prompts to select the channels you want. I just said yes to all of them, which is unfortunately not the default. Note there are some missing (eg. YESSHOP), and some that no longer exist (eg. U).
Now onto the fun part.
6. Configure TVHeadend
To make sure everything is available, it's a good idea to restart TVHeadend before you start to configure it. This makes sure it can see the EPG script and tuners if you've added them after installing it.
sudo service tvheadend restart
From your PC, log into the TVHeadend admin site with the credentials you set up way back in step 3. This will be by entering the IP address into your browser (eg http://192.168.1.50:9981/).
6.1 EPG
Let's start with the EPG, as TVHeadend can figure out the channels automatically if that's already there. Go to Configuration -> Channel/EPG -> EPG Grabber. If you've added the script correctly, you should be able see it as "XMLTV: New Zealand (py)" in the "Module" list for the Internal Grabber section. If you can't see it, go back and make sure it's been set up correctly as above.
Set the grab interval to 1 day. The online file is only updated daily, so more than that is unnecessary.
6.2 Adapter Setup
Now jump over to Configuration -> DVB Inputs. If everything is working as expected, you should be able to see your USB tuners listed in the drop-down box on the TV Adapters tab. If they're not there, it's likely the driver isn't installed properly. Jump back up to step 2 above, and make sure that's working before coming back.
Assuming you do see your tuners in the list, select one of them.
If you have multiple tuners, you probably want to give it a useful name, otherwise make sure the following options are ticked:
Enabled
Autodetect muxes
Idle scanning
Close device handle when idle
The rest should be unticked, or left at default values. Save. Do this for each adapter you have.
6.3 Multiplexes
Now for any adapter, switch to the multiplexes tab, and click "Add mux(es) manually...". Set the bandwith to 8MHz, and everything else to auto. For the frequency, the only list I've found is here. Unfortunately, I know that list is wrong, but it's a good starting point.
For the Waiatarua tower in Auckland, the frequencies you want are 538MHz, 570MHz, 586MHz and 602MHz. Since you need to enter them in kHz, enter 538000 etc. Add them all one by one, until you've got all 4 in. Then click the "Save Changes" button at the top.
At this point TVHeadend should scan the muxes to find channels. Leave it for a while to give it a chance to do this, then head to the Services tab. With luck, you'll see a whole bunch of channels, including duplicates, and some that don't work.
Once all the services are showing happily, head back to the General tab under the adapter list, and hopefully you can click the "Map DVB services to channels..." button. If not, or if the number under "Muxes awaiting initial scans" on the right is not 0, wait a bit longer, or try refreshing the page, and coming back here.
Click "Map DVB services to channels...".
If you have multiple adapters, you need to copy the multiplexes to them. Go back to the Multiplexes page for the adapter you have already set up, and select all the multiplexed (hold down Shift and click each in turn). Then click the "Copy to another adapter..." button, and select one. Repeat for each extra adapter.
6.4 Channels
Now head over to Configuration -> Channel/EPG -> Channels. There should now be a list of channels ready to be viewed. Hopefully most of them have an entry under the "EPG Grab source" columns as well. If not, double click the column and match it as appropriate.
Similarly, you can change or add the channel number assignments by double clicking on the "Number" column and entering what you like. Once you've set it up as desired, make sure you click the "Save Changes" button at the top.
6.5 (optional) Recording
Go to Configuration -> Recording. For the "Recording system path", enter the path that you mounted your USB drive on. I would recommend using a subdirectory in case you want to put anything else in there.
/media/usb/data/pvr
Select all the other options as desired. I don't believe the "Skip Commercials" option works in NZ, but we can always hope. :-)
Click "Save configuration".
=======================
At this point it should all be working. If you go to the "Electronic Program Guide" page, you should see a (horribly formatted) list of programs. If you have VLC installed, you can quite easily test it.
Click a currently showing program in the EPG, then click the Play link. This will open a box that will say you don't have the VLC Mozilla plugin. Right click the "Direct URL" link, and copy the link.
Open VLC, then File -> Open Network. Paste in the URL, and click Open. The username and password are the same as you entered for the admin (note you can set up different usernames via Configuration -> Access Control in the TVHeadend admin). You should now be watching TV.
======================
CLIENT
======================
If you want to setup a Raspberry Pi client, start with step 1. If you want to set up any other XMBC installation, jump to step 2. Note it's WAY easier to install XBMC on your PC to test before trying to set it up on a Raspberry Pi.
1. Install OpenELEC
What you need:
- Raspberry Pi (with SD card, power supply and HDMI cable)
Note - get the official Raspberry Pi image from this page. They haven't updated the installation instructions with the new image location. I'm running the 4.1.4 beta, and it seems perfectly stable to me.
I'm not going to cover setting up network, remote controls etc here. If you need help with that, I would recommend Googling, or asking in another stream. It's been pretty well covered.
Aside: If you prefer RaspBMC or Xbian, they'll both work too, and the instructions below are still valid for them. I prefer OpenELEC over RaspBMC as it seems much more responsive in the menus, and seems to start playing videos quicker. I haven't tried Xbian myself.
2. Configuring XBMC (note this works for all XBMC clients, not only OpenELEC)
Quick tip - if you're configuring OpenELEC on a Raspberry Pi, there are remote control apps for both iOS or Android that make it a lot easier. Not only do they have all the necessary buttons, but you can use the on-screen keyboard too!
Go to the System -> Settings menu, then select Add-Ons -> Disabled Add-Ons -> Tvheadend HTSP Client. Enable it, then click Configure, and enter the IP address, username and password of your server.
Back in System -> Settings, select Live TV. Under the General options, make sure it's Enabled, then select "Reset the PVR database". You should see the system pulling all the channel data from the server.
Configure everything else as desired.
Now you should be able to select Live TV from the main menu, and view the EPG, and all the channels shown in the TVHeadend admin page.
If the TV channels are interlaced, you can fix that by selecting the "Video" options while viewing a channel (bring up the OSD and look for the Reel icon). Switch Deinterlace Video to "Auto", then select "Set as default for all videos", and close.
If you see unwanted subtitles, bring up the OSD and select the "Sound" options (speaker icon), deselect "Enable subtitles", and again select "Set as default for all videos".
Test the PVR functionality by selecting a program in the EPG, and selecting record. Since recordings are saved by the server, you can play them back on any XBMC client you have, which is a nice feature. You can also download the saved files from the TVHeadend web admin if you want to do that.
You should be able to view all the channels without issue on a Pi XBMC client, including HD channels. The Pi is a fantastic little computer, and is quite able to cope with this.
=======================
Well, I hope somebody finds this useful. If/when you find errors in what I've written, or if I've missed something, please let me know and I'll fix this post.
If you have any questions or comments, please fire away, and I'll be happy to help out as I can. If you're an incredibly generous soul and want to donate a USB DVB-S tuner for me to try out, get in touch.
