Our tall ship youth sail training vessel, the St. Lawrence II, has, among other Victron components, a Color Control GX. The original intent for this device was to provide logging of DC power consumption and battery charging over the course of each summer's sailing season. However, with the addition of a GPS receiver and a cellular modem, the CCGX is now pushing location data up to the Victron Cloud in real time.
The cellular uplink is an old LandCell cellular modem combined with a small whip antenna. The antenna is currently mounted below a steel deck, within a steel hull. But we are surprised at the range we do obtain. Long term plans would include a current model Peplink cellular modem combined with a higher gain MIMO antenna pair on the mast head.
Using the VRM API, we are able to make use of this data for real time tracking of the vessel. This is a fun toy, but also lets us make these details available to the parents who have kids on the vessel; either as crew or as trainees.
Two API end points were used:
.../v2/users/.../installations
.../v2/installations/.../gps-download
The "installations" end point gives the speed of the ship and the date/time that an update was last received from the CCGX by the Victron Cloud. It also gives the current latitude/longitude of the ship.
The speed is in m/s and is converted to knots for this nautical application, and displayed in the format of an analogue gauge. A third party toolkit, Canvas Gauges, was used for the display.
The last update date/time is displayed in a format mimicking the previous VRM console. i.e. "Last updated xx ago". This is important so that the viewer is aware if the location information is out-of-date due to the ship being outside cellular communication range.
The current location enables the map to show the ship on the map immediately, while the parsing and plotting of the historical track is being performed.
The "installations/.../gps-download" end point returns a list of latitude/longitude pairs matching a specified date range. A drop down menu on the web page permits the user to select from 24 hours of history (the default) as far back as 14 days. The latter being an arbitrary number.
The only real challenge was the GPS accuracy. Using each location as returned had the ship bouncing all over the map. By remembering the previous location, and a cool function that somebody else wrote, the distance between pairs of latitude/longitude points can be calculated. Through trial and error, it was found that discounting a point that was less than 37m from the previous point gave a smooth track, and held the ship in a single position when at anchor.
The Google Maps API provides the mapping and track functionality. A custom icon was used to show the ship's present location. A polyline provides the track through each latitude/longitude pair, excluding the "errors" noted above. After the track is displayed, the map is auto-zoomed to fit the boundaries of the track. The only trick was to catch if the user had manually zoomed the map, and thus not trigger an auto-zoom.
The complete Java Script is attached index_track.txt . Note that I have limited experience with Java Script programming, so there may be better implementation methods.
The public page can be found at https://www.tallshipexpeditions.com/whereistheship.
One, unanswered, request I have into Victron is to log the speed data with the location history. That would enable the display of a speed graph corresponding to the GPS track. This would be super cool!
Allan.