Home » Ham Radio » Homebrew Equipment and Projects » Raspberry Pi Greenhouse Controller And Data Logger (This thread is for sharing code related to the Raspberry Pi Greenhouse controller project from The Farmacy Seeds Network youtube channel.)
|
Re: Raspberry Pi Greenhouse Controller And Data Logger [message #3282 is a reply to message #3280] |
Tue, 28 January 2020 00:36   |
 |
kd2iin
Messages: 27 Registered: December 2016 Location: Tivoli, NY
|
Junior Member |
|
|
Starting from Video 1: Part 1 Setup Your Own Raspberry Pi For Monitoring Temperatures And More
https://www.youtube.com/watch?v=BUOTY3fs_jI&list=PL837tk -T71LhGmSG2YEuA2U-LLvAQMhXs&index=15
Monitor your greenhouse, cabin, garage, shed, barn, carport, or any other environmentally controlled area with a Raspberry Pi! This video is the first in a series of videos describing how to set up a Raspberry Pi to monitor temperatures via a database as well as provide controls for heating, venting, hydronic water circulation, hydroponics, watering and many other automated applihoneyions. This setup does NOT use any websites for retrieving remote data, but rather serves it out directly to the internet through the use of Apache Web Server. Through the use of MYSQL and databases we are able to log historical data as well as manipulate any controls required or desired. We will go over hardware, connections, software, databases, SQL query statements, integration to automated controls, and so much more!
We start with a new Pi, raspian jesse, and an sd card and build the whole system out from scratch.
Help me help you on patreon: https://www.patreon.com/TFSN
Download links:
Windisk Imager 32: https://sourceforge.net/projects/win3...
MYSQL Query Browser: https://downloads.mysql.com/archives/...
SQL Dashboards: http://www.timestored.com/b/sql-dashb...
Putty: https://www.putty.org/
OS Image: Raspian Jesse Image from 01 10 2017: http://downloads.raspberrypi.org/rasp... (This is the image we will be using, not the stretch version mentioned in the video)
Bitvise: https://www.bitvise.com/
The candle that burns twice as bright burns half as long
[Updated on: Tue, 28 January 2020 00:40] Report message to a moderator
|
|
|
|
Re: Raspberry Pi Greenhouse Controller And Data Logger [message #3284 is a reply to message #3283] |
Tue, 28 January 2020 00:41   |
 |
kd2iin
Messages: 27 Registered: December 2016 Location: Tivoli, NY
|
Junior Member |
|
|
Part 3 Setup Your Own Raspberry Pi raspi-config and apt-get update upgrade Enable SSH
https://www.youtube.com/watch?v=-xfNXrUA71s&list=PL837tk -T71LhGmSG2YEuA2U-LLvAQMhXs&index=13
In this section we configure the basics:
sudo su
raspi-config
Enable expanded files system, Enable SSH, Enable SPI, Enable 1-wire, set timezone, set default password, etc
sudo reboot now
apt-get update
apt-get upgrade
cd /sys/bus/w1
ls
OS Image: Raspian Jesse Image from 01 10 2017: http://downloads.raspberrypi.org/rasp... (This is the image we will be using, not the stretch version mentioned in the video)
Windisk Imager 32: https://sourceforge.net/projects/win3...
Putty: https://www.putty.org/
Initial Setup From Monitor / keyboard / mouse on Pi: https://raspberrypi.stackexchange.com... (enable ssh, set time zone, expand filesystem etc)
Angry IP Scanning Tool: http://angryip.org/download/#windows
The candle that burns twice as bright burns half as long
|
|
|
|
|
Re: Raspberry Pi Greenhouse Controller And Data Logger [message #3287 is a reply to message #3286] |
Tue, 28 January 2020 00:46   |
 |
kd2iin
Messages: 27 Registered: December 2016 Location: Tivoli, NY
|
Junior Member |
|
|
Part 6 Setup Your Own Raspberry Pi Install Apache MySQL PHPMyAdmin LAMP Server
https://www.youtube.com/watch?v=C7ayFZqDzEo&list=PL837tk -T71LhGmSG2YEuA2U-LLvAQMhXs&index=10
In this video we go over how to install a LAMP Server. LAMP stands for Linux, Apache, MySQL, PHPMyAdmin. This is a critical step that installs the webserver, database and many other integral parts towards the end goal: remote monitoring and control of a greenhouse or other climate related project.
Load webpage to test(use the ip address that you used for the raspberry pi, putty, etc):
http://192.168.254.30/phpmyadmin
Link to tutorial:
https://pimylifeup.com/raspberry-pi-mysql-phpmyadmin/
install commands:
sudo apt install apache2
sudo apt-get install mysql-server
sudo mysql_secure_installation
sudo mysql -u root -p
sudo apt-get install python-mysqldb
sudo mysql -u root -p
GRANT ALL PRIVILEGES ON mydb.* TO 'test'@'localhost' IDENTIFIED BY 'test';
sudo apt-get install phpmyadmin
sudo nano /etc/apache2/apache2.conf
add line at bottom of file (use right click in putty):
Include /etc/phpmyadmin/apache.conf
sudo /etc/init.d/apache2 restart
Load webpage to test(use the ip address that you used for the raspberry pi, putty, etc):
http://192.168.254.30/phpmyadmin
The candle that burns twice as bright burns half as long
|
|
|
|
Re: Raspberry Pi Greenhouse Controller And Data Logger [message #3289 is a reply to message #3288] |
Tue, 28 January 2020 00:48   |
 |
kd2iin
Messages: 27 Registered: December 2016 Location: Tivoli, NY
|
Junior Member |
|
|
Part 8 Setup Your Own Raspberry Pi MySQL Query Browser Create And Edit TABLES
https://www.youtube.com/watch?v=dj6C3gKmhaw&list=PL837tk -T71LhGmSG2YEuA2U-LLvAQMhXs&index=8
This section will be about creating a table in the databse we created in part 7. We will go over the basics of editing a database table to set it up for data collection. We will work with MySQL Query Browser to manipulate the databse so that later when we add sensors and work with Python Scripts, it will be relatively easy to import that data to the database and from there we can create charts, webpages, and analyze collected data. Additionally, I'll explain some basics in MySQL Command Line so it's relate-able to the MySQL Query Browser.
If you haven't already, download MySQL Query Browser:
https://downloads.mysql.com/archives/query/
If you don't know how to log in, refer to Part 7 in this series:
https://www.youtube.com/watch?v=riOEvxc0Ro4
example of creating a table via MySQL command line:
CREATE TABLE pet (name VARCHAR(20), owner VARCHAR(20), species VARCHAR(20), sex CHAR(1), birth DATE, death DATE);
SHOW TABLES;
DROP TABLE temps;
more info on command line MySQL:
https://dev.mysql.com/doc/refman/5.5/en/creating-tables.html
values:
date_time default value:
'0000-00-00 00:00:00'
modified default value:
CURRENT_TIMESTAMP
First Sensor default value:
'0.00'
The candle that burns twice as bright burns half as long
|
|
|
|
|
|
|
|
|
Re: Raspberry Pi Greenhouse Controller And Data Logger [message #3296 is a reply to message #3295] |
Tue, 28 January 2020 00:55   |
 |
kd2iin
Messages: 27 Registered: December 2016 Location: Tivoli, NY
|
Junior Member |
|
|
So here is the code from the most recent video for "Setting Up Your Own Raspberry Pi" Part 13: Here's a link to the video:
https://www.youtube.com/watch?v=uNVuQg1fAoY&list=PL837tk -T71LiUuXWUAkwMVonwd1M5koAW
Quote:Pycurl: Use the following at command prompt to install : sudo apt-get install python-pycurl
Quote:
import pycurl #this is used to do an http post to the temp updater
import time
import MySQLdb
conn = MySQLdb.connect(host= "localhost",
user="dbusernamehere",
passwd="yourdbpasswordhere",
db="databasenamehere")
x = conn.cursor()
try:
x.execute("INSERT INTO temps (greenhouse_id,OUTSIDE,AVGGH,cpu,DSK,RMU,RMF,cpuse,HUMTEMP,H UMI\
DIN,date_time) VALUES (1,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)",(outsidetemp,avgtemp,CPU,DISK_perc,RAM_used\
,RAM_free,CPU_usage,humtemp,humidity,time.strftime('%Y-%m-%d %H:%M:%S')))
conn.commit()
except:
# print "MySQL Error [%d]:%s" % (e.args[0], e.args[1])
conn.rollback()
print "end of database insertion"
The candle that burns twice as bright burns half as long
|
|
|
Re: Raspberry Pi Greenhouse Controller And Data Logger [message #3299 is a reply to message #3296] |
Sun, 02 February 2020 03:30   |
 |
kd2iin
Messages: 27 Registered: December 2016 Location: Tivoli, NY
|
Junior Member |
|
|
Part 14 Raspberry Pi 4 Ultimate Cooling System With Python Code
https://youtu.be/DX-ciuGmqpg
This video goes into some detail about my hybrid cooling system for the Raspberry Pi 4 that controls and monitors (data logs) my greenhouse. This system uses a combination of the Canna Kit heat sinks and included fan as well as extra fans (200 CFM for the cabinet and 100 CFM for the CPU) to maintain cool processor temps. The greenhouse can exceed 150 degrees in the summer with the vents closed, so this processor cooling, in the event of a vent failure ,is critical. The window between 150 degrees F and the max operating temperature of The Raspberry Pi 4 at 176 degrees F is not much!
More thermal info: https://www.raspberrypi.org/blog/thermal-testing-raspberry-p i-4/
Here's the cpu.py code:
#!/usr/bin/python
import sys
from termcolor import colored, cprint
import RPi.GPIO as GPIO
import os
try:
# Python 3
from io import BytesIO
except ImportError:
# Python 2
from StringIO import StringIO as BytesIO
#import smtplib
# smtp lib used for sending text messages
#import pifacedigitalio as p #used for piface (fan relays)
import time
#setup GPIO
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BCM)
#List pins assoc with relay board
pinList = [6, 12, 13, 16, 19, 21]
while (True):
print ("Wait 10 seconds: CPU and BOX Cooling Loop")
time.sleep (10.0)
def read_temperature(device):
# open/read/close the file with the temperature; the output is like
# in the example above.
#/sys/bus/w1/devices/28-000004fc61d3/w1_slave
#28-000005160247
tfile = open("/sys/bus/w1/devices/"+device+"/w1_slave")
text = tfile.read()
tfile.close()
lines = text.split("\n")
# make sure the crc is valid
if lines[0].find("YES") > 0:
# get the 9th (10th) chunk of text and lose the t= bit
temp = float((lines[1].split(" ")[9])[2:])
# add a decimal point
temp /= 1000
temp = temp * 1.8 + 32
return temp
# Return CPU temperature as a character string
def getCPUtemperature():
res = os.popen('vcgencmd measure_temp').readline()
return(res.replace("temp=","").replace("'C\n",""))
temp1 = int(float(getCPUtemperature()))
CPU = 9.0/5.0*temp1+32
print "CPU:",CPU
# turn on fan directed at cpu
if CPU > 140:
print colored ("CPU over 140 - Fan ON", 'green')
GPIO.setup(6, GPIO.OUT)
GPIO.output(6, GPIO.LOW)
GPIO.setup(12, GPIO.OUT)
GPIO.output(12, GPIO.LOW)
# turn off fan directed at cpu
elif CPU <= 135:
print colored ("CPU Below 135 - Fan OFF", 'red')
GPIO.setup(6, GPIO.OUT)
GPIO.output(6, GPIO.HIGH)
GPIO.setup(12, GPIO.OUT)
GPIO.output(12, GPIO.HIGH)
# turn on fan exhausting from box
# get Pi Box temp sensor reading
box = 0
#read_temperature("28-051691db2aff")
print "box:",box
# based on box temp, turn on fan exhausting from box
#turn on:
#if box > 105:
# GPIO.setup(12, GPIO.OUT)
# GPIO.output(12, GPIO.LOW)
# turn off fan exhausting from box
#elif box < 100:
# GPIO.setup(12, GPIO.OUT)
# GPIO.output(12, GPIO.HIGH)
# based on CPU temp, turn on fan exhausting from box
# if CPU > 130:
# GPIO.setup(12, GPIO.OUT)
# GPIO.output(12, GPIO.LOW)
# based on CPU temp, turn off fan exhausting from box
# elif CPU < 125:
# GPIO.setup(12, GPIO.OUT)
# GPIO.output(12, GPIO.HIGH)
And here's the cpucheck code:
#!/bin/bash
while true; do
/root/cpu.py &
wait $!
sleep 10
done
exit
and here's the crontab line to add:
# m h dom mon dow command
* * * * * /root/cpucheck
The candle that burns twice as bright burns half as long
[Updated on: Sun, 02 February 2020 04:11] Report message to a moderator
|
|
|
Re: Raspberry Pi Greenhouse Controller And Data Logger [message #3300 is a reply to message #3299] |
Tue, 04 February 2020 20:34  |
 |
kd2iin
Messages: 27 Registered: December 2016 Location: Tivoli, NY
|
Junior Member |
|
|
Part 14 B Raspberry Pi 4 Ultimate Cooling System With Python Code IMPORTANT CODE UPDATE!
https://youtu.be/uJRf22QJkqg
In this video I detail an important code update relative to my last video on this subject (Raspberry Pi Part 14). We edit the checkcpu script as well as the crontab to address a RAM issue I overlooked initially. If you don't update your code like this, you will watch all your free RAM get used up and eventually the machine will run out of RAM and lock up.
code updated:
crontab: (use crontab -e)
# For more information see the manual pages of crontab(5) and cron(
#
# m h dom mon dow command
* * * * * /root/ownew.py
# * * * * * /root/cpucheck
# * * * * * /root/ghcheck
@reboot /root/cpucheck
cpucheck code:
File Edit Options Buffers Tools Sh-Script Help
#!/bin/bash
while true; do
/root/cpu.py
wait $!
sleep 10
done
exit
The candle that burns twice as bright burns half as long
[Updated on: Tue, 04 February 2020 20:35] Report message to a moderator
|
|
|
Goto Forum:
Current Time: Wed Mar 29 20:52:16 EDT 2023
Total time taken to generate the page: 0.04531 seconds
|