Showing posts with label marinetraffic RTL-SDR. Show all posts
Showing posts with label marinetraffic RTL-SDR. Show all posts

Thursday, 2 June 2016

Raspberry Pi RTL-SDR AIS marinetraffic image

Here is a Raspberry Pi SD card image that will decode AIS messages on VHF radio using an RTL-SDR dongle.

It will upload the data to marinetraffic.com (you will need to sign up to marinetraffic.com for this) and also broadcast the AIS sentences on your local area network.

This way, you can use the Raspberry Pi and RTL-SDR as an AIS receiver for OpenCPN

I have shrunk the image to fit on Dropbox.

Image file (.zip) for Raspberry Pi: *8GB SD card*

https://www.dropbox.com/s/pflj3xtczzfb2p2/marinetraffic_rtl_sdr01.zip?dl=0

Edit July 2017 - new link:

https://www.dropbox.com/s/p4wqacko4ru3jpl/marinetraffic_rtl_sdr01.zip?dl=0

~1.6GB download

Instructions for copying an image to SD card are given here:
https://www.raspberrypi.org/documentation/installation/installing-images/windows.md

Setup Instructions:

https://www.dropbox.com/s/nez9zzmkkcxcky4/Raspberry%20Pi%20RTL-SDR%20AIS%20receiver%2001.pdf?dl=0

https://www.dropbox.com/s/1q21f23xkysovd5/Raspberry%20Pi%20RTL-SDR%20AIS%20receiver%2001.pdf?dl=0


[update March 2017 - Fitipower FC0012/13 chips have different gain ranges than the suggested values in the notes. My notes are for RT820x based RTL receivers. To see your receiver's allowable gain values, 1) log into Pi via SSH2) stop the AIS code from auto running:   sudo nano ~/ais.sh 
   change line to GO=0
3) reboot the Pi (sudo reboot)
4) log in again, and run the commands:
    cd /usr/local/bin
    rtl_test
   (exit with CTRL-c)
This will list the allowable gain values for your device. Edit ~/ais.sh to use your new gain value.

I am by no means an expert. This image works for me. YMMV. I welcome feedback and improvements.

You might consider using KPLEX http://www.stripydog.com/kplex/examples/marinetraffic.html to distribute AIS to marinetraffic as well as local network addresses, instead of the 'pipe tee' method used on the image.

Thursday, 19 May 2016

source code on GIT

source code for the AIS receiver/repeater (Teensy 3.1):
https://github.com/beinnlora/AIS-repeater

credit to Stuart Robinson for the base LoRa code
https://www.dropbox.com/sh/na2d9yt09nr91f7/AADqSNprExezpBEcqIxewDpBa?dl=0


source code for the Raspberry Pi LoRa gateway:
https://github.com/beinnlora/lora-gateway

credit to Dave Ackerman for the base LoRa code
https://github.com/PiInTheSky/lora-gateway

Tuesday, 9 February 2016

Rasperry Pi RTL-SRD AIS tracker for OpenCPN and MarineTraffic.com

Raspberry Pi 2 Model B
RT820T based RTL SDR USB dongle
1/4 wave groundplane antenna / moxon loop



I have a raspberry Pi 2 running with RTL-SDR USB stick successfully feeding AIS to marinetraffic.com  and to my local network. The rough steps (and links to guides are below)

Start with fresh install of raspbian Jessie lite 2016-5-10

Install RTL SDR on Raspberry Pi and add to blacklist of USB devices: http://goo.gl/tXnW13.
sudo apt-get update

Now install the required utils to compile the RTL-2832U USB dongle driver

sudo apt-get install git 
sudo apt-get install cmake
sudo apt-get install libusb-1.0-0.dev
sudo apt-get install build-essential

Now install the RTL-2832U USB dongle driver src and compile

git clone git://git.osmocom.org/rtl-sdr.git
cd rtl-sdr/
mkdir build
cd build
cmake ../
make
sudo make install
sudo ldconfig

Edit the following file /etc/modprobe.d/raspi-blacklist.conf

use your favourite editor like nano or vi 

sudo nano /etc/modprobe.d/raspi-blacklist.conf

add the following lines in the file.

blacklist dvb_usb_rtl28xxu
blacklist rtl2832
blacklist rtl2830


Save and exist.
 (ctrl-X --> y -->enter)

REBOOT then plug in your RTL-SDR stick

Confirm the RTL is working using rtl_test first before proceeding:

sudo rtl_tcp -t

Install gnuradio(dev) http://goo.gl/TVogHw  (takes a long time!) :
sudo apt-get install gnuradio gnuradio-dev
install osmosdr:
sudo apt-get install gr-osmosdr

install Boost
sudo apt-get install libboost1.50-all

install Cppunit:
sudo apt-get install libcppunit-dev

install liblog4cpp5:
sudo apt-get install liblog4cpp5-dev

install socat:
sudo apt-get install socat
install swig:
sudo apt-get install swig

install gr-ais https://goo.gl/QXXzhO.  :

 git clone https://github.com/bistromath/gr-ais.git
 cd gr-ais
 mkdir build
 cd build
 cmake ../
 if you get an error at this point:
CMake Error at CMakeLists.txt:114 (find_package):
  Could not find a configuration file for package "Gnuradio" that is
  compatible with requested version "3.7.6".


then edit cmake to force 3.75 (a bodge, but works!):

cd ~/gr-ais
nano CMakeFiles.txt

find the section #Find gnuradio build dependencies
edit the line:
find_package(Gnuradio "3.7.6" REQUIRED)
change to

find_package(Gnuradio "3.7.5" REQUIRED)


 exit nano(Ctrl-x -->y-->enter)
 
resume with building:

cd ~/gr-ais/build
cmake ../
make
 sudo make install
 sudo ldconfig


if you get an error
ImportError: No module named ais_swig
then check you have installed swig, reboot and then re-try the steps to build gr-ais

Install and run "kal" :

mkdir ~/src
cd ~/src
sudo apt-get install libtool autoconf automake libfftw3-dev
git clone https://github.com/asdil12/kalibrate-rtl.git
cd kalibrate-rtl
git checkout arm_memory

./bootstrap
./configure
make
sudo make install

" to calibrate the RTL dongle to work out the error value to use in ais_rx
http://goo.gl/wbqOts. MY RTL dongle had an error of around minus 33 ppm, and this is the value passed to ais_rx below. replace with your error value. As the dongle warms up this value may change so check again after some time. don't forget to put an antenna on your SDR stick.
in the UK we have 900MH\ gsm base stations. for the US this is usually 850MHz. Command below is for 900MHz :

sudo kal -s 900

this will give you a channel number of a nearby GSM station

use the channel number to get a calibration value. e.g. below found chan: 114

sudo kal -c 114

this will then give you a ppm value -make note of it below
average absolute error: -33.163


profile your hardware by running the following command: (takes a long time!)
volk_profile

You can then pipe AIS messages to MarineTraffic using "socat" (sudo apt-get install socat) using the command below (where 1.2.3.4:1234 should be changed for your marinetraffic upload IP and port and --error -33 should be changed for your error value obtained from kal

ais_rx --gain 44 --error -33 -s osmocom | socat - UDP4-DATAGRAM:1.2.3.4:1234

if you run OpenCPN on a computer on your LAN, you can send the traffic to that at the same time as marinetraffic (assuming your OpenCPN computer is running on LAN 192.168.1.101:9999) and also pipe the raw AIS sentences to the console for confirmation of reception:
ais_rx --gain 44 --error -33 -s osmocom | tee >(socat - UDP4-DATAGRAM:1.2.3.4:1234) | tee >( socat - UDP4-DATAGRAM:192.168.1.101:9999)

to keep this running when you disconnect your console session, create a file and save the above commandline into it:
touch ~/ais.sh
sudo nano ~/ais.sh
paste the above commandline into file and save (Ctrl-x Ctrl-y)
make the file executable
sudo chmod +x ais.sh
Then to run as background process on startup, edit /etc/rc.local to have it run on startup)
sudo nano /etc/rc.local
paste the following line into it and save
/home/pi/ais.sh &

It is fairly processor-intensive on the Pi - 100% of two cores and 50-75% of the remaining cores.

I am no raspberry pi expert so optimisations could be made for sure. I'm happy to make my SD card image available to anyone who wants a copy, but I don't have sufficient hosting for the image file.

As the script runs headless on startup, no output is sent to the console by default.
To see it is working you can either
a) open up OpenCPN and see the traffic
b) sniff the network traffic on the destination computer using nc -l -n 192.168.1.101 9999 (linux)
c) sniff the network traffic using Wireshark (windows)
d) You can use rTail and pipe the output of the AIS parser to stream it to a webpage hosted on your Pi