Saturday, December 31, 2016

NMEA Multiplexer, OpenCPN, GPSd...

I have been working on an NMEA Multiplexer that can run on small boards, like the Raspberry PI Zero. The code is available on github, see the documentation in the README.md.

It allows to mix all kinds of NMEA Sources into a single (or multiple) stream(s). You can read from Serial Ports, Log file(s), TCP, WebSocket, Sensors (like BME280, HTU21DF, LSM303, etc), merge those data and rebroadcast them on Serial port, TCP, Log file, WebSocket, GPSd, etc. UDP is being worked on.

Data can also be computed and injected in the output stream, like True Wind, Current direction and speed, etc.

As a graphical desktop can be cumbersome on small boards, the Multiplexer comes with a tiny HTTP server that provides a Web UI and REST services to allow remote Admin.

It also comes with several demos and samples
This all works just fine with OpenCPN, SeaWi, that can take TCP streams as NMEA Data Input.
I was also wondering about GPSd. I had some mixed feelings about it. Mostly, I was asking myself "Why should I parse GPSd json objects if I can parse NMEA Sentences?", and could not find any satisfying reason. The topic is mentioned on the GPSd web site's FAQ pages, but nothing clear (to me) came up from that.
Interestingly, OpenCPN can also take GPSd streams as input. But there is a trick.
The first GPSd exchange begins with a ?WATCH request. It is followed by a JSON Object like this:
  ?WATCH={"enable":true,"json":true}
... and here is the trick, OpenCPN sends a
 ?WATCH={"enable":true,"nmea":true}
This nmea option is "poorly" documented, but very useful. Instead of sending JSON objects, GPSd spits out the raw NMEA sentences, as they were read. Then GPSd is just a regular TCP stream, and OpenCPN already knows how to parse the NMEA sentences it delivers. This way, GPSd is not limited to strictly GPS-related sentences. It can convey all NMEA sentences, Boat Speed related, Wind related, etc. This is what the GPSd forwarder that comes with the Multiplexer is doing.
Happy Streaming, happy new year!

Sunday, July 24, 2016

Live Wallpaper, offline

The Live Wallpaper (in the navigation console) has been improved. Several bugs were fixed (like the one for the daylight), and you can now use it offline, like when no NMEA data are coming. This can be useful when you are not on the boat (like at home).

You can give a default position (in the preferences), and it will be used when no GPS Data is available.
New features:
  • The tilt is based on the Sun declination
  • You can have Moonlight and Sunlight
  • The tide curve of the closest station is displayed (closest in a radius of 100 nautical miles)
  • Sun and Moon positions are displayed (when the body is visible)
Code and (some) doc are available on GitHub.

Sunday, March 13, 2016

IoT for dummies

Internet of things, what's the big deal?
We have a device, that can read sensors on one side, and connect to the Internet on the other, nothing revolutionary here. The challenge is to reach the device, from somewhere on the Internet, the device that reads the sensors does not necessary have a public IP address.
This is why the key component is the IoT server.
The device (the one with sensors) pushes data on the IoT server. The server can then be read from anywhere on the net.

On top of that, you can push data to the IoT device. For example, in a room:
  • the device is connected to a temperature sensor, and pushes temperature data to the IoT server (and so, they can be read from a browser, smartphone...)
  • the device is connected to a relay, data can be sent to the device (like from a browser, smartphone...), to drive the relay. If the relay is connected to a heater, you can manage the room temperature.


Typically, you can have a Raspberry PI, Arduino, or similar board, reading - at home - a temperature sensor to publish the air temperature onto the IoT server. You access those data from a browser (from your office, your smart-phone, whatever). Then you may decide to turn the heater on at home, the Raspberry PI (or its friends) has a relay that drives the heater.

Many server also use some push technology (like WebSocket or similar), so a client can be notified. A server like Adafruit IO provides this service for free, Particle also does it to some extend.

In addition, Adafruit IO provides a REST interface, very slick.
See an example of a REST client - in Java - on github. It shows how to read and write data on the server.

A real IoT application is also featured here in github, along with its Adafruit IO dashboard. It reads a BME280 (for the air temperature), and provides a toggle button (switch) that drives a relay on the Raspberry PI, to turn a heater on or off.

Friday, December 11, 2015

Raspberry PI Zero is here

I just received mine. And it just works. It takes a ridiculous amount of energy, and works just like its bigger brothers. Just a couple of things to keep in mind:
  • Use the latest RasPian image, I used - successfully - the one from Nov-11, 2015 (2015-11-21-raspbian-jessie.img)
  • If you use a desktop USB keyboard, you need a powered USB hub
  • Once started, do not forget to expand your file system, so it uses all the space available on your SD card
I used it with the small Edimax Wireless USB dongle (the powered hub is not required for this one), I got started in no time. I was able to ssh to it and run everything on it! So far, it is an amazing machine. A real fully featured Linux computer for $5. And 20 times more memory than the one I had in my desk 25 years back...
Check out Eben Upton's video about that:

That would remind many things to some of us... Amstrad, Amiga, Atari, wow! I must be getting old.

PS: About the pinout: Put the SD Card on top, the biggest Raspberry design under the board. The pin #1 (3V3) is at the top left of the header.

Thursday, November 19, 2015

Monitor the Boat, remotely

With a FONA connected on the Raspberry PI (where the NMEA Console is running), you can remotely monitor what's going on.
Sending a '?' returns the menu, all subsequent available commands are 1 or 2 character long.

The feature has been implemented - as usual - as a UserExit. This UserExit is in the Desktop repo, the FONA Java interface is here.
Add the following parameter to the command line:
 -ue:olivsoftdesktopuserexits.FONAUserExit

Just by sending an SMS, you can retrieve the data read by the Raspberry PI on board, like True Wind Speed, Battery Voltage, Air and Water Temperature, etc, all you need is a smart phone that can send and receive SMSs.

That sounds promising...

This assumes that the boat is docked in a place where there is SMS coverage, of course. I'm working on an Internet version, with a Particle Photon, or an ESP8266...

Saturday, June 06, 2015

Scala on the Raspberry PI

As Scala compiles its files as Java class-files, they run on a regular JVM, with a few Scala-specific jar-files in the classpath.
Even if it is not the most productive way to get work done, it is possible to compile Java files on the Raspberry PI, as well as Scala files. Personally, I prefer to develop in an IDE, and use FTP to push the classes to the Raspberry PI, it's much faster, and the IDE is much more productive than vi.
The explanations I found here got me started.
And again, as Scala runs on a Java Virtual Machine (JVM), all the work done with PI4J is fully available from Scala.
The following code (available on github) shows how to read a BMP180 from Scala:
 import adafruiti2c.sensor.AdafruitBMP180

 object Scala_101 {
   def main(args: Array[String]) {
     println("Hello, Scala world!")
     val bmp180 = new AdafruitBMP180
     try
     {
       val temp  = bmp180.readTemperature
       val press = bmp180.readPressure / 100
       println(s"CPU Temperature   :  ${SystemInfo.getCpuTemperature}\272C")
       println(s"Temp:${temp}\272C, Press:${press} hPa")
     }
     catch
     {
       case ex: Exception => {
         println(ex.toString())
       }
     }
   }
 }
  
To run it, I used a script like this:
 #!/bin/bash
 # 
 SCALA_HOME=/home/pi/.sbt/boot/scala-2.10.3
 PI4J_HOME=/opt/pi4j
 #
 CP=$SCALA_HOME/lib/scala-library.jar
 # 
 CP=$CP:$PI4J_HOME/lib/pi4j-core.jar
 CP=$CP:../AdafruitI2C/classes
 CP=$CP:./out/production/Scala.101
 # 
 sudo java -classpath "$CP" Scala_101
  
And all is good, the output is
 Hello,Scala world!
 CPU Temperature  :40.6°C
 Temp:22.5°C, Press:1010.73 hPa

Thursday, May 07, 2015

Web Console improvements

With the Raspberry PI now able to behave as an Access Point, almost all devices can connect to it (Apple, Android, all kind of phones or tablets). Using an HTML5 enabled browser makes live easier than writing a dedicated application for the given Operating System.
That's why we now have some improvements in the Web Console:
See above the "Night" scheme, with or without borders for the displays
Same for the "Day" scheme.

The HTML5 console is accessed from http://machine:port/html5/console.html, default port being 9999.
If you have installed node.js and the WebSocket user-exit, then you access the WebSocket console from http://machine:9876/data/console.ws.html
It is still self-contained, no external framework is used (like JQuery et al). Those are great - for sure - but this is to be run on a boat at sea, with Internet out of reach.
Notice on the snapshots that several data come from some sensors hooked-up on the Raspberry PI. They can be shown or hidden from the preferences or from the Console Admin page.
Notice that the Console Admin page has been removed from the Console, it can now be accessed from a separate URL, on the admin port (8080 by default) at http://machine:port/html5/admin.html, started when the console is in headless mode:
The default values on the pages above come from the Desktop Preferences.
And there is now a CLI (Command Line Interface) for to access those preferences from a non-graphical environment (like on the Raspberry PI).
The class to launch is olivsoftdesktop.PreferencesCLI. An entry will added soon in the User Interfaces.

All this runs fine on the Raspberry PI, all the snapshots above have been taken with the Raspberry PI run node.js as server.

An idea...

Anyone with a smartphone or a tablet can access those live data. The problem is to type in the right URL...
Once you have chosen your configuration (IP address and ports), you can generate QR Code (https://www.the-qrcode-generator.com/ worked for me), print them, and post them somewhere in the boat. Whoever wants to reach the data just uses his QR Scanner - all smart stuffs have at least one - and boom! You're in!

HTML5 console

HTML5 WebSocket console

HTML5 Admin console
Those pages support query string parameters theme and border. theme can be 'white' or 'black', border can be 'Y' or 'N'.
Like in http://machine:9999/html5/console.html?theme=white&border=N

There are several QR Code generators, including some you can run off-line. This one works just fine, and can be installed on the computer on the boat, so you can generate your codes from anywhere. As you can see here.