Winter season monitor

Logging and monitoring parameters from winter storage

A monitor of vital parameters inside the boat when laid up or placed in a bubble berth for the winter is quite cool. I have put together a simple setup using a small Orange Pi computer and a 4G router together with some sensors to provide a yacht monitor for the winter.

The picture show the plastic box with the following items from the left:

    1. A two channel 230 VAC Solid state relay

    2. A bread bord for rapid prototyping and flexible connections

    3. An Orange Pi lite single board computer

Making a circuit board and connections and organizing it in a box would look nice and less of a rat nest, but a lot of flexibility would be lost. There are good reasons for breadboards, patch cables and Wago connectors to exist. It will, after a somewhat stable design is found, become a nice box to be deployed every fall.

Computer

The computer used is a simple Orange Pi Lite single board computer from Xunlong Software CO.,Limited in Shenzhen, China, see web : http://www.orangepi.org/ . The Orange Pi Lite is a relatively small system with an AllWinner H3 System on a Chip processor and has 512MB DDR3 SDRAM. Orange Pis are very cost effective and comes in a broader range then Raspberry Pis. It also have the well known 40 pin GPIO bus well known from Rasperry Pi. my current setup uses the GPIO for I2C, one wire and digital on/off signals. Running Raspberian Linux it operates just like any Linux system. Programming is done on the common languages and scripts, of which I have used Python and Bourne shell. It could run any of the scripting languages or compiled languages commonly found under Linux. The half Gigabyte memory is not really a limiting factor when running small tasks like this. Only limitation I have found is that emacs tend to be a bit on the large side, nano is better suited for this limited system, others users might use vi. Some times I miss the possibility to launch a web browser, but I could set om forwarding and proxy to bring it all to my workstation at home.

Internet connection

The connection to internet used to be by an old phone acting as a wifi gateway, later a 4G travel router was used. However, both failed in sub zero temperatures and the connection failed. Isolation is needed to keep the access point above freezing, fleece is ok together with the USB charger as extra heating. In addition it turned out that DHCP lease time was too low and the lease was lost, the access point shut itself off when there is no clients. Some keep alive steps was taken, using cron schedule a dhclient -r and dhclient -v once a day in addition to setting the lease time to two days.

The router is charged a few hours every day. The extra SSR on the relay card is used to turn the charger on and off (controlled by a cron job). By using a twin SIM card the need to an extra subscription is eliminated. The amount of data transferred is very limited. On a simple file containing a few tens of bytes is sent, the image is about from 30k for a low res webcam picture to over 300k for a high resolution one, in addition the string sent to thingspeak.com is just a few tens of bytes. This is really an internet of things setup.

I have also set up reverse ssh so that I can log in from my home server.

autossh -N ole@myserver.mydomain.no -R 8081:localhost:22 -C

To make sure you don't forget to launch this when the system boots, I have placed this line in /etc/rc.local to start it at boot time. To connect to the orangepi onboard:

ssh localhost -p 8081 -l root

Sensors

As for sensors I'm currently using:

    1. DS18B20 one-wire temperature sensors, three sensors.

    2. BMP180 barometer, I2C interface

    3. DTH11 humidity sensor

    4. Water level float switches, two locations.

Webcam

A simple webcam is also installed, mostly to monitor the LEDs on the dehumidifier. When it operates normally and the tank is not full the green LED is lit. When the reservoir tank is full the red LED lit up. Then it's easy to follow the status of the dehumidifier.

A high res webcam (1280x720) is monitoring the cockpit, mostly to check that the tarpaulin is still there. The harbour of Holmestrand is a good sheltered harbour, the major reason the town was located there in the first place a few hundred years ago.

Display of the data

The system send two files to the home server, a data file with 6 lines of data and an image at about 25kBytes. This need to be reviewed manually.

In addition the system send key data to thingspeak.com a web site by the makers of matab often used by makers, internet of things developers and hobbyists.

The data from Algol is publicly available. An example is shown here (captions in Norwegian) :

In some cases the send-to-thingspeak script fails, it does not check for valid humidity values. In these cases the data can be updated from the home server using a simple script, written in Lua which btw is a nice scripting language bridging the bash shell and Python.

Script in Lua to extract data from the newest file and push it to thingspeak web page :

f = io.popen("ls -lthr *data*| tail -1")

s = f:read('*a')

f:close()

b,e = s:find("algol")

fn=s:sub(b,s:len()-1)

f=io.open(fn,"r")

line=f:read('*line')

j=1

url="http://api.thingspeak.com/update?api_key=MY-API-KEY"

while line do

url=url..'&field'..tostring(j)..'='

if j<4 then

url=url..line:sub(5,8)

else

url=url..line:sub(1,line:len())

break

end

j=j+1

line=f:read('*line')

end

f:close()

com="curl "..'"'..url..'"'

os.execute(com)

Program code

The code to read the temperatures.

OrangePi/python $ cat readtemp.py :

import glob

import time

base_dir = '/sys/bus/w1/devices/'

sensors=glob.glob(base_dir + '28*')

j=1

for sensor in sensors:

sens=sensor+'/w1_slave'

raw = open(sens, "r").read()

temperature = float(raw.split("t=")[-1])/1000

# print("Temperature sensor %d : %4.1f deg C" %(j, temperature))

print("%d %4.1f" %(j, temperature))

j+=1

The code to read the DHT11 humidity and temperature sensor. There have been some issues with reading the DHT11 sensor, either the board, pins or sensor. Need a loop to read until a valid answer.

from pyA20.gpio import gpio

from pyA20.gpio import port

import dht

import time

PIN2 = port.PA0

gpio.init()

# read data using pin

instance = dht.DHT(pin=PIN2, sensor=11)

result = instance.read()

valid=result.is_valid()

print(valid)

print("Temperature: %.2f C" % result.temperature)

print("Humidity: %.2f %%" % result.humidity)

The code to read the BMP180 pressure sensor.

import sys

import os

import glob

import time

import math

# without the BMP180 library some more direct readot is needed.

pressure=open("/sys/bus/i2c/drivers/bmp280/0-0077/iio:device1/in_pressure_input","r").read()

# Correct for 1 m above sea level, scale height (8.314*278)/(0.029*9.82); This correction was needed at home at 156 m above sea level.

P=float(pressure)*10.0*math.exp(1.0/8160.0)

#print P,"hPa"

All files related to this project can be found at github.