A simple forwarder for AIS and NMEA 0183 data over TCP/IP

I've recently moved the NMEA 0183 HS serial port from my Windows PC input to the central Linux micro computer, and written a small script that retransmits the serial data out over TCP/IP.

This has a number of advantages in my particular install:
  • It allows me to log the AIS data stream.
  • It allows me to view the AIS on both Expedition and Nobeltec software at the same time.
  • It allows me to simultaneously access the AIS stream from my iPad. I've tested it with Digital Yacht's iAIS app, but it should work with other apps running on the iPad.
So instead of being able to use the AIS data only on a single Windows application I can now use it on all navigation hardware access that I have on the boat. Quite an achievement for moving one plug and writing a little bit of PHP code.

The code really is very simple - it reads an entire line from the serial, detects any new clients and then forwards it to all TCP clients that have connected to it. Then loop. As a bonus it will cache the last received 200 AIS messages and send those immediately to any client that connects. This in the hope that this contains a number of VDM type 5 and 24 messages so that the client can show static AIS data immediately.

You can download the nmea_to_tcp script here. I'm releasing this under the GPL v3.

To use this code you must have a computer that has a PHP5 CGI interpreter. On Microsoft Windows you may want to remove the first line of the nmea_to_tcp script, as this instructs a Linux system to use the PHP interpreter. You may need to install the DIO direct I/O package.

Connect you AIS receiver to a serial port, and then start the script with the name of that serial port as it's first argument, for instance nmea_to_tcp /dev/ttyUSB0 on Linux; it is probably something like nmea_to_tcp //./com1 on Microsoft Windows.

That's all. You should now be able to connect to the system at TCP port 2000.

Nobeltec and TCP streams

By the way, to get Nobeltec to use the TCP stream -- you can't rely on the built-in Glass bridge functionality. You have to convert the TCP stream back to serial data, for instance using the open source com0com and com2tcp software.