HomeIO Articles about real life tech solution and HomeIO - an universal system for remote monitor and control

Wind turbine instance frontend demo movie

I wanted to show how wind turbine works with HomeIO, how can I control it, so I’ve recorded a simple demo.

I’ve used kazam and kdenlive while recording.

Spyware and buffer storage

I wanted to have something like centralized place to check measurement and if all instances are working. Had some problems with HTTP requests in C++ so I did something ugly - run curl command. It works.

Next feature is periodically store measurements from RAM to file. It works, but there are problems while restarting. I need to check it. I need to remove buffer files before running backend.

I’ve fixed bug when storing measurements (not buffer) in csv files. Everyone should remember about return in functions returning values. It’s a bad habit from working in Ruby.

Some photos of wind turbine hardware

Batteries are those white boxy things below. Current sensors and charge circuits are in white stripped box on left. Microcontroller with HomeIO compatible firmware is in the black box on right.

Control hardware + batteries

Installed wind turbine.

Wind turbine

Why not Redis?

Because Redis would store values in list as string while measurements are unsigned int objects. That lead to massive memory usage or would not allow to have big measurement buffer in memory.

This is the main reason I have rewritten backend in C++.

If I remember correctly redis used about 40-50% memory, when C++ version took max 3%. I am not sure about buffer size, it is possible that I have used much bigger buffer in C++ version.

How to deploy HomeIO on Raspberry Pi + Arduino Leonardo

Why Arduino?

HomeIO can be deployed on typical Gnu/Linux server connected with hardware. Arduino is the most common hardware platform available now, so first tutorial will utilize it as a hardware.

I recommend using Arduino Leonardo, because it’s the most popular model and Raspberry Pi has no problems with powering it. More info here.

It is a good thing to buy proper sensor shield. It is an external board which you plug onto Arduino and allow it to connect multiple sensors very easily. This board looks like this.

Arduino Leonardo with sensor shield

The server

You can use nearly every PC as a server for HomeIO. Keep in mind power usage. (There are also other requirements, but I can not specify them all)

Raspberry Pi has very low power usage and is powerful enough to allow HomeIO deployment. In this tutorial I will choose it as a server platform. If you have other PC everything should be similar.

Preparing server

I prefer Debian distribution, so you can install Raspbian. How to install.

You need quite fresh packages repository. In case of Raspbian I recommend you to change to jessie because HomeIO needs C++ compiler version 4.9. I’m not sure about version of Go language needed at this moment.

apt-get install g++-4.9
apt-get install go-lang

Configure backend

I assume you have similar system to monitor as I have - 3 plants with moisture sensor + 1 light sensor :)

Everything regarding backend is set in backend code. Everything is in one place. I have added comments in wind turbine version, but I will try to describe it also.

To start git clone backend repository.

git clone https://github.com/HomeIO/homeio_backend.git

Fetch cycle

HomeIO works by fetching measurements in cycles. There is measurement types array and it fetch every some time.

h->measFetcher->betweenMeasInterval = 10000;

That means there is 10000 microsecond = 10 miliseconds delay between fetching another measurement type. All delays are in microseconds, but times are stored in miliseconds.

If all measurement types were fetched it waits for next cycle. You can set it here.

h->measFetcher->cycleInterval = 10000000;

That means there is 10000000 microsecond = 10000 miliseconds = 10 seconds delay between fetching another cycle. Soil moisture and light is quite slowly changing thing. Note: in wind turbine version this is set to 50 miliseconds because of it is different kind of system.

Measurements

MeasType *m;

It is C++ definition of variable. If you don’t understand it [you’re going to have a bad time][http://godlessmom.com/wp-content/uploads/2015/03/youre-going-to-have-a-bad-time.png].

m = new MeasType();

Create MeasType object. It represents everyting about one type of measurements.

m->name = "light";

It is the name of this measurement type. If you put some weird characters here and it breaks, it is your fault. If you want get something regarding one type, you must use name for identification.

m->unit = "%";

It is only used in frontend.

m->command = '0';

Character command which is send to Arduino. Please check Arduino firmware info later.

m->responseSize = 2;

Response is 2 byte long. Analog to digital in AVR/Atmega is 10-bit so the response needs 2 bytes.

m->coefficientLinear = -0.09765625;
m->coefficientOffset = -1023;

Real value = ( raw value + coefficientOffset ) * coefficientLinear. Both this parameters are used for calculation real float value. If you do not know what to set you can remove theese lines. There are default values.

m->minTimeDiffToStore = 5000;

Apart of fetching measurements backend can do a lot of cool thins. One of them is storing values. It stores them in CSV files in data directory.

Example of stored measurement:

coil_1_u; 1432046783261; 1432046784395; 0.000000

It is: name; time from (in miliseconds from 1970, the JS format); time to; real value

Setting minTimeDiffToStore tells backend not to store if last one was stored within 5000 miliseconds from now.

m->maxTimeDiffToStore = 3600000;

Force store if last one was stored more or equal than 3600000 miliseconds from now, this equals 1 hour.

m->valueDiffToStore = 3.0;

If current value changed more than 3.0 of real units then store. Keep in mind that two previous conditions apply as priority.

m->priority = 1;

It is only used in frontend to separate more important measurements from less one.

h->measTypeArray->add(m);

Add measurement to fetchable measurement array.

Is that all?

Yes and no. This is the most important thing to start HomeIO with. Other parts will be described soon.

Run frontend

export GOPATH=~/gopath

Go needs path to store its stuff.

go get github.com/gin-gonic/gin

Frontend uses gin framework. You must run this one time only.

go run homeio.go

Run frontend. Keep in mind that backend is required to frontent to work. Everything is fetched from backend. There is frontend configuration needed.

Result

Multigraph sample