MNBB – Trial run

A quick recap:

MNBB is abbreviated for Mariners NMEA Black Box. It does not replace the existing navigation instruments or multifunctional display on a sailboat. The purpose is to log your boat’s instrument data and show you useful information about your trips. It may also show you useful trip information while underway. I just started developing the application software and now have it up and running on a Raspberry Pi. If you would like an introduction to this project, take a look at my prior post.

I have not made a lot of progress on the project over the last week but I have made some important decisions on the architecture to keep the entire project simple and easy for other web developers to contribute to. The entire platform is written in JavaScript, which was once a language designed for web browsers and is now an excellent language for building what we programmers like to call full-stack software. The idea is to use a single language for the entire application which should cut down on the amount of code needed to make it work and also make much of the code more purposeful. One of the important decisions I made is how to build it so others can contribute to the project. Right now it is still just scaffolding but eventually I will produce the first displays to show things like maximum and minimum values for a given trip, broken into days, hours, etc. It would be nice to know the maximum wind speed, minimum wind speed, maximum boat speed and even compare apparent and true wind speed over a given trip. This is the next step for the project.

Another part of the MNBB project I am working on is taking the realtime NMEA data and displaying it just like you would see on an instrument panel. With the use of web sockets I should be able to provide a universal display similar to what you would see on a chartplotter or in your instrument panel. The most exciting part of this project is the fact that the entire setup would cost less than $100 to duplicate for another vessel. This excludes the NMEA wifi client but they cost only $200 and can then allow you to use it for other charting apps for Android and iPhone.

The Raspberry Pi, Router and NMEA wifi client
The Raspberry Pi, Router and NMEA wifi client

The above photo shows one of the navigation station lockers containing the network electronics. It may look like a big spaghetti mess of wires but this setup is a good configuration. The power supply is a terminal block with every component fused with one-amp fuses. Each component has it’s own dedicated switch, which is simply labeled and run inline of the wire. I could build a switch panel but I don’t foresee using them much but in case I want to turn them on and off, I added them for convenience. The Raspberry Pi is powered using a Blue Sea USB hub, which simply uses a standard micro-usb cable. The total power consumption for all of these components is less than one amp. Everything can be switched off at the breaker panel or individually if needed. There is an extra ethernet (POE) cable which connects to the wifi booster antennae on the stern of the boat. Eventually I hope to be able to connect to the wifi network while I’m on shore or also pickup wifi from shore using the same router.

On Saturday I am heading to Port Townsend for Fiddle Tunes  and will be anchored at Fort Worden State Park for the week. While heading there and sailing around the bay I should be able to collect some useful NMEA data for the purpose of building some of the first applications. The key is to use the unit while underway but then power it off while at anchor. Most of the useful information is when the boat is actually moving so logging here at the marina isn’t nearly as useful aside from gathering weather data.

Summer is here and I’m still sailing at least one evening during the week just to stay practiced at preparing the boat to sail and then putting her away, plus keeping her uncluttered for an unscheduled trip. There are more trips planned in the future, including the PNW Westsail Rendezvous .

MNBB – TCP Client, Parsing and Queries

From here forward I will be including technical posts about my new project; MNBB which stands for Mariners NMEA Black Box. I mentioned it a couple of posts back and have been hacking on it for the last week getting the foundation going so I can start working on the small parts.

First, a little background about how I decided to start this project.

When I first took up sailing, I had no idea about NMEA or even marine networks. It’s a technical topic with several layers of confusion. First, the NMEA standard is extremely out of date. When you have an instrument such as a barometer, you can send the barometer data to another instrument. NMEA experts call this talking. Any instrument can talk to several other instruments. When that instrument wants to receive data from different instrument, it is limited to one single source. This is where the problem lies. To make your marine navigation system play well with others you need to take all of the instrument NMEA wires and plug them into something called a multiplexer so it can listen to many instruments and then talk to many other instruments, multifunctional displays or networking devices. A multifunctional display would include your chartplotter and a networking device can transmit the nmea data to something like a computer or smartphone so the apps can use the data to assist you in navigating your vessel.

What does not exist already is a data logger or any kind of device that can recall what your instruments were outputting on a given voyage. If they do exist, they would cost exorbitant amounts of money and deliver not so promising capabilities. For a recreational consumer this cost tends to be prohibitive. The idea came up to develop this capability using a very inexpensive computer and completely open source software so the consumer can actually afford this kind of instrument. Since it’s just me working on MNBB this could take the better part of a year in my spare time. I’ve opened the project to anyone who is capable of contributing in the hopes that it will speed up development and deliver a beta version as soon as possible.

The benefit to this kind of product is mainly for those who would like to have a look at their instrument data and try to make better decisions about their current and future voyages. For example, if you could follow barometric pressure over a selected period of time, perhaps you could see that the barometer is dropping at an alarming rate. I like to be able to use technology to help me keep track of what has happened in the past so I can recall this information whenever I want. What about comparing wind speed and barometric pressure? Can you think of anything that might be useful in that comparison? I think there is quite a bit worth looking at.

Getting Started

The first step in this project was getting my Raspberry Pi computer up and running. This required just a few temporary peripherals. I needed a monitor, mouse and keyboard so I could install the operating system and boot the computer for the first time. After that, I no longer needed the peripherals because I use my laptop to login to the Pi and do everything I need. The second step was to decide what technology I can use to start writing the application. Since I am a JavaScript engineer and I like the simplicity of Node.js, I decided to use it for the entire architecture stack. The benefit is that the entire application will be written in one single language. We call this full-stack JavaScript. Don’t let anyone convince you that this is not a good application platform. It has been proven for it’s simplicity at working with networking, file systems, database communication and most other common needs of an application platform. Once I had Node running, I could use a simple client script to connect to the network and stream NMEA sentences from the Vesber XB wifi NMEA client. It took about an hour to get it working.

The next step after knowing my Raspberry Pi was receiving NMEA sentences was to start parsing the sentences to something meaningful. I had already seen a Node NMEA parser in Github and it is under the same license as the MNBB project so I forked the project and it worked right out of the box. Each NMEA sentence has an identifier that tells you what type of sentence it is. The parser already includes the following: GPGGA, GPRMC, GPGSA, GPGSV, GPVTG. To prove that the parsing library was built properly and easy to contribute to I decided to write my own parser for GPGLL as a proof of concept, which is a simple global positioning latitude and longitude sentence. To my surprise, within an hour I had developed a complete parser for an unsupported sentence. 

NMEA parser
NMEA parser
NMEA data storage at intervals
NMEA data storage at intervals

The next step is storing the data. This is called a data logger and so the next step is to build a simple database that can collect the parsed sentences and store them for later retrieval. This will take some time to complete because I am not completely certain the best way to store everything. An important step is ensuring that not every single sentence is stored. I only need a subset of the data because there will be a ton of duplicate data, which can cause storage capacity issues over a long period of time. One issue I can see is how some types of data may need more sentences to be stored than others. For example, AIS sentences provide real-time information about other vessels broadcasting their position, speed, distance, etc. These sentences need to be parsed differently than something like water temperature, where you might only need to log the single value once every five minutes.

NMEA data parsed into JSON
NMEA data parsed into JSON

What’s next?

At this point in time I am building a Mongo database for Linux on the Pi and should be able to begin storing all of the supported sentences at whatever intervals I want. I am able to connect to the NMEA client, receive a set of data and then send the data to a Mongo database. I can also run queries with a given talker type (e.g.- GPGLL) and respond with a set of results that can used in a web application. I am going to integrate the web application framework next so I can write the first web app and view it from any device I have connected to the same network. I am also hoping that by the time I have the first release that getting Mongo installed on a Pi will not take twenty-four hours to build from scratch.

The scale of some of the projects is beyond my capabilities at the moment. It’s a perfect way to understand how to gain skills to understand how some of the information is determined for marine navigation. For instance, comparing apparent wind and true wind requires an algorithm that will calculate true wind speed and direction from several input parameters (speed over water, heading, etc) . Once I have written the algorithm I can use this input as part of any wind instrument application.

Almost summer

If you’re not from Seattle then you would probably feel a bit ripped off by the weather gods by now. The skies are cloudy, sun is lost somewhere up there and some rain is in the forecast. I’m running the Dickinson stove during the day, on a June afternoon. The pup is sleeping instead of bothering me to take her fetching. This morning I also had my forward berth measured for making a brand new foam mattress with new canvas and a breathable bottom barrier. I will take  some time after work and start cleaning the mildew stains and also do some painting to prepare the new mattress for installation. Fortunately I can still sleep comfortably in the settee while this is all happening. The lockers underneath will also be cleaned out and painted. I might have a chance to install some LED lighting to add some cool factor.

Forward Berth mildew
Forward Berth mildew

As you can see from the photo above, the forward berth has been long neglected and has an issue with moisture. I plan on making some modifications to allow for better air circulation and prevent mildew from coming back. Adding some fans will help out with both moisture and keeping the cabin cool.

Another project I have been wanting to complete is another canvas piece. The hatches are made entirely of teak with a thick piece of plexiglass to allow light into the cabin. There are two hatches on a Westsail 32, one forward and another right over the settee. The amount of light that enters the cabin from the top is great and when the hatches and companionway are open there is a lot of air circulation. The issue is when the sun is out and directly overhead with no wind. The cabin warms up considerably so I decided to make a hatch cover with a canvas insert to block sunlight to keep the cabin cool. Also, in the forward berth it’s nice to have less light so I can sleep in as needed.

Hatch Cover with Canvas insert
Hatch Cover with Canvas insert
Hatch Cover with vinyl
Hatch Cover with vinyl

I’m not entirely sure if the snaps will be all that is needed to prevent the insert from flying off but the snaps are pull-the-dot style which takes quite a bit of work to disconnect. I added a strap on the back side to snug the cover over the hatch. I may also add some way of connecting the cover to the hatch for high winds. Either way, it’s a nice improvement and addition to keeping things dark and cool down below.

Last Thursday I took Satori out on a sunset tour. The weather was great, with winds up to 15 knots and Satori was in great shape. As usual I had issues with getting her out of the marina. This time I tried walking her back but the bow line was too short so I had less control of her bow. Eventually she came around and we motored forward but another lesson learned and another collision with parked vessels avoided. Since my crew consisted of a vey pregnant woman and two disabled parents I treated this trip as a single handing cruise. Getting the sails up was a snap as was navigating through the shipping lanes. Later Strange Advice came out to join us on our crossing. We took lots of photos of each other and another J105 was also out and as we passed them from the west they also took some photos and later one of the crew members stopped at the boat to say hi and exchange info.

Satori shrouded by the sunset. Photo by Tom Muir of Seattle Sailing Club
Satori shrouded by the sunset. Photo by Tom Muir of Seattle Sailing Club
Strange Advice passing by
Strange Advice passing by
Satori in front of the sun. Photo by Stew Sowers
Satori in front of the sun. Photo by Stew Sowers