Wednesday 28 March 2012

Web Application System Setup and Architecture

We can run web applications from embedded device.  There are 3 ways to access the web applications.

1) Internal network, such as using http://192.168.1.1
   This is straight forward. Devices connected internally through the Local Area Network are able to access the embedded device, eg. using the embedded device internal IP address of 192.168.1.1.

2) Dynamic DNS, such as using http://victor.dyndns-blog.com
   Devices connected through Internet, access the embedded device via Dynamic DNS. The embedded device needs to run a dynamic DNS client, such as inadyn. inadyn supports www.dyndns.org. The user needs to register a hostname on www.dyndns.org. The hostname will point to the dynamic IP address of the embedded device.

3) Apache Web services, such as using http://service.victor.com
  Deployed the web application front-end on Apache web services, the Apache web services will do reverse proxy to the web applications back-end on the embedded device. The front-end can be developed using Javascript, JQuery, SQL, Java server application such as Tomcat.

Setting up web applications on embedded device:

1) install php and lighttpd
  PHP is an HTML-embedded scripting language. The goal of the language is to allow web developers to write dynamically generated pages quickly.
 Lighttpd is a web server built for embedded systems.

2) setup php.ini

3) setup lighttpd.conf

fastcgi.server             = ( ".php" =>
                               ( "localhost" =>
                                 (
                                   "socket" => "/tmp/php-fastcgi.socket",
                                   "bin-path" => "/usr/bin/php-cgi"
                                 )
                               )
                            )


url.rewrite-once = (
         "^/z/$" => "/z/app/webroot/",
         "^/z/home/(.*)" => "/z/home/$1",
         "^/z/(js|ico|gif|jpg|png|css)/(.*)" => "/z/app/webroot/$1/$2",
         "^/z/(.*)$" => "/z/app/webroot/index.php?url=$1"
      )

4) install cakephp
CakePHP is a freeopen-sourcerapid development framework for PHP It helps programmers to create web applications.

5) setup cakephp
   Modify routes.app

Router::connect('/devices', array('controller' => 'devices', 'action' => 'index'));
 Router::connect('/devices/:action/*', array('controller' => 'devices'));

6) Install sqlite database
Sqlite is a light weight SQL database engine

Web applications access to Bluetooth devices

Imagine there are two ways, one on right hand side, read direct from bluetooth devices, the other on left hand side, read from database on embedded device.


Thursday 1 March 2012

IP Port Forwarding

check:
cat /proc/sys/net/ipv4/ip_forward

enable:
echo "1" >  /proc/sys/net/ipv4/ip_forward

Example iptables rules: (forward port 81 to 192.168.60.10:80)
/usr/sbin/iptables -A FORWARD -p tcp --dport 80:80 -m state --state NEW,ESTABLISHED,RELATED -j ACCEPT
/usr/sbin/iptables -t nat -A PREROUTING -p tcp --dport 81:81 -j DNAT --to 192.168.60.10:80