Step 4: Install kPlex NMEA Multiplexer

kPlex is the software that we’ll use to receive and forward NMEA network data between all of the NMEA0183 (2 USB adapters like this one) and TCP/IP (Ethernet and WiFi) interfaces.   It will also serve as a source of data for OpenCPN running directly on the Raspberry Pi.

kPlex Website: http://www.stripydog.com/kplex/index.html

First we need to install kPlex itself.  There is a package already built for Raspbian, but it’s not in the APT repository, so we will just need to download that package and install it manually.

Download the package for Raspbian Wheezy
cd ~
  sudo wget http://www.stripydog.com/download/kplex_1.3.4-1_armhf.deb

Then we will install the package we just downloaded
  sudo dpkg -i ./kplex_1.3.4-1_armhf.deb

Next we can configure kPlex to automatically start when the rPi boots up
sudo update-rc.d kplex defaults

Now we will set up a basic NMEA Server by setting the appropriate parameters in the kplex config file.
  sudo nano /etc/kplex.conf
Edit the file as follows

[serial]
filename=/dev/ttyUSB0
direction=in
baud=4800
name=mux

[serial]
filename=/dev/ttyUSB1
direction=in
baud=38400
name=ais

[tcp]
mode=server
port=10110
direction=out

[udp]
port=10110
address=255.255.255.255
type=broadcast
coalesce=no

#[broadcast]
#direction=out
#device=br0

[global]
failover=GP***:0:mux:60:ais

Save and Exit (CTRL-X)

Okay, let’s explain what this config file actually does.  You will likely need to adjust this based on your configuration

The first [serial] section defines an NMEA to USB interface that I’ve named “mux” because the data coming in that port is coming from a Digital Yacht NMEA MUX100 device.  It’s set to 4800 because that’s the speed that the MUX100 device’s output is configured for.  This port is configured to receive NMEA data but not send any.

The second [serial] section defines another NMEA to USB interface named “ais” because that connection is attached to the NMEA output port of the West Marine AIS-1000.  Since AIS NMEA ports run at 38400 baud that is defined in this configuration as well.   Again, this port receives data but does not send out.

In both of the above cases, I’m using a low cost USB to Serial Adapter (Trendnet TU-S9) which goes for about $10 on Amazon.com

Then we have a [tcp] section which defines the network server on port 10110 for devices like iPad’s and laptops to query kPlex for NMEA data.  This is configured to send NMEA data out but not receive it.

Following that there is the [udp] section which defines a broadcast server on port 10110 for devices that merely listen for NMEA data coming in rather than asking for it. This is also using port 10110 (if not specified, kPlex uses that port by default anyway) and it’s configured to send to the all-hosts broadcast address of 255.255.255.255.

The [broadcast] section is an older version of the [udp] section and I’ve included it in case you run in to any issues with UDP.  You can comment out the [udp] section and uncomment the [broadcast] section if you need to.

Lastly because both the MUX100 and the AIS will be sending GPS position data, I configured a failover rule in the [global] section that makes the mux100 the primary source and the AIS a failover source for just the GPS data.   As long as GPS position data is coming in on USB0, all of the GPS data on USB1 will be ignored.  If GPS data stops coming in on USB0, then kPlex will start accepting it from USB1. All other data coming in on both ports is unaffected by this rule.

There are also ways to configure filters so certain NMEA data is not accepted but I am not configuring that right now until I have a chance to see what data actually shows up when everything is connected.

Full documentation for the kplex.conf file is here: http://www.stripydog.com/kplex/configuration.html

I started with the quickstart guides and used the configuration guide above to enhance and adjust.
http://www.stripydog.com/kplex/quickstart.html
http://www.stripydog.com/kplex/examples/nmeaserver.html

Finally, assuming the file is configured correctly and all the devices and interfaces are connected and installed (ie: the USB devices need to be plugged in and seen by Raspbian) you can start the kplex daemon.

sudo service kplex start

Next Step: Step 5: Install OpenCPN Chartplotting Software

%d bloggers like this: