Monday, March 4, 2013

Silliness on a bike


A POCSAG -> email gateway

EDITED 26-Nov-2013: Minor bugfixes on commands, moved script to Google Drive, added more explanation.

I put this script together a while ago. It examines the output from Multimon-NG, and forwards selected POCSAG messages via email. Note that it uses SMTP via TLS, which may not work for your email provider. Gmail works fine.

First off, copy the script to the home directory of your Pi.

Then:

sudo apt-get install libnet-smtp-tls-perl libdatetime-perl
chmod +x pocsag_fwd.pl

Next, configure it. Lines 31-33 need to be updated to include your SMTP server and login details.
Also, the definition of the @stream variable (lines 11-26) need to be modified to include the POCSAG address ID's and email addresses you want. Hopefully the syntax and meaning of the fields will be self-explanatory. You might want to examine the output from multimon-ng for a while to find the addresses you're interested in.

To use it:

rtl_fm -N -o 4 -l 10 -A fast -r22050 -s88200 -C -D -f 148.7125M - |multimon-ng  -t raw -a POCSAG512 -f alpha /dev/stdin|./pocsag_fwd.pl

Putting rtl_fm and Multimon-NG together

Unix pipes are awesome.

To decode POCSAG on the Pi, this is all you need:


pi@raspberrypi ~ $ rtl_fm -N -o 4 -l 10 -A fast -r22050 -s88200 -C -D -f 148.7125M - |multimon-ng -t raw -a POCSAG512 -f alpha /dev/stdin
Found 1 device(s):
  0:  Realtek, RTL2838UHIDIR, SN: 

Using device 0: ezcap USB 2.0 DVB-T/DAB/FM dongle
multimonNG  (C) 1996/1997 by Tom Sailer HB9JNX/AE4WA
            (C) 2012 by Elias Oenal
available demodulators: POCSAG512 POCSAG1200 POCSAG2400 EAS UFSK1200 CLIPFSK AFSK1200 AFSK2400 AFSK2400_2 AFSK2400_3 HAPN4800 FSK9600 DTMF ZVEI SCOPE
Enabled demodulators: POCSAG512
Found Elonics E4000 tuner
Oversampling input by: 3x.
Oversampling output by: 4x.
Buffer size: 7.74ms
Tuned to 148977100 Hz.
Sampling at 1058400 Hz.
Output at 22050 Hz.
Exact sample rate is: 1058400.010094 Hz
Tuner gain set to automatic.
POCSAG512-: Address:   12935  Function: 2
POCSAG512-: Numeric: 4-23U7]47978140-0[93-]]338.50.2.U7 [62795]0.659560U9- 660.6182836.7.-]560180482-]43683818 .569696926]281-04-201.6 920-01U1405 2647438.9169[81-0.85]277U410000
POCSAG512-: Blah blah blah - content redacted by me<NUL><NUL>
POCSAG512-: Address: 1720997  Function: 0
POCSAG512-: Numeric: U-U1  5 .4.3161395]..0. 2 270.9]3U.45428].5 925143 024U802960-97 228]U352280733.9-46 20-538  562-9740155.1 1]2950.9255.[ 5619502U1869-40915.[ 62868[ 1]-05.5 2]2950.924U85 059]358  2637. 2014U84-2.49502U1 2U5]0U 14-46100
POCSAG512-: Alpha: THIS IS A TEXT MESSAGE, IT WAS ANOTHER TEXT MESSAGE, BUT NOW IT INCRIMINATES NO PERSON<NUL>

And it's going. You can now construct a veritable daisy chain of processes to do all sorts of things with the output.

Compiling Multimon-NG for the Raspberry Pi

EDITED 26-Nov-2013: Minor bugfixes on commands, added more explanation.

Got my mouth all ready to do some POCSAG decoding on the Pi, running Raspbian Wheezy.

Enter Multimon-NG. I tried compiling it as per this page. Had no problems. In summary:

sudo su -
apt-get install libpulse-dev libx11-dev qt4-qmake
apt-get install git cmake build-essential
git clone https://github.com/EliasOenal/multimonNG.git
cd multimonNG/
mkdir build
cd build
qmake ../multimon-ng.pro
make
make install

A previous version of this post listed lots of problems, mainly due to the lack of qmake. I later found that it's included in the qt4-qmake package. I used the latest (2013-09-25) version of Raspbian, which may have also helped.

Compiling rtl_fm on the Raspberry Pi

EDITED 13-Sep-2013: Minor bugfixes on commands, added more explanation.

I got myself an RTL2832 DVB-T dongle from the bestest provider of cheap stuff in the whole Internets.

Getting it going on Raspbian Wheezy on the Pi turned out to be easy (ref):

sudo su -
apt-get update
apt-get install git
git clone git://git.osmocom.org/rtl-sdr.git
apt-get install libusb-dev libusb-1.0 libtool cmake
apt-get install build-essential

cd rtl-sdr/
mkdir build
cd build
cmake ../
make
make install
ldconfig

I found that the instructions about running cmake ../ -DINSTALL_UDEV_RULES=ON  to allow non-root access didn't work, so I copied the udev rule over manually to the correct directory:

cd ..
cp rtl-sdr.rules /etc/udev/rules.d/


Proof of the pudding, reboot, plug in the dongle, test it as a regular user.


pi@raspberrypi ~ $ rtl_test -t
Found 1 device(s):
  0:  ezcap USB 2.0 DVB-T/DAB/FM dongle

Using device 0: ezcap USB 2.0 DVB-T/DAB/FM dongle
Found Elonics E4000 tuner
Supported gain values (14): -1.0 1.5 4.0 6.5 9.0 11.5 14.0 16.5 19.0 21.5 24.0 29.0 34.0 42.0 
Benchmarking E4000 PLL...
[E4K] PLL not locked for 51000000 Hz!
[E4K] PLL not locked for 2217000000 Hz!
[E4K] PLL not locked for 1109000000 Hz!
[E4K] PLL not locked for 1243000000 Hz!
E4K range: 52 to 2216 MHz
E4K L-band gap: 1109 to 1243 MHz

And we're all done!

You'll notice the first command I entered is sudo su - .This gives root access, saving you from having to type Simon Says sudo for every command. Once you're done, exit brings you back to the unprivileged user.