Greenhouse

From openPicus Wiki
Jump to: navigation, search

Contents

Introduction

Our goal is to build a greenhouse with a flyport, a set of sensors and an active internet connection.

Requirements

  • 1 flyport
  • 1 groove system
  • 1 light sensor
  • 1 moisture sensor
  • 1 temperature sensor
  • 1 chainable led
  • 10 minutes to do the project

Optional:

  • A apache server with mysql and php for a personal use

Do it

Configuring the system

Let's connect the sensor to the groove system:

  • Analog input 1 with light sensor
  • Analog input 2 with temperature sensor
  • Analog input 3 with moisture sensor
  • Digital Output 1 with chainable led

Greenhouse flyport.jpg


First we have to download the sketch of the project from http://code.google.com/p/grove-nest/downloads/list Download the version that fits with your flyport version.

So let's open the openpicus Ide and open the sketch just downloaded.

Configuring preprocessor

Open taskFlyport.c and erase the content of file. Perform the wizard to configure the internet connection and to change the size of socket buffer.

First we have to insert the preprocessor guards and the include for external library.

#ifndef TASK_FLYPORT_H
#define TASK_FLYPORT_H
#include "taskFlyport.h"
#endif
#include "httplib.h"
#include "dev_sensor.h"
#include "grovelib.h"
#include "rgb.h"
#include "analog_temp.h"

The first 4 lines are preprocessor guards against an erroneous library import in the project. httplib.h and dev_sensor.h are the header files for the libraries we are gonna to use in this project, grovelib.h is the groove system library.

We have to download the external library. You can find that at: https://github.com/joxer/HTTPicus and https://github.com/joxer/FlyMySensors http://code.google.com/p/grove-nest/downloads/detail?name=analog_temp.zip http://code.google.com/p/grove-nest/downloads/detail?name=rgb.zip

Download the files and import them (headers and c source codes) in the project pressing external lib button in the toolbar, then press add and search for the files.

Configuring web site

Actually openpicus doesn't have a public website for this project, so i've created a dummy system with registration to see if sensors work at http://176.58.109.10:9001

you can alse configure a personal website on your machine, checkout at the bottom of the page

Go on the left sidebar and open httplib.c, put on the head of the file the following line:

#define PORT "9001"

Now open dev_sensor.c and put on the head of the file the following line:

#define HOST "176.58.109.10"

Writing the code

With this lines of code you connect the flyport to the wifi connection you have defined in the wizard.

void FlyportTask()
{	
vTaskDelay(100);
WFConnect(WF_DEFAULT);
while (WFStatus != CONNECTED);


Now we have to initialize the groove system with each sensor configured for the proper analog input and the rgb output. We have also to initialize 3 float values to store the values of our sensors.

vTaskDelay(200);
 
UARTWrite(1,"initialize groove system\n");
 
void *board = new (GroveNest);
 
void *rgb = new(Rgb, 1);
void *moisture_sensor = new (An_i);
void *tempAn = new(An_i);
void *light_sensor = new (An_i);
 
attachToBoard(board, light_sensor, AN2);
attachToBoard(board, tempAn, AN1);
attachToBoard(board, moisture_sensor, AN3);
attachToBoard(board, rgb, DIG4);
 
float manVal = 0;
float lightVal = 0;
float tempVal = 0;

Next we have to initialize the HTTP system with our values so let's write our connection information with the dev site

UARTWrite(1,"initialize HTTP system\n");
 
char* username = "dummy";
char* password = "dummy";
char* project = "greenhouse";
char* apikey = "123123123123123123123";

Let's begin to write the main section of our program. We have now to get the values from each sensor.

while(1)
{
   manVal = get(moisture_sensor);
   lightVal = get(light_sensor);
   tempVal = get(temperature_sensor);
   lightVal = (float)(1023-lightVal)*10/((float)lightVal);

Now we want to introduce an output feedback to see if the terrain is too much humid or too much dry. So we have to introduce a conditional to test moisture level.

if(manVal < 200){
	configure(rgb, 1, 255, 0, 0);
	set(rgb, ON);
	//DRY
}
else if(manVal > 600){
	configure(rgb, 1, 0, 255, 0);
	set(rgb, ON);
	// HUMID
}
else{
	set(rgb,OFF);
}

Now we have to write to internet site our request

UARTWrite(1,"write to site\n");
 
UARTWrite(1,"write hum\n");
send_to_site(username,password,project,apikey,"humidity",manVal);
UARTWrite(1,"write bright\n");
send_to_site(username,password,project,apikey,"brightness",lightVal);
UARTWrite(1,"write temp\n");
send_to_site(username,password,project,apikey,"temperature",tempVal);
vTaskDelay(2000);
}
}

Flash it

Now compile it and flash the rom with the program. Open the system monitor in the right sidebar and see the output.

Zip file of the project

Download the zip file of the project to use directly it:

Serra.zip

Final Result

This is an image of 'Eva', my plant with the greenhouse system:

Eva plant.jpg

The video shows our final result of the project:


Proposal of automation

You could connect a relay to the flyport and control a valve for an irrigation system when the terrain is too much dry or to turn on a lamp when there's a cloudy weather.

Configure personal web server

You can install an apache webserver with php and a database storage server. Get the code of the web application at: https://github.com/joxer/flymysensor_site

You have to configure the database server. You have to create a database called picus and add a user with password with all privileges on this database.

See here how to create a new database and grant privileges to user: http://dev.mysql.com/doc/refman/5.0/en/create-database.html http://dev.mysql.com/doc/refman/5.1/en/adding-users.html

Now configure the web server to point the document root to picus-php. An example configuration is:

<VirtualHost *:9000>
	ServerAdmin webmaster@localhost
	DocumentRoot /home/myhome/code/picus-php
 
	<Directory />
		Options FollowSymLinks
		AllowOverride None
	</Directory>
</VirtualHost>

Open the site on localhost at the port you have configured ( in this case the 9000).

Go to the address localhost/index.php/install/default and configure your parameters for the database. The you can register on the site and create a project per user.

Personal tools
Namespaces

Variants
Actions
START HERE
DEVELOPMENT
HARDWARE INFO
RESOURCES
PHASED OUT
Toolbox