Tutorial: PlexConnect on a Tomato router via entware

Requirements

- USB stick - 1G or more in size

- USB-capable router running TomatoUSB.

 

Install entware

Pick a USB stick that you can dedicate to your router since it will be completely erased by the following process.

 

Configure the GUI for entware

In the web GUI, go to the "USB and NAS->USB Support" section and tick the following options:

[x] Core USB Support
[x] USB 2.0 Support
[x] USB Storage Support
[x] Ex2/Ext3 File Systems Support
[x] Automount

 

Paste this text into the "Run after mounting" box:

#!/bin/sh
/opt/etc/init.d/rc.unslung start

Paste this text into the "Run before unmounting" box:

#!/bin/sh
/opt/etc/init.d/rc.unslung stop
sleep 15
for i in `cat /proc/mounts | awk '/ext3/{print($1)}'` ; do
  mount -o remount,ro $i
done 

Click the "Save" button and then check the "USB Status" at the bottom of the screen. If your USB stick is mounted, click "Unmount". In subsequent steps, we are going to format the USB stick, so we don't want it mounted.

 

Go to the "Administration->Scripts->Init" page. Paste the following into the "Init" script section:

echo "LABEL=ENTWARE /opt ext3 rw,noatime 1 1" >> /etc/fstab
sleep 5
python /opt/PlexConnect/PlexConnect.py

Go to the "Administration->Scripts->Init" page. Paste the following into the "Firewall" script section:

iptables -t nat -A PREROUTING -s 192.168.1.111 -d 192.168.1.1 -p tcp --dport 80 -j DNAT --to-destination 192.168.1.1:8080
iptables -t nat -A PREROUTING -s 192.168.1.111 -d 192.168.1.1 -p tcp --dport 443 -j DNAT --to-destination 192.168.1.1:8443 

substitute your AppleTV IP address for 192.168.1.111 and your router's IP address for 192.168.1.1

 

Click the "Save" button.

 

For reference, most of the above is taking from the entware USB setup instructions.

 

Prepare the USB stick

Plug the USB stick in and ssh to the router. Remember, the next steps will completely erase the USB stick!

 

Find the device name for your USB stick

Run "fdisk -l" to display all the block devices and their partitions. Here is an example:

# fdisk -l

Disk /dev/sdb: 16.2 GB, 16231956480 bytes
64 heads, 32 sectors/track, 15480 cylinders
Units = cylinders of 2048 * 512 = 1048576 bytes

Device Boot Start End Blocks Id System
/dev/sdb1 1 15480 15851504 83 Linux 

You can see that the disk /dev/sdb is a 16GB block device. Since there are no other 16GB devices on my router, I can be pretty sure that the 16GB stick that I plugged in is mapped to /dev/sdb.

 

Partition the USB stick

Use fdisk to delete all the partitions on your USB disk. Then create a single partition spanning the entire drive and set its type to 83 (Linux). Write the partition table and exit fdisk.

 

Format the USB stick

Replace the /dev/sdb1 below with the path to your newly created partition.

mkfs.ext3 -L ENTWARE /dev/sdb1

Perform the entware install

mount /opt
entware-install.sh 

REBOOT the router.

 

PlexConnect

​Now that entware is installed on your router, it is time to add PlexConnect.

 

Install PlexConnect dependancies

opkg update
opkg install git
opkg install python
opkg install python-openssl
opkg install pyload
opkg install nano
opkg install ca-certificates

Create a Symlink for Git

ln -s $(which git) /opt/lib/git-core/git

Install PlexConnect

cd /opt
git clone git://github.com/iBaa/PlexConnect.git

Create Certificates

mkdir /opt/PlexConnect/assets/
mkdir /opt/PlexConnect/assets/certificates/
openssl req -new -nodes -newkey rsa:2048 -out /opt/PlexConnect/assets/certificates/trailers.pem -keyout /opt/PlexConnect/assets/certificates/trailers.key -x509 -days 7300 -subj "/C=US/CN=trailers.apple.com"

openssl x509 -in /opt/PlexConnect/assets/certificates/trailers.pem -outform der -out /opt/PlexConnect/assets/certificates/trailers.cer && cat /opt/PlexConnect/assets/certificates/trailers.key >> /opt/PlexConnect/assets/certificates/trailers.pem

chmod -R +x /opt/PlexConnect
chmod -R 755 /opt/PlexConnect

Settings.cfg

Run PlexConnect so it will create Settings.cfg

cd /opt/PlexConnect
./PlexConnect.py

wait few secs and stop PlexConnect with CTRL + C

 
use nano to make the following changes to Settings.cfg:
change port_webserver from 80 to 8080
change port_ssl from 443 to 8443
change ip_plexconnect to your router's IP address (192.168.1.1)
enable_dnsserver = False
enable_plexconnect_autodetect = False
nano /opt/PlexConnect/Settings.cfg
[PlexConnect]
enable_plexgdm = True
ip_pms = 192.168.178.10
port_pms = 32400
enable_dnsserver = False
port_dnsserver = 53
ip_dnsmaster = 8.8.8.8
prevent_atv_update = True
enable_plexconnect_autodetect = False
ip_plexconnect = 192.168.1.1
hosttointercept = trailers.apple.com
port_webserver = 8080
enable_webserver_ssl = True
port_ssl = 8443
certfile = ./assets/certificates/trailers.pem
allow_gzip_atv = False
allow_gzip_pmslocal = False
allow_gzip_pmsremote = True
loglevel = Normal
logpath = . 

CTRL + X to exit and Y for save. 

 
Dnsmasq Custom Configuration

On your router's Tomato web page, Go to Advanced -> DHCP/DNS -> Dnsmasq Custom configuration and enter:

address=/trailers.apple.com/192.168.1.1
address=/atv.plexconnect/192.168.1.1 
substitute your router's IP address for 192.168.1.1
 
REBOOT your router
 
AppleTV
Now that PlexConnect is installed, we must configure your AppleTV.  We are using iptables and dnsmasq to do the redirections so changing your AppleTV's DNS is not necessary.
 
1.) Go to the AppleTV settings menu.
2.) Select “General” then scroll the cursor down to highlight “Send Data To Apple” and set to "No".
3.) With "Send Data To Apple" highlighted, press “Play” (not the normal “Select” button) and you will be prompted to add a profile.
Enter:
http://trailers.apple.com/trailers.cer

ENJOY!

 

How to Update

To update entware:

opkg update
opkg upgrade

To update PlexConnect:

cd /opt/PlexConnect
git pull 

Credit to dferg and shroud for their contributions to the community.

Edited by moderation to include ca-certificates as prereq

This seems to work prefectly for me. Thanks for this.

Thanks for this, saved for future reference

I just tried updating entware and PlexConnect. Entware update when fine but when updating PlexConnect I get the following error:

fatal: Unable to find remote helper for 'https'
 

any ideas why?

I just tried updating entware and PlexConnect. Entware update when fine but when updating PlexConnect I get the following error:

fatal: Unable to find remote helper for 'https'
 

any ideas why?

I have just experienced the same issue.  It appears Entware has overhauled python.  I've update the tutorial to include the necessary changes.  All of these steps may not be necessary but it successfully worked for me.

How to upgrade:

- backup /opt/PlexConnect/Settings.cfg

- backup certificates

- remove the folder /opt/PlexConnect

- uninstall the existing packages

- reinstall the necessary packages (python-expat is no longer available/necessary)

- creat a symlink to git

- git clone PlexConnect using git:// instead of https://

- restore certificates

- restored Settings.cfg to /opt/PlexConnect/Settings.cfg

- reboot

Barring another Entware overhaul, future updates should be possible as stated in the above tutorial.  Below are the commands outlined above:

mkdir /opt/PlexConnect_backup
cp /opt/PlexConnect/Settings.cfg /opt/PlexConnect_backup/Settings.cfg
cp /opt/PlexConnect/assets/certificates/trailers* /opt/PlexConnect_backup/

rm -R /opt/PlexConnect

opkg remove --force-removal-of-dependent-packages git
opkg remove --force-removal-of-dependent-packages python
opkg remove --force-removal-of-dependent-packages python-openssl
opkg remove --force-removal-of-dependent-packages python-expat
opkg remove --force-removal-of-dependent-packages pyload

opkg update

opkg install git
opkg install python
opkg install python-openssl
opkg install pyload

ln -s $(which git) /opt/lib/git-core/git

cd /opt
git clone git://github.com/iBaa/PlexConnect.git

cp /opt/PlexConnect_backup/trailers* /opt/PlexConnect/assets/certificates/

mv /opt/PlexConnect_backup/Settings.cfg /opt/PlexConnect/Settings.cfg

rm -R /opt/PlexConnect_backup

chmod -R +x /opt/PlexConnect
chmod -R 755 /opt/PlexConnect

reboot

If your updating why not copy the old certificates and reload them into the certificates folder, that way your atv will already have the correct profile. Just saves a step and confusion

If your updating why not copy the old certificates and reload them into the certificates folder, that way your atv will already have the correct profile. Just saves a step and confusion

Great suggestion.  Upgrade procedure updated.

Thanks for this.  I gave it a try but I must have messed something up trying to do the update. I had to reinstall Entware from scratch.  Since TomatoUSB hasn't been updated for move away from googlecode, to install Entware I had to use:

wget -O - http://entware.wl500g.info/binaries/mipselsf/installer/entware_install.sh | sh

Reinstalling also reminded me that I had to use

mount /dev/sda1 /opt

instead of just mount /opt . (or sbd1 if that is the case)

Finally, since there may be someone trying to follow this, without knowing how to partition the USB stick, you may want to add instructions for this:

#Partition your usb flash drive
umount /dev/sda1
fdisk /dev/sda

Type in the following commands to create a primary partition on your USB Flash drive
# p # list current partitions
# o # to delete all partitions
# n # new partition
# p # primary partition
# 1 (one) # first partition
# # default start block
# # default end block #use the whole flash drive
# w # write new partition to disk

Once again, thanks for the great instructions.

Would this work using a Netgear WNR3500Lv2 with Tomato 1.28 firmware "inside" the ISP router connected LAN to LAN with all devices on the same IP range and subnet mask? There is no DHCP anywhere. Currently, the Neatgear is providing VPN access to the ATV so I can watch my Netflix account from overseas. The PMS and PC are currently on a MacMini where the media files reside.

In this instruction set:

[PlexConnect]

enable_plexgdm = True
ip_pms = 192.168.178.10
port_pms = 32400
enable_dnsserver = False
port_dnsserver = 53
ip_dnsmaster = 8.8.8.8
prevent_atv_update = True
enable_plexconnect_autodetect = False
ip_plexconnect = 192.168.1.1
hosttointercept = trailers.apple.com
port_webserver
= 8080
enable_webserver_ssl = True
port_ssl = 8443
certfile = ./assets/certificates/trailers.pem
allow_gzip_atv
= False
allow_gzip_pmslocal = False
allow_gzip_pmsremote = True
loglevel = Normal
logpath = .

Is it not necessary to change the IP in red to the IP address of where PMS resides?

In this instruction set:
[PlexConnect]
enable_plexgdm = True
ip_pms = 192.168.178.10
port_pms = 32400
enable_dnsserver = False
port_dnsserver = 53
ip_dnsmaster = 8.8.8.8
prevent_atv_update = True
enable_plexconnect_autodetect = False
ip_plexconnect = 192.168.1.1
hosttointercept = trailers.apple.com
port_webserver = 8080
enable_webserver_ssl = True
port_ssl = 8443
certfile = ./assets/certificates/trailers.pem
allow_gzip_atv = False
allow_gzip_pmslocal = False
allow_gzip_pmsremote = True
loglevel = Normal
logpath = .


Is it not necessary to change the IP in red to the IP address of where PMS resides?


Because the line above (enable plex gdm) is true this IP address is ignored.

Thanks.