-
Notifications
You must be signed in to change notification settings - Fork 8
3. Software Installation
Starting with a fresh Raspbian installation.
Establish a SSH command line interface connection to the greenhouse Raspberry Pi.
$ ssh pi@Your-GreenhousePis-IP-Address
$ 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.
DirectoryIndex index.php
Options +ExecCGI
AddHandler cgi-script .py
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
$ cd Downloads/
$ git clone https://github.com/thegroundhogwhisperer/Ay-yahs-Greenhouse/
$ cd Ay-yahs-Greenhouse
$ mv -T Greenhouse /home/pi/Greenhouse/
$ sudo cp -r ./var/www/html/* /var/www/html/
$ mv -T Greenhousealarmemail/ /home/pi/Greenhouse/Greenhousealarmemail/
$ mv -T Greenhousereportemail/ /home/pi/Greenhouse/Greenhousereportemail/
$ sudo apt-get install php
$ sudo apt-get install php-sqlite3
$ sudo /etc/init.d/apache2 restart
$ sudo chown -R www-data:www-data /var/www/html
$ sudo chmod 777 /var/www/html/*
$ sudo apt-get install python-matplotlib
$ sudo apt-get install python3-matplotlib
$ sudo apt-get install python-statistics
$ sudo pip install Adafruit_DHT
$ sudo pip3 install Adafruit_DHT
$ curl https://get.pimoroni.com/automationhat | bash
$ sudo apt-get install pigpio
$ pigpiod -v
$ 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
$ 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
$ sudo chmod +X /var/www/html/*.php
$ 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
$ sudo adduser www-data gpio
$ sudo adduser www-data i2c
$ sudo chmod g+rw /dev/mem
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.
$ sudo crontab -e
# 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
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.
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'
The greenhousereportemail.py script requires configuration of a valid SMTP server address and valid account credentials before an alarm notification may be sent.
$ 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'
$ sudo reboot
Visit http://Your-GreenhousePis-IP-Address using your web browser. (e.g. http://192.168.1.118)
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.
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
Understand well as I may, my comprehension can only be an infinitesimal fraction of all I want to understand. - Ada Lovelace
Home 🌸
4. Remote Monitoring Alarm Email
5. Remote Monitoring Report Email
6. Remote Monitoring Radio Frequency Broadcast
7. Remote Monitoring Radio Frequency Reception
8. Remote Monitoring POTS (Plain Old Telephone Service) Landline
9. Ubuntu Desktop Alarm Notifications