Skip to content

Thaldos/Raspberry-water-the-garden

Repository files navigation

Raspberry-water-the-garden

Water the garden with a Raspberry pi


Prerequisites

You'll need:

Total: 244€


Hardware

Connect your devices like this:

Hardware


Raspberry Pi installation

Installation of Raspbian

Download the NOOBS OS : https://downloads.raspberrypi.org/NOOBS_latest

Extract the archive.

Copy past the files on your SD cart.

Insert the SD cart in your Raspberry Pi and start it.

Follow the installations steps.

Installation of PHP 7.3

nano /etc/apt/sources.list

Uncomment the line : deb-src http://raspbian.raspberrypi.org/raspbian/ stretch main contrib non-free rpi

apt-get update

apt-get install -t stretch php7.3 php7.3-curl php7.3-gd php7.3-fpm php7.3-cli php7.3-opcache php7.3-mbstring php7.3-xml php7.3-zip

Test by typing php -v in your terminal. You should have something like :

PHP 7.3.16 (cli) ( NTS )  
Copyright (c) 1997-2016 The PHP Group  
Zend Engine v3.0.0, Copyright (c) 1998-2016 Zend Technologies  
with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2016, by Zend Technologies

Installation of Curl

Type in Raspberry terminal :

sudo apt-get install curl

Installation of Composer

Type in Raspberry terminal :

cd /usr/src  
curl -sS https://getcomposer.org/installer | sudo php -- --install-dir=/usr/local/bin --filename=composer

Wi-Fi autoconnecting

Type in your terminal : sudo nano /etc/wpa_supplicant/wpa_supplicant.conf

And append some thing like :

network={  
    ssid="Livebox-12345"  
    psk="123456789AZERTY"  
}

Now when you will restart your Raspberry, it will automatically connects to this network.

Fixing of the Raspberry Pi IP

Type in Raspberry terminal : sudo nano /etc/network/interfaces and append this :

# interfaces(5) file used by ifup(8) and ifdown(8)
# Please note that this file is written to be used with dhcpcd
# For static IP, consult /etc/dhcpcd.conf and 'man dhcpcd.conf'
# Include files from /etc/network/interfaces.d:
source-directory /etc/network/interfaces.d
auto lo
iface lo inet loopback
iface eth0 inet manual
allow-hotplug wlan0
iface wlan0 inet manual
wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
allow-hotplug wlan1
iface wlan1 inet manual
wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf

Then type in Raspberry terminal sudo nano /etc/dhcpcd.conf and append this :

# Configuration ip fix wlan :
interface wlan0
static ip_address=192.168.1.201/24 #replace 201 by your wish
static routers=192.168.1.1
static domain_name_servers=192.168.1.1

More details on this step here (French link)

Check if your IP address is set well:

  • Reboot then check your local IP : hostname -I

  • Reboot again and re-check your local IP

It should be the same.

Installation of VNC server on the Raspberry

To easily access to your Raspberry every time, you should use VNC. You have to enable VNC server on your Raspberry and install VNC viewer on you desktop.

Menu > Preference > Raspberry configuration > Interfaces > Enable VNC

Raspberry VNC

Installation of VNC viewer on your desktop

https://www.realvnc.com/en/connect/download/viewer/

Launch VNC viewer and add a new connection to 192.168.1.201, with the user pi and password raspberry.

Important note: be sure te be on same Wi-Fi network on both sides.

Installation of SMTP

Follow this good tutorial:

https://hotfirenet.com/blog/1704-envoyer-mail-depuis-le-raspberry-pi/ (French link)

If, like me, you use gmail, this is a good configuration :

hostname=anexistingwebdomain.com
root=monLogin@gmail.com
mailhub=smtp.gmail.com:587
AuthUser=monLogin@gmail.com
AuthPass=monbeauPaSsWoRd
FromLineOverride=YES
UseSTARTTLS=YES

Project installation

Copying of the project files on your Raspberry pi

Copy all this project files to your Raspberry in /home/pi/Raspberry-water-the-garden/ by typing :

cd /home/pi/
git clone https://github.com/Thaldos/Raspberry-water-the-garden.git

Configuration

Copy .env.dist to .env and customize the constants in the .env file as your wish.

Download the vendors

Then type in Raspberry terminal :

cd /home/pi/Raspberry-water-the-garden/ 
composer install

Set the cron tab

On your Raspberry, in terminal, type crontab -e and add the lines:

0 15 * * * sudo php /home/pi/Raspberry-water-the-garden/storecurrenttemperature.php 2>&1
0 23 * * * sudo php /home/pi/Raspberry-water-the-garden/waterthegarden.php 2>&1

Enjoy!

Your Raspberry pi will check every day at 23pm if your garden need to be watered, and if it is needed, the Raspberry will water your garden during the appropriate delay.


Note

You can run manually the watering by typing in your Rapsberry Pi terminal :

sudo php /home/pi/Raspberry-water-the-garden/waterthegarden.php now 

The garden will be watered during the delay defined by DELAY_MIN in .env.


You can reset the relay by typing in your Rapsberry Pi terminal :

sudo php /home/pi/Raspberry-water-the-garden/waterthegarden.php reset 

Thanks

Special thanks to my lovely wife for the logic contained in the function getDelayForWatering($temperature).

About

Water the garden with a Raspberry pi

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages