KB9IQX AIS Receiver & APRS.fi Reporter using RTL-SDR
I saw that APRS.fi had ship locations on the map! So I wanted to add AIS receive function to my RX-only iGate station. Both AIS and APRS are using an SDR, one for each.
Raspberry Pi Zero W - looked like it worked; received no packets. RETEST WITH KNOWN GOOD SPY SHED ANTENNA SETUP
Raspberry Pi 3A+ - TESTED. WORKS
Raspberry Pi 3B/3B+ - TESTED. WORKS
USB RTL-SDR dongle. I used the Nooelec NESDR Nano 3 RTL-SDR USB - it's tiny! it's metal! it has a heat sink and gets hot! All 4 Pi USB ports can be filled with these.
an Antenna - wire gets excite gets bzzzzts sends to computer
AIS uses 9600 bps GMSK on 161.975 and 162.025 MHz [source].
Other sites with installation instructions that I referenced before wandering off on my own.
This was the key to bridging the decoder part to the send-to-APRS.fi part [source] :
After fiddling around for some days, I found rtl-ais which is a modified version of rtl-sdr, with direct support for AIS decoding. It worked! Just specifying the tuner error, and it was outputting AIS messages.
However, the decoder was not that elegant, and GNUAIS had interesting features, like the ability to feed data directly to mysql.
AIS is transmitted at 161.975 and 162.025MHz, which is within the 2MHz bandwidth of the RTL-SDR sticks, so both channels can be received at once. The rtl_ais software is a modified version of rtl_fm, which can do exactly this. Feeding the output audio to a named pipe, and setting gnuais up to read from that named pipe, instead of audio card, worked just perfectly!
1. Install an image. I used a general Raspbian Stretch (9) because that's what I had lying around on my desktop.
2. Log into or SSH into your machine.
3. Install and build Osmocom RTL-SDR At this other page you will find great,detailed instructions... don't worry that it's ADS-B not AIS, the basic drivers are the same.
4. Install and build DGiardini's RTL-AIS. Whether you installed the libsdr libraries via apt repository (apt-get install librtlsdr-dev librtlsdr0) or you installed the OsmoCom RTL-SDR libraries, the default paths in the Makefile are incorrect. There is some futzing you'll have to do with the Makefile to point libraries to the correct paths changes in red bold. Here is what worked for me:
5. Create a named pipe.
More info about named pipes is here. It seems that gnuais can read a file for input but not take raw input from stdin/command line. It is designed to take raw audio input from a soundcard, back when the only way to receive AIS was to tap into the discriminator audio output of a radio. This does not work for SDR.
There is a test feature which allows gnuais to read sound input from a test file. In this case, our "test file" is the actual audio that is being dumped into a file by rtl_ais. But audio can eat up a lot of room when dumped into a file...
we will tell rtl_ais to dump received SDR audio into the named pipe -- basically a zero-length "file" that resides only in memory and which to applications looks like any other file. Finally we will tell gnuais to read the audio from that same file/named pipe.
In short, the named pipe acts as a regular file... but it does not grow in size -- it only grows in memory -- and clog up your file system.
6. Install and build GNU AIS Make sure you have the curl development libraries (raspberryPiOS: sudo apt-get install libcurl4-openssl-dev); it will build without them but they are needed for gnuais to send AIS position reports to APRS.fi. If you want to log data to a mySQL database, make sure you have the requisites.
7. Configure gnuais.conf
8. Calibrate your SDR to find the PPM offset. This is a good idea. For the life of me I could not get kalibrate-rtl to compile. So I am just running on luck.
Command Line Operation
rtl_ais -> named pipe -> gnuais
The exciting and magic sauce here is the name pipe sitting between rtl_ais receiving from the SDR and gnuais first decoding the audio and subsequently sending it to aprs.fi. The named pipe looks zero-length but accumulates data in system memory from rtl_ais going in on one side and let's another application take data out of it
In one terminal, run rtl_ais:
rtl_ais -l 161.975M -r 162.025M -A /path/to/named_pipe
This command tells rtl_ais to listen to both "left" and "right" AIS frequencies (tho the official spec calls them A and B freqs). The -A turns off the decoding function, instead sending out the undecoded audio from the SDR.
If successful, you will see the output seem to hang forever. But it is actually sending the data to the named pipe instead of the screen. So as long as it is "hanging" it is working.
VHF is really full of all sorts of crap, so using a tuned antenna and a band pass filter is really necessary if you want to receive anything else than FM radio on your rtl-sdr dongle. Remember that adding a cheap pre-amp will hardly solve any interference issues, since the pre-amp does not know the difference between what you want to receive and what you don’t. Fortunately, AIS signals are relatively strong and even under poor receiver conditions you should be able to pick up something if you are located near marine traffic. [source].