connect two AIS receivers to one kplex device?

80 views
Skip to first unread message

Helmut Fischer

unread,
Aug 30, 2023, 6:09:45 AM8/30/23
to kplex
Hello everyone,

is it possible to connect two AIS receivers to one Raspberry Pi running kplex?

Background:

currently I run two AIS systems, both with direct USB output, each connected to a Raspi running kplex 1.4. I am using them to upload to MarineTraffic and to experiment with different antenna setups. I have defined two MT stations for this purpose.

Once I have found a satisfying antenna combination (e.g. one omidirectional for the nearer surroundings and one directional pointing towards the open sea), I would like to combine the messages to one station. MT doesn't allow sending from two devices to one MT station, so I am thinking of combining the inputs already at the kplex system.

Both my AIS (currently with simple DIY dipole antennas) have a mean range of 5 nm and a maximum range of ca. 10 nm, with some spikes up to 20 nm. They deliver 100 to 150 sentences per minute each, so the amount of data is relatively small.

Thanks in advance and regards,

Helmut, Bremen, Germany

Klaus Lohmann

unread,
Aug 31, 2023, 4:39:55 AM8/31/23
to kplex

Hello Helmut,
does MT recognize duplicate AIS messages from the same station?

If you can do some programming: receive the packets from two ports, keep a list of the last twenty or so, send new to kplex via localhost, discard duplicates ;).

Or do this directly in the kplex source code (not recomended).

Regards, Klaus

Helmut Fischer

unread,
Sep 1, 2023, 6:00:23 AM9/1/23
to kplex
Hello Klaus,

thanks for the proposal, but I fear that the necessary programming is beyond my current skills.

However, your answer lets me hope that the connection of two receivers to one kplex system should be possible.

I just contacted MT asking whethter duplicates from one station are a problem. They should well know how to handle duplicates from different stations, in my area there are at least five stations with similar ranges and seeing the same ships.

Regards, Helmut

Olivier ELIZON

unread,
Sep 10, 2023, 3:53:23 AM9/10/23
to kplex
I think this is possible : 
Assuming you have 2 raspberries:
- you setup your raspberry so that it is listenning to your 2 AIS receiver in client mode (so your kplex will receeive the 2 flows)
- you setup your raspberry kplex to send the traffic to MT server 
- if your 2 raspberry are using 2 different internet connection, on your internet router where you Raspberry #2 is connected, you need to redirect the flow using PAT/NAT to the local ip adress of your rapsberry #2
- if same network, then just work with local IP adresses and ports

All this seems feasible without coding, just with 2 kplex configuration and NAT/PAT potentially to me but requires testing and fine tuning :-)

if you have only 1 Raspberry: just setup 2 client AIS and setup 1 output to MT. 

good luck!!!!!!!


configuration with 1 raspberries: and 2 USB receivers:

###### Local input with USB receveir #1
[serial] 
filename=/dev/serial0  (maybe this need to be changed)
direction=in
baud=38400

###### Local input with USB receveir #2
[serial] 
filename=/dev/serial1 (maybe this need to be changed)
direction=in
baud=38400


# Marine Traffic Output
[udp]
direction=out
port=(replace with MT port)
address=(replace with MT IP Address)




configuration with 2 raspberries:

Raspberry #1 configuration
--------------------------------------------
your kplex.conf file should look like this : 
###### Local input with USB receveir #1
[serial] 
filename=/dev/serial0
direction=in
baud=38400

# Sending traffic to Raspberry #2 
[udp]
direction=out
port=5466
address=<IP Address of your raspberry #2> (if PAT/NAT, this is the internet IP adress of your router where there is the raspberry 2 ; if no PAT/NAT, local IP Address of your Raspberry)




Raspberry #2 configuration
--------------------------------------------
###### Local input with USB receveir #2
[serial] 
filename=/dev/serial0
direction=in
baud=38400

###### Input coming from your raspberry #1
[UPD] 
direction=in
port=5466
address=127.0.0.1 (in case of PAT / NAT)

# Marine Traffic Output
[udp]
direction=out
port=(MT port)
address=(MT IP Address)








Helmut Fischer

unread,
Sep 19, 2023, 11:56:19 AM9/19/23
to kplex
Hi Olivier,

thanks for the detailed instructions!

Once I'll have acquired or built a directional antenna (this may take a while) I will give it a try and report here.

Best regards,

Helmut
> --
> You received this message because you are subscribed to the Google Groups "kplex" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to kplex+un...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/kplex/a3b6667c-2f8f-4630-bcde-dcba88a2ad73n%40googlegroups.com.

Keith Young

unread,
Sep 28, 2023, 5:19:57 PM9/28/23
to kplex
Getting kplex to multiplex two data streams *in general* ... trivial. That is its very raison d'être. However AIS is a slightly special case and the risk when "crossing the streams" is that it may look fine but you may end up losing data.

The single messages are fine.  The issue is the multi-part ones.  A receiver will tag these with a sequence number and a fragment number.  Sequence will rotate through the digits 0-9 for each multi-part message.  The problem comes if you mix the output of two separate receivers and different fragments of different messages with the same sequence number get interleaved.  It's a race condition and you'll end up losing data, although you may not realise because some (maybe most?) data will get through just fine.

I'm not sure how you easily solve this and I don't even know how marine traffic deals with non-sequential fragments.  There's certainly ways to mitigate the problem so that the majority of data gets through.  Firstly you could run 2 instances of kplex on the same pi and output data over udp to marine traffic using the "coalesce=yes" option.  With that option specified, kplex will try to put all parts of an AIS message with the same sequence number into a single UDP packet.  IF marine traffic's data handler is single threaded (for one receiver endpoint at least) they might hopefully mean that all fragments of a single AIS message would get processed in sequence.  Sending from 2 kplex instances on the same pi would yield the same source address but different source ports which may or may not be an issue.  NAT of the outbound connection to be a single source port is entirely do-able but obviously beyond what the casual user may wish to do.

Unfortunately kplex is so utterly multithreaded that even if you coalesce data into a single udp packet and then recycle the data back into kplex there's no guarantee it'll end up being sequentially output without interleaving from multiple sources.

So..best idea submit via udp from 2 instances on the same pi (suggested config available on request) *IFF* marine traffic will accept udp input from 2 different ports on the same adderess.  If not, NAT may be an option.  If not...other ideas solicited but you may just have to accept the possibility of data loss due to race conditions / interleaving of multipart messages form different sources
Reply all
Reply to author
Forward
0 new messages