Building a Raspberry Pi greenhouse

MySQL Database

The data collected by the sensors is saved in a MySQL database to be evaluated later and displayed in a graph. The best way to install the database is to use the datalogger.sql SQL file downloaded from the FTP site:

$ mysql -u root -p < datalogger.sql

Otherwise, you will spend a lot of time typing.

The SQL script automatically sets up the username datalogger together with a database and password of the same name. The script creates the tables datalogger and history. You should make sure that mysql does not use the root password of the operating system but rather the root database user password that was chosen during the installation of the MySQL server. Using scripts, you can then log five values into the tables: date, sensor, temperature, humidity, and pwm.

The datalogger and history tables differ from one another by the column pwm, which appears only in the datalogger table. This column holds the values produced by the fan-regulating algorithm. Graphs generated from the history table show the course of changes in temperature and humidity, so you don't need the PWM data.

Putting PHP on Apache

Apache serves as the webserver for our greenhouse. If you prefer a more lightweight server, then you can use Lighttpd or Cherokee. All that is necessary is that the webserver be able to execute PHP scripts. If you have followed the guidelines in this article, then Apache is installed along with MySQL.

To determine whether the Apache and PHP installation was successful, you should run a small test script:

$ echo '<?php phpinfo();?>' | sudo tee -a /var/www/phpinfo.php

Afterward, you can monitor the installation via http://<RaspPI-IP>/phpinfo.php. Either the ipconfig or, in a pinch, the information that comes up on the screen when Raspbian boots, will provide the IP address.

Buy this article as PDF

Express-Checkout as PDF

Pages: 6

Price $2.95
(incl. VAT)

Buy Raspberry Pi Geek

Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content