How to deploy HomeIO on Raspberry Pi + Arduino Leonardo25 May 2015
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.
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.
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
I assume you have similar system to monitor as I have - 3 plants with moisture sensor + 1 light sensor :)
To start git clone backend repository.
git clone https://github.com/HomeIO/homeio_backend.git
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.
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.
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.
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.