Giter Club home page Giter Club logo

rtl-ais's Introduction

rtl-ais, a simple AIS tuner and generic dual-frequency FM demodulator

rtl-ais provides the rtl_ais command, which decodes AIS data from Software Defined Radio (SDR) and outputs AIVDM / AIVDO sentences.

OS support
Linux
Windows
OSX

Command Line

Use: rtl_ais [options] [outputfile]
        [-l left_frequency (default: 161.975M)]
        [-r right_frequency (default: 162.025M)]
            left freq < right freq
            frequencies must be within 1.2MHz
        [-s sample_rate (default: 24k)]
            maximum value, might be down to 12k
        [-o output_rate (default: 48k)]
            must be equal or greater than twice -s value
        [-E toggle edge tuning (default: off)]
        [-D toggle DC filter (default: on)]
        [-d device_index (default: 0)]
        [-g tuner_gain (default: automatic)]
        [-p ppm_error (default: 0)]
        [-R enable RTL chip AGC (default: off)]
        [-A turn off built-in AIS decoder (default: on)]
            use this option to output samples to file or stdout.
        Built-in AIS decoder options:
        [-h host (default: 127.0.0.1)]
        [-P port (default: 10110)]
        [-T use TCP communication as tcp listener ( -h is ignored)]
        [-t time to keep ais messages in sec, using tcp listener (default: 15)]
        [-n log NMEA sentences to console (stderr) (default off)]
        [-L log sound levels to console (stderr) (default off)]
        [-I add sample index to NMEA mesages (default off)]
        [-S seconds_for_decoder_stats (default 0=off)]
        When the built-in AIS decoder is disabled the samples are sent to
        to [outputfile] (a '-' dumps samples to stdout)
            omitting the filename also uses stdout
        Output is stereo 2x16 bit signed ints
        Examples:
        Receive AIS traffic,sent UDP NMEA sentences to 127.0.0.1 port 10110
             and log the senteces to console:
        rtl_ais -n
        Tune two fm stations and play one on each channel:
        rtl_ais -l233.15M  -r233.20M -A  | play -r48k -traw -es -b16 -c2 -V1 -

Compiling

Make sure you have the following dependencies:

  • librtlsdr
  • libusb
  • libpthread
$ # Get the source code:
$ git clone https://github.com/dgiardini/rtl-ais
$ # Change to the source dir
$ cd rtl-ais
$ make
$ # Test running the command
$ ./rtl_ais

For compiling a MS Windows executable you will need a working MSYS/MinGW environment. Edit the Makefile, and modify these lines:

#### point this to your correct path ###
RTLSDR_PATH="/c/tmp/rtl-sdr/"
RTLSDR_LIB=$(RTLSDR_PATH)/build/src/
########################################

Installing

  • On Linux, sudo make install
  • On Windows, put the librtlsdr.dll and libusb-1.0.dll files in the same directory with rtl_ais.exe. You'll need the zadig driver installed too.

Running

rtl-ais uses software defined radio (SDR). The specific hardware we use for this is a DVB-T dongle. A good starting point is: https://www.rtl-sdr.com/about-rtl-sdr

You'll need also an antenna, and be located near (some miles) the passing vessels.

You'll also need to do some procedure to get the tunning error for the specfic dongle you have (aka ppm error), and pass that number as parameter of rtl-ais.

Docker Container

Now you can run rtl-ais in a docker container. No dependencies to install. Total container size is approximately 75 MB. Get/install docker here.

Two options for obtaining the container: Either download and run a pre-built container, or build the container locally.

  1. Just to test things out: docker run -it --rm --device=/dev/bus/usb ghcr.io/bklofas/rtl-ais:latest

    • This downloads a pre-built container from the Github container registry.
    • This image will run by default ./rtl_ais -n, showing the received packets on STDOUT. All other default values.
    • You can add other ./rtl-sdr options, see below.
    • Make sure at least one RTL-SDR dongle is connected.
    • Startup messages and decoded packets will display in the terminal.
    • Ctrl-C to kill.
    • Using the --rm flag will delete the container when you kill it. Otherwise, it will stay around until you prune.
  2. For a more permanent setup, run the container in the background and add any options you want: docker run -d --name rtl-ais --restart=unless-stopped --log-driver=local --network=host --device=/dev/bus/usb ghcr.io/bklofas/rtl-ais:latest ./rtl_ais -n -d 00000002 -h 127.0.0.1 -P 10110

    • -d: Start this container in daemon/background mode.
    • --name: Name this anything you want.
    • --restart=unless-stopped: Automatically restart the container if something happens (reboot, USB problem), unless you have manually stopped the container (with docker stop rtl-ais).
    • --log-driver=local: By default, docker uses the json log driver which may fill up your harddrive, depending on how busy your station is. local log driver defaults to 100MB of saved logs, and automatically rotates them.
    • --network=host: Allows the container to talk to the internet, if you are sending the packets to an online service.
    • --device=: Allows the container to talk to the USB bus to access the RTL-SDR dongle.
    • ./rtl_ais: Same command-line options as above.
    • View the startup messages and decoded packets with docker logs --follow rtl-ais

Building the container:

  • git clone https://github.com/bklofas/rtl-ais.git the repository, then from the folder docker build -t rtl-ais .
  • Or, build the container without cloning the repository: docker build https://github.com/bklofas/rtl-ais.git

Other tips and tricks:

  • If you have the -n flag, view the decoded AIS packets in real-time with docker logs --follow rtl-ais
  • If you are only sending packets to one internet service (such as marinetraffic.com), you can use the -h and -P options that they send you.

Testing

TODO: something like https://github.com/freerange/ais-on-sdr/wiki/Testing-AISDecoder#with-an-audio-file

Known Issues

rtl-ais's People

Contributors

bertoldvdb avatar bklofas avatar devnulling avatar dgiardini avatar fredericguilbault avatar ikatz-drizly avatar keenerd avatar klapligehesten avatar neheb avatar nohal avatar nunojpg avatar odyno avatar rhaamo avatar sayzard avatar seandepagnier avatar v15n avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

rtl-ais's Issues

RTL AIS in OpenWrt, broadcast AIS Message issue

i failed to broadcast rtl_ais messages through built in wifi in openwrt

  1. I can only send it to specific ip

  2. I've tried send to broadcast ip address (my openwrt ip is 192.168.1.1, and according you answer before try to sent it to 192.168.0.255) but when im running the command there's ABORTED message.

  3. You said to try to send it through 192.168.1.1 well... It run on openwrt but on the client side (192.168.1.2) cant receive the AIS data
    Screenshot_2023-05-16-12-36-19-424_com android chrome

  4. Im trying TCP listener too, but same with no 3
    Screenshot_2023-05-16-13-04-50-768_com android chrome

The only way i can send ais data is to use
rtl_ais -n -h 192.168.1.2 -P 1234 it shows ais data on client just with input same port

I still can't find answer to this problem...

Raspberry Pi OS

Hi ! It seems that you still must edit the Makefile and change to "LDFLAGS+=-lpthread -lm -lrtlsdr -L /usr/lib/arm-linux-gnueabihf/" to make it compile. The bug in "rtl-sdr" package was never fixed ... and it's not mentioned in you readme...

TCP server stops streaming; bug or intentional?

Hi there! I have what may be a silly question about the intended usage of the TCP listener (./rtl_ais -T)

When I run rtl_ais in this mode, and connect a new client to the host and port (eg telnet localhost 10110), the client receives a burst of buffered messages, then nothing further. Sending a character from the client causes the connection to be closed.

What I'd expect: The client receives buffered messages, and continues to receive all newly-parsed messages, until either side terminates the connection.

Taking a look at docs and code, I can't quite see anything I'm doing wrong, so I'm thinking this is either intentional or perhaps just disused. Before I prep a PR, can you share any insight? Thanks for maintaining this!

Won't compile on Debian Buster

I'm getting tons of errors interfacing with the rtl_sdr library.

# make
cc -c main.c -o main.o -O2 -g -Wall -W  -I./aisdecoder -I ./aisdecoder/lib -I./tcp_listener -I/
cc -c rtl_ais.c -o rtl_ais.o -O2 -g -Wall -W  -I./aisdecoder -I ./aisdecoder/lib -I./tcp_listener -I/
cc -c convenience.c -o convenience.o -O2 -g -Wall -W  -I./aisdecoder -I ./aisdecoder/lib -I./tcp_listener -I/
convenience.c: In function 'atofs':
convenience.c:51:9: warning: this statement may fall through [-Wimplicit-fallthrough=]
    suff *= 1e3;
    ~~~~~^~~~~~
convenience.c:52:3: note: here
   case 'm':
   ^~~~
convenience.c:54:9: warning: this statement may fall through [-Wimplicit-fallthrough=]
    suff *= 1e3;
    ~~~~~^~~~~~
convenience.c:55:3: note: here
   case 'k':
   ^~~~
convenience.c: In function 'atoft':
convenience.c:78:9: warning: this statement may fall through [-Wimplicit-fallthrough=]
    suff *= 60;
    ~~~~~^~~~~
convenience.c:79:3: note: here
   case 'm':
   ^~~~
convenience.c:81:9: warning: this statement may fall through [-Wimplicit-fallthrough=]
    suff *= 60;
    ~~~~~^~~~~
convenience.c:82:3: note: here
   case 's':
   ^~~~
cc -c aisdecoder/aisdecoder.c -o aisdecoder/aisdecoder.o -O2 -g -Wall -W  -I./aisdecoder -I ./aisdecoder/lib -I./tcp_listener -I/
cc -c aisdecoder/sounddecoder.c -o aisdecoder/sounddecoder.o -O2 -g -Wall -W  -I./aisdecoder -I ./aisdecoder/lib -I./tcp_listener -I/
cc -c aisdecoder/lib/receiver.c -o aisdecoder/lib/receiver.o -O2 -g -Wall -W  -I./aisdecoder -I ./aisdecoder/lib -I./tcp_listener -I/
cc -c aisdecoder/lib/protodec.c -o aisdecoder/lib/protodec.o -O2 -g -Wall -W  -I./aisdecoder -I ./aisdecoder/lib -I./tcp_listener -I/
cc -c aisdecoder/lib/hmalloc.c -o aisdecoder/lib/hmalloc.o -O2 -g -Wall -W  -I./aisdecoder -I ./aisdecoder/lib -I./tcp_listener -I/
cc -c aisdecoder/lib/filter.c -o aisdecoder/lib/filter.o -O2 -g -Wall -W  -I./aisdecoder -I ./aisdecoder/lib -I./tcp_listener -I/
cc -c tcp_listener/tcp_listener.c -o tcp_listener/tcp_listener.o -O2 -g -Wall -W  -I./aisdecoder -I ./aisdecoder/lib -I./tcp_listener -I/
cc main.o rtl_ais.o convenience.o ./aisdecoder/aisdecoder.o ./aisdecoder/sounddecoder.o ./aisdecoder/lib/receiver.o ./aisdecoder/lib/protodec.o ./aisdecoder/lib/hmalloc.o ./aisdecoder/lib/filter.o ./tcp_listener/tcp_listener.o -o rtl_ais -lpthread -lm -L -lrtlsdr
/usr/bin/ld: rtl_ais.o: in function `rtlsdr_thread_fn':
/opt/rtl-ais/rtl_ais.c:368: undefined reference to `rtlsdr_read_async'
/usr/bin/ld: rtl_ais.o: in function `rtl_ais_start':
/opt/rtl-ais/rtl_ais.c:570: undefined reference to `rtlsdr_open'
/usr/bin/ld: /opt/rtl-ais/rtl_ais.c:610: undefined reference to `rtlsdr_set_agc_mode'
/usr/bin/ld: /opt/rtl-ais/rtl_ais.c:595: undefined reference to `rtlsdr_cancel_async'
/usr/bin/ld: /opt/rtl-ais/rtl_ais.c:596: undefined reference to `rtlsdr_close'
/usr/bin/ld: rtl_ais.o: in function `rtl_ais_cleanup':
/opt/rtl-ais/rtl_ais.c:657: undefined reference to `rtlsdr_cancel_async'
/usr/bin/ld: /opt/rtl-ais/rtl_ais.c:668: undefined reference to `rtlsdr_cancel_async'
/usr/bin/ld: /opt/rtl-ais/rtl_ais.c:673: undefined reference to `rtlsdr_close'
/usr/bin/ld: convenience.o: in function `nearest_gain':
/opt/rtl-ais/convenience.c:116: undefined reference to `rtlsdr_set_tuner_gain_mode'
/usr/bin/ld: /opt/rtl-ais/convenience.c:121: undefined reference to `rtlsdr_get_tuner_gains'
/usr/bin/ld: /opt/rtl-ais/convenience.c:126: undefined reference to `rtlsdr_get_tuner_gains'
/usr/bin/ld: convenience.o: in function `verbose_set_frequency':
/opt/rtl-ais/convenience.c:142: undefined reference to `rtlsdr_set_center_freq'
/usr/bin/ld: convenience.o: in function `verbose_set_sample_rate':
/opt/rtl-ais/convenience.c:154: undefined reference to `rtlsdr_set_sample_rate'
/usr/bin/ld: convenience.o: in function `verbose_direct_sampling':
/opt/rtl-ais/convenience.c:166: undefined reference to `rtlsdr_set_direct_sampling'
/usr/bin/ld: convenience.o: in function `verbose_offset_tuning':
/opt/rtl-ais/convenience.c:183: undefined reference to `rtlsdr_set_offset_tuning'
/usr/bin/ld: convenience.o: in function `verbose_auto_gain':
/opt/rtl-ais/convenience.c:195: undefined reference to `rtlsdr_set_tuner_gain_mode'
/usr/bin/ld: convenience.o: in function `verbose_gain_set':
/opt/rtl-ais/convenience.c:207: undefined reference to `rtlsdr_set_tuner_gain_mode'
/usr/bin/ld: /opt/rtl-ais/convenience.c:212: undefined reference to `rtlsdr_set_tuner_gain'
/usr/bin/ld: convenience.o: in function `verbose_ppm_set':
/opt/rtl-ais/convenience.c:226: undefined reference to `rtlsdr_set_freq_correction'
/usr/bin/ld: convenience.o: in function `verbose_ppm_eeprom':
/opt/rtl-ais/convenience.c:241: undefined reference to `rtlsdr_get_usb_strings'
/usr/bin/ld: convenience.o: in function `verbose_reset_buffer':
/opt/rtl-ais/convenience.c:266: undefined reference to `rtlsdr_reset_buffer'
/usr/bin/ld: convenience.o: in function `verbose_device_search':
/opt/rtl-ais/convenience.c:277: undefined reference to `rtlsdr_get_device_count'
/usr/bin/ld: /opt/rtl-ais/convenience.c:284: undefined reference to `rtlsdr_get_device_usb_strings'
/usr/bin/ld: /opt/rtl-ais/convenience.c:297: undefined reference to `rtlsdr_get_device_usb_strings'
/usr/bin/ld: /opt/rtl-ais/convenience.c:301: undefined reference to `rtlsdr_get_device_name'
/usr/bin/ld: /opt/rtl-ais/convenience.c:291: undefined reference to `rtlsdr_get_device_name'
/usr/bin/ld: /opt/rtl-ais/convenience.c:307: undefined reference to `rtlsdr_get_device_usb_strings'
/usr/bin/ld: /opt/rtl-ais/convenience.c:324: undefined reference to `rtlsdr_get_device_name'
/usr/bin/ld: /opt/rtl-ais/convenience.c:317: undefined reference to `rtlsdr_get_device_usb_strings'
collect2: error: ld returned 1 exit status
make: *** [Makefile:59: rtl_ais] Error 1

Apt installed:

librtlsdr-dev/now 0.6-1 amd64 [installed,local]
  Software defined radio receiver for Realtek RTL2832U (development)

Build in debian:buster-slim docker container:
Linux [image hash] 5.4.0-59-generic #65-Ubuntu SMP Thu Dec 10 12:01:51 UTC 2020 x86_64 GNU/Linux

main.h file missing

Hi,
main.h is missing during compilation in android studio.

#include "rtl-ais/main.h"

Are multiline AIS messages always send in order?

Hey,

if we enable two channels, ais it guaranteed that multiline AIS messages are send in order and without being 'interrupted' by the other channel?

For example:

!AIVDM,3,1,8,A,8h30otA?0@<o;NPPPP<i>nskl4tSp1m>@00o;NPPPP<iCnsm<4tPG286@00o;NPP,0*3D
!AIVDM,3,2,8,A,PP<j>nsphTtHBR7@@00o;NPPPP<jCnssG4tCk2N0@00o;NPPPP<k>nsuPTt6m2Mt,0*44
<-- is it guaranteed no message of the other channel will appear here?
!AIVDM,3,3,8,A,@00o;NPPPP<kCnsuwTt3?2lB@00,2*3D

Compiling on a RasPi - Package librtlsdr was not found

Hiya.. help needed. This is what I get when trying make:

albert@ais-maresme:~/rtl-ais $ sudo make Package librtlsdr was not found in the pkg-config search path. Perhaps you should add the directory containing librtlsdr.pc'
to the PKG_CONFIG_PATH environment variable
No package 'librtlsdr' found
cc -c rtl_ais.c -o rtl_ais.o -O2 -g -Wall -W -I./aisdecoder -I ./aisdecoder/lib -I./tcp_listener
rtl_ais.c:42:10: fatal error: rtl-sdr.h: No such file or directory
42 | #include <rtl-sdr.h>
| ^~~~~~~~~~~
compilation terminated.
make: *** [Makefile:62: rtl_ais.o] Error 1`

I previously installed rtl_sdr but librtlsdr shows up with a 0 at the end:

albert@ais-maresme:~/rtl-ais $ sudo find / -name librtlsdr* /var/lib/dpkg/info/librtlsdr0:armhf.prerm /var/lib/dpkg/info/librtlsdr0:armhf.postinst /var/lib/dpkg/info/librtlsdr0:armhf.triggers /var/lib/dpkg/info/librtlsdr0:armhf.postrm /var/lib/dpkg/info/librtlsdr0:armhf.preinst /var/lib/dpkg/info/librtlsdr0:armhf.shlibs /var/lib/dpkg/info/librtlsdr0:armhf.list /var/lib/dpkg/info/librtlsdr0:armhf.md5sums /var/cache/apt/archives/librtlsdr0_0.6.0-3_armhf.deb /usr/lib/arm-linux-gnueabihf/librtlsdr.so.0 /usr/lib/arm-linux-gnueabihf/librtlsdr.so.0.6.0 /usr/share/metainfo/librtlsdr0.metainfo.xml /usr/share/doc/librtlsdr0 albert@ais-maresme:~/rtl-ais $

Should I create a symlink and try? may be install something different?

albert@ais-maresme:~/rtl-ais $ uname -a Linux ais-maresme 5.15.32+ #1538 Thu Mar 31 19:37:58 BST 2022 armv6l GNU/Linux

Thanks in advance,

Missing 'rtl-sdr.h'

make
cc -c rtl_ais.c -o rtl_ais.o -O2 -g -Wall -I./aisdecoder -I ./aisdecoder/lib -I./tcp_listener -I/usr/local/include/ -I/tmp/libusb/include/libusb-1.0 -I/tmp/rtl-sdr/include
rtl_ais.c:42:10: fatal error: 'rtl-sdr.h' file not found
#include <rtl-sdr.h>

double/duplicate TCP messages ?

I seem to be getting every message twice, via TCP to OpenCPN:

output of rtl-ais with "./rtl_ais -T -P 11111 -n -R on" :
!AIVDM,1,1,,A,H4eIMs@L4hDpD00000000000000,0*68
output of OpenCPN/nmea debug window:
08:25:46 (TCP:127.0.0.1:11111) !AIVDM,1,1,,A,H4eIMs@L4hDpD00000000000000,0*68<0x0D><0x0A> 08:25:56 (TCP:127.0.0.1:11111) !AIVDM,1,1,,A,H4eIMs@L4hDpD00000000000000,0*68<0x0D><0x0A>
this seems specific to rtl-ais, when using a PI4 as TCP server with an old NMEA0183 AIS connected via serial port, I am not getting duplicate messages.

TCP LISTENER/Host network forward issue

Hi, I'm an independent research scholar and I'm actually trying to receive the AIS signal reception. I could see the least signal reception compared to commercially available ais receiver in the market. I'm actually going a comparitive analysis on how effectively we could use the open source resource to achieve the requirements. So in this case I'm using commercial ais receiver with scan brand ais antenna Vs raspi integrated neolec nano3 sdr connected with scan brand ais antenna. I could see more signal reception at the commercial one than our open source. Also I found issue with tcp listener and network forwarder. The following command to run the rtl ais system is

rtl_ais -l161.976M -r162.025M -h192.168.0.9 -P10110 -n -R

It is not working...the static ip assigned to the same raspberry pi is 192.168.0.9

Whereas if I pass the following command

rtl_ais -l161.976M -r162.025M -T -P10110 -t120 -n -R

Everytime I need to open and close the socket to update the incoming string. So my question is

  1. How to increase the incoming signals or increase the accuracy of detecting the ais signals
  2. How to make the data forwarding to another ip address
  3. How to make the tcp listener always receive without closing the socket connectivity.
  4. Does ppm calibration helps us to increase the signals?

Could you please help me on this.

Thanks in advance.
SAI

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.