The goal of this repository is to share what I've created to monitor and automate my aquaponic greenhouse. I tried to use docker almost everywhere to easily replicate/automate the setup and let everyone use it in a simple way.
I have a raspberry pi 3 in my greenhouse with few sensors connected through I2C on it. It currently monitors :
- Fishtank temperature
- Greenhouse temperature
Using a bridge to flower power it also monitors the light, the soil moisture, and fertilizer. It uses this project: https://github.com/Parrot-Developers/node-flower-bridge.
How to install it
Server (at home)
The server needs less things than the client in order to run. We only need docker.
The structure of the server
The server has few files located in
- docker-compose.yml: contains all the services to launch and the parameters to give to containers
- env.grafana: This file allow to easily pass environment variables to grafana
- env.influxdb: This file allow to easily pass environment variables to influxdb
- nginx.conf: I chose to expose my grafana to public and add a specific url to access it. I use nginx as a reverse proxy here
- telegraf.conf: It allows to expose server metrics
If you don't want to expose publicly your grafana, you can remove the nginx block from the
As you can see, paths are hardcoded, that means you will have to change the
/home/seraf/ by your home path.
The influxdb is a bit special about volumes. It uses two volumes :
/home/seraf/docker-data/influxdb/datais a directory external to this git repository where all the metrics/data are stored
/home/seraf/nas/backupis a NFS mount where I do my backups
I'm using this cron to do my backup everyday on my NAS:
0 0 * * * cd /home/seraf/greenhouse/server/ && /usr/local/bin/docker-compose exec influxdb influxd backup -database grafana /backup/influxdb
Client (in the greenhouse)
First, you will need to install your raspberry pi. I won't explain here how to do it, it's up to you to choose the distribution you prefer.
The packages needed are :
I let you install
docker by yourself as it depends of your distribution, but it's easy to do
Ideally, be sure you have
pip3 to install the following packages:
Then, clone the repository :
git clone https://github.com/Seraf/greenhouse
The structure of the client
I created few directories in the client directory to sort a bit the different components.
checksdirectory contains all the checks (written in python to access the GPIO) to get the sensors values.
cronsdirectory contains script that will be called as crons by your cron scheduler. It is used for example to recalibrate your pH sensor according the temperature changes.
dockerdirectory contains the docker image source I used to create the containers I'm currently using.
flower-powerdirectory should contains the credentials file to use if you have flower power devices. Else, ignore this directory.
telegrafdirectory contains the configuration I use to send values to the metrics database.
docker-compose.ymlis the docker-compose file to launch all the containers
Telegraf is an agent that will trigger the checks, get the values and send them to the metrics database.
telegraf/telegraf.conf configuration file will need some changes according your own setup.
The main thing to change is the line :
[[outputs.influxdb]] urls = ["http://192.168.1.21:8086"] # required
You should obviously use the ip address of your server configured previously.
[[inputs.exec]] ## Commands array commands = [ "/checks/htu21df.py", "/checks/flower_power.py", "/checks/ezoph.py", "/checks/ezotemp.py" ]
There is also the checks section to modify according your own sensors/checks.
docker-compose.yml file is simple when you already understand the concepts of docker.
It will launch 2 services :
telegraf (the agent responsible to transmit data), and
flower-power which is a bridge to my flower power devices.
If you don't have flower power devices, I recommend to remove all the lines concerned as it's not necessary (and don't forget to remove the check in the telegraf configuration)
Create the crons
Here are the crons I'm currently using:
13,28,43,58 * * * * /usr/bin/python3 /home/pi/greenhouse/client/crons/ph_calibration.py 0 12,15,18 * * * /usr/bin/curl -X POST "http://192.168.1.21:8086/write?db=grafana&precision=s" --data-binary 'events title="Nourriture",text="Dose niveau 3"' 0 9 * * * /usr/bin/curl -X POST "http://192.168.1.21:8086/write?db=grafana&precision=s" --data-binary 'events title="Nourriture",text="Dose niveau 4"'
The first one is to calibrate the pH sensor each 15 minutes according to the temperature change.
Why I didn't use
*/15 ? Because it's doing a read on the I2C interface at the same time than telegraf. Then, one of them is failing. To avoid that, I'm changing the temperature between two checks.
The two other crons are used to create annotations in my metrics database to have an annotation each time my auto-feeder is giving some food to fishes. Then I'm able to track the changes of other parameters according to the quantity of food delivered.
Launch it !
To launch the client, once configured, it's pretty simple, just execute this command :
pi@serre:~/greenhouse/client $ docker-compose up -d