Skip to content

3. Software Installation

The Groundhog Whisperer edited this page Jul 28, 2019 · 72 revisions

Setting up the greenhouse Raspberry Pi software

Starting with a fresh Raspbian installation.

Establish a SSH command line interface connection to the greenhouse Raspberry Pi.

$ ssh pi@Your-GreenhousePis-IP-Address

Prerequisites

Install the Apache web server software

$ sudo apt-get install apache2

Configure Apache to serve index.php by default using the nano editor to modify the /etc/apache2/apache2.conf configuration file.

Apache Configuration Screenshot 0

Locate <Directory /var/www/> and below this line add a new blank line

Apache Configuration Screenshot 1

Apache Configuration Screenshot 2

Populate the empty line with the following three lines:

DirectoryIndex index.php

Options +ExecCGI

AddHandler cgi-script .py

Apache Configuration Screenshot 3

Press Ctrl-O then the Enter key to save the apache2.conf file

Apache Configuration Screenshot 4

Press Ctrl-X to exit the nano editor

Apache Configuration Screenshot 5

Note: The last option added during the modification of /etc/apache2/apache5.conf (AddHandler cgi-script .py) enables Apache support for .py Python files. The first line of any Python script executed from /var/www/html/ should contain a header directive telling Apache which interpreter to use. Below is an example header directive:

#!/usr/bin/env python

Change directory to the Downloads folder

$ cd Downloads/

Download Ay-yah's Greenhouse repository using the git command

$ git clone https://github.com/thegroundhogwhisperer/Ay-yahs-Greenhouse/

Change directory to the Ay-yahs-Greenhouse folder

$ cd Ay-yahs-Greenhouse

Move the Greenhouse folder and its contents to your home folder

$ mv -T Greenhouse /home/pi/Greenhouse/

Copy the greenhouse web interface and support files to the /var/www/html/ folder

$ sudo cp -r ./var/www/html/* /var/www/html/

Move the optional Greenhousealarmemail folder and its contents to your home folder

$ mv -T Greenhousealarmemail/ /home/pi/Greenhouse/Greenhousealarmemail/

Move the optional Greenhousereportemail folder and its contents to your home folder

$ mv -T Greenhousereportemail/ /home/pi/Greenhouse/Greenhousereportemail/

Install PHP using the apt package manager

$ sudo apt-get install php

Install PHP for SQLite3 using the apt package manager

$ sudo apt-get install php-sqlite3

Restart the Apache web server service

$ sudo /etc/init.d/apache2 restart

Change ownership of all files in /var/www/html/ recursively to the user named: www-data

$ sudo chown -R www-data:www-data /var/www/html

Configure write permissions to all files located in /var/www/html/

$ sudo chmod 777 /var/www/html/*

Install the matplotlib Python module

$ sudo apt-get install python-matplotlib

$ sudo apt-get install python3-matplotlib

Install the Python statistics module

$ sudo apt-get install python-statistics

Install the Adafruit Python DHT Library

$ sudo pip install Adafruit_DHT

$ sudo pip3 install Adafruit_DHT

Install the Pimoroni automation HAT support files

$ curl https://get.pimoroni.com/automationhat | bash

Install the pigpio daemon

$ sudo apt-get install pigpio

Test pigpio daemon installed

$ pigpiod -v

Enable remote gpio access using the raspi-config tool:

Raspi-config Configuration Screenshot 0

Select menu item 5 Inferfacting Options

Raspi-config Configuration Screenshot 1

Enable P8 Remote GPIO by selecting P8 Remote GPIO Enable/Disable remote access to GPIO pins

Raspi-config Configuration Screenshot 2

Select Ok on the Remote access to the GPIO server is enabled confirmation screen

Raspi-config Configuration Screenshot 3

Select P1 Camera

Raspi-config Configuration Screenshot 4

Select Yes to enable the camera interface

Raspi-config Configuration Screenshot 5

Select Ok on the camera interface is enabled confirmation screen

Raspi-config Configuration Screenshot 6

Select Yes to reboot the Pi

Raspi-config Configuration Screenshot 7

Reconnect to the Pi after the reboot is complete.

$ ssh pi@YourPisIPAddress

Enable socket access to the pigpio daemon at boot. The pigpio daemon provides access to control the GPIO interface. The greenhouse manual operation functions utilize the pigs binary to control the GPIO ports. Pigs provides command line socket access to the pigpio daemon.

$ sudo systemctl enable pigpiod

Configure file execution permissions on the Python scripts

$ sudo chmod +X /home/pi/Greenhouse/greenhouse.py

$ sudo chmod +X /home/pi/Greenhouse/powerout.py

$ sudo chmod +X /home/pi/Greenhouse/camera.py

$ sudo chmod +X /home/pi/Greenhouse/Greenhousealarmemail/greenhousealarmemail.py

$ sudo chmod +X /home/pi/Greenhouse/Greenhousereportemail/greenhousereportemail.py

Configure file execution permissions on the PHP scripts in /var/www/html/

$ sudo chmod +X /var/www/html/*.php

Configure file execution permissions on the Python scripts in /var/www/html/

$ sudo chmod +X /var/www/html/*.py

Create a user account named greenhousecron with no password used to execute timed water scheduling via this user accounts crontab configuration

$ sudo adduser greenhousecron

Add www-data to the gpio users group

$ sudo adduser www-data gpio

Add user www-data to the i2c users group

$ sudo adduser www-data i2c

Grant group read and write access to /dev/mem allow for Python module access as www-data

$ sudo chmod g+rw /dev/mem

Configure crontabs

The greenhouse.py script performs environmental monitoring and the conditional evaluation process. Configure cron to execute greenhouse.py, the primary automation script, every two minutes.

The powerout.py script writes file stored values, relays, and outputs to their default due to power outage. Configure cron to execute powerout.py, the power outage reset defaults script, at boot.

The camera.py script writes one high and ten low resolution .jpg images to /var/www/html. These images are referenced in the index.php and the desktop gui interface. The low resolution images are processed by ImageMagic into a single animated .gif image file. This script also reads the luminosity sensor adjusting the camera shutter speed relative the ambient light.

The greenhousealarmemail.py produces conditional notifications via email.

The greenhousereportemail.py produces simple report notifications via email.

The last crontab entry configures the system to import the current crontab configuration for scheduled system automation as the greenhousecron user account.

Configure the greenhouse Pi's Python script crontabs.

$ sudo crontab -e

Crontab Configuration Screenshot 0

Add the following lines

# Reset default values, relays, and output states after a power outage
@reboot python /home/pi/Greenhouse/powerout.py

# Capture a camera image every five minutes
*/5 * * * * /usr/bin/python /home/pi/Greenhouse/camera.py

# Execute the primary greenhouse automation script every two minutes
*/2 * * * * /usr/bin/python /home/pi/Greenhouse/greenhouse.py

# Execute the email alarm notification script every thirty minutes
*/30 * * * * /usr/bin/python /home/pi/Greenhouse/Greenhousealarmemail/greenhousealarmemail.py

# Execute the email report notification script every 12 hours
0 12 * * * /usr/bin/python /home/pi/Greenhouse/Greenhousereportemail/greenhousereportemail.py

# Crontab to import the current crontab configuration for scheduled system automation as the greenhousecron user
*/1 * * * * crontab -u greenhousecron /var/www/html/schtempcron.txt

Crontab Configuration Screenshot 1

Press Ctrl-O then the Enter key to save the crontabs

Crontab Configuration Screenshot 2

Press Ctrl-X to exit the nano editor

Crontab Configuration Screenshot 3

Optional configuration of the email/SMS alarm notification script greenhousealarmemail.py

The greenhousealarmemail.py script requires you to configure the minimum and maximum alarm values located in the script header. The greenhousealarmemail.py script also requires a valid SMTP server address and valid account credentials before an alarm notification may be sent.

Edit the greenhousealarmemail.py using nano and configure the following values.

nano /home/pi/Greenhouse/Greenhousealarmemail/greenhousealarmemail.py

# Minimum temperature to trigger an email/sms alarm notification
MINIMUM_TEMPERATURE_ALARM = 32.05

# Maximum temperature to trigger an email/sms alarm notification
MAXIMUM_TEMPERATURE_ALARM = 101.99

# Maximum soil moisture to trigger an email/sms alarm notification
MAXIMUM_SOIL_MOISTURE_ALARM = 3.1

# Email message from address value
FROM_EMAIL_ADDRESS_VALUE = '[email protected]'

# Email message recipients destination address values
RECIPIENTS_EMAIL_ADDRESS_VALUES = ['[email protected]', '[email protected]']

# SMTP email servers host name
EMAIL_SMTP_SERVER_HOST_NAME = 'smtp.email.example'

# SMTP server user name
SMTP_SERVER_LOGIN_NAME = '[email protected]'

# SMTP server password
SMTP_SERVER_LOGIN_PASSWORD = 'shhhhaplaintextpasswordvalue'

Optional configuration of the email report notification script greenhousereportemail.py

The greenhousereportemail.py script requires configuration of a valid SMTP server address and valid account credentials before an alarm notification may be sent.

Edit the greenhousealarmemail.py using nano and configure the following values.

$ nano /home/pi/Greenhouse/Greenhousereportemail/greenhousereportemail.py

# Email message from address value
FROM_EMAIL_ADDRESS_VALUE = '[email protected]'

# Email message recipients destination address values
RECIPIENTS_EMAIL_ADDRESS_VALUES = ['[email protected]', '[email protected]']

# SMTP email servers host name
EMAIL_SMTP_SERVER_HOST_NAME = 'smtp.email.example'

# SMTP server user name
SMTP_SERVER_LOGIN_NAME = '[email protected]'

# SMTP server password
SMTP_SERVER_LOGIN_PASSWORD = 'shhhhaplaintextpasswordvalue'

Reboot your GreenhousePi

$ sudo reboot

Test your GreenhousePi web interface

Visit http://Your-GreenhousePis-IP-Address using your web browser. (e.g. http://192.168.1.118)

Web interface screenshots

Greenhouse Web Interface Screenshot One

Test your GreenhousePi system configuration values

Scroll down to the bottom of the greenhouse web interface page and locate the automation system configuration values. From here you may update and configure your GreenhousePi. Be sure to click the "flotation device icon" below the system configuration values form to save your settings.

Greenhouse Web Interface Configuration Screenshot

Progressing to a hardware deployment project phase

As soon as you have your automation HAT and DHT sensor installed you can configure the greenhouse.py script to begin reading values. To disable fake sensor readings edit the greenhouse.py file and set the following value to False.

ENABLE_FAKE_SENSOR_VALUES = True

Your own version of Ay-Yahs GreenhousePi should now be up and running. Now on to the hardware and deployment project phases. Happy GreenhousePi gardening!

Want to skip all of this software installation and boot your version of Ay-yah's greenhouse automation system now?

Proceed to the next section 3.1 Raspbian Image Download

Or proceed to section: Section 3.2 Web Interface

Clone this wiki locally