Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean up #25

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
*.log
logs/

#local
*.local*
# MISC
camera.sh
manual_transfer.py
Expand Down
8 changes: 7 additions & 1 deletion ControlPanel/README.md
Original file line number Diff line number Diff line change
@@ -1 +1,7 @@
This is an website built to directly interface with the garden and display status from the various modules in the system.
# Control Panel

This is an website built to directly interface with the garden and display status from the various modules in the system.

## **Warning:** This will probably be replaced with [Home Assistant](https://www.home-assistant.io/) in the future.

![alt text](https://raw.github.com/ataffe/smartGarden/Dev/images/ControlPanel.PNG)
3 changes: 3 additions & 0 deletions GardenModules/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Garden Modules

This folder houses the gardent modules. Each module represents and manages some form of input or output, e.g. a soil moisture sensor. The idea behind this approach is to make adding features as simple as adding a new module.
3 changes: 3 additions & 0 deletions GardenModules/artificalLight/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Artificial Light Sensor

This is a module to control a relay that controls artificial lighting for plants. This module was built for the [SunFounder 2 Channel DC 5V Relay Module with Optocoupler Low Level Trigger Expansion Board for Arduino](https://www.amazon.com/gp/product/B00E0NTPP4/ref=ppx_yo_dt_b_search_asin_title?ie=UTF8&psc=1)
3 changes: 3 additions & 0 deletions GardenModules/gardenServer/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Garden Server

This is a server that uses Flask to remotely interface with the garden. This includes a heartbeat REST endpoint, that can be used to detect if a sensor is still working.
61 changes: 54 additions & 7 deletions GardenModules/gardenServer/gardenServer.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import logging
import time

app = Flask(__name__, template_folder='/home/pi/Desktop/smartGarden/smartGarden/ControlPanel', static_folder="/home/pi/Desktop/smartGarden/smartGarden/ControlPanel")
app = Flask(__name__, template_folder='./ControlPanel', static_folder="./ControlPanel")
CORS(app)
Debug(app)

Expand Down Expand Up @@ -105,9 +105,56 @@ def get_light():
print(e)


@app.route('/soil')
def soil_route():
try:
with open("./soilLog.txt") as file:
#lines = file.readlines()
table = ""
for count, line in reversed(list(enumerate(file))):
fields = line.split()
raw_value = fields[8]
percent = fields[3]
date = fields[4]
time = fields[5]

if count % 2 == 0:
table = table + "<tr style='background-color: #f2f2f2;border: 1px solid;padding: 8px; text-align: center'>"
else:
table = table + "<tr style='border: 1px solid;padding: 8px; text-align: center;'>"

table = table + "<td>" + date + "</td>"
table = table + "<td>" + time + "</td>"
table = table + "<td>" + percent + "</td>"
table = table + "<td>" + raw_value + "</td>"
table = table + "</tr>"
return '''
<html>
<head>
<title>Soil Moisture - Smart Garden</title>
</head>
<body>
<h1 style="font-family: 'Roboto', sans-serif;">Soil Moisture Data</h1>
<table style="width:100%">
<tr>
<th style="font-size: medium;padding: 8px;background-color: #4CAF50;color: white;">Date</th>
<th style="font-size: medium;padding: 8px;background-color: #4CAF50;color: white;">Time</th>
<th style="font-size: medium;padding: 8px;background-color: #4CAF50;color: white;">Soil Moisture Percent</th>
<th style="font-size: medium;padding: 8px;background-color: #4CAF50;color: white;">Soil Moisture Raw Value</th>
</tr>
''' + table + '''
</table>
</body>
</html>
'''
except Exception as e:
logging.warn("There was an exception returning soil data to rest endpoint: " + str(e))
return "There was an exception: " + str(e)


@app.route('/garden')
def garden_route():
with open("/home/pi/Desktop/smartGarden/smartGarden/logs/smartGardenLog.txt") as file:
with open("./logs/smartGardenLog.txt") as file:
return file.read()


Expand All @@ -119,31 +166,31 @@ def control_panel():

@app.route('/water')
def control_panel_water():
with open('/home/pi/Desktop/smartGarden/smartGarden/ControlPanel/water.html') as file:
with open('./ControlPanel/water.html') as file:
return file.read()


@app.route('/light')
def control_panel_light():
with open('/home/pi/Desktop/smartGarden/smartGarden/ControlPanel/light.html') as file:
with open('./ControlPanel/light.html') as file:
return file.read()


@app.route('/soilMoisture')
def control_panel_soil_moisture():
with open('/home/pi/Desktop/smartGarden/smartGarden/ControlPanel/soilMoisture.html') as file:
with open('./ControlPanel/soilMoisture.html') as file:
return file.read()


@app.route('/sun_css')
def sun_css():
with open('/home/pi/Desktop/smartGarden/smartGarden/ControlPanel/sun.css') as file:
with open('./ControlPanel/sun.css') as file:
return file.read()


@app.route('/status_css')
def status_css():
with open('/home/pi/Desktop/smartGarden/smartGarden/ControlPanel/status.css') as file:
with open('./ControlPanel/status.css') as file:
return file.read()
# End Control Panel Endpoints

Expand Down
3 changes: 3 additions & 0 deletions GardenModules/luxSensor/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Lux Sensor

This is a module for a [Adafruit TSL2591 High Dynamic Range Digital Light Sensor.](https://www.amazon.com/gp/product/B00XW2OFWW/ref=ppx_yo_dt_b_search_asin_title?ie=UTF8&psc=1)
2 changes: 1 addition & 1 deletion GardenModules/luxSensor/luxSensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def __init__(self, log, queue):
self._sensor.gain = 0
self._grow_light_lux = 535
self._lux_interval = 120
self._data_file = "/home/pi/Desktop/smartGarden/smartGarden/Data/luxData.csv"
self._data_file = "./Data/luxData.csv"
self._log.info("Lux sensor start up successful")
except Exception as exception:
self._log.error("Lux sensor failed to start up.")
Expand Down
4 changes: 2 additions & 2 deletions GardenModules/prune/prune.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
def prune(file):
lines = []
try:
logFile = open("/home/pi/Desktop/smartGarden/smartGarden/logs/" + file, "r")
logFile = open("./logs/" + file, "r")
for line in logFile:
lines.append(line)
except Exception as e:
Expand All @@ -12,7 +12,7 @@ def prune(file):
logFile.close()

try:
logFile = open("/home/pi/Desktop/smartGarden/smartGarden/logs/" + file, "w")
logFile = open("./logs/" + file, "w")
if len(lines) > 5000:
# Only keep the last 5000 lines
for x in range(5000):
Expand Down
3 changes: 3 additions & 0 deletions GardenModules/pump/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Water Pump Module

This module is to control a DC water pump connected to a [DROK 200203 DC 5-36V 400W Dual Large Power MOS Transistor Driving Module](https://www.amazon.com/gp/product/B01J78FX9S/ref=ppx_yo_dt_b_search_asin_title?ie=UTF8&psc=1) [Here](https://www.amazon.com/gp/product/B07DW4WRV8/ref=ppx_yo_dt_b_search_asin_title?ie=UTF8&psc=1) is the pump used.
3 changes: 3 additions & 0 deletions GardenModules/soilMoisture/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Soil Moisture Sensor

This is a module to control a [Gikfun Capacitive Soil Moisture Sensor](https://www.amazon.com/gp/product/B07H3P1NRM/ref=ppx_yo_dt_b_search_asin_title?ie=UTF8&psc=1) via I2C. The soil moisture sensor is connected to a [Onyehn ADS1115 16 Byte 4 Channel I2C IIC Analog-to-Digital ADC Converter](https://www.amazon.com/gp/product/B07L3Q7N7T/ref=ppx_yo_dt_b_search_asin_title?ie=UTF8&psc=1)
4 changes: 2 additions & 2 deletions GardenModules/soilMoisture/soil.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def __init__(self, log, queue):
self.soilInterval = 120 # 1800
self._log.info("Channel: " + str(self.channel))
self.setName("soilThread")
self._data_file = "/home/pi/Desktop/smartGarden/smartGarden/Data/soilMoistureData.csv"
self._data_file = "./Data/soilMoistureData.csv"

# Set Gain to 16 bits
# Gain = 1 # Wet: 13884 Dry: 21680
Expand Down Expand Up @@ -69,7 +69,7 @@ def _checkSoil(self):
self._log.exception("Error calculating soil moisture")

try:
with open("/home/pi/Desktop/smartGarden/smartGarden/logs/soilLog.txt", "a+") as logFile:
with open("./logs/soilLog.txt", "a+") as logFile:
logFile.write("Soil Moisture Level: " + str(self.getSoilPercentage()) + "% " + str(
datetime.now()) + " Raw Value: " + str(self.channel.value) + "\n")
except Exception as exception:
Expand Down
3 changes: 3 additions & 0 deletions GardenModules/tempSensor/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Temperature Sensor

This is a module to read data from a [DFRobot Waterproof DS18B20 Temperature Sensor Kit](https://www.amazon.com/gp/product/B07434MB77/ref=ppx_yo_dt_b_search_asin_title?ie=UTF8&psc=1)
6 changes: 3 additions & 3 deletions ModuleTests/Data/luxData.csv → Tests/Data/luxData.csv
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
527.978462833967,2020-11-29 02:55:51.918946
528.5072462839585,2020-11-29 02:56:02.070627
529.5646851648721,2020-11-29 02:56:12.221543
527.978462833967,2020-11-29 02:55:51.918946
528.5072462839585,2020-11-29 02:56:02.070627
529.5646851648721,2020-11-29 02:56:12.221543
Loading