Skip to content

AK-Homberger/NMEA2000-AIS-Gateway

Repository files navigation

NMEA0183 to NMEA2000 AIS Gateway

This repository shows how to build a gateway to read NMEA0183 AIS messages and transform them to NMEA2000 PGNs.

The purpose is to use an existing NMEA0183 AIS receiver together with devices (e.g. MFD) that support only NMEA2000. Many new chart plotters only support NMEA2000 and do not have an additional RS232 or RS422 input.

If you need the opposite direction, then this might be of interest for you: https://github.com/ronzeiller/NMEA0183-AIS

I had to change and add some AIS related PGN structures in addition to the NMEA2000 library to make this work also with Raymarine MFDs.

AIS1 AIS2

Function

The ESP32 reads AIVDM messages from UART2 (connected to GPIO 16, baud rate 38400). Forwarding to NMEA2000 is done via a CAN bus transceiver.

The solution is re-using AIS decoder code from this GitHub repository. It is published under MIT-License.

It was necessary to change the code, to make it usable with the Arduino IDE and the ESP32. The reason for the changes was the different C compiler versions (clang#14 to clang#11). It was quite an effort to do the backport to Arduino clang#11 version, because of missing functions.

Supported AIS message types:

  • 1-3: Class A position report -> PGN 129038.
  • 5: Class A static and voyage related data -> PGN 129794.
  • 14: Safety related broadcast message -> PGN 129802. This is needed for AIS SART devices!
  • 18: Class B standard position report -> PGN 129039.
  • 19: Class B extended position report -> PGN 129040.
  • 24A: Class B static data part A -> PGN 129809.
  • 24B: Class B static data part B -> PGN 129810.

Detailled information regarding AIS messages can be found here.

Only AIVDM messages (other ships) are decoded by default. If you also want to decode and forward own ship messages (AIVDO) comment/uncomment the appropriate lines (code change requires Arduino IDE):

// Select (comment/uncomment) if you want to decode only other ship (AIVDM) or also own ship (AIVDO) messages
// if (!NMEA0183Msg.IsMessageCode("VDM") && !NMEA0183Msg.IsMessageCode("VDO")) return;   // Not a AIVDM/AIVDO message, return
if (!NMEA0183Msg.IsMessageCode("VDM")) return;   // Not a AIVDM message, return

Software Install

To install the program on the ESP32 you do have two options:

  1. Install the binary file with the NodeMCU PyFlasher tool
  2. Compile and upload the program with the Arduino IDE

NodeMCU PyFlasher

The easiest way to upload the binary file is to use the NodeMCU PyFlasher tool.

Download the appropriate version for your operating system. Then download the binary file MyAISToN2k.ino.esp32.bin to the PC.

Then start the NodeMCU PyFlaher program and select the downloaded binary and set the following options including the correct COM port:

Esptool

Then press "Flash NodeMCU". On some ESP32 it might be nessessary to press the "BOOT" button to start uploading.

Arduino IDE

To install the software with the Arduino IDE you have to install the IDE and the ESP32 board support.

To use the gateway the following libraries have to be installed (as ZIP file):

Click on the name of each repository, then click on "Code" and select "Download ZIP". Then in the Arduino IDE: Sketch, Include library, select Add .ZIP library and select the location of the downloaded libraries for each of the three libraries and install them one by one.

Then download the repository as ZIP file and upack it. The Arduino code is in the "MyAISToN2k" folder. Open "MyAISToN2k.ino" in the Arduino IDE.

How to install and use the Arduino IDE is explained in the NMEA2000 workshop.

Hardware

The schematics and the PCB from the WLAN gateway can be used for the gateway. Just ignore the not needed parts.

schematics

PCB

The board can be ordered at Aisler.net: https://aisler.net/p/DNXXRLFU

!!! Be careful with placing the the ESP32 on the PCB. The USB connector has to be on the right side !!!

Remove the 120 Ohm resistor from the transceiver

For unknown reasons, many CAN bus transceivers for the ESP32 have a 120 Ohm resistor built into them. The resistor does not belong to the devices at the ends of the stub lines, but to the ends of the backbone cable.

Whether the transceiver contains a 120 ohm resistor can be determined either by looking at the circuit diagram or by measuring with the multimeter.

A knife tip is suitable for removing the SMD resistor. Use it to scratch or pry off the resistance. With the transceiver shown here, place the tip of the knife in front of the resistor (between the chip and the resistor) and support the knife against the chip. Then lever the tip against the resistance and use it to scratch / loosen / break the resistance. Whichever happens first.

Transceiver

It then looks like the picture. Then measure to be on the safe side. Without a 120 ohm resistor, the multimeter shows approx. 75 kOhm.

Parts:

You only need these parts for the gateway:

  • U1 ESP32 Link
  • J5 SN65HVD230 Link
  • J2 D24V10F5 Link
  • R4 Resistor 4,7 KOhm Link
  • R5 Resistor 33 KOhm Link
  • Q2 Transistor BC547 Link
  • D1 Diode 1N4001 Link
  • D2 Diode 1N4148 Link
  • J1, J3 Connector 2-pin Link

Updates:

  • 13.01.22 Version 0.7: Select wether AIVDO messages (own ship) are to be decoded also in addition to AIVDM.
  • 13.01.22 Version 0.6: Corrected time PGNs for ETA calculation and changed AIS PGN handling for Raymarine MFDs.
  • 01.03.21 Version 0.5: Send message type 19 as PGN129040 (instead of 18 and 24a/24b PGNs).
  • 20.02.21 Version 0.4: Added message type 14 support.
  • 19.02.21 Version 0.3: Added message type 19 support.
  • 19.02.21 Version 0.2: Added ETA calculation for message 5.
  • 18.02.21 Version 0.1: Initial version.

About

An ESP32 based gateway to read NMEA0183 AIS messages and transform them to NMEA2000 PGNs.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages