Purpose: Augmented reality is an exciting new area of computing, with many ‘apps’ available. On this Cranfield University site, we will describe building a server for the popular ‘Layar’ app (http://www.layar.com/), builds on the earlier GeoThread project to Build a LAMP server on the Raspberry Pi computer. The Raspberry Pi is an amazing low-cost computer (see http://www.raspberrypi.org/). The Layar server uses PHP, MySQL and Apache for serving up Layar ‘POI’ (point of interest) objects as a JSON (http://www.json.org/) data stream from the MySQL database.
The mobile phone and tablet ‘layar’ app allows you to connect to an augmented reality server to look at points of interest etc in the world around you. But what does the data the app ‘consumes’ look like? In this tutorial we use the Raspberry Pi to serve up Layar data as a JSON data stream.
This assumes you have a Raspberry Pi, installed with Apache, MySQL, PHP and PHPMyAdmin, plus vsftpd as per the earlier instructions. Get filezilla and ssh terminal working (or use the tightvnc service).
These notes are really to support and extend the basic ‘Layar’ tutorial at:
http://www.layar.com/documentation/browser/tutorials-tools/create-simple-geo-location-layer/
Download the layar sample source code (held in a zip file) at:
http://static.layar.com/media/content_media/186/FirstTutorial_APIv6.zip
Unpack the files. Note that we had to undertake this process manually in File Explorer, due to the format of the zipfiles not being accepted by the Windows ‘zip extract’ tool.
There are several parts to the tutorial files that you receive – an SQL script to build and populate the database, and then a number of PHP scripts.
If you are likely to load and reload and reload the SQL script – inevitably one does, then consider editing the SQL script to add these lines above each of their respective database table definitions (thus allowing you to rebuild the tables as required).
DROP TABLE IF EXISTS `Layar`; DROP TABLE IF EXISTS `POI`;Building web services always leads to a few errors until you fix the problems. We find it helps to turning on Apache and MySQL logging on the Raspberry Pi until such inevitable snags are removed. To do this, edit the configuration files thus:
cd /etc/mysql/my.cnf sudo nano my.cnfthen, uncomment the lines:
#general_log_file = /var/log/mysql/mysql.log #general_log = 1Now restart MySQL and the logging operation is commenced.
sudo service mysql restart tail –f /var/log/mysql/mysql.logReverse this to stop logging once all is working correctly.
sudo more /var/log/apacheor better still to see only new lines as they appear in (are being written to) the logfile
sudo tail –f /var/log/apache2
layar_customRun the supplied Layar example SQL script (use the IMPORT button for the database in phpmyadmin) to create and populate the two database tables. Create a new db user ‘layar’ (password ‘layar’ – or whatever you wish) and add privileges ‘select, insert, update, delete’ rights to the ‘layar_custom’ database on 127.0.0.1 (you can change the IP later for a public website address if you want to go that far).
sudo chmod 775 /var/www/layar sudo chmod 554 /var/www/layar/*Next, you need to customise the ‘config.inc.php’ file to enable your specific database credentials. Edit the file and add in your details, thus:
define('DBHOST', '127.0.0.1'); define('DBDATA', 'layar_custom'); define('DBUSER', 'layar'); define('DBPASS', 'layar');The files you uploaded, such as “192.168.1.100/layar/firstTutorial_simplified.php” have a call that loads in the configuration file above only once. You may find you need to disable this until the tool works. In which case, edit the require code thus: //require_once(‘config.inc.php’); require(‘config.inc.php’);
Changing from ‘require_once()’ to ‘require()’ means the code is read in every time you refresh the browser. Once all works, put it back as was.
http://192.168.1.100/layar/firstTutorial_complete.php?lang=en&countryCode=NL&lon=4.9342500000&userId=6f85d06929d160a7c8a3cc1ab4b54b87db99f74b&developerId=4441&developerHash=26ec094e19db2c4a82ebafa200ea2a5e87a7d671&version=4.0&radius=2500×tamp=1286357071952&lat=52.3741180000&layerName=layername&accuracy=100
http://192.168.1.100/layar/firstTutorial_simplified.php?countryCode=NL&lon=4.9342500000&userId=ed48067cda8e1b985dbb8ff3653a2da4fd490a37&radius=2500&lat=52.3741180000&layerName=layername&accuracy=100This returns a stream of ‘JavaScript Object Notation’ JSON data, e.g.
{"layer":"layername","hotspots":[{"id":"geo_1","imageURL":"http:\/\/custom.layar.nl\/Layar_banner_icon.png","anchor":{"geolocation":{"lat":52.374118,"lon":4.93425}},"text":{"title":"The Layar Office","description":"The Location of the Layar Office","footnote":"powered by Layar"}}],"errorCode":0,"errorString":"ok"}