Connecting to the TCP Feed

How to connect to the Spire Maritime AIS TCP feed.

Connect to the Spire Sense TCP Server

To be able to use the Spire AIS TCP Service, an authorization token needed, which is used to authenticate the service.

Initiating the TCP Feed: Initiate Connection.

For TCP connections, client systems must open a port connection to the Spire service on the Service Address : streaming.ais.spire.com

Port number: 56784.

To initiate the stream of messages, and initial authentication string must be sent as below:

A|T|<auth_token_goes_here>

Note: Depending on which system you are using, you might want to send a new line ‘\n’ to make sure that the token is sent in one piece directly

If connection is successful then the stream of AIS data in NMEA format will start.

Possible initial delay.

Once your connection has been established, AIS messages should begin streaming into your client. Note: It can take up to 60 seconds for the TCP server to start up a new stream after sending your token. 

Recommended Reconnection Strategy

The TCP server should keep your connection alive indefinitely and send keep-alives every 15 minutes to your client, however, exceptions still happen. Occasionally there might still be instances of unexpected disconnects to the TCP feed. In these cases, you can simply reconnect, re-authenticate with your token and the data stream will resume.

In order to minimize loss of data and impact on latency, we recommend setting up a reconnection method that automatically acts within an hour of any unexpected disconnect.

Interruptions continue where left off

The behaviour of the TCP service is to provide a continuous stream of AIS messages in the order that they are received by Spire systems. If the service stops, due to disconnection or client system problems, then no matter how long the delay in re-connecting, the stream of data will continue from the time of disconnection and no data will be missed. If however the service is disconnected for a long time, then it can cause a large backlog of now old data to be streamed before the service catches up to current time and entirely new messages are received. 

Multipart messages

AIS message 5 is commonly received in multiple parts, generally 2 message sentences. Spire AIS stream always provides these sequentially so not grouping message ID is required

An example of multi part AIS message 5

\c:1601972308*58\!AIVDM,2,1,5,A,543lNb02=vi5ED4d000P4`@4l4d400000000000l28?5753Q0;i3QD4ShUAl,0*61
\c:1601972308*58\!AIVDM,2,2,5,A,jnBH8888880,2*2F
\c:1601972310*51\!AIVDM,2,1,5,A,58JU7L02<=kCUKGO3N0e=B0d4p<Tj2222222220O1h@5400Ht00000000000,0*58
\c:1601972310*51\!AIVDM,2,2,5,A,00000000000,2*21
\c:1601972308*58\!AIVDM,2,1,5,A,56:V3vP000033333331PTq0TpL`T4pO73;F2221A8hA776Se05k2C`8862@C,0*28
\c:1601972308*58\!AIVDM,2,2,5,A,Qp888888888,2*08
\c:1601972310*51\!AIVDM,2,1,5,B,55NB<R800001L@cS7OI<5H4pp4R18UHE:15DDDpt1@c334000D0000000000,0*1B
\c:1601972310*51\!AIVDM,2,2,5,B,00000000000,2*22
\c:1601972309*59\!AIVDM,2,1,5,B,53VAS842Eaba=H7O3KDuE84pu>2222222222220U4H?366Mc080AjjDm4RH8,0*03
\c:1601972309*59\!AIVDM,2,2,5,B,88888888880,2*22

parts of the AIS message stream above explained

message timestamp and checksum   \c:1601972308*58
message header !AIVDM
message sentence count 2
message sentence number 1 or 2
message number 5
AIS channel A or B
Encoded AIS data and checksum (the rest of the message record)

Example Python to connect

A simple python program for connecting to the Spire TCP service is available for testing from this Google Drive link https://drive.google.com/drive/folders/1UHH7vGTVZCxqrATQGWsMkFtV0RdPt4Nx?usp=sharing

It can be called  in the following fashion (using a demo or client authentication token)

python call_spire_tcp_feed_parameters.py test_tcp.txt 100 streaming.ais.spire.com 56784 2 <CLIENT AUTHENTICATION TOKEN>

Example

python call_spire_tcp_feed_parameters.py test_tcp.txt 100 streaming.ais.spire.com 56784 2 eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJjdXN0b21lciI6eyJpZCI6IjcxMSIsIm5hbWUiOiJTcGlyZSBUQ1AgREVNTyBET1ZFUiIsInV1aWQiOiI3MTEifSwiaXNzIjoic3BpcmUuY29tIiwiaWF0IjoxNTk1NDA0MTUxfQ.kOiZqAYH2-uY6EJZHLKwuqyMhP763CttvFm8DuQZQW8

Sample Results

python3 call_spire_tcp_feed_parameters.py t
est_tcp.txt 100 streaming.ais.spire.com 56784 2 eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJjdXN0b21lciI6eyJpZCI6IjcxMSIsIm5hbWUiOiJTcGlyZSBUQ1AgRE
VNTyBET1ZFUiIsInV1aWQiOiI3MTEifSwiaXNzIjoic3BpcmUuY29tIiwiaWF0IjoxNTk1NDA0MTUxfQ.kOiZqAYH2-uY6EJZHLKwuqyMhP763CttvFm8DuQZQW8
Program Start Time: 2020-07-22T09:55:43+02:00
server set to parameter value: streaming.ais.spire.com
Run TCP client for 2 minutes
Debug set to default of False - False
Parameter Debug = : False
Using API Token from parameters
Using API Token: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJjdXN0b21lciI6eyJpZCI6IjcxMSIsIm5hbWUiOiJTcGlyZSBUQ1AgREVNTyBET1ZFUiIsInV1aWQiOiI3MTEi
fSwiaXNzIjoic3BpcmUuY29tIiwiaWF0IjoxNTk1NDA0MTUxfQ.kOiZqAYH2-uY6EJZHLKwuqyMhP763CttvFm8DuQZQW8
About to try connecting to:
Server: streaming.ais.spire.com on port: 56784

Writing text data stream to file test_tcp.txt20200722-075543.txt
Writing nmea data stream to file test_tcp.txt20200722-075543_nmea.txt
Setting job message limit : 100
Connecting..
program has run for 0.0 minutes. 20200722-075546 Last Minute captured 1 records.
Stopping as max_records number reached: 100
Stopping as max_records number reached: 100
Stopped after receiving 100 messages 100
API Processing ran from 20200722-075543 to 20200722-095546 received 100 lines of results

Program run from 20200722-075543 to 20200722-095546 took (0.0, 2.779322) minutes

Start time as unix time: 1595397343.0
End time as unix time: 1595397346.0
Elapsed time in seconds: 3

wc -l test_tcp.txt20200722-075543_nmea.txt
100 test_tcp.txt20200722-075543_nmea.txt

Showing the captured results

head -5 test_tcp.txt20200722-075543_nmea.tx
t
20200722-075546,b'\\c:1595382932*50\\!AIVDM,1,1,,B,13Hj;iPP00P7Am0M1`cN4?w02>`<,0*01\r'
20200722-075546,b'\\c:1595382943*56\\!AIVDM,1,1,,A,33QFvD500007=4nM1a0raF5F0>`<,0*3F\r'
20200722-075546,b'\\c:1595382957*53\\!AIVDM,1,1,,A,B3HjFSP0Fh1ba>7A4HFmwwtUoP06,0*1B\r'
20200722-075546,b'\\c:1595382966*51\\!AIVDM,1,1,,B,B3`erch0081Otk7D0MwQ3wS1nE6b,0*00\r'
20200722-075546,b'\\c:1595382969*5E\\!AIVDM,1,1,,B,13aFfS@P00P7Dc8M1VSN4?vB2>`<,0*05\r'

 

For further questions or support please submit questions to the Spire Sales Engineering team using our client web support form here https://spire.com/developers/support/