Showing posts with label XBMC. Show all posts
Showing posts with label XBMC. Show all posts

Wednesday, 31 July 2013

Raspbmc as a wireless bridge

I have XBMC installed on a Raspberry Pi using Raspbmc to stream content to my TV over WiFi but I wanted to make use of the Pi’s Ethernet port to give internet access to a Sky+ set top box which only has an Ethernet port.

I started with a Raspberry Pi with Raspbmc installed over WiFi using an Edimax EW-7811UN USB WiFi adapter. My home network uses the 192.168.0.0/24 subnet with my WiFi router using 192.168.0.1 and the Raspberry Pi using a static IP of 192.168.0.51.

Setting up the bridge was based heavily on the following guide which is for Raspian:
http://qcktech.blogspot.dk/2012/08/raspberry-pi-as-router.html

The following post was also helpful in starting things at boot which is an area that Raspbmc differs from the above guide:
http://forum.stmlabs.com/showthread.php?tid=3552&pid=33455#pid33455

Raspbmc doesn’t use /etc/network/interfaces so you need to edit the settings.xml file:
sudo nano /home/pi/.xbmc/userdata/addon_data/script.raspbmc.settings/settings.xml
The WiFi settings were already configured from the install but you need to setup the wired interface. Give it a static IP in the “nm.address” entry (I used 192.168.1.1), set the gateway to the same IP, set an appropriate netmask and make sure DHCP is disabled for the wired interface and finally. I set the DNS to one of Google’s (8.8.8.8) but I’m not sure if this is needed.

My final settings.xml file looked like this:


If you want your Pi to give out IP addresses to devices connected to the wired port using DHCP, you can install isc-dhcp-server using the instructions in the link mentioned earlier, but I decided to use a fixed IP for simplicity.

I found that with both the USB WiFi and wired connections being used, my Pi wasn't reaching the internet any more. I fixed this by creating a script to set the default gateway for the Wifi adapter when the wired adapter comes up:
sudo nano /etc/network/if-up.d/wlan0defgateway
and adding the following:
#!/bin/sh 
if [ "$IFACE" = "eth0" ]; then  
  route add default gw 192.168.0.1 dev wlan0 
fi
then set permissions using:
sudo chmod 755 /etc/network/if-up.d/wlan0defgateway
 Next you need to enable IP forwarding by editing /etc/sysctl.conf using:
sudo nano /etc/sysctl.conf
Uncomment the line “net.ipv4.ip_forward=1” and save the file.

Finally setup iptables using:
sudo iptables -t nat -A POSTROUTING -o wlan0 -j MASQUERADE
Then save the iptables rules. I couldn’t save straight to /etc so I saved it in ~ and then moved it to /etc using:
sudo iptables-save > iptables.up.rules
sudo mv iptables.up.rules /etc

Create a script to restore the rules using:
sudo nano /etc/init/iptables.conf
And paste in:
# Restore iptables rules on boot 
start on (started dbus and started mountall) 
stop on (xbmc-do-stop or runlevel [!2345])  
exec iptables-restore < /etc/iptables.up.rules
Now restart the Pi and plug an Ethernet cable into the Pi and the other end into something else (I used a laptop for testing). Then set a static IP in the same range on the something else such as:
IP: 192.168.1.2
Netmask: 255.255.255.0 
Gateway: 192.168.1.1
DNS: 8.8.8.8 

Update:
I've noticed that the Pi doesn't keep its IP address recently (I'm not sure if a change in a recent release of RaspBMC caused this). I was able to fix it by editing the NetworkManager config file for the wired interface:
sudo nano "/etc/NetworkManager/system-connections/Wired connection 1"
And setting the IP address:
[ipv4]
method=manual
dns=8.8.8.8;
addresses1=192.168.1.1;24;192.168.1.1;
I then restarted NetworkManager with:
sudo service network-manager restart 
 

Friday, 26 August 2011

XBMC on the Apple TV 2

As previously mentioned, I've been playing with XBMC on the Apple TV 2.

Its worth noting that you need to finish running through the Apple TV setup (selecting language and location etc.) before you can access the device. This needs to be done after updating the firmware.

After installing the latest official build using these instructions I wanted to try the nightly builds. When attempting to update XBMC to a nightly version using the instructions on the same page, dpkg would halt on:
Preparing to replace org.xbmc.xbmc-atv2 10.0-9 ...

It turns out that because my Apple TV is running iOS 4.3, rm -rf which is used to remove the previous version when upgrading, is broken. I therefore needed to manually remove the previous version before updating using the following:
rm -r /Applications/XBMC.frappliance

Skins can be added manually to the Apple TV 2 build of XBMC by SSH'ing to it and downloading them with wget to the addons directory and unzipping:
cd /private/var/mobile/Library/Preferences/XBMC/addons/
wget <url of skin.zip>
unzip <skin zip file >
rm <skin zip file >
The skin can then be selected in XBMC (I'm using 'Night' at the moment).

If using an advancedsettings.xml for custom settings, this needs to go here on the Apple TV 2:
/private/var/mobile/Library/Preferences/XBMC/userdata
And the ever useful log file is at:
/private/var/mobile/Library/Preferences/xbmc.log

A Shared MySQL Database for XBMC

I want to use XBMC to stream media from my home server to various devices on my network. XBMC supports using a central MySQL database to store details about media such as the cast of a movie which can be accessed by any device on the network. This means that all devices are in sync, media only has to be scanned once rather than on each device and if you stop playback on one device you can resume from the same place on another device.

I followed this guide to set up the database.

I had to open port 3306 for TCP in the Vista firewall to allow devices to access to the database.

XBMC threw up some errors and I found that I had to scrap the databases I had created (xbmc_video and xbmc_music) and build them again with the following commands:
CREATE DATABASE xbmc_video CHARACTER SET latin1 COLLATE latin1_general_ci;
CREATE DATABASE xbmc_music CHARACTER SET latin1 COLLATE latin1_general_ci;

After getting it working with a XBMC 10.01 for Windows, I installed a nightly build of XBMC on an Apple TV 2 and found I had problems with the Apple TV build expecting a different database version. It looks like you need to be careful about using builds that that expect the same database version. XBMC creates the required tables automatically when scanning the library provided it can get to the DB and has access, so to rebuild the DB to a different version you just need to drop the tables (or drop and recreate the databases) and re-scan the library from XBMC.

The advancedsettings.xml file used by XBMC to enable the MySQL DB needed to go in the following locations:
Windows - C:\Users\<USERNAME>\AppData\Roaming\XBMC\userdata
Apple TV 2 - /private/var/mobile/Library/Preferences/XBMC/userdata

The XBMC log files are really helpful in diagnosing issues like these and are in the following locations:
Windows - C:\Users\<USERNAME>\AppData\Roaming\XBMC\xbmc.log
Apple TV 2 - /private/var/mobile/Library/Preferences/xbmc.log