Saturday, November 9, 2013

NMEA with Raspberry PI: All Good!

The last step - after this one - was not as straight forward. But finally, everything works fine.
The idea was to use PI4J to read the serial port (/dev/ttyAMA0). All the tests I made with PI4J were all very positive, but apparently, there is a bug when the baud rate is 4800. And unfortunately, this is the one we need.
But as reading a USB port (/dev/ttyUSB0) was not a problem, a simple adapter (serial 9 pin to USB) fixed everything. And on Linux (Raspberry PI runs Linux, a tweaked version of Debian), no driver or any such thing is required. Plug it in, and boom! It works.
The Raspberry PI reads the serial port with the headless console, and rebroadcasts everything appropriately.
The NMEA Console and OpenCPN can use TCP to get the data, The html5 Console uses HTML..., everything goes seamlessly. For less than 700mA. And around $50.
We will detail later all the steps to go through to get this done anywhere. This is just an easy check list.
And we'll built a nice box to host all this. The Raspberry, an optional small screen, and possibly a small keyboard.
More soon.

And just to give you a taste of what will come next,node.js works like a charm on the Raspberry PI, and the WebSocket protocol works as if it had been designed for this platform... That is going to seriously rock.

To summarize

This project goes along with the NMEA console, found here.

The main points this project addresses:
  • Serial ports (most of the data we're interested in come through a serial port) are accessed exclusively. Only one program at a time can access the data. I had the problem on the ketch, when the cartography soft was accessing the data port (to plot the boat on the chart), the console (the one evaluating current and performances) had to wait.
  • The laptop you can use to read the data draws a substantial amount of electricity (around 10W is not unusual).
  • Several devices on the boat (tactician, driver, navigator, trimmers) might need to have simultaneous access to the data, and they might need to be already processed and smoothed (damped)
The various devices needing access to the data might not run the same Operating System (MacOS, iOS, Android, Windows, Linux...). We assumed here that they have a network access, and a browser supporting HTML5 (the tests I made for this particular point are positive).
So, here is the story:
  1. The Raspberry PI creates its own ad-hoc network when it boots, and you start on it a utility that reads the data from the serial (or whatever) port connected to the NMEA station
  2. The data are read, and stored on the raspberry in some cache (a hashmap).
  3. The data are logged (optional), and processed (true wind is calculated, current is evaluated, VMG - on the wind or on the mark, performance, are evaluated). Those data are cached as well. Those calculations require some parameters to be set (max leeway, deviation curves, polars of the boat, some coefficients for the instruments, etc), they are available on the Raspberry PI.
  4. The data rebroadcasted on TCP, UDP, and HTML (also possibly RMI; I dropped GPSd). You can select one or more of those channels for rebroadcasting.
Basically, this is all the RaspPi is doing.

The SD card containing the OS of the PI needs to be 4Gb big, minimal recommended. Mine is 8, and it can go beyond 32. This allows DAYS of logging.

Now, when a device from the boat wants to see what's going on (i.e. visualize the data), it connects to the boat's ad-hoc network. Then, depending on its possibilities and needs, it can use the NMEA Console (that one can read any channel for its data input), or the HTML5 Console (at the bottom of this page).

The chart plotting program (like OpenCPN) can use the exact same data stream.
And when you're done watching your device, you can turn it off, hibernate it, what not, the RaspPi keeps reading and broadcasting.

The RaspPi does not take more than 700mA.
And it costs less than $50.
The RaspPi does not need any keyboard or screen. (I use SSH from a laptop to start the reading program on it).
The main points are:
  • Low consumption (and low price, if it makes any sense in this context)
  • Data rebroadcasting
  • Logging (ages of logging).
    I log VWR, RMC, MWV, RMB, VHW, VLW, HDG, MTW and GLL. It's about 1 Mb per hour.
    One day would be 24 Mb. One week around 168 Mb. Peanuts.
I have a lot of data, some logged during our Polynesian trip, I can replay them. This story seems to work.

I was very interested during the recent America's Cup, to see all the crews watching several kind of devices..., many had those displays on their fore-arms, tacticians had some iPad-like devices, fasten on their bellies with some shock-cords and velcro..., it kind of rang a bell! Those boats had for sure way more sensors that just an NMEA station (up to 3000 sensors for Oracle, I heard), but I believe that there is already a LOT to do with the data you can get from a regular NMEA station.

Once the ad-hoc network is setup, the crew members can even use their smart phone to access it, and visualize the HTML5 Console. That actually enhances one point: All the technology is here - nothing has been built or invented specially for this project. It's all about getting access to it with existing devices and techniques. Everyone (including me!) now has a smartphone, Linux has been around for ages, NMEA is one of the (if not THE) oldest standards in IT... And again, a small device you can get for less that $50 makes it all possible!
I like that.

Friday, November 8, 2013

Tropical phenomenons, Pacific, fall 2013

We've had quite a few tropical phenomenons in the Pacific since the end of August... Here is a list - still open - of what we've had, along with the time they were active, and their highest strength. Wind speeds are in knots. 60 G 75 is to be read 60 knots, gusting 75 knots.
Sep 01-02 TS Kiko, 60 G 75
Sep 13-16 TS Man-Yi, 60 G 75
Sep 17-18 Typhoon Usagi, 65 G 80
Sep 13-16 TS Man-Yi, 60 G 75
Sep 19 Hurricane Manuel, 65 G 80
Sep 21-27 Typhoon Pabuk, 90 G 110
Oct 01-04 Typhoon Fitow, 85 G 105
Oct 04-06 Typhoon Danas, 95 G 115
Oct 11-16 Typhoon Wipha, 115 G 140
Oct 16-30 Super Typhoon Francisco, 140 G 170
Super Typhoon Lekima, 140 G 170,
Hurricane Raymond, 95 G 105
Nov 04-now Super Typhoon Haiwan, 165 G 200
As a reminder, a hurricane (force 12 on the Beaufort scale) is over 64 knots.
Over 64 knots, it's a Category One hurricane.
Over 82 knots, it's a Category Two hurricane.
Over 95 knots, it's a Category Three hurricane.
Over 112 knots, it's a Category Four hurricane.
Over 136 knots, it's a Category Five hurricane.

Hurricanes and Typhoons are similar phenomenons. Hurricanes belong to the East Pacific, Typhoons to the West Pacific.

We also note that the Beaufort scale does not mention any such thing as a "Super Storm". You have Storm, Violent Storm, and Hurricane...
"Super Storm" is something invented by some journalists.

Thursday, November 7, 2013

For Navigatrix users of the WeatherWizard

Apparently, the soft has been installed as root, and some write permissions are not granted to everyone.
That makes it difficult to write on the file system, like when downloading a file!
To fix that, you need to go to a Console, and enter the following commands:
 Prompt> cd /opt/WeatherWizard
 Prompt> sudo find . -name '*' -exec chown $USER {} \;
You might as well change the group of the same files. If your group is "mygrp", then just type:
 Prompt> cd /opt/WeatherWizard
 Prompt> sudo find . -name '*' -exec chgrp mygrp {} \;
Be careful, all characters are important.
That's a bit cryptic, but that should work!

Monday, November 4, 2013

From Scratch to NMEA Re-broadcasting on TCP, with a Raspberry PI

This post will demonstrate how to connect a Raspberry PI on some NMEA input - a GPS in this case - to re-broadcast all its data using other protocols, HTTP and TCP in this case.
The cool thing about this configuration is that:
  • As many devices as you want can access the NMEA data
  • The Raspberry PI only draws 700 mA
  • When they're done using rthe NMEA data, devices (laptops, tablets...) can shutdown, the NMEA data will still be read and available whenever a device connects on the Raspberry Pi's network
The NMEA data being read can also be logged on the Raspberry PI, if necessary.

We assume that you already have a Raspberry PI, along with its power supply (AC or DC, whatever).
We will show how to setup everything so the Raspberryt PI reads the NMEA data, and re-broadcasts them. As an example, we will show how to consume them from OpenCPN.
We will also need to edit several configuration files and other scripts. You can use any editor you wish, "nano" can do the job, I myself prefer "vi". At the end of the day, that's the same, only the result is important.

Requirements

First, flash the SD card, as explained here. I used the Raspbian image. Comes with Java.
Next, we will require several softwares to be installed on the Raspberry PI, some are necessary, others are convenient.

An FTP server

This one will be very convenient when you will need to transfer files on you Raspberry PI.
To install, type:

 Prompt> sudo apt-get install vsftpd
    
Then edit (sudo edit) /etc/vsftpd.conf:

 anonymouse_enable=NO
 local_enable=YES
 write_enable=YES
 local_umask=022
 chroot_local_user=YES
 user_sub_token=$USER
 local_root=/home/$USER/ftp
    
Start this ftp as a service on the PI:
  
  Prompt> sudo service vsftpd restart
    

Install RXTX Java libraries

Read this good article.
Just type:

 Prompt> sudo apt-get install librxtx-java
    
We will see in the next section what to do with this.

Fing

A very cool utility. Combination of Find and Ping.

 Prompt> wget http://www.overlooksoft.com/packages/download?plat=arm
 Prompt> sudo dpkg -i overlook-fing-2.3.deb
 Prompt> sudo apt-get install libpcap*
    
and finally:

 Prompt> sudo fing
    

OlivSoft

You have just installed the libraries you need to use the serial ports (Serial or USB), now we need to modify the launching script to take that in account.
Make sure you have the last version of the soft, up to date.
It is available on Google Code, in the download section.
The best way to do that is probably to install it on a box connected to the internet, and to let the software update itself.
Then you can transfer all the directory where it is installed (using FTP) on the Raspberry PI.
Once this is done, navigate to the all-scripts directory, and edit the script named olivsoft.
You can add a line in the menu:

  echo \| P for Weather Wizard, with http proxy 
  echo \| S for NMEA Sniffer
  echo \| H for Headless NMEA Console
  echo \| POL for Polar Tool
    
... and then the corresponding execution definition:
    ...
  elif [ $choice = "H" ] || [ $choice = "h" ] 
  then
    JAVA_OPTIONS="$JAVA_OPTIONS -Dverbose=false"
    JAVA_OPTIONS="$JAVA_OPTIONS -Dheadless=yes"
    JAVA_OPTIONS="$JAVA_OPTIONS -Dserial.port=/dev/ttyUSB0"
    JAVA_OPTIONS="$JAVA_OPTIONS -Djava.library.path=/usr/lib/jni"
    #
    HEADLESS_OPTIONS="-output=HTTP:9999"
    HEADLESS_OPTIONS="$HEADLESS_OPTIONS -output=TCP:7001"
    # HEADLESS_OPTIONS="$HEADLESS_OPTIONS -output=FILE:.\logged-data\headless.nmea
    java -client -Xms512m -Xmx1024m -classpath $CP $JAVA_OPTIONS olivsoftdesktop.OlivSoftDesktop $HEADLESS_OPTIONS
  elif ...
    
Notice that /dev/ttyUSB0 is the USB port the GPS in connected on. In this case, the data will be re-broadcasted on TCP, port 7001, as well as on HTTP port 9999.
We will see below how to start the program.

Create an ad-hoc network, from the Raspberry PI

Read this good article.
Make a backup:

 Prompt> sudo cp /etc/network/interfaces /etc/network/interfaces_backup
    
Then edit (sudo edit) /etc/network/interfaces:

 auto lo
 iface lo inet loopback
 iface eth0 inet dhcp
 
 auto wlan0
 iface wlan0 inet static
   address 192.168.1.1
   netmask 255.255.255.0
   wireless-channel 1
   wireless-essid RPiOnTheBoat
   wireless-mode ad-hoc
    
In the lines above, RPiOnTheBoat will be the name of your ad-hoc network.
Restart wlan0 (wlan0 is the name of the wireless network interface).

 Prompt> sudo ifdown wlan0
 Prompt> sudo ifup wlan0
    
(reboot in case you have an error message)

Then we might need a DHCP Server:

 Prompt> sudo apt-get update
 Prompt> sudo apt-get install dhcp3-server
    
Then edit (sudo edit) /etc/dhcp/dhcpd.conf

 ddns-update-style interim;
 default-lease-time 600;
 max-lease-time 7200; 
 authoritative;
 log-facility local7;
 subnet 192.168.1.0 netmask 255.255.255.0 {
   range 192.168.1.5 192.168.1.150;
 }
    
Reboot..., all should be all set!
Let's if that's true.

Run it

Connect the things first:

Only the Wireless dongle is in

Plug the SD Card in (contains the OS)

Plug in the GPS

Connect the power supply
Connecting the power supply will boot the device. Now, wait a couple of seconds for Linux to boot, and we are going to connect to the Raspberry PI from another machine, using ssh.
Notice in the steps above, that there is no mouse, no keyboard, and no screen connected on the Raspberry PI. We could have done so. But we didn't.
To demonstarte the full compatibility of this scenario, we will do the subsequent operations from a Windows box.

Connect to the Raspberry PI's ad-hoc network

The wireless networks are usually available in the Windows taskbar. If not, open your Network Control Panel, you'll find it there.
Notice the network's name (RPiOnTheBoat), this is the one you defined.
Then, we will use ssh (PuTTY) to start the re-broadcast:
Connect with your username (default: pi) and password (default: raspberry), and cd to olivsoft, and start the script olivsoft:

 Prompt> ./olivsoft
    
It's on its way! You can leave the session if you wish, the process will keep going.
To stop it:
Re-connect on the Raspberry PI with ssh
Find the process, by typing:

 Prompt> ps -ef | grep java    
    
Then send it a SIGTERM signal:

 Prompt> kill -SIGTERM 2493
    
Where 2493 is the process id. This way, the process will shut down nicely (by design, it understands that signal, which would be a Ctrl+C from the command line).

The process being up and running, define a network connection in OpenCPN:
Notice the Address, the one you have defined.
Click Apply...
See the top right, the GPS is connected. As you can see in the NMEA log.
You can connect like this with as many devices as you want.
Voilà!

Next, we will try with the full NMEA station, with Pi4j. Then the HTML5 console will also be available, from http://192.168.1.1:9999/html5/console.html.

Saturday, October 26, 2013

Investigating the Raspberry PI

The more I play with it, the more I like it... It's so small - and so cheap - and it is a real Linux system, based on Debian. It comes with Java. It runs from a small SD card (4Gb recommended minimum). All the info are available on the Raspberry PI web site.

Development config

Minimal config

The GPIO can be managed with PI4J, works like a charm. Example:
----------------------------------------------------
HARDWARE INFO
----------------------------------------------------
Serial Number     :  00000000a36c8782
CPU Revision      :  7
CPU Architecture  :  7
CPU Part          :  0xb76
CPU Temperature   :  49.8
CPU Core Voltage  :  1.2
MIPS              :  697.95
Processor         :  ARMv6-compatible processor rev 7 (v6l)
Hardware Revision :  000e
Is Hard Float ABI :  true
Board Type        :  ModelB_Rev2
----------------------------------------------------
MEMORY INFO
----------------------------------------------------
Total Memory      :  459505664
Used Memory       :  240529408
Free Memory       :  219484160
Shared Memory     :  0
Memory Buffers    :  20328448
Cached Memory     :  141778944
SDRAM_C Voltage   :  1.2
SDRAM_I Voltage   :  1.2
SDRAM_P Voltage   :  1.23
----------------------------------------------------
OPERATING SYSTEM INFO
----------------------------------------------------
OS Name           :  Linux
OS Version        :  3.6.11+
OS Architecture   :  arm
OS Firmware Build :  4f9d19896166f46a3255801bc1834561bf092732 (clean) (release)
OS Firmware Date  :  Sep  1 2013 23:31:02
----------------------------------------------------
JAVA ENVIRONMENT INFO
----------------------------------------------------
Java Vendor       :  Oracle Corporation
Java Vendor URL   :  http://java.oracle.com/
Java Version      :  1.7.0_40
Java VM           :  Java HotSpot(TM) Client VM
Java Runtime      :  Java(TM) SE Runtime Environment
----------------------------------------------------
NETWORK INFO
----------------------------------------------------
Hostname          :  raspberrypi
IP Addresses      :  192.168.1.251
FQDN              :  raspberrypi.att.net
Nameserver        :  192.168.1.254
----------------------------------------------------
CODEC INFO
----------------------------------------------------
H264 Codec Enabled:  true
MPG2 Codec Enabled:  false
WVC1 Codec Enabled:  false
----------------------------------------------------
CLOCK INFO
----------------------------------------------------
ARM Frequency     :  700000000
CORE Frequency    :  250000000
H264 Frequency    :  0
ISP Frequency     :  250000000
V3D Frequency     :  250000000
UART Frequency    :  3000000
PWM Frequency     :  0
EMMC Frequency    :  100000000
Pixel Frequency   :  108000000
VEC Frequency     :  0
HDMI Frequency    :  163683000
DPI Frequency     :  0

The first goal will be to have such a device running in the chart table, reading the NMEA Data (connected on the NMEA Station through its serial port, read with GPIO, as mentioned above), and re-broadcasting the data on HTTP, TCP or UDP. The re-broadcasting part has been tested (see here), with logged data.
Next:
  • Connect the serial port, and read it from Pi4J
  • Create an ad-hoc network FROM the Raspberry PI
This way, several applications can use the NMEA Data, simultaneously. It has been tested with the NMEA Console, and OpenCPN, with TCP and UDP. The HTTP re-broadcast can be used from an HTML5 browser, from a laptop or a tablet, connected on the boat's ad-hoc network.

HTML5 NMEA Console, on a tablet

Wednesday, August 21, 2013

South California Free Anchorages

Working on it. There is this site, quite interesting, and I'm trying to use Google Maps as well.


View Free anchorages in a larger map

More to come soon, stay tuned.

Saturday, July 6, 2013

Part of Navigatrix!

As of July 3, 2013, the Weather Wizard is part of Navigatrix! Cool recognition ;0). And the user manual is now available directly from the soft, as a pdf file, downloadable from the Internet. Lulu.com still provides the binded version of the document.

Thursday, July 4, 2013

Spot GRIB Request

saildocs provides support for the Spot GRIB requests. Spot requests returns forecasts for a given location. Let's say you just dropped the hook, and you want to know what your night is going to look like...
If you send an email to query@saildocs.com, with a body like this:

 send spot:37.5N,122.5W|5,3|PRMSL,WIND,RAIN
, you will receive a response like that one:

Data extracted from file gfs130704-12z.grb dated 2013/07/04 16:52:56
request code: spot:37.5N,122.5W|5,3|PRMSL,WIND,RAIN

Forecast for 37°30N 122°30W (see notes below)
Date  Time  PRESS  WIND DIR RAIN
        utc    hPa  kts deg mm/h
----------- ------ ----- --- ----
07-05 00:00 1005.7  9.8 288  0.0
07-05 03:00 1005.7  11.5 297  0.0
07-05 06:00 1006.8  12.9 302  0.0
07-05 09:00 1006.7  13.0 303  0.0
07-05 12:00 1006.7  12.6 303  0.0
07-05 15:00 1007.0  11.7 299  0.0
07-05 18:00 1007.7  10.3 280  0.0
07-05 21:00 1007.2  11.4 270  0.0
... etc
This is "human readable", as they call it, but not that catchy, hey?
The cool thing is that this content can be parsed, using basic regular expressions.
If you drop the content of the request's response in the box below, you will have a chance to render it visually.
See in full
The browser you use must support HTML5 for that.

Thursday, February 14, 2013

Reviving the Weather Wizard Applet

It needs to be signed (to be trusted)..., but give it a try: here (in full), or below (in small).

This demonstrates a small subset of the features of the Weather Wizard. There is no GRIB, no routing, no possibility to save anything.
But that gives you a taste of the possibilities.

The applet is signed. That means it wants to get out of the Sun sandbox. Namely, it wants to read the faxes from an external website.
Once you have selected your composite (from the top drop-down list), do not forget to hit the "Go" button...

Wednesday, February 6, 2013

Version(s) 3.0.1.3

Released today the version 3.0.1.3 of the Weather Wizard, the Navigation Desktop, and the Polar Smoother.
The release includes some bug fixes, cosmetic improvements, and a decomposition of the deviation curve (in the NMEA Console), as shown below.


Click the image to enlarge.

And with the NMEA re-broadcast, the Navigation Console works like a charm with OpenCPN 3.1.1328.