Satyavrat Wagle
Published © GPL3+

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,496
Future Sight Greenhouse System - Predictive Plants on Cloud!

Things used in this project

Story

Read more

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
this = csvread('test_data.csv')
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
db = MySQLdb.connect('localhost','root',*MYSQL_PASSWORD_HERE*,*DATABASE_NAME_HERE*)
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)
    conn,addr = s.accept()
    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)

humval = int(hum.read())

time.sleep(10)

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

    humval = int(hum.read())
    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)
    conn,addr = s.accept()
    data = conn.recv(BUFFER_SIZE)
    val = str(data)
    print (val)
	val = int(data)
	humval = int(hum.read())
	if(val > humval):
		relay.write(1)
		delay(5000)
		relay.write(0)
	if (val < humval):
		relay.write(0)

Credits

Satyavrat Wagle

Satyavrat Wagle

1 project • 42 followers
I have an active interest in IoT, Wireless Sensor Networks, Single Board Computing Implementations, Embedded Systems, and Robotics.

Comments

Add projectSign up / Login