Tuesday 8 September 2020

NMEA-2000 Data on BeagleBone Black using SignalK

 Hi everyone,

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

Updated to describe installation on both Debian 9 and Debian 10

Appended notes following several months use

24 hours at anchor in Poole Harbour
BeagleBone Black
(beaglebone.org photo)

The capture, recording and display of our NMEA-2000 data on a Macbook was a big step forward.  However it required the Macbook to be running.  This uses a lot of power.  We have two low-power BeagleBone computers aboard, one of which we use for SSBMinder to run a 24 hour schedule on our HF/SSB.  We decided to try SignalK and InfluxDB on the BBB. 

Here's how we did it, noting that we have an ActiSense NGT-1 NMEA-2000 to USB interface directly connected to the BBB.  If you follow in our footsteps you should replace 'ZenAgain' with your boat name, and our IP addresses to your own.  Needless to say, the BBB and Macbook are on an ethernet network and they have internet access during this installation process.

NOTE1: Commands were executed in a ssh session, in our case from our Macbook.  We connected as the default user 'debian' but used 'su' and 'sudo' for some commands.  This is shown below.

NOTE2: I'm NOT a Linux expert and made many mistakes along the way.  I believe what follows is correct but there may be errors.  Proceed with care and backup your BBB before starting!

NOTE3: An advantage of the BBB over the Raspberry Pi is it runs from 5.0V, not the weird 5.1V demanded of current Pis.  We use this power supply to provide 5V from ship's 12V power.

Making Room

The BBB has only 4GB internal storage.  Much of this is consumed by the Debian Linux distribution.  We ran Debian 9 'bone-debian-9.9-iot-armhf-2019-08-03' before updating to Debian 10 'bone-eMMC-flasher-debian-10.3-iot-armhf-2020-04-06-4gb'.  We knew we'd need more space for the InfluxDB database so we added a micro SD card.  We've used 4GB and 32GB SD cards.
  1. Insert the SD card in the BBB
  2. Connect to BBB as 'debian'
  3. Run 'su'
  4. Run 'lsblk' to identify SDcard (usually /dev/mmcblk0p1)
  5. Run 'fdisk /dev/mmcblk0'
  6.   'd' to delete current partition
  7.   'p' to print the partition table
  8.   'n' to create new partition, then <enter> to take defaults
  9.   't' then '83' to set partition type to Linux (ext4)
  10.   'w' to write
  11. Run 'mkfs.ext4 /dev/mmcblk0p1' to create file system on the new partition
  12. Run 'lsblk' to check partitions (see first image below)
  13. Use nano to add a line to /etc/fstab: '/dev/mmcblk0p1 /media/sdcard auto auto,async,rw,nofail 0 0'
  14. Run 'reboot now'
  15. Reconnect to BBB as 'debian'
  16. Run 'lsblk' to check partitions (see second image below)
  17. Run 'df' to view space available
  18. Run 'sudo chmod 777 /media/sdcard'
  19. Run 'sudo mkdir /media/sdcard/influxdb'
'lsblk' output before mounting

'lsblk' output after mounting

Disable Services

The BBB runs a number of services which clash with putting SignalK's web server on IP port 80 and/or compete for resources.  Here's what I disabled...
  1. Connect to BBB as 'debian'
  2. Run 'sudo systemctl disable cloud9.service'
  3. Run 'sudo systemctl disable gateone.service'
  4. Run 'sudo systemctl disable bonescript.service'
  5. Run 'sudo systemctl disable bonescript-autoscript.service'
  6. Run 'sudo systemctl disable bonescript.socket'

Remove cloud9

  1. Connect to BBB as 'debian'  
  2. Run 'sudo rm -R /opt/cloud9 /var/lib/cloud9'

Install Dependencies

This was the toughest part.  NodeJS is required by SignalK and it took me a while to realise the BBB had the wrong version installed.  Likewise 'dns_sd.h' was reported missing.  Hopefully the following is correct.  If not Google is your friend, as it was mine!

Debian 9
  1. Connect to BBB as 'debian'
  2. Run 'sudo apt-get install libavahi-compat-libdnssd-dev'
  3. Run 'curl -sL https://deb.nodesource.com/setup_10.x | sudo bash -'
  4. Install specific version of NodeJS by running 'apt-get install nodejs=10.22.0-1nodesource1 -V'
Debian 10

  1. Connect to BBB as 'debian'
  2. Run 'sudo apt-get install software-properties-common'
  3. Run 'curl -sL https://deb.nodesource.com/setup_10.x | sudo bash -'
  4. Run 'sudo apt-get install libavahi-compat-libdnssd-dev'

SignalK Installation and Setup

  1. Connect to BBB as 'debian'
  2. Run 'sudo npm install -g --unsafe-perm signalk-server'
  3. Run 'sudo signalk-server-setup'
  4.    Enter your boat's name and MMSI, and set IP Port to 80

Initial Run and ActiSense Connection Setup

  1. Connect to BBB as 'debian'
  2. Run 'signalk-server' to start the SignalK server
  3. In a remote browser (ie Macbook), open 'http://192.168.1.21' to access the server
  4. On the 'Server => Connections' page click on 'Add'
  5.   Set ID to 'actisense'
  6.   Set NMEA 2000 Source to 'Actisense NGT-1 (canboatjs)', noting the 'js'
  7.   Set Serial Port to '/dev/serial/by-id/usb-Actisense_NGT-1_...', modifying the '...' to suit your BBB
  8.   Accept defaults for the other fields and click 'Apply'
  9. On the 'Dashboard' page check the Stats show ActiSense data being received.
  10. On the 'Data Browser' page select 'Self' and check for data, noting the use of SI units.
The SignalK server starts automatically on boot.

Here are some screenshots, noting that some aren't from the BBB...

SignalK New Connection

SignalK Dashboard

SignalK Server Settings

SignalK Server Connections

OpenCPN SignalK Connection

Use OpenCPN running on our Macbook 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?

I had trouble using the ActiSense NGT-1 with canboatjs prior to SignalK Server version 1.34.0.  The error was indicated on the Dashboard page.  This simplest fix was...
  1. Connect to BBB as 'debian'
  2. On the 'Server => Connections' page click on the 'actisense' connection
  3.   Change NMEA 2000 Source to 'Actisense NGT-1 (canboat)'
  4.   Set Serial Port to 'dev/ttyUSB0'
  5. Run 'sudo reboot now' to reboot
  6. In a remote browser (ie Macbook), open 'http://192.168.1.21' to access the server
  7. On the 'Dashboard' page check the Stats show ActiSense data being received.

If the above fails try installing canboat separately.  Here's how that's done...
  1. Connect to BBB as 'debian'
  2. Run 'sudo apt install xsltproc' since canboat needs xsltproc
  3. Run 'git clone https://github.com/canboat/canboat' to download canboat source
  4. Run 'cd canboat'
  5. Run 'make' to built the executables from the downloaded source
  6. Run 'sudo cp rel/linux-armv7l/* /usr/local/bin' to move the executables for use
  7. Run 'which actisense-serial' to check the executable we need is ready for use
  8. Run 'nano ~/.signalk/settings.json' and replace its contents with the text illustrated below, replacing '/dev/ttyUSB0' with the correct string for your NGT-1
  9. Run 'sudo reboot now' to reboot
  10. In a remote browser (ie Macbook), open 'http://192.168.1.21' to access the server
  11. On the 'Dashboard' page check the Stats show ActiSense data being received.
SignalK ~/.signalk/settings.json for canboat

InfluxDB Installation

  1. Connect to BBB as 'debian'
  2. Run 'sudo apt install influxdb'
  3. Run 'which influxd'
Debian 10
  1. Connect to BBB as 'debian'
  2. Run 'sudo nano /lib/systemd/system/influxdb.service'
  3. Append ‘ media-sdcard.mount’ to After statement so influxdb service waits for SDcard to mount

InfluxDB Configuration

  1. Connect to BBB as 'debian'
  2. Run 'sudo chown influxdb:influxdb /media/sdcard/influxdb'
  3. Run 'sudo nano /etc/influxdb/influxdb.conf' and edit the three database pointers to suit the above locations.

InfluxDB Start

  1. Connect to BBB as 'debian'
  2. Run 'sudo systemctl unmask influxdb.service'
  3. Run 'sudo systemctl enable influxdb.service'
  4. Run 'sudo systemctl start influxdb'
The InfluxDB daemon will now start automatically on boot.

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.

Another way to see if InfluxDB is running is to run 'ss -tlpn' which lists all ports on which the BBB is listening for traffic.

InfluxDB Database Creation

  1. Connect to BBB as 'debian'
  2. Run 'curl -X POST http://localhost:8086/query?q=CREATE+DATABASE+ZenAgain' to create influxdb database
  3. Run 'journalctl -u influxdb.service' to view the log

signalk-to-influxdb Installation

  1. In a remote browser (ie Mac), open 'http://192.168.1.21'
  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. Connect to BBB as 'debian'
  5. Run 'sudo reboot' to reboot
  6. Back in the remote browser wait (several minutes) for the Server page to refresh then go to 'Server => Plugin Config' page, and click on 'Influx DB'
  7. On the page, tick the 'Enable' checkbox, enter 'ZenAgain' as the Database, then click on 'Submit' at the bottom
Here are some screenshots...

SignalK Server Plugin Config

SignalK Server Plugin Config InfluxDB

The BBB is now setup with SignalK and InfluxDB running.  Lastly we need to tell our Mac (or other machine running Grafana) to read data from the BBB's InfluxDB.

Grafana Setup Modification on Macbook

  1. Open Grafana in browser at 'http://localhost:3001'
  2. In 'Configuration => Data Sources' click 'Add Data Source' then 'Influx DB'
  3.   Set Name to 'InfluxDB-BBB' and switch Default on
  4.   Set HTTP URL to 'http://192.168.1.21:8086' (don't leave it greyed-out)
  5.   Set Influx DB Details Database to 'ZenAgain'
  6.   Set Influx DB Details user/password to 'debian/password'
  7.   Click 'Save & Test' and confirm all 'green'
  8. Open your Dashboards and check data is flowing from the BBB's database
Here are some screenshots...

Grafana Add Data Source (top of page)

Grafana Add Data Source (bottom of page)

Grafana with 2 Data Sources

It's worth noting that the Grafana Dashboards setup on the Macbook used the default Data Source for all their data.  Adding the BBB Data Source and making it the default brought the Dashboards to life immediately.  Very nice.

Overall Usage

We've been running SignalK and InfluxDB on our BBB for several months now, including for weeks at a time.  No unexplained (ie non user error) crashes and so far it has used only 8% of the 32GB SDcard.

Backup

Here's how I backup the InfluxDB databases and the BBB generally...
  1. Connect to BBB as 'debian'
  2. Run 'sudo systemctl disable signalk.socket'
  3. Run 'sudo systemctl disable signalk.service'
  4. Run 'sudo systemctl stop signalk.socket'
  5. Run 'sudo systemctl stop signalk.service'
  6. Run 'sudo systemctl stop influxdb'
  7. Run 'sudo tar -cvf /media/sdcard/backup/<date>_bbb_influxdb.tar /media/sdcard/influxdb'
  8. In a Terminal window on the Macbook run 'scp debian@bbb:/media/sdcard/backup/<date>_bbb_influxdb.tar .'
  9. Back on the BBB, run 'sudo umount /media/sdcard'
  10. Remove the InfluxDB SD card from the BBB
  11. Insert a backup SD card into the BBB
  12. Run 'sudo /opt/scripts/tools/eMMC/beaglebone-black-make-microSD-flasher-from-eMMC.sh'
  13. When the BBB powers down on completion of the backup, remove the backup SD card
  14. Insert the InfluxDB SD card into the BBB
  15. Power up the BBB
  16. Connect to the BBB as 'debian'
  17. Run 'df' to check /media/sdcard connected
  18. Run 'sudo systemctl enable signalk.service'
  19. Run 'sudo systemctl enable signalk.socket'
  20. Run 'sudo systemctl start signalk.service'
  21. In a browser on the Macbook check the Signal K Server and Grafana are functioning normally

Upgrading SignalK

I had problems upgrading SignalK from within the browser.  Instead I did this...
  1. Stop SignalK as described above (steps 1..3)
  2. Run 'sudo npm install -g --unsafe-perm signalk-server'
  3. While updating SignalK perhaps do the same for Debian generally... 
  4.   'sudo apt-get update'
  5.   'sudo apt-get upgrade'
  6. Run 'sudo reboot now'

Recent Steps

We now have SignalK and InfluxDB installed and tested on three Beagles.  Two BBBs (active and spare) plus a BeagleBone Black Wireless as a demo unit.  We transmit SignalK data to our Macbooks, iPads and iPhones using the WilhelmSK app.  We also feed wired SignalK-generated NMEA0183 to our autopilots.

Improving Usability and Reliability

Modify restart of SignalK service to simplify stopping/restarting for backups...
  1. Edit /etc/systemd/system/signalk.service, changing to 'Restart=on-failure'
Auto-reboot daily (below at 23:50) to stop /dev/mmcblk1p1 gradually filling to capacity...
  1. Use 'sudo crontab -e' to append '50  23 *   *   *     /sbin/reboot'
Backup InfluxDB database monthly and create new, to avoid BBB slowing to a crawl and losing data...

  1. sudo systemctl stop signalk.service
  2. sudo systemctl stop signalk.socket
  3. sudo systemctl stop influxdb
  4. cd /media/sdcard
  5. sudo tar -cvf ./backup/<year+month>_influxdb.tar ./influxdb
  6. sudo rm -rf influxdb/*
  7. sudo systemctl start influxdb
  8. curl -X POST http://localhost:8086/query?q=CREATE+DATABASE+ZenAgain
  9. sudo reboot


No comments:

Post a Comment