JSON AIS feeding to aprs.fi

My narrowboat lives on a canal far away from the coastal Marine AIS receivers, so I wanted feed up the position from a Linux/Ubuntu machine via the internet and directly into APRS.fi. There is a mechanism for this, but all the examples I found for feeding the AIS and APRS data into aprs.fi were broken in some way. They received polite, but opaque error codes such as "jsonais content not found in HTTP post" or ""jsonais JSON message did not contain the 'protocol' key"". The submission must be a multipart/form-data upload (not a plain POST), with the "name=jsonais". For the actual JSON data, it must be wrapped inside two layers, one giving the protocol (again) as jsonais with an encodetime (which must be within the last minute), and the second being a multi-message array called "msgs".

There appear to be at least two more discrepancies against the formal JSON AIS specification: firstly "msgtype": "sp" does not work for combined: it needs to be separate numerical AIS codes; and secondly "rxtime" is needed instead of "timestamp". If you get a bit further and succeed with your static test data, you will probably get a rather more positive "jsonais JSON message 'encodetime' differs from current UTC time by over 60 seconds" error. For submission, I tried wget at first but gave up, only managing to make test submissions work with curl because of built-in support for multipart/form-data

Command-line to use: curl -i -X POST --form jsonais="`cat my.json`"';type=application/json' http://aprs.fi/jsonais/post/SeCrEtKeY

Where "my.json", looks like:

{
 "protocol": "jsonais",
 "encodetime": "20131231235959",
 "groups": [
  {
   "path": [ { "name": "MYACCOUNT", "url": "http://www.example.com/" } ],
   "msgs": [
    {
     "msgtype": "18",
     "mmsi":123456789,
     "callsign":"C4LL5GN",
     "shipname":"MY BOAT NAME",
     "shiptype":37,
     "status":5,
     "speed":0,
     "lon":0.00000,
     "lat":0.00000,
     "course":0.0,
     "heading":0.0,
     "length":12,
     "width":2,
     "ref_front":6,
     "ref_left":1,
     "draught":1,
     "rxtime":"20131231235959"
    }
   ]
  }
 ]
}

Your AIS SeCrEtKeY can be found in https://aprs.fi/account/ under "AIS password". Hope it helps and saves you a couple hours of hair-pulling. Note that you can't send everything in one "msgtype". Just sent it multiple times with differing msgtypes (msgs is an array).