Thursday, April 4, 2019

Nodered, influxdb and Grafana

I had installed nodered to help monitor some of the systems on the boat and elsewhere some time ago. It has the ability to display some data, charts and plots with the extra "dashboard" module.

I also installed mosquitto to collect data from the ESP devices and the OPis. I probably followed someone's notes, but I didn't seem to log it.

It was OK for a while, but each time I restarted a display, it would start with no historical data. There was also no way to remove erroneous data. As I change things, plug in or forget to plug in things, I do get erroneous data points on occasion.

I tried sqlite/sqlite3 on op2e and croc for a while. It is like mysql, only a little simpler. I found an example flow for nodered and tried it for a while.

Then I saw the youtube from Andreas and decided to try it.

It didn't take too long to get some data going into influxdb, but it did take some learning. The data had to be formatted just right to be inserted in a way that grafana could read it back.

For the simple case of a two values JSON string this is it. It did take a while fo make it this simple:

var tokens  = msg.topic.split("/");
msg.measurement   =tokens[1];       //get device  name from topic  level 3 /v1.6/devices/tokens[3]
var dest    = tokens[tokens.length-1];
inputjson   =JSON.parse(msg.payload);
msg.payload =inputjson;
return msg;
// End

For the more complex report for the disk space it took several days:

var tokens  = msg.topic.split("/");
sys = tokens[1];       

function extract(elem) {
    let extr = elem;// { fileSystem: "/home", percent: "96" }
   // node.warn(extr)
    var tag = {"host": sys, "filesystem": extr.fileSystem};
    msg.measurement = "Disk";
    msg.payload= [{"percent": extr.percent}, tag];
    return extr;
// End

But it is working now.

The next hurdle was to get the data out into a graph with Grafana. A longer learning curve. And I'm not sure how to show it. Several windows for input all have to agree for the data to show up.


Just the battery monitor

Saturday, January 19, 2019

A Quick Look at RFID

Back in 2002, I was working a short contract in Seattle, just as the company was notified by Walmart that they must implement RFID on ALL of their products or no longer be eligible to sell through them. I dreamed of starting a consulting company specializing in implementing RFID, but then I realized I'd rather be retired and sailing in warm waters.

Just for kicks I ordered this RFID kit to evaluate, "MFRC-522 RC522 RFID RF IC Card Sensor Module". I would post a link, but I bought it in Chinese via Google Translate. It was only $2.63 so I couldn't pass it up.

I tested it on a Wemos D1 Mini, ESP8266, my current CPU of choice. The Arduino IDE has a library for the  MFRC-522 from It includes several examples. It is 3.3v and has a SPI interface plus a RST signal.

I tried several of the examples and the reader actually works! The blue tag needed to be less than 1cm to read, but the white card worked out to about 2.5cm.

Writing also worked. Both types of tags are identified as 1kilobhyte. I only wrote my name so I didn't test the limits.

MFRC-522 RC522 RFID Card Sensor Module

Tuesday, January 1, 2019

More Battery Monitor

It was still too hard to tell whether the new batteries were coming up to full charge, so while I waited, I added to the monitor. I already have a current shunt for the old "Heart/Cruising Designs" monitor and now the Xantrex LinkLite, so all I had to do was hook the ADS1115 differential input channels to it.

I added the current monitor with amp hour calculation and a status web page to the Batt_volt_mon. I re-factored the code using the tab capability of the Arduino IDE rev 1.8.8.

I also copied from a friend the idea to make each tab's code optionally included at compile time with #ifdef's. This makes it easier to debug.

  #define DO_ADS
  #ifdef DO_ADS
     #include "ads.h"
  #endif //DO_ADS
  #ifdef DO_ADS
  #endif // DO_ADS
  #ifdef DO_ADS
     if ( (last_ads + ads_time) < millis() ){
       last_ads = millis();
  #endif //DO_ADS

And I uploaded the new code to my github.

Top of the board with the modules out to see the wires
The bottom of the board

And then I documented the connections in Fritzing.
The Fritzing layout

Tuesday, April 3, 2018

Boat "House-Battery Bank" Monitor

The batteries on my boat seem to be failing. I decided to monitor the voltage to see how it is doing. I have 8 each 6 volt golf-cart deep cycle batteries wired series-parallel to give 12volts with 880 Amp-hours. But 2 have a shorted cell and are disconnected.

They are usually charged by 4 each 150 watt solar panels connected to 2 each 30 amp MPPT solar controllers. Also sometimes large frame alternators on the main engine or the diesel powered watermaker.

Anyway, the monitor is a Wemos D1 Mini with an ADS1115 4 channel A to D to measure the battery voltage. The 12volts (11.9 to 14.4) is outside the normal range of the ASD1115 so there is a resistor voltage divider implemented as a trimpot to set the voltage below the max allowed.

Also there is a cheap 3.3v buck converter on the board.

Once a minute it measures the battery (supply) voltage and sends to to node-red via mosquitto MQTT. It also checks for an OTA update each cycle.

The code is available on my GitHub:

Thursday, March 29, 2018

Capacity Testing 18650 LiPo

I made a battery powered ESP8266 IoT device and wanted to check the real capacity of my 18650 battery. All 18650s are not created equal and may not be labeled correcdt either.

This is the setup:
Discharge through USB tester to load
First and last discharge the battery through a USB tester that counts milliamp hours.

Charging setup
Charge the battery with a USB LiPo charge module through the USB tester and note the mA hours.

Note the handy adapter board, electronic load and USB monitor are  from Aliexpress. But came as a bundle that I can't find today.The USB monitor is an ATorch brand.

Wednesday, March 7, 2018

Refrigerator Monitor

This is the first version of frig_mon as a Wemos D1 Mini, a waterproof DS18B20 and a real time clock module. I wanted the data time stamped but the ESP8266 does not keep good time during deepsleep. I powered it with a 18650 battery direct with no voltage regulator, wired to the 3.3v pins. It seemed to function OK.

The fully charged battery at 4.2v is a little over the ESP spec, but it seemed to boot and run OK. The battery soon drops to around 3.7v where is lasts quite a while.

Wemos D1 Mini, RTC and DS18B20
Then I tested the lowest voltage the ESP would function. 2.6v appeared to be OK however soon the ESP burned up. The guess at the problem is that when the battery gets too low the ESP can't finish boot, so it retries, continuously depleting the battery without getting to the code that would stop it "if the battery is too low". It generates a lot of heat during this and overheats.

Testing the low voltage for the ESP
I noticed the Wemos board uses a lot of current even in deepsleep mode. It seems the USB converter chip does not sleep. And the voltage regulator consumes power even though the battery was plugged in to the output side.

So I switched to an ESP8266-007 on a breakout board with no regulator installed. Much better battery life.

A ESP-007 on a breakout board w/o voltage regulator

Also added OTA update capability, but then the -007 didn't have enough memory. I switched it for a -012E on a breakout board. I get more than a month run-time with 15 minute mqtt updates, and a check for OTA update.

The current board

The code is on GitHub at

Tuesday, February 20, 2018

Compile OpenCPN 4.8.2 for Armbian

As of Armbian 5.65 with Ubuntu Bionic this is not necessary. The Ubuntu PPA has arm version of the latest release of OpenCPN

A fresh clean install of OpenCPN 4.8.2 on Armbian 5.38 - Ubuntu 16.04 - Orange Pi PC Plus

My laptop is named pot, the Orange Pi PC Plus gets renamed cpn.

Download the latest desktop version of Armbian for the Orange Pi board you have. It still needs to be the Legacy kernel 3.4.113 because the accelerated GPU drivers are not yet in the mainline kernel.

Write the OS image to the sd-card:

pot# dd bs=4M of=/dev/sdc if=Armbian_5.38_Orangepipcplus_Ubuntu_xenial_default_3.4.113_desktop.img

Do the normal setup of a fresh image:

pot# scp /etc/hosts root@cpn:/etc
passwd, config networking, ssh-copy-id, scp setup, fix ~larryl/.ssh ownership, ./confi   
reboot   # to finish filesystem resize
updatedb  # for the locate command

I had to wait quite a while for the daily cron: apt to finish before I could do:

apt update; apt upgrade
apt-get install build-essential cmake gettext git-core gpsd gpsd-clients libgps-dev \
   wx-common libwxgtk3.0-dev libglu1-mesa-dev libgtk2.0-dev wx3.0-headers libbz2-dev \
   libtinyxml-dev libportaudio2 portaudio19-dev libcurl4-openssl-dev libexpat1-dev \
   libcairo2-dev wx3.0-i18
   ... 0 upgraded, 105 newly installed, 1 to remove and 0 not upgraded. (as of Feb 18, 2018)

The default build image does not have enough swap space for the compile so I plugged in a USB SSD that had alinux installed once and setup that swap partition:

mkswap -f /dev/sda2
swapon /dev/sda2
armbian-config   # set hostname to cpn and TZ to Asia/Taipei

Now to get and compile OpenCPN source as a normal user:

git clone  
git ccheckout v4.8.2
cd OpenCPN; mkdir build; cd build
make package
dpkg -i /home/larryl/OpenCPN/build/opencpn_4.8.2-1_armhf.deb 

******** errors *******
dpkg: dependency problems prevent configuration of opencpn:
 opencpn depends on libwxgtk3.0-0; however:
  Package libwxgtk3.0-0 is not installed.
 opencpn depends on libtinyxml2.6.2; however:
  Package libtinyxml2.6.2 is not installed.
******** errors *******

So this is the reason I hate Ubuntu, needlessly changing the package name instead of the revision fields so the dependencies no longer match the "new package name"!!! So adjust the depends in the package description file for the variable ending in "PACKAGE_DEPS" about line 98:

vi ../CMakeLists.txt
SET (PACKAGE_DEPS "libc6, libwxgtk3.0-0v5, wx3.0-i18n, libglu1-mesa (>= 7.0.0), \
  libgl1-mesa-glx (>= 7.0.0), zlib1g, bzip2, libtinyxml2.6.2v5, libportaudio2")

Add the v5 to the dependencies as above

make package
sudo dpkg -i /home/larryl/OpenCPN/build/opencpn_4.8.2-1_armhf.deb

If you have unmet dependencies, you can attempt to fix them with:

sudo apt install -f

Ready to configure OpenCPN with charts, tide data, connections and your favorite settings.

PS: The finished package should soon be up on github repositories.