Sunday 27 October 2024

AIS Monitoring - RTL SDR

Today I had a hankering to setup and monitor Maritime VHF AIS.  I've done it the past for fun and could see that our area had very good coverage by number of other enthusiasts / operators:

To view area of coverage - See via MarineTraffic.com

I've always enjoyed monitoring maritime voice traffic.  I normally always have my HT or base station rig monitoring Marine VHF CH 12 (156.600 MHz) "Brisbane VTS". If I want to monitoring more I would normally spin up SDRConsoleV3 with a RTL-SDR and monitor local (CH12, CH16 CH73 etc).

If I wanted to monitor the marine VHF repeaters (at 161 MHz) I would either use the existing RTL-SDR so would need to stop listening to the simplex maritime traffic (at 156 MHz) due to the ~2MHz bandwidth window or grab another RTL-SDR plug it in and open another SDRConsole instance which starts becoming a little annoying. 

The Plan...

I've kept one eye on the "OpenWebRx" project and have been impressed with the way we can now easily set up multiple RTL-SDRs and associated profiles. Since the RasPi4 wasn't been used and I had a couple of RTLSDR not doing much I thought, OK how about we setup the following:

  1. First RTLSDR would be limited to a single profile to cover the VHF Marine Repeaters and AIS
  2. Second RTLSDR would be free to switch between multiple profiles to provide access to (FMBC, Air, Ham 2m/70cm, Maritime Simplex (156MMHz) for starters.

AIS Decoders...

Reviewed the following AIS decoders:

  1. rtl_ais
  2. AISRecWin
  3. AIS-Catcher 

I tested rtl_ais and felt the decode rate was a little low.   I switched to AISRecWin and the decode count skyrocketed, however it only runs 20min for trail version.  

I then downloaded and setup AIS-Catcher and boy what a fabulous application. Not only was the decode rate better than AISRecWin, but it also provides an awesome web UI with great stats, allowing you to monitor your own data without having to publish it to one of the external sites (i.e AISHub/MarineTraffic).   

When you are ready to publish you feed,  the application provides multiple means i/e. UDP/HTTP etc.  It also include its own internal "AIS Dispatcher" (So no need to install and set up AISDispatcher.) so you can configure as many external feeds as you wish.   One great feature was ability to feed AIS data to "aprs.fi"!!   

All this from one application!!!

RTLTCP Compatible Port...

I now needed to consider how I was going to access the 2 RTLSDRs by OpenWebRx.  I could simply just configure OpenWebRx to access the devices directly (via "rtl_connector").  However this got me thinking about how best to a feed from OpenWebRx to the AIS-Catcher decoder.

OpenWebRx RTLSDR connector does provide an option to enable a "RTL_TCP" compatible like port. 

Important Note
  • You will need to reboot OpenWebRX to ensure the connector correctly restart with the new option enabled.
  • Don't forget to set the config option to "alway run the device" as it will only start an instance when a user selects the device profile.

I configured AIS-Catcher to point to the port and bingo it worked!  

Ok great!! but....... While I can open multiple OpenWebRx tabs and select different frequencies...  I thought if I wanted to also access the sdr feed via SDRConsole and/or SDRSharp..........

RTLTCP and RTLMUX...

RTLTCP  only allows a single client to connect.  However if we also used RTLMUX, it now allows multiple clients to connect and control the RTLSDR.

This allows us to set up each RTLSDR being made available by multiple applications without having to shut one done, start one up etc.

Installing RTL_TCP...

sudo apt install rtlsdr

sudo wget -O /etc/udev/rules.d/20-rtlsdr.rules https://raw.githubusercontent.com/osmocom/rtl-sdr/master/rtl-sdr.rules
sudo udevadm control --reload-rules && sudo udevadm trigger

 

Building and Installing TCP_MUX...


sudo apt update && sudo apt upgrade
sudo apt install -y libusb-1.0-0-dev git cmake pkg-config
sudo apt install -y libevent-dev

cd $PROJ_HOME
git clone https://github.com/slepp/rtlmux.git
cd rtlmux
make
sudo cp ./rtlmux /usr/bin/rtlmux

Running Manually...


1. Start RTL_TCP

rtl_tcp -d 1 -a 127.0.0.1 -p 4333 -n 1000 -P 2
 

2. Start RTL_MUX

rtlmux -p 4333 -h 127.0.0.1
 

3. Start AIS-catcher via MUX Port 7878

./AIS-catcher -N 8100 STATION VK4TMZ-2 LAT -27.2969 LON 152.9565 SHARE_LOC on FILE stat.bin BACKUP 5 MSG on -c AB -t 127.0.0.1 7878 -gt TUNER auto rtlagc on -p 2 -s 1536000

  • Notes:
    • Use one of the following rate to prevent up sampling and noise:
      • 96K, 192K, 288K, 384K, 768K, 1536K, 3072K, 6144K, 12288K 
    • However if you wish to also allow SDRConsole and / or SDRSharp to connect then use 2.048 MS/S as this is the only one common between the 2.  It does mean AIS-Catcher will up sample to the next double from 1536 * 2 -> 3072K

4. Monitor RTL_MUX stats

http://localhost:7879/stats.json



Notes on adding  RTL_TCP device to OpenWebRX for AIS...

  • CenterFreq - 162MHz has this is where AIS-catcher defaults to.
  • IMPORTANT: 
    • When attaching SDRSharp, SDRConsole ensure you set CentreFreq to 162 MHZ, else it will sent through possibly bad frequency and disturn the AIS-Capture decoder.
    • 1.536 MS/s allows inclusion of NOAA Weather Radio and Marine VHF Repeater Frequencies.

Running as Services...

The following are some commands / scripts to enable registering multiple RTLSDR instances of RTLTCP / RTLMUX services.
 
Because rtl_tcp only accesses RTLSDR using its device index and not the device serial, I've utilised the following work so I could specify serial and it will determine index:
1. Create an unprivileged user for running RTL_TCP and RTL_MUX

sudo adduser --system rtltcp
sudo addgroup rtltcp
sudo usermod -aG dialout,rtltcp,plugdev -a rtltcp

2. Following creates script for looking up serial based on device index:

sudo mkdir /opt/rtltcp
sudo tee /opt/rtltcp/rtlsn2dev.sh << 'EOF'
#!/bin/bash
# usage: ./rtlsn2dev.sh [serial number]
# returns: device ID
if [ $1 ]
then
  rtl_num_devices=$(rtl_eeprom 2>&1 >/dev/null | grep "Found [0-9][0-9]*" | sed -E 's/.*([0-9]+).*/\1/')
  if [ $rtl_num_devices ]
  then
    for i in $(seq 1 $rtl_num_devices);
    do
      rtl_device=$((i-1))
      rtl_serial=$(rtl_eeprom -d$rtl_device 2>&1 >/dev/null | grep "Serial number\:" | sed -E 's/Serial number:[[:blank:]]+//')
      if [ "$1" == "$rtl_serial" ]
      then
        echo $rtl_device
      fi
    done
  fi
fi
EOF
sudo chmod +x /opt/rtltcp/rtlsn2dev.sh
sudo chown -R rtltcp:rtltcp /opt/rtltcp



3. Create service unit template file for RTL_TCP:

sudo tee /etc/systemd/system/rtltcp@.service << 'EOF'
[Unit]
Description=rtl_tcp radio streaming service
After=network.target

[Install]
WantedBy=multi-user.target

[Service]
Type=simple
User=%p
Restart=always
WorkingDirectory=/opt/rtltcp
ExecStart=/bin/sh -c "/usr/bin/rtl_tcp -d $(/opt/rtltcp/rtlsn2dev.sh %i) -a 0.0.0.0 -p $((7000+%i)) -n 1000"
EOF


4. Register RTL_TCP service for each dongle:

# Now reload systemd, create a couple instances of this service, and start them
sudo systemctl --system daemon-reload
sudo systemctl enable --now rtltcp@00000001.service
sudo systemctl enable --now rtltcp@00000003.service


5. Create service unit template file for RTL_MUX:

sudo tee /etc/systemd/system/rtlmux@.service << 'EOF'
[Unit]
Description=rtlmux radio streaming service
Wants=rtltcp@.service
After=rtltcp@.service

[Install]
WantedBy=multi-user.target

[Service]
Type=simple
User=rtltcp
Restart=always
WorkingDirectory=/opt/rtltcp
ExecStart=/bin/sh -c "/usr/bin/rtlmux -h 0.0.0.0 -p $((7000+%i)) -l $((7100+(%i*10))) "
EOF


6. Register RTL_MUX service for each dongle:

# Now reload systemd, create a couple instances of this service, and start them
sudo systemctl --system daemon-reload
sudo systemctl enable --now rtlmux@00000001.service
sudo systemctl enable --now rtlmux@00000003.service


7. Test Access 

Using SDRConsole / SDRSharp and or any other tool that provide RTL_TCP connection. Don't forget to connect using he RTL_MUX Port number in my case (7110 and 7120)

My AIS feed status and coverage


End Note......

Its been just over 5 years since my last post here back in June 2019...   That doesn't mean I've not been still tinkering with radios, SDRs, antennas, software etc, etc   I just  haven't had anything of interest to report sorry.....  As you can see if and when I do have anything of interest to share, I've come back here and post my thoughts :)

73's
Mark (VK4TMZ)


No comments:

Post a Comment