The DIY Smart Garden System

I’m going to take you on a tour of Do It Yourself Smart Gardening

My name is Cory, I’m a Technical Craftsman specializing in creative problem solving within electronics and software engineering.  Professionally, I’ve worked as an electronics engineer, a plastics fabricator, software engineer, an industrial laser technician, and, of course, a coffee barista.  I’ve spent the last several years working on a Smart Garden System project I named, hydroMazing.  I’m sharing my work with you because I would like to empower everyone who is interested in a “Smart” approach to gardening.

What we’ve covered so far:cropped-hydromazing_smart_garden_system

 

Are you interested in following me on this journey?

Now that we have an understanding of what it takes to provide an optimum indoor growing environment we can start analyzing the cost-benefit of further optimizing and automating the system.  Please share with friends and follow to receive a notification when I publish the next section.

Section 1:  Let’s start by using an Arduino Nano on an Expansion Board to monitor the indoor gardening environment.  We will measure light intensity, ambient temperature, relative humidity, nutrient/water temperature.

Section 2:  Continue working with the Arduino Nano on an Expansion Board to control appliances in the indoor gardening environment.  We can continue working directly wired or we can start working with wireless communications.  Wired or Wireless?

Section 3:  Add an Arduino Uno using an LCD with Buttons Shield to provide a display and alerts.

Section 4:  Add the Raspberry Pi for remote access, notifications, data collection, and analytics.

Section 5:  More sensors:  moisture probe, pH, E.C., carbon dioxide level, flow-rate, liquid, float (liquid level switch).Peristaltic Pump

Advanced:  Using Dosing/Peristaltic Pumps for Nutrient Solution Management.

Using a Raspberry Pi and USB Camera  Use Raspberry Pi to monitor or collect snapshots of the garden using a USB webcam.

Do It Yourself:  hydroMazing Smart Garden System Kit

Kit includes wired and ready sensors and components for making the Controller Module (Arduino Nano) and Web Services Module (Raspberry Pi)?  Let me know, Contact Cory

Please share with friends and follow to receive a notification when I publish the next section.

The Decider

 

The Coreconduit: Garden Controller System was the first version of the hydroMazing project .  The author of the Instructable drones on and on about healthy plants requiring attention and boredom until,

“…I’ve programmed into the Arduino a function I called, “TheDecider” that makes decisions based on maintaining optimum environmental conditions for growing plants. I added 2.4Ghz Wireless Radio Transceiver modules and a modular receiver system so that data is transmitted to within 1000 feet.”

TheDecider” was originally hardcoded with specific values that were fixed in place until I changed them in the Arduino sketch, recompiled, and uploaded.  There are two types of decisions that TheDecider executes, timed-based, and sensor-based rules.  The time-based rules simply compare the current time to the last time the appliance was turned-on or off.  The sensor-based rules use a minimum value threshold and a maximum value threshold that are compared to the current sensor reading and then execute the corresponding action for the appliance.  For example, if the temperature is below 55° then turn-off the ventilation fans; if the temperature is above 80° then turn-on the ventilation fans.  Each appliance has corresponding rules for sensor reading thresholds, time-based automation, and a combination of both, priority depending on the order of the rules.

Today’s hydroMazing uses the Raspberry Pi to provide an interface to the rules and the notifications.  The Pi communicates with the Arduino Nano microcontroller wirelessly sending updates and receiving data. TheDecider is a rules engine that executes the checks sent to it from the Pi.  The settings are stored in the EEPROM of the Arduino Nano allowing it to operate without further communications with the Pi.  hydroMazing doesn’t require an Internet connection to operate with the exception of receiving emails or text-alerts.  The Raspberry Pi can be configured to operate only within your WiFi network and be allowed to send emails and text-alerts.  Or, you can configure your router to allow access from outside and even assign a domain name, such as http://coreconduit.ddns.net.  See my Instructables for steps to a secure Pi.

 

Keep Fingers Out of your Pi

In my previous article , I explain how to setup the Raspberry Pi to be a web server.   I also demonstrate searching log files for “footprints” from the IP requests that have been made to your web server.  Now, I would like to discuss protecting your web server from becoming a victim to a potentially malicious attack.

Keep your Pi updated!

sudo rpi-update

The command will automatically update the Raspberry Pi’s firmware and then ask for a reboot.  If your Pi is already up-to-date, then you can continue with:

sudo apt-get update
sudo apt-get upgrade

Now, you’ve got the latest and greatest firmware and software!!

2016-11-04-092217_1920x1080_scrot

Pi Passwords

Ideally, we would disable the default pi account,  at the very least, set the default password for your pi account.  Another major in-security is that most users have SSH (Secure Socket sHell) and VNC (Virtual Networking Computer) enabled so that they can remote into their machines.  I don’t recommend allowing access outside of your network when running a publicly exposed web server.

Apache Web Server

If you are serving web content world-wide then you’ll eventually want to adopt some sort of blacklist, or exclusion list, where you can keep specific IP addresses from accessing your server.  However, if you want to tighten-down your security and only allow a select few access then you’ll need to make some changes.

cd /etc/apache2
sudo cp apache2.conf apache2.conf.bak
sudo vi apache2.conf OR sudo nano apache2.conf

Travel down the file until you reach this section that allows everyone access to your web server from the outside:

<Directory /var/www/>
 Options Indexes FollowSymLinks
 AllowOverride None
 Require all granted
</Directory>

The AllowOverride directive is set to None meaning we will not be using an .htaccess file to override these settings.  The next directive, Require is set to all granted, meaning allow anyone access.

UPDATE:  I have found a significant number of bot requests in my log files, snooping for those of Us using phpmyadmin, be sure to limit access:

<Directory /usr/share/phpmyadmin/>
Order Deny, Allow
Deny from All
# localhost
Allow from 127.0.0.1
# Local-Area Network
Allow from 192.168.x.x
</Directory>

Next, we can add a directory that we want to protect:

<Directory /var/www/html/hydroMazing/>
 Options Indexes FollowSymLinks
 AllowOverride All
</Directory>

The AllowOverride directive is set to All meaning we will be using an .htaccess file to override these settings.  We will provide the Require directive in our .htaccess file inside the directory we specified, in this case, “/var/www/html/hydroMazing/”   One last setting of importance before we save:

# AccessFileName: The name of the file to look for in each directory
# for additional configuration directives. See also the AllowOverride
# directive.
#
AccessFileName .htaccess

You could change the name of the .htaccess file here to something harder to guess.  Keep the dot at the beginning because it means hidden file.   Use your imagination 😉  Now you can use an .htaccess file as your whitelist, or inclusion list:

To create a .htaccess ( or whatever you’ve named it ) file:

cd /var/www/html/mydirectory/

sudo vi .htaccess OR sudo nano .htaccess
# Allow access to localhost 
Require ip 127.0.0.1

# Allow access to my cell phone
Require ip 98.97.34.23

Second entry is an example, change it to your IP address, or the IP address that your web server logged.  See my previous article for instructions on checking your log files.  Save and close the file.  You can add additional access as desired.

 

Build a Wallimg_20160814_195916221

Install the open-source firewall builder

Pop open a terminal from your Raspberry Pi’s desktop and type the following:

sudo apt-get install fwbuilder

After the installation has completed, you will have a new option under the Menu/Internet option from your desktop for the firewall builder GUI.

Add a new firewall and name it the same as your server.

 2016-11-04-090801_1920x1080_scrot

Select the “web server” template to load default rules.

Note that the default rules restrict your server from accessing the outside Internet.  In order to allow access, you’ll need to add a rule.  The easiest way to add a rule is to copy an existing rule that is similar to your needs.

2016-11-04-090900_1920x1080_scrot

Compile and Install

We can build our firewall through this interface, but we won’t be able to install it because we won’t have sufficient permissions to write to the file system.  Enter the following at a terminal window’s command line assuming you named your server the same as your DDNS name:

sudo mkdir /etc/fw
sudo touch /etc/fw/servername.ddns.net.fw
sudo chmod 777 /etc/fw/servername.ddns.net.fw

Now, you should be able to use the firewall builder program to compile and install the firewall.   You can either restart the apache web server or simply reboot.

Anything incorrect, missing, or not working?  Please let me know.