Git Product home page Git Product logo

patrickhallek / automated-irrigation-system Goto Github PK

View Code? Open in Web Editor NEW
681.0 38.0 87.0 1.22 MB

This is the software of an open source automated irrigation system. The complete setup including hardware can be found in the README.

HTML 4.11% JavaScript 76.81% CSS 12.99% Dockerfile 0.46% C++ 5.34% Pug 0.29%
automation irrigation watering system smart-home iot gardening garden-automation raspberry-pi esp8266

automated-irrigation-system's Introduction

License: MIT PRs welcome!

Automated irrigation system

This is an open source application to water plants automatically. Up to now there is almost no free professional software and instructions available to build a DYI irrigation that is scalable, accurate and most importantly, durable. The app is also not only there to look good and for the love of data. Above all, it is a tool to tailor the sensors to the exact needs of the plants. This is where most irrigation systems with direct soil moisture measurement fail because every soil and plant is different and therefore manual calibration and possibly after some time also recalibration is essential.

The app contains the following features:

  • Monitor and display time series data at the minute, hour, day, week and month levels
  • Setting the water level from which automatic watering should be triggered.
  • Setting how long the pump works during an irrigation
  • Manual activation of irrigation with a button
  • Switching between different sensor profiles
  • Switching between dark and light theme
App dark themed App light themed
App dark themed App light themed

Table of contents

  1. Part list
  2. Hardware Architecture
  3. Software Architecture
  4. Setup NodeMCU ESP8266
  5. Setup the Raspberry Pi with Docker (recommended)
  6. Setup the Raspberry Pi manually
  7. Usage
  8. Contributing
  9. License

Part list

Name Anmount Description
NodeMCU ESP8266 1 - n Wifi module for reading capacities and sending them to the backend (Raspi)
Raspberry Pi Zero 1 Running the whole software and triggering the pump(s)
Raspberry Pi SD Card 1 This is the data memory for the raspberry pi
Relay 1 - n To close or open the pump circuit on signal from the raspi
Capacitive Soil Moisture Sensors 1-n To measure the soil moisture. Capacitive sensors do not dissolve. Never use electrodical humidity sensors, as they wear out very quickly
Pump 1 - n Theoretically any pump can be used, as it is controlled by a separate power supply and the relay
Aquarium tube and irrigation nozzles - Water transfer to the plants and to distribute the water on the earth

*all product links are also affiliate links to exactly the same products I bought for the system. If you order via the link, I will receive a tiny commission.

The "n" in the anmount is due to the number of pumps or different plants. For example, in a raised bed it is usually sufficient to have one pump and one sensor. However, if you have different potted plants, they all need to be watered separately and therefor you have to get one pump and sensor for each potted plant.

Hardware architecture

Hardware Architecture

The architecture was chosen so that pump logic and recording of measurement data is separate. This makes it possible to control up to 26 pumps with the Raspberry Pi (amount of default available GPIO pins). It is also not possible to read the analog signals of the capacitive sensor with the Raspberry itself, because the Raspberry can only process digital signals. Surely it is possible to read the sensors with an MCP3008 and the serial interface, but this requires more pins and the setup is not as clean as it used to be. The pumps are also separately connected to a power supply, whose circuit is controlled by the relay. So it is also possible to use 12V or higher pumps.

Software architecture

Software Architecture

For the software architecture the MERN Stack was used. The software consists of a Node.js backend with Express.js, a Mongo database and a React frontend. A C++ script runs on the NodeMCU ESP8266, which sends data to the REST interface of the backend. The data is processed in the backend, where it is decided whether to irrigate or not. In addition, the data is then stored in the MongoDB. With the frontend, this data can also be requested from the backend via REST.

Setup the NodeMCU ESP8266

To flash the NodeMCU microcontroller you have to follow the steps described in this video.

Before you upload the program you have to set your wifi password, wifi name (ssid), the ip of the raspberry pi (host) and the sensor name. The sensor name will be the name that is displayed in the app. So it's best to choose the name of the plant the sensor should be associated with.

If the Arduino IDE is successfully configured for the NodeMCU, you can upload the program you find in this repository under arduino-code/ESP8266_moisture/ESP8266_moisture.ino to the NodeMCU.

Setup the Raspberry Pi with Docker (recommended)

To avoid having to install the required programs manually, you can also run the application with Docker in containers. To do this, carry out the following steps:

curl -sSL https://get.docker.com | sh
sudo usermod -aG docker pi
sudo apt-get install -y libffi-dev libssl-dev
sudo apt-get install -y python3 python3-pip
sudo apt-get remove python-configparser
sudo pip3 install docker-compose

Now you have to pass the ip address of your pi into the REACT_APP_BACKEND_URL=http://<YOUR-RASPI-IP>:3000 environment variable in the docker-compose file:

sudo nano docker-compose.yml

You can find the ip with the command ifconfig. It should be something like 192.168.178.44. You can save your input in the Nano editor with ctr + x, then type in yes, finally exit with enter.

Now everything should be ready and you can start the application with the following command:

sudo docker-compose up

Attention: If you have a Raspberry Pi with a processor other than ARMv7, you need to adjust the image for the mongodb in the docker-compose file. Since this is only suitable for ARMv6.

Setup the Raspberry Pi manually

To set everything up we first have to burn an image to the SD card and connect to the Raspberry pi via an ssh connection. Follow this video to perform these steps.

After everything has worked out, connect to the raspberry pi and take the next steps

Installing Node

Node.js is an open source server environment with which we developed the backend and thus the logic for automated irrigation. The backend is the heart of the application and connects the sensor data, user interface, database and hardware (relay to the pump).

Execute the following commands on the raspi in oder to install Node:

wget https://nodejs.org/dist/v11.9.0/node-v11.9.0-linux-armv6l.tar.gz
tar -xvf node-v11.9.0-linux-armv6l.tar.gz
cd node-v11.9.0-linux-armv6l
sudo cp -R * /usr/local/

That the installation has worked can be checked with the two commands for version query of Node.js and NPM:

node -v
npm -v

Installing MongoDB

MongoDB is a universal, document-based, distributed noSQL database where we will store our settings and time series data.

Execute the following commands on the raspi in oder to install MongoDB:

sudo apt update
sudo apt upgrade

sudo apt install mongodb

sudo systemctl enable mongodb
sudo systemctl start mongodb

That the installation has worked can be checked with the command below:

mongo

Installing the Project

Download the project from this repository with the following command and go in the project directory:

git clone https://github.com/PatrickHallek/automated-irrigation-system
cd automated-irrigation-system

After downloading the project you have to create environment files for the frontend and backend with the following commands:

sudo nano .env

If you are in nano edit mode, copy the following text into it and type in your raspi ip. You can find the ip with the command ifconfig. It should be something like 192.168.178.44

SKIP_PREFLIGHT_CHECK=true
PORT=4200
REACT_APP_BACKEND_URL="http://<YOUR-RASPI-IP>:3000"

You can save your input in the Nano editor with ctr + x, then type in yes, finally exit with enter.

We need to do the same for the backend environment:

sudo nano backend/.env

Copy the following line into the editor in order to set the database connection:

MONGO_DB="mongodb://localhost/irrigation"

In order to install all dependencies in the frontend and backend, you need to run the following

npm install
cd backend
npm install

If everything is installed, you are able to start the frontend and backend separately

npm run build
npm start &
cd backend 
npm start &

Usage

The frontend can be accessed at the following URL if you are in your home wifi network: http://<RASPI_IP>:5000

In order to get the Raspberry Pi IP-address, execute ifconfig on the Raspi. If everything worked out fine, you should see the measurements in the Last Minute view in the statistics and the default preferences (which do not equal to 0).

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

License

MIT

automated-irrigation-system's People

Contributors

dependabot[bot] avatar patrickhallek avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

automated-irrigation-system's Issues

Video and Pictures of your finished project/demo

I really love this project and the detail and work that you put into this. It would be even more helpful if you had time to include pictures or a video walking people through your actual setup.

Has anyone modified for MCP3008?

I would like to modify my MCP3008 setup to take advantage of this awesome UI and reporting.
However, at a bit of a loss of where to start.

Connection to database failed! Exitcode 132 MongoDB

Hi, when i run "sudo docker-compose up" i get two errors.

"automated-irrigation-system_mongodb_1 exited with code 132"
"Connection to database failed!"
database

I try to run it on a Raspberry PI Zero W with Raspberry Pi OS Lite - Kernel version: 5.4
cpuinfo

Here is my Docker-Compose.
docker-compose

I build it with these steps:

curl -sSL https://get.docker.com | sh
sudo usermod -aG docker pi
sudo apt-get install -y libffi-dev libssl-dev
sudo apt-get install -y python3 python3-pip
sudo apt-get remove python-configparser
sudo pip3 install docker-compose
sudo apt install git
git clone https://github.com/PatrickHallek/automated-irrigation-system
cd automated-irrigation-system
sudo nano docker-compose.yml  #change ip adress
sudo nano Dockerfile #change from issue https://github.com/PatrickHallek/automated-irrigation-system/issues/14#issuecomment-656077450
cd Backend 
sudo nano Dockerfile #change from issue https://github.com/PatrickHallek/automated-irrigation-system/issues/14#issuecomment-656077450
sudo docker-compose up

Thanks

Bring in changes

I`m opening an issue to bring up a large change I would like to create a pull request for.

I`m adding some features to the system and would like to check if it would be ok to initiate a pull request.

A summary of the new features (Its been a couple years since I forked it, so I might have missed a couple small things)

  1. Auto-discovering of sensors using mDNS (no need to hardcode server IP to Arduino, and the server doesn`t need a static IP in the network).
  2. Setting sensor "Nicknames". I now use the sensor MAC as its name, to avoid having to hardcode the sensor name in Arduino
  3. Sensor wifi auto-setup with captive portal, avoiding hardcode wifi password to Arduino.
  4. Items 1, 2 and 3 allow sensors to be flashed with the code straight out of github. The user then plugs it in, connects to its wifi, chooses the ssid and sets the password, and the sensor is good to go.
  5. Battery mode allows sensors to send data and go into a deep sleep, allowing them to run on batteries.
  6. Rewrite calls to backend to avoid having to set the server ip in the Docker-compose file. We can now publish the server straight to docker with no requirement for the user to edit any files.
  7. Set sensor preferences through the front end. they get synced when the sensor uploads data (Battery mode on/off, sending interval)
  8. Allow pumps and sensors to be on the same or different ESP devices. We can use an ESP for all the pumps, or connect the pump directly to each sensor.
  9. Modifications to allow it to run in docker in a Windows computer (in WSL) or Linux. No need for a Rasberry Pi board.
  10. Compatibility with ESP32 and ESP8266 boards. We can now use the Lilygo pre-built irrigation sensor (https://www.aliexpress.com/item/1005005767792425.html)
  11. Hability to delete a sensor from the server, or delete its previous readings.
  12. Updated the docker image and dependencies for the backend to the latest packages.

To do / WIP:

  1. Gather more data from the sensor besides soil moisture (Fertility/salt levels, Light, temperature, etc) - will probably be done in a week or so.
  2. Freeze backend dependency versions.
  3. Update frontend node and dependencies (This has proven to be a larger challenge than I thought, so I`m running the same versions as your repository).

ERROR: Service 'backend' failed to build

When attempting to, sudo docker-compose up
I get:
`Building backend

Step 1/6 : FROM node:10
---> 5097189edcdc
Step 2/6 : COPY . /src
---> Using cache
---> 6553134477ae
Step 3/6 : WORKDIR /src
---> Using cache
---> 8f4aaa1bbc70
Step 4/6 : RUN npm install
---> Running in 34f24dadfe6c
ERROR: Service 'backend' failed to build: The command '/bin/sh -c npm install' returned a non-zero code: 139
`

I checked to verify I had npm installed and I do.

Any ideas?

Get ERROR Message with sudo docker-compose up

Hi,
I get an error message with the command "sudo docker-compose up". The message is the following:

ERROR: Top level object in './docker-compose.yml' needs to be an object not '<class 'str'>'.

Do you have an idea?
Thanks

Obtain the status of Relay

Hello,

I am trying to obtain the status of the relay and I have imported the library gpio in the file Preferences.js.

When I tried to build all completed fine but when I start npm in the console is the following error.

image

You could help me?

Thanks!

Static URL REACT_APP_BACKEND

when i start a docker-compose services, it gets its own DNS and set of IP will be configured to all containers. I found that the REACT_APP_BACKEND_URL variable is referring to a static IP address "192.168.178.50" while node container has got different IP.
can you explain why this particular IP address is chosen ?

Linechart.js uses the host rpi IP address to fetch data from the node container.
you may have to name the container using "container_name" in docker-compose.yml

also while get calls are made to the node container through the host raspberry-pi IP means if my pi has "192.168.178.51" the call will be made to "http://192.168.178.51:5000/undefined/measurements/day/..."
is it not simple to connect the two containers by giving some name?
as they will be in same network they can ping using these names as the DNS in docker will take care of that.

Error when "docker-compose up"

Hi.

First off, thanks for the Project. Exactly what i was looking for. I am an absolute Coding noob and have no idea what im doing, building this. But i like the challenge.

When im trying to docker-compose up it runs through nearly all steps, except this:

eight@waterpi:~/automated-irrigation-system $ sudo docker-compose up
[+] Building 3.8s (5/5) FINISHED
=> [automated-irrigation-system_backend internal] load .dockerignore 0.7s
=> => transferring context: 2B 0.2s
=> [automated-irrigation-system_frontend internal] load build definition 0.7s
=> => transferring dockerfile: 285B 0.3s
=> [automated-irrigation-system_frontend internal] load .dockerignore 1.1s
=> => transferring context: 63B 0.2s
=> [automated-irrigation-system_backend internal] load build definition 1.4s
=> => transferring dockerfile: 367B 0.2s
=> ERROR [automated-irrigation-system_backend internal] load metadata fo 2.0s

[automated-irrigation-system_backend internal] load metadata for docker.io/library/node:10:


failed to solve: rpc error: code = Unknown desc = node:10: no match for platform in manifest sha256:59531d2835edd5161c8f9512f9e095b1836f7a1fcb0ab73e005ec46047384911: not found

From the other posts i'm guessing i have to switch to node:10-alpine, but i have absolutly no idea how.

can not build

When I issue the build command I have this error, following by several others:

make: Entering directory '/src/node_modules/rpio/build'
CXX(target) Release/obj.target/rpio/src/rpio.o
CC(target) Release/obj.target/rpio/src/bcm2835.o
../src/bcm2835.c: In function 'bcm2835_gpio_pad':
../src/bcm2835.c:487:3: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
if (bcm2835_pads == MAP_FAILED)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.