# Future Sight Greenhouse System - Predictive Plants on Cloud!

Let your Cloud Connected Plants take a peek into the future and see if they will need water with Future Sight using Machine Learning!

IntermediateFull instructions provided6 hours1,993

## Things used in this project

### Hardware components

 Intel Edison
×1
 Seeed Grove starter kit plus for Intel Edison
×1
 Raspberry Pi 3 Model B OPTIONAL
×1

### Software apps and online services

 ThingSpeak API

## Schematics

### Edison

Please note that Fritzing does not have modules for the Grove Relay board or the Moisture Sensor. I have used equivalent modules. hence the connections remain the same.

## Code

### Sample Regression Algorithm

MATLAB
This is how a regression algorithm works in MatLab, you can use this code for reading and plotting CSV values from ThingSpeak. You can also use the same functions after importing numpy and matplotlib in Python.
```clear all
close all
hold on
len = size(this)
x = 0:1:len-1
y = this
line_eq = polyfit(x,y',1)
fit_line = line_eq(1)*x+line_eq(2)
plot(x,fit_line)
plot(x,y)
pred_value = line_eq(1)*(len(1)+1)+line_eq(2)
```

### listen.py

Python
This is the Python file to be run in the background of the Raspberry Pi to listen for incoming TCP messages
```import socket
import MySQLdb
cursor = db.cursor()

TCP_IP = *RASPBERRY PI IP ADDRESS HERE*
TCP_PORT = 5005
BUFFER_SIZE = 25
s = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
s.bind((TCP_IP,TCP_PORT))

while 1:
s.listen(2)
data = conn.recv(BUFFER_SIZE)
val = str(data)
print (val)
com = 'INSERT INTO Moisture (Value) VALUES ('+val+')'
cursor.execute(com)
db.commit()
```

### edison_send.py

Python
This file is to be run on the Intel Edison to regularly read and send moisture values to the Raspberry Pi
```import socket
import mraa
import sys
import time

TCP_IP = *RASPBERRY PI IP ADDRESS HERE*
TCP_PORT = 5005
BUFFER_SIZE = 1024
MESSAGE = "Edison Here"
hum = mraa.Aio(0)

time.sleep(10)

while(1):
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((TCP_IP, TCP_PORT))

humval = str(humval)
print "Moisture : "+humval
sendis = humval
bytes = str.encode(sendis)
s.send(bytes)
time.sleep(2)

print ("Done!")
print (" ")
time.sleep(60)
```

### listen_ed.py

Python
This file is to be run in the background for Intel Edison to listen for predicted values over TCP and switch on and off the relay as needed.
```import socket
import mraa
import time

TCP_IP = *INTEL EDISON IP ADDRESS HERE*
TCP_PORT = 5005
BUFFER_SIZE = 25
s = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
s.bind((TCP_IP,TCP_PORT))

hum = mraa.Aio(0)
relay = mraa.Gpio(13)
relay.dir(mraa.DIR_OUT)

while 1:
s.listen(2)
data = conn.recv(BUFFER_SIZE)
val = str(data)
print (val)
val = int(data)
if(val > humval):
relay.write(1)
delay(5000)
relay.write(0)
if (val < humval):
relay.write(0)
```

## Credits

### Satyavrat Wagle

6 projects • 51 followers
I have an active interest in IoT, Wireless Sensor Networks, Single Board Computing Implementations, Embedded Systems, and Robotics.