Monday 7 September 2020

NMEA-2000 Data Display on Mac OS X using SignalK

Hi everyone,

This is a technical post.  It is the first of two posts describing how we installed and setup software to capture, record and display data from our NMEA-2000 network.  This post describes how we did so on a Macbook laptop running Mac OS X.  The second will describe how we moved the NMEA-2000 capture and recording onto a cheap, low-power BeagleBone Black computer.

Zen Again Graphs on our Macbook

Our NMEA-2000 network includes the following devices and data:

  • Vesper XB8000 AIS
    • GPS
    • AIS
  • Garmin GPSmap451 Chart Plotter
    • GPS
  • Garmin VHF300iAIS VHF Transceiver
    • AIS
    • DSC
  • Airmar DST800 Speed/Depth Transducer
    • Depth
    • Boat Speed
    • Log
    • Water Temperature
  • Raymarine SPX5 Autopilot
    • Rudder Angle
  • Airmar 220WX Weather Station
    • GPS
    • 3D Attitude
    • 3D Attitude Rate
    • Air Temperature
    • Air Pressure
  • YachtDevices YDVR-04
    • Recorder
  • TechnoSpark Replicator
    • WiFi Hotspot
  • ActiSense NGT-1
    • NMEA-2000 to USB Gateway

So there's a lot of data on the network, including 3 sets of GPS data.  We've previously described some of the ways we use the data:

  • Displaying Live Data here;
  • Plotting Recorded Data here; and
  • Network Traffic Analysis here

All the above are useful.  But they involved writing and maintaining our own Python scripts.  Meanwhile the marine electronics world has lots of open-source technologies to offer.  One particular development was particularly interesting - SignalK.

SignalK provides a means of gathering data from NMEA-0183, NMEA-2000 and other boat networks and making it available in a 'web-friendly' (JSON) format.  Sounded great, but research seemed to show it is most heavily used with OpenPlotter on Raspberry Pi computers.  OpenPlotter provides a 'ready to go' suite of software for the Raspberry Pi including SignalK, OpenCPN and more.  However our navigation system runs OpenCPN on Macbook laptops so OpenPlotter wasn't for us.

More recently we discovered InfluxDB and Grafana.  InfluxDB is a time-based database system which can be populated from SignalK.  Grafana is a graphing system which can plot data from InfluxDB.  This combination looked nice and convinced us to give them a try.  Initially we aimed to install them all on a Macbook.

Here's how we did it, noting that we have an ActiSense NGT-1 NMEA-2000 to USB interface.  If you follow in our footsteps you may wish to replace 'ZenAgain' with your boat name.

ActiSense NGT-1 Installation

To install drivers which work in Mac OS X 10.15 Catalina, get them from FTDI at FTDIUSBSerialDriver_v2_4_4.dmg.  This link was provided to me by ActiSense Support.

Homebrew Installation

Homebrew is a package installation manager.  It is used to install and control some of the software we need.  Here's how to install it.

  1. In a Terminal window run 'ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" < /dev/null 2> /dev/null'.

Note that Ruby will install Xcode command line tools if they are absent.

SignalK Installation

  1. Download nodejs from https://nodejs.org/en/download/
  2. Run the install pkg and accept all defaults.
  3. In a Terminal window and type 'npm -v' to show the version installed.
  4. Download signalk-server-node from https://github.com/SignalK/signalk-server-node
  5. In the Terminal window run 'cd signalk-server-node'
  6. In the Terminal window run 'sudo npm install -g --unsafe-perm signalk-server'
  7. Start the server using sample NMEA2000 data by running `signalk-server --sample-n2k-data`
  8. In a browser, open 'http://localhost:3000'.  Explore!
  9. Kill the server by typing <ctrl>c in the Terminal window.
The signalk-server is installed in '/usr/local/lib/node_modules/signalk-server'.

SignalK Setup

  1. In a Terminal window run 'sudo signalk-server-setup'
  2. Enter your boat name and MMSI and accept defaults otherwise

Initial Run and ActiSense Connection Setup

  1. In a Terminal window run 'signalk-server' to start the server
  2. In a browser, open 'http://localhost:3000' to access the server
  3. On the 'Server => Connections' page click on 'Add'
  4.   Set ID to 'actisense'
  5.   Set NMEA 2000 Source to 'Actisense NGT-1 (canboatjs)', noting the 'js'
  6.   Set Serial Port to '/dev/serial/by-id/usb-Actisense...', where '...' identifies your NGT-1
  7.   Accept defaults for the other fields and click 'Apply'
  8. On the 'Dashboard' page check the Stats show ActiSense data being received.
  9. On the 'Data Browser' page select 'Self' and check for data, noting the use of SI units.
Thanks to Scott Bender (SignalK team member and WilhelmSK guy) for describing how to use canboatjs versus the tricky installation of canboat.  More on that later.

Here are screenshots...

SignalK Server Actisense Connection Setup

SignalK Dashboard

SignalK Data Browser

OpenCPN SignalK Connection

Use OpenCPN to test availability of the SignalK data.  OpenCPN support for SignalK began with version 5.2.  Here's our OpenCPN connection setup...

OpenCPN SignalK Connection

ActiSense Connection not working?

We had trouble using the ActiSense NGT-1 with canboatjs.  This was indicated by an error on the Dashboard page.  To fix this I installed canboat which worked fine.  Here's how i's done...
  1. Download canboat source files from https://github.com/canboat/canboat
  2. In a Terminal window run 'cd canboat-master'
  3. In the Terminal window run 'make' to build the executables
  4. In the Terminal window run 'sudo cp rel/darwin-x86_64/* /usr/local/bin' to move the executables for use
  5. In the Terminal window run  'which actisense-serial' to check the executable we need is ready for use
  6. In the Terminal run 'nano ~/.signalk/settings.json' and replace its contents with the text illustrated below, replacing '/dev/tty...' with the correct string for your NGT-1
  7. If the SignalK server is running kill it by typing <ctrl>c in its Terminal window
  8. Start the SignalK server by running 'signalk-server' in its Terminal window
  9. In a browser, open 'http://localhost:3000' to access the server
  10. On the 'Dashboard' page check the Stats show ActiSense data being received.
SignalK ~/.signalk/settings.json for canboat

InfluxDB Installation

  1. In a Terminal window run 'brew install influxdb' to install
  2. In the Terminal window run 'which influxd' (note no 'b') to check installation success

The InfluxDB executables install area is '/usr/local/Cellar/influxdb'.

InfluxDB Start

  1. In a new Terminal window start the influxdb service with the command 'influxd'.
  2. In a new Terminal window create a new database run 'curl -X POST http://localhost:8086/query?q=CREATE+DATABASE+ZenAgain'.

The InfluxDB config file is in '/usr/local/etc' and databases are in '~/.influxdb'.

InfluxDB uses IP port 8086 to service client requests.  It doesn't provide a web page but browsing there is a handy way to see if InfluxDB is running.  Doing so produces a page with '404 page not found' text.


signalk-to-influxdb Installation

  1. In a browser, open 'http://localhost:3000'
  2. Go to 'AppStore => Available' page, find the 'signalk-to-influxdb' entry and click on the download link on the right.
  3. Go to 'AppStore => Installed' page and check 'signalk-to-influxdb' installed.
  4. In the Terminal Window running 'signalk-server', enter <ctrl>c to shutdown, then 'signalk-server' to restart.
  5. Back in the browser, go to 'Server => Plugin Config' page, click on 'Influx DB'
  6. On the page, tick the 'Enable' checkbox, enter 'ZenAgain' as the Database, then click on 'Submit' at the bottom.
Here are some screenshots...

SignalK AppStore / Installed

SignalK Server / Plugin Config

SignalK InfluxDB Config

Grafana Installation

  1. In a Terminal window run 'brew install grafana' to install
  2. In the Terminal window run 'ls -l /usr/local/etc/grafana/' to check installation

The Grafana install area is '/usr/local/Cellar/grafana', config files are in '/usr/local/etc/grafana/' and the log file is in '/usr/local/var/log/grafana'.

Change Grafana's IP port since its default is the same as signalk-server...

  1. In a Terminal window run the command 'sudo nano /usr/local/etc/grafana/grafana.ini'.
  2. After the line ';host_port = 3000', enter a new line containing 'host_port = 3001'.
  3. Enter '<ctrl>o' to save, '<enter>' to confirm, then '<ctrl>x' to exit.

Grafana Setup

These steps start and setup Grafana.  I won't describe the steps needed to create dashboards since Grafana's documentation is good and there are many YouTube videos on the topic.

  1. In a Terminal window run 'brew services start grafana'.
  2. In a browser, open 'http://localhost:3001'.
  3. Login with admin/admin then change the password.
  4. In 'Configuration => Data Sources' add 'Influx DB'.
  5.   Set HTTP URL to 'http://localhost:8086 (don't leave it greyed-out).
  6.   Set Influx DB Details Database to 'ZenAgain'.
  7.   Set Influx DB Details user/password to those of your login account.
  8.   Click 'Save & Test' and confirm all 'green'.
Here are screenshots at various stages...

Grafana Welcome Page

Grafana Add Data Source Page

Grafana Data Source / InfluxDB Page

Overall Manual Start

These steps manually start and check the three servers/services:

  1. In a new Terminal window, run 'influxd'.
  2. In another new Terminal window, run 'signalk-server'.
  3. In another new Terminal window, run 'brew services start grafana'.
  4. In a browser, open 'http://localhost:3000' and check 'ActiSense' and 'InfluxDb writer' running.
  5. In a new browser tab, open 'http://localhost:3001' and check Grafana running.

Overall Automatic Start

Mac OS X starts servers/services/daemons using .plist files.  I won't describe the format since it's easy to copy an existing file and adapt it.  Overall here's the process for SignalK and InfluxDB...

  1. Create file ~/Library/LaunchAgents/signalk-server.plist
  2. Create folder /usr/local/var/lib/signalk-server
  3. Create folder /usr/local/var/log/signalk-server
  4. Create file ~/Library/LaunchAgents/influxd.plist
  5. Create folder /usr/local/var/lib/influxd
  6. Create folder /usr/local/var/log/influxd

Grafana is started or stopped using Homebrew by running 'brew services <start>|<stop> grafana'.

Overall Usage

On completion of the above steps, and a few mis-steps along the way, Zen Again had a working system.  While the Macbook, NGT-1 and NMEA-2000 network were running all NMEA-2000 data was being stored in the InfluxDB database.  And whenever required we could display the data as numbers or as graphs, choosing the latest data or any previously recorded data or data interval. 

Zen Again's Grafana Welcome Page

Zen Again's 'Graphs' Dashboard

Zen Again's 'Stats' Dashboard

Next Steps

All the above is great, but we don't really want to run the Macbook 24/7 to capture and record data.  It uses too much power.  So our attention turned to using a cheap, low power computer for those tasks.  We have two BeagleBone Black computers which fit the bill.  We'd still use the Macbook to run Grafana, but it would access an InfluxDB database on the BBB.

3 comments:

  1. Hi and thanks for a nice article. I use mac os catalina and when I try command to create new influx database I only get this: jonny @ Mac-mini ~% curl -X POST http: // localhost: 8086 / query? Q = CREATE + DATABASE + Fri
    zsh: no matches found: http: // localhost: 8086 / query? q = CREATE + DATABASE + Fri
    jonny @ Mac-mini ~% which influx
    / usr / local / bin / influx
    Suspected error due to influxdb version 2.x. Do you have an updated solution to this?
    For info I use mac mini (i7 16gb ram late 2012) which has been converted to a 12v supply as the motherboard runs on 12v. Powerful and uses "little" power "

    ReplyDelete
    Replies
    1. Hi Jonny's, No update I'm afraid. I moved SignalK and InfluxDB onto a BeagleBone Black and that's working well (and is very low power). I now only run Grafana on the Mac.
      Your command seems to have many incorrect spaces - it should be ''curl -X POST http://localhost:8086/query?q=CREATE+DATABASE+Fri'.
      Interesting that you've converted your Mini to 12V. What did that involve?

      Delete
  2. I would love to have the Zen again stats dashboard on my onboard mac! That looked awesome. But I am afraid I am not technical emnough to get through the 40 steps of this post :)

    ReplyDelete