Webserver and database combination on Raspberry Pi

My normal combination on the big-server side would be Apache + MySQL (or PostgreSQL), but on the RPi this seems to be absolute overkill. For data-logging operations I would not use the local system anyway (looking at MQTT as well as Remote MongoDB datastore via REST Webservices). After some poking around and reading up on the options I decided to go for the following combo: LightHTTPD + SQLite. Both are lightweight replacement of their fully-featured big-server counterparts (Apache HTTP & MySQL) and have very familiar configurations. There would be other options that have even less resource usage, but I really don't have the time to start from scratch somewhere. Another reason to go for this combination is that these are very well supported systems with regular security audits. Even though I am not planning to use my RPi's for anything mission-critical this is always worth a consideration as you don't need to unnecessarily introduce vulnerabilities to your network. Install & configure LightHTTPD sudo apt-get install lighttpd php5 php5-cgi php5-sqlite sudo lighty-enable-mod fastcgi sudo lighty-enable-mod fastcgi-php Further config changes can be also made via the config file. sudo vim /etc/lighttpd/lighttpd.conf sudo service lighttpd force-reload Install & configure SQLite sudo apt-get install sqlite3 sqlite3 /home/username/database_name.db All other commands are standard SQL from the 'sqlite>' command prompt or via SQL scripts like sqlite3 /home/username/database_name.db < sql_script.sql Access Databases from the webserver (using PHP) < ?php $db = new SQLite3('mysqlitedb.db'); $results = $db->query('SELECT bar FROM foo'); while ($row = $results->fetchArray()) { var_dump($row); } ?>…

Continue Reading

Chromebook tips to get started

Just got myself (actually it's for our Office Manager back in OZ) one of these Chromebooks while in Europe (since Google Australia with their absolutely hopeless hardware strategy do not seem to be able to ship any devices - Nexus 4 anyone ?) . Since the first days turned out to be a bit of a frustrating experience, I thought I share some of the findings as I had a hard time finding much useful info on troubleshooting ChromeOS. Wireless Connection (WIFI) Do not use WPA (or for that matter WEP) connections with ChromeOS. I had extreme difficulties browsing webpages on the Chrombook. Some pages would load, some pages would not load at all. There seemed to be no consitency to it as some would load one day, but not another. Somewhere in the Google Groups there seemed to be people reporting issues with wireless connections using WEP. It turned out that the Wireless Modem Router (Telekom Austria supplied Pirelli PBS modem) where I was staying was set to WPA encryption only by default. Once I figured out how to set the unit to WPA2 (which these days should really be the default anyway) things started to actually work consistently. Check the sections below (specially chrome://diagnostics) to see how you can find out what's going wrong. However to save some trouble & frustrations, before you do anything make sure your Chrombook connects using WPA2 ! Terminal CTRL+ALT+T will launch the Chrome Shell which is a slightly odd and very cut-down…

Continue Reading

Raspberry Pi – Raspbian post install tasks

The Raspbian Install process is fairly well documented using the Raspbian Installer. This is just to document common tasks after the stock install. Install base utils apt-get install sudo vim ntpdate git-core binutils make gcc ca-certificates rpi-update Allow non-root user account access to 'sudo' adduser USERNAME sudo For those Ubuntu users there is no 'admin' group in Raspbian (Debian Wheezy). NTP time update sudo rm /etc/localtime sudo ln -s /usr/share/zoneinfo/Australia/Adelaide /etc/localtime sudo ntpdate -u au.pool.ntp.org Probably best to choose an NTP Server closest to your location or provided by your ISP Firmware upgrade EDIT (2014-03-31): rpi-update is now part of the Raspbian repositories and can be installed via apt-get install rpi-update (I have added this to the above line). Note: unless you want the latest firmware this is not a necessary step as apt-get will update the firmware to the latest stable release. Using Hexxeh updater. Install dependencies wget http://goo.gl/1BOfJ -O /usr/bin/rpi-update && sudo chmod +x /usr/bin/rpi-update sudo rpi-update Install WiringPi Thanks to the excellent work of Gordon Henderson (https://projects.drogon.net/raspberry-pi/wiringpi/) this is a C-based program to read/write to the Raspberry Pi GPIO pins. cd /usr/share git clone git://git.drogon.net/wiringPi cd wiringPi git pull origin ./build Output: wiringPi Build script ===================== The wiringPi I2C helper libraries will not be built. WiringPi library [UnInstall] [Compile] wiringPi.c [Compile] wiringPiFace.c [Compile] wiringSerial.c [Compile] wiringShift.c [Compile] gertboard.c [Compile] piNes.c [Compile] lcd.c [Compile] piHiPri.c [Compile] piThread.c [Compile] wiringPiSPI.c [Compile] softPwm.c [Compile] softServo.c [Compile] softTone.c [Link (Dynamic)] [Install] GPIO Utility [Compile] gpio.c [Link] [Install] All Done. Testing the…

Continue Reading

Mongodb / Python development install on Ubuntu

Add apt repository key sudo apt-key adv --keyserver keyserver.ubuntu.com --recv 7F0CEB10 Add apt repository sudo vim /etc/apt/sources.list.d/10gen.list #add the following line: deb http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen Install mongodb & python utils sudo apt-get update sudo apt-get install mongodb-10gen python-pip python-dev build-essential pip install pymongo

Continue Reading

Accessing 1-wire devices on Raspberry Pi using OWFS

To connect 1-wire serial devices to the RPi I am using a DS9490R USB 1-wire adapter (rather than wiring I2C 1-Wire master components to GPIO I2C - which I might look at sometime down the track) Install packages sudo apt-get install owfs ow-shell Edit config file vim /etc/owfs.conf ! server: server = localhost:4304 # USB device: DS9490 server: usb = all ######################### OWFS ########################## mountpoint = /mnt/1wire allow_other ####################### OWHTTPD ######################### http: port = 2121 ####################### OWFTPD ########################## ftp: port = 2120 ####################### OWSERVER ######################## server: port = localhost:4304 Create Startup Script I created a startup script for owfs modelled on the owserver script (not sure why this one is actually missing) vim /etc/init.d/owfs #!/bin/sh ### BEGIN INIT INFO # Provides: owfs # Required-Start: $remote_fs $syslog $network $named # Required-Stop: $remote_fs $syslog $network $named # Should-Start: owfs # Should-Stop: owfs # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: 1-wire file system mount & update daemon # Description: Start and stop 1-wire file system mount & update daemon. ### END INIT INFO CONFFILE=/etc/owfs.conf DESC="1-Wire file system mount" NAME="owfs" DAEMON=/usr/bin/$NAME case "$1" in start) echo "Starting $NAME" $DAEMON -c $CONFFILE ;; stop) echo "Stopping $NAME" killall $NAME ;; *) echo "Usage: $N {start|stop}" >&2 exit 1 ;; esac exit 0 Starting daemons /etc/init.d/owserver start /etc/init.d/owfs start Checking output #ls /mnt/1wire/ Should show output similar to: 10.575349000000 12.95DD17000000 alarm simultaneous uncached 10.575349000000 12.95DD17000000 bus.0 statistics 12.57DD16000000 81.B2EA2E000000 bus.1 structure 12.57DD16000000 81.B2EA2E000000 settings system cat /mnt/1wire/10.575349000000/temperature Will then show…

Continue Reading

Installing OMXPlayer on Raspberry Pi

Since I didn't have any luck playing videos on the RPi using mplayer I found omxplayer after some search. It has the ability to use the RPi's GPU thus taking some load of the CPU. UPDATE 2013-04-01: omxplayer is now included in the Raspbian (Debian Wheezy) repositories and can be simply installed by one line. sudo apt-get install omxplayer Check another article on how to install Raspbian. OMXPlayer binary (.deb) downloads can be found here: http://omxplayer.sconde.net/ Install dependencies apt-get install libpcre3 fonts-freefont-ttf fbset libpcre3-dev libpcrecpp0 libva-dev libva-x11-1 libva1 Install omxplayer wget http://omxplayer.sconde.net/builds/omxplayer_0.2.4~git20121205~ec7ac68f_armhf.deb dpkg -i omxplayer_0.2.4~git20121205~ec7ac68f_armhf.deb Play video omxplayer -o hdmi video.mp4 Note: If there is no sound when playing through the HDMI interface make sure your /boot/config.txt file has the following line (and it's not commented out). hdmi_drive = 2 OMXPlayer Key bindings Key Action 1 Increase Speed 2 Decrease Speed j Previous Audio stream k Next Audio stream i Previous Chapter o Next Chapter n Previous Subtitle stream m Next Subtitle stream s Toggle subtitles q Exit OMXPlayer Space or p Pause/Resume - Decrease Volume + Increase Volume Left Seek -30 Right Seek +30 Down Seek -600 Up Seek +600

Continue Reading

Raspberry Pi – Text to Speech

Just a quick note on Speech Synthesis a Raspberry Pi project. I had to research some of the options on the Raspberry Pi while looking into a project where I need some audio announcements. Configuring Sound echo 'snd-bcm2835' >> /etc/modules sudo modprobe snd-bcm2835 sudo apt-get install mplayer alsa-base alsa-utils pulseaudio mpg123 # make mplayer use mpg123 codec instead of default ffmp3float echo "afm=mp3lib" >> ~/.mplayer/config Since I am using Raspbian which is a Debian based (Wheezy) Distribution I used some Ubuntu documentation (https://help.ubuntu.com/community/TextToSpeech) as the starting point. Festival sudo apt-get install festival festival-english echo "Hello World - Testing" | festival --tts Plus: Local install (no internet connection required) Minus: Mechanical sounding voice Espeak sudo apt-get install espeak espeak -v en "Hello World - Testing" Plus: Local install (no internet connection required) Minus: Mechanical sounding voice (slightly better than Festival) Google Translate Create a shell script tts.sh #!/bin/bash mplayer -ao alsa -noconsolecontrols "http://translate.google.com/translate_tts?tl=en&q=$*" > /dev/null 2>&1 chmot +x tts.sh ./tts.sh "Hello World - Testing" Plus: needs live internet connection Minus: excellent human sounding voice Google Speech API I will most likely look at this in the long run to get better control rather than calling the Google Translate url too much.

Continue Reading

Creating Twitter Archives

One of the more common uses of Twitter for me is to monitor "back-channels" at events (often events I can attend, but more often these days events I am unable to attend). Unfortunately Twitter's search capabilities cease to be useful after a little while and so it is very handy to be able to create an archive for the events 'hashtag'. There used to be a number of tools in the early days, but mainly because of Twitter's changes to policies and very unfortunate morphing into a closed 'media-publishing' platform, the developers of such tools were forced to discontinue their services. Here is IMHO the best remaining tools I have found that still work: TweetArchivist This is an easy to used & fairly polished product which allows download of raw data. http://www.tweetarchivist.com/ TAGSExplorer This is a more involved, but open solution based on a Google Spreadsheet and can be modified to suit. http://mashe.hawksey.info/2011/11/twitter-how-to-archive-event-hashtags-and-visualize-conversation/ Kudos Martin Hawksey from JISC CETIS

Continue Reading

Enable GeoIP lookups on CentOS

GeoIP enables you to identify the location, organization, connection speed, and user type of your website visitors. yum install GeoIP mod_geoip cd /usr/share/GeoIP/ wget http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry/GeoIP.dat.gz wget http://geolite.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz gunzip GeoIP.dat.gz gunzip GeoLiteCity.dat.gz rm -f *.gz Edit the VirtualHost settings in httpd.conf <ifmodule mod_geoip.c> GeoIPEnable On GeoIPDBFile /usr/share/GeoIP/GeoIP.dat Standard GeoIPDBFile /usr/share/GeoIP/GeoLiteCity.dat Standard </ifmodule> Restart Apache /etc/init.d/httpd restart

Continue Reading

Accessing Amazon RDS from Desktop

Every once in a while it is handy to be able to access an Amazon RDS Database Instance remotely from a desktop. ssh -i YOUR-AMAZON-PRIVATE-KEY.pem -l YOUR-AMAZON-RDS-USERNAME -L 33060:YOUR-AMAZON-RDS-PRIVATE-IPADDRESS:3306 -N ec2-usr@YOUR-AMAZON-EC2-INSTANCE-PUBLIC-ADDRESS Note: YOURAMAZONRDSPRIVATEIPADDRESS needs to be the AWS internal RDS IP Address - not the external hostname You can then connect to RDS using mysql commands or any GUI tool such as MySQL Workbench via localhost:33060 Thanks to: Dirk Taggesell via AWS Forums

Continue Reading