Saturday 29 May 2010

Setting up a Development Environment

In order to perform any development, you need a development environment. How you choose to setup yours is up to you, however below I will detail how I did mine. Whichever way you choose you need to do 4 things: -
  • Provide a web server to serve up your modified content.
  • Create a web proxy server to redirect access to your web server.
  • Point your Panasonic device to your web proxy.
  • Download and host content from Panasonic's Viera Cast servers and modify them to your needs. This will be covered in the next post.
For my current environment I'm using Ubuntu Linux since it provides a full set of features including Apache 2 (web server) and Squid (web proxy). In future I intend to replicate this setup on my Western Digital MyBook World (NAS unit), which has a much smaller power footprint and is always-on. In theory the same should be possible for other customisable NAS units (Synology, Q-NAP et al).


Web Server

The web server I use is Apache 2. For development purposes I'm using a bog-standard out-of-the-box installation. In Ubuntu this serves pages from /var/www on port 80.


Web Proxy

The web proxy I'm using is Squid (default port 3128). I modified this slightly (by editing /etc/squid/squid.conf) to minimize the footprint as follows: -
  • Add "http_access allow all" (bad practice but this is development in my own home - You need to add something that lets your TV/device and development PC access the proxy).
  • Add "cache_dir null /tmp" and "maximum_object_size 0 KB" (to disable disk cache - we only care about the URL redirection features so this saves space).
  • Add "useragent_log /var/log/squid/useragent.log" (the reason will become clear soon).
  • Add "url_rewrite_program /etc/squid/mirror_and_redirect.sh" (this points to a redirect script we will create)
I then created a URL rewrite program called /etc/squid/mirror_and_redirect.sh (and made it executable) containing the following: -

#!/bin/bash

while read url rest; do
filename=`echo $url | sed 's^http://^^g' | sed 's^?.*^^g'`
if [ -f /var/www/$filename ]; then
# We found a matching local file to replace, so redirect to it and log the redirect.
echo "http://localhost/$filename"
echo "http://localhost/$filename" >> /var/log/squid/mirror_and_redirect.log
else
# No match, so don't modify the URL and log the URL.
echo
echo "$url" >> /var/log/squid/mirror_and_redirect.log
fi
done

The purpose of this script is a follows. Every HTTP request passed via our proxy is parsed by the script and compared against the contents of /var/www. If a matching file exists then it adds a redirect to http://localhost/our_replacement_file to redirect the client (i.e. the Panasonic device) to our local modified file. It logs all this information to mirror_and_redirect.log so we can see what's been served locally and what's been passed through.


Configure TV

Finally I configured my TV to access the web via the proxy. On my Panasonic G20 Plasma this is accessed under Menu...Setup...Network Setup...Proxy Settings. I set the address to the IP address of my Ubuntu server and port to 3128 (Squid). How you do yours depends on what you've got. If you can't figure it out, you probably shouldn't go any further :D

Assuming Squid is now working, Viera Cast should work as normal on your device. And now the fun begins...

6 comments:

  1. I'm glad to find this blog :-)

    If you control the local DNS in your lan, you can also "poison" it so it responds with the IP address of your own webserver to all requests done to 'vieracast.eu'. Then, with some php + curl magic you can implement the mirror-and-redirect stuff.

    I did something similar to inject my own RSS feed instead of the default bloomberg news :)

    ReplyDelete
  2. I've improved your mirror_and_redirect script, please find it here...

    http://www.zaurus.org.uk/download/scripts/mirror_and_redirect.sh.txt

    ReplyDelete
  3. How I can set my user and password of my proxy connection in my 42g20?
    I can setup adress and port but i don't find anymore to set user and password. When I've executed the list of net task tv send the message about proxy error autentication...

    Thanks..

    ReplyDelete
  4. Hi

    I am new to the Vieracast environment. I want to create an app with multiple screens with navigation between them. Do I need multiple STAGE object. How to do this? Can you give me a simple example?

    Thank you so much!!

    ReplyDelete
  5. Hi

    I have create a forum dedicated to discussion on vieracast development in the hope of gathering all information in one place.

    Check it out here:
    http://vieracast.hotsource.net/

    ReplyDelete
  6. http://vieracast.hotsource.net/

    ReplyDelete