$10 GPS

pciegpsOn ebay you can find cheap u-blox mini-pcie gps units for around $10 including shipping. They are for internal use in laptops and similar (most likely hooking up to the usb bus over Mini PCIe), but it turns out that the pads on the backside expose connectivity options such as uart and usb data.

I soldered on a pin header for ease of use, and also attached a cheap ceramic antenna using double sided tape.

The UART pins will spew over standard NMEA 183 data, so it should be easy to use with both computers and microcontrollers.

On the raspberry pi you can install the gpsd and gpsd-clients packages. Connect the tx gps pin to GPIO 15 RXD on the pi (you only really need one way uart, unless you want to change settings on the gps). Also connect ground and vcc, the gps requires 3.3v and probably need more umphf than the 50mA max 3.3 pin on the pi can deliver. I connected power via a 5v pin and a 3.3v regulator. I do not know if the gps is 5v tolerant, but probably not.

Launch the daemon ( gpsd -b /dev/ttyAMA0 ) and a client ( cgps ).. Remember to disable the tty running on /dev/ttyAMA0 before you use the UART pins for something like this.

Advertisements

Popcorn Hour

The Popcorn Hour is a relatively small networked mediaplayer running linux. Out of the box it’s fanless, so the only source of noise is the added harddrive (it supports a SATA-drive or external USB drives), making it a good candidate for a quiet multimedia system. It can read most filesystems, but only has write-support for ext2/3. I put a 1 tb western digital green power drive in mine. On the output side it supports component, svideo, composite, hdmi 1.3a, analog and digital sound.

There are several ways to provide it with media, you can upload it via samba, ftp, nfs, etc.. etc.. stream it over the network from a variety of servers and shares, or simply plug it into your computer (it will act as a normal USB-disk). It’s available on the network when you suspend it, so you can upload files to it at all times. And the good thing is, it basically plays everything you throw at it, including 1080p h264 mkv files. Sound is outputted either as the original stream (ac3, dts, aac) or  as PCM over HDMI, and it works great with my receiver. It has a thriving community providing all sorts of cool hacks and the firmware people provide regular updates.

This could have been the holy grail of mediaplayers, but it has a few issues and annoyances. It’s not future proof, if a new format shows up, then there’s no guarantee that you can play it. The remote control sucks, you have to basically aim it directly at the unit for it to work (you can however use USB-input devices, so it would probably be possible to replace it, a keyboard works fine for example), maybe it would be possible to create an iPhone app to replace the remote. The user interface is slow and based on HTML. While being easy to customize, who decided it was a good idea to base a mediaplayer interface around a webbrowser?? The interfaces are quite static, no smooth transitions when moving around, and it’s noticeably slow and laggy. Some settings I want to customize (for example buffer size when streaming) isn’t possible.. If I could set the buffer size up to maybe 50 mb, then I could easily stream HD-media from my server at home.. It also no good for large music collections.

There are several custom user interfaces showing up, I haven’t really tried them out yet, but I suspect they are as slow as the original, but maybe more visually pleasing.. But all in all, it’s small, portable, very low noise, very hackable, plays as good as everything.. and if you can live with the slow interface it’s well worth the money. A full HTPC would probably be better, but this gives you like 95% of the features for 5% of the effort..

Bergen 3D

I’ve spent some time working on a virtual 3d bergen as a part of INF251 (Computer Graphics) this semester. Basically what we did was to render the terrain based on a height map (a file containing a height value at every x,y position), modeled some buildings, added textures, spline based camera paths.. etc.. Mine was developed on linux and uses Glut, GLEW, GLM, DevIL, Vmath.. etc.. You can fly around in Bergen using FPS-style controls (WASD+RF/mouselook).

See my page over at the university for som larger screenshots and a movie..

Automated offsite backup.

In order to sleep better at night I’ve decided to be better at taking backups of important data. Knowing myself it would need to be automated, and also preferably offsite. Also didn’t want to depend on my own servers (since they are down from time to time, lately I’ve been fighting an ethernet switch that stops working until someone cycles the power.. very annoying, it’s getting replaced now..). I had a look at amazon S3, which seems to be fairly popular these days. $0.15 per gb per month of storage, and a little bit for bandwidth. That’s basically free for my storage needs, especially considering the current dollar value (when are they going to rename it american pesos?). Sounds great, cheap offsite backup. However I want to encrypt my data, since I don’t trust anyone further than I can throw them in matters like this, and it’s hard to throw someone the size of amazon.. I had a look around and found duplicity, which does encrypted incremental backups. It’s made in python and uses librsync, it supports loads of different destinations – for example scp, rsync, ftp and even S3! So I installed the newest version of duplicity and it’s dependencies ( boto – for S3 support, the rest can be found in most distributions ) and also made a GPG-key specifically for backup use (gpg –gen-key). And made a little script:

#!/bin/bash

# Amazon S3 keys:
export AWS_ACCESS_KEY_ID="XXXXXXXXXXXXXXXXXX"
export AWS_SECRET_ACCESS_KEY="XXXXXXXXXXXXXXXXXXXXXXXXXXXX"

# GPG passphrase and key:
export PASSPHRASE=XXXXXXXX
GPG_KEY=XXXXXXXX

# MYSQL password:
MYSQLPW=XXXXXXXX

DATE=`date +%d`

SOURCE=/
DEST="s3+http://nameofyourbackupbucket"

mysqldump --all-databases --password=$MYSQLPW > /root/mysql/mysql-backup.sql

# Force a full backup twice a month..

if (( "$DATE" % 15 == "0" )) ; then

        duplicity full 
                --include-globbing-filelist /root/backuplist.txt 
                --encrypt-key "$GPG_KEY" 
                --sign-key "$GPG_KEY" 
                --exclude=/** 
                $SOURCE $DEST

        # Don't really need more than 2 months of backup..
        duplicity remove-older-than 2M $DEST

else 

        duplicity 
                --include-globbing-filelist /root/backuplist.txt 
                --encrypt-key "$GPG_KEY" 
                --sign-key "$GPG_KEY" 
                --exclude=/** 
                $SOURCE $DEST

fi

export AWS_ACCESS_KEY_ID=
export AWS_SECRET_ACCESS_KEY=
export PASSPHRASE=

Everything i want to backup is listed in the file backuplist.txt, and the script runs once every night using cron…. This should cover my backup needs, if I only remember to backup my GPG-key :p

Asterisk – Resolve callerid using online phone directories.

Here’s how to automatically resolve incoming callerids using a public online phone directory with a bit of PHP.

First you need a few packages installed.. php(4/5)-cli and php(4/5)-curl.. Copy the following code and save it as a file (‘resolvnum.agi’) in your agi-bin directory, most likely /usr/share/asterisk/agi-bin. Make sure it’s executable: chmod +rx resolvnum.agi

#!/usr/bin/php -q
<?php

// Do not wait more than 4 secs..
ob_implicit_flush(false);
set_time_limit(5);

$stdin = fopen("php://stdin", "r");
$stdout = fopen("php://stdout", "w");

// Get all agi-variables from asterisk via stdin:
while (!feof($stdin)) {
        $temp = fgets($stdin);
        $temp = str_replace("n", "", $temp);
        $s = explode(":", $temp);
        $agivar[$s[0]] = trim($s[1]);

        if (($temp == "") || ($temp == "n"))
                break;
}

// Get callerid from agi-variables.
$callerid = $agivar['agi_callerid'];

if (!is_numeric($callerid)) exit(1);

// Set up curl:
$user_agent = "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)";
$ch = @curl_init("http://www.kvasir.no/telefonkatalog/searchresult.html?q=".$callerid."&x=0&y=0/");

@curl_setopt($ch, CURLOPT_USERAGENT, $user_agent);
@curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
@curl_setopt($ch, CURLOPT_TIMEOUT,4);

// Fetch us some data...
$html = str_replace("r", "", @curl_exec($ch));
curl_close($ch);

// Got nothing? Oh, bother...
if (!$html) exit(0);

// Replace Norwegian characters..
$html = str_replace(array(chr(230), chr(248), chr(229), chr(198), chr(216), chr(197)),
                 array("ae", "oe", "aa", "AE", "OE", "AA"), $html);

// Try to match some names..
preg_match_all("|<h4 class="forste_linje">n(.*)n</h4>|U", $html, $names, PREG_SET_ORDER);

// Yay, we found something, set calleridname.. leave number alone..
if (isset($names[0][1])) {
        fputs($stdout,"SET CALLERID "".$names[0][1]." (".$callerid.") <".$callerid.">"n");
        fflush($stdout);
}

exit(0);
?>

Then add the agi to your incoming extensions in extensions.conf. Mine is set up like this:

[from-sip]
exten => 85XXXXXX,1,AGI(nummeroppslag.agi)
exten => 85XXXXXX,2,Macro(dialer,101,SIP/101&SIP/102,101)
exten => 85XXXXXX,3,Hangup

It should now query www.kvasir.no/telefonkatalogen and set the callerid-name (which will show up on your phone) if it finds something. Since I’m pretty sure that kvasir won’t like this (I take no responsibility for your usage), I would recommend implementing a cache if you have a lot of traffic. You can also easily adapt it to other phone directories by changing the search URL and regexp.

Cell SDK on Ubuntu (Feisty Fawn).

I ended up installing ubuntu on my playstation 3, pretty straight forward installation. Getting the Cell SDK up and running on ubuntu turned out to be a bit of a challenge however. There’s really not much information out there about how to do it, the closest I got was Gammel’s “Installing Cell SDK under Ubuntu” – which almost worked. Most of the following is based on his recipe.

1. Install a few needed packages:

$ apt-get install rpm freeglut3 freeglut3-dev libxmu-dev libxext-dev 
   build-essential perl rsync flex byacc tk8.4 tcl8.4 libelf1 gawk bash 
   libnetpbm10 libnuma1

2. Make sure sh points to bash:

$ ls -la /bin/sh
lrwxrwxrwx 1 root root 9 2007-08-25 07:33 /bin/sh -> /bin/bash

if it doesn’t then replace it:

$ rm  /bin/sh && ln -s /bin/bash /bin/sh

3. Replace mawk with gawk:

$ update-alternatives --set awk /usr/bin/gawk

4. Add symlinks to a couple of libs:

$ ln -s /usr/lib/libtcl8.4.so.0 /usr/lib/libtcl8.4.so
$ ln -s /usr/lib/libtk8.4.so.0 /usr/lib/libtk8.4.so

5. Download the Cell SDK (v2.1 is current version). Mount it and copy out the software.

$ mkdir /media/cell && mount -o loop CellSDK21.iso /media/cell
$ cp -r /media/cell/software /tmp/

6. Fix the install script, i needed to add –ignorearch since it complained about the system not beeing ppc64 for some reason. Then run it..

$ cd /tmp/software
$ sed -i 's/rpm -i/rpm -i --nodeps --ignorearch/g' cellsdk
$ ./cellsdk install

7. Mount up the SPU-filesystem (if you get errors like “Unable to create SPE thread: Invalid argument” or “spu_create(): No such file or directory” while running your code this is probably why).

$ mkdir /spu
$ echo "none /spu spufs defaults 0 0" >> /etc/fstab
$ mount -a