Skip to content

Commit

Permalink
Finished prototype script for trap camera module, rearchitecture is c…
Browse files Browse the repository at this point in the history
…urrently underway (save & sort code modules appropriately for development, create some basic runnables that package functionality)
  • Loading branch information
MikeHLee committed Aug 11, 2023
1 parent b6e9aed commit e29f931
Show file tree
Hide file tree
Showing 19 changed files with 182 additions and 44 deletions.
6 changes: 3 additions & 3 deletions equipment/air_pump.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
sys.path.append('/home/pi/oasis-cpu')

import rusty_pins
from peripherals import relays
from peripherals import digital_relays
from utils import concurrent_state as cs
from utils import error_handler as err

Expand All @@ -28,7 +28,7 @@
try:
while True:
print("Turning air pump on at " + cs.structs["control_params"]["time_start_air"] + ":00 and off at " + cs.structs["control_params"]["time_stop_air"] + ":00, refreshing every " + cs.structs["control_params"]["air_interval"] + " minutes...")
relays.actuate_time_hod(pin, int(cs.structs["control_params"]["time_start_air"]), int(cs.structs["control_params"]["time_stop_air"]), int(cs.structs["control_params"]["air_interval"]), interval_units = "minutes", wattage=cs.structs["hardware_config"]["equipment_wattage"]["air_pump"], log="air_pump_kwh")
digital_relays.actuate_time_hod(pin, int(cs.structs["control_params"]["time_start_air"]), int(cs.structs["control_params"]["time_stop_air"]), int(cs.structs["control_params"]["air_interval"]), interval_units = "minutes", wattage=cs.structs["hardware_config"]["equipment_wattage"]["air_pump"], log="air_pump_kwh")
cs.load_state() #no time recorded here because it is not on an interval
time.sleep(1)
except SystemExit: #This is handled by the relay as well when terminated from main
Expand All @@ -41,7 +41,7 @@
finally:
print("Shutting down air pump...")
try:
relays.turn_off(pin)
digital_relays.turn_off(pin)
except:
print(resource_name + " has no relay objects remaining.")

Expand Down
8 changes: 4 additions & 4 deletions equipment/dehumidifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
sys.path.append('/home/pi/oasis-cpu')

import rusty_pins
from peripherals import relays
from peripherals import digital_relays
from utils import concurrent_state as cs
from utils import error_handler as err
from networking import db_tools as dbt
Expand All @@ -29,12 +29,12 @@
while True:
if cs.structs["feature_toggles"]["dehum_pid"] == "1":
print("Running dehumidifier in pulse mode with " + cs.structs["control_params"]["dehum_feedback"] + "%" + " power...")
relays.actuate_slow_pwm(pin, float(cs.structs["control_params"]["dehum_feedback"]), wattage=cs.structs["hardware_config"]["equipment_wattage"]["dehumidifier"], log="dehumidifier_kwh") #trigger appropriate response
digital_relays.actuate_slow_pwm(pin, float(cs.structs["control_params"]["dehum_feedback"]), wattage=cs.structs["hardware_config"]["equipment_wattage"]["dehumidifier"], log="dehumidifier_kwh") #trigger appropriate response
else:
print("Running dehumidifier for " + cs.structs["control_params"]["dehumidifier_duration"] + " minute(s) on, " + cs.structs["control_params"]["dehumidifier_interval"] + " minute(s) off...")
if (time.time() - float(cs.structs["control_params"]["last_dehumidifier_run_time"])) > (float(cs.structs["control_params"]["dehumidifier_interval"])*60): #convert setting units (minutes) to base (seconds)
cs.write_state("/home/pi/oasis-cpu/configs/control_params.json", "last_dehumidifier_run_time", str(time.time()), db_writer = dbt.patch_firebase)
relays.actuate_interval_sleep(pin, float(cs.structs["control_params"]["dehumidifier_duration"]), float(cs.structs["control_params"]["dehumidifier_interval"]), duration_units= "minutes", sleep_units="minutes", wattage=cs.structs["hardware_config"]["equipment_wattage"]["dehumidifier"], log="dehumidifier_kwh")
digital_relays.actuate_interval_sleep(pin, float(cs.structs["control_params"]["dehumidifier_duration"]), float(cs.structs["control_params"]["dehumidifier_interval"]), duration_units= "minutes", sleep_units="minutes", wattage=cs.structs["hardware_config"]["equipment_wattage"]["dehumidifier"], log="dehumidifier_kwh")
cs.load_state()
time.sleep(1)
except SystemExit:
Expand All @@ -47,7 +47,7 @@
finally:
print("Shutting down dehumidifier...")
try:
relays.turn_off(pin)
digital_relays.turn_off(pin)
except:
print(resource_name + " has no relay objects remaining.")

Expand Down
8 changes: 4 additions & 4 deletions equipment/fan.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
sys.path.append('/home/pi/oasis-cpu')

import rusty_pins
from peripherals import relays
from peripherals import digital_relays
from utils import concurrent_state as cs
from utils import error_handler as err
from networking import db_tools as dbt
Expand All @@ -30,12 +30,12 @@
while True:
if cs.structs["feature_toggles"]["fan_pid"] == "1":
print("Ventilating in pulse mode with " + cs.structs["control_params"]["fan_feedback"] + "%" + " power...")
relays.actuate_slow_pwm(pin, float(cs.structs["control_params"]["fan_feedback"]), wattage=cs.structs["hardware_config"]["equipment_wattage"]["fan"], log="fan_kwh") #trigger appropriate response
digital_relays.actuate_slow_pwm(pin, float(cs.structs["control_params"]["fan_feedback"]), wattage=cs.structs["hardware_config"]["equipment_wattage"]["fan"], log="fan_kwh") #trigger appropriate response
else:
print("Fans on for " + cs.structs["control_params"]["fan_duration"] + " minute(s), off for " + cs.structs["control_params"]["fan_interval"] + " minute(s)...")
if (time.time() - float(cs.structs["control_params"]["last_fan_run_time"])) > (float(cs.structs["control_params"]["fan_interval"])*60): #convert setting units (minutes) to base (seconds)
cs.write_state("/home/pi/oasis-cpu/configs/control_params.json", "last_fan_run_time", str(time.time()), db_writer = dbt.patch_firebase)
relays.actuate_interval_sleep(pin, float(cs.structs["control_params"]["fan_duration"]), float(cs.structs["control_params"]["fan_interval"]), duration_units= "minutes", sleep_units="minutes", wattage=cs.structs["hardware_config"]["equipment_wattage"]["fan"], log="fan_kwh")
digital_relays.actuate_interval_sleep(pin, float(cs.structs["control_params"]["fan_duration"]), float(cs.structs["control_params"]["fan_interval"]), duration_units= "minutes", sleep_units="minutes", wattage=cs.structs["hardware_config"]["equipment_wattage"]["fan"], log="fan_kwh")
cs.load_state()
time.sleep(1)
except SystemExit:
Expand All @@ -48,7 +48,7 @@
finally:
print("Shutting down fans...")
try:
relays.turn_off(pin)
digital_relays.turn_off(pin)
except:
print(resource_name + " has no relay objects remaining.")

Expand Down
8 changes: 4 additions & 4 deletions equipment/heater.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
sys.path.append('/home/pi/oasis-cpu')

import rusty_pins
from peripherals import relays
from peripherals import digital_relays
from utils import concurrent_state as cs
from utils import error_handler as err
from networking import db_tools as dbt
Expand All @@ -30,12 +30,12 @@
while True:
if cs.structs["feature_toggles"]["heat_pid"] == "1":
print("Heating in pulse mode with " + cs.structs["control_params"]["heat_feedback"] + "%" + " power...")
relays.actuate_slow_pwm(pin, float(cs.structs["control_params"]["heat_feedback"]), wattage=cs.structs["hardware_config"]["equipment_wattage"]["heater"], log="heater_kwh") #trigger appropriate response
digital_relays.actuate_slow_pwm(pin, float(cs.structs["control_params"]["heat_feedback"]), wattage=cs.structs["hardware_config"]["equipment_wattage"]["heater"], log="heater_kwh") #trigger appropriate response
else:
print("Heater on for " + cs.structs["control_params"]["heater_duration"] + " minute(s), off for " + cs.structs["control_params"]["heater_interval"] + " minute(s)...")
if (time.time() - float(cs.structs["control_params"]["last_heater_run_time"])) > (float(cs.structs["control_params"]["heater_interval"])*60): #convert setting units (minutes) to base (seconds)
cs.write_state("/home/pi/oasis-cpu/configs/control_params.json", "last_heater_run_time", str(time.time()), db_writer = dbt.patch_firebase)
relays.actuate_interval_sleep(pin, float(cs.structs["control_params"]["heater_duration"]), float(cs.structs["control_params"]["heater_interval"]), duration_units= "minutes", sleep_units="minutes", wattage=cs.structs["hardware_config"]["equipment_wattage"]["heater"], log="heater_kwh")
digital_relays.actuate_interval_sleep(pin, float(cs.structs["control_params"]["heater_duration"]), float(cs.structs["control_params"]["heater_interval"]), duration_units= "minutes", sleep_units="minutes", wattage=cs.structs["hardware_config"]["equipment_wattage"]["heater"], log="heater_kwh")
cs.load_state()
time.sleep(1)
except SystemExit:
Expand All @@ -48,7 +48,7 @@
finally:
print("Shutting down heater...")
try:
relays.turn_off(pin)
digital_relays.turn_off(pin)
except:
print(resource_name + " has no relay objects remaining.")

Expand Down
8 changes: 4 additions & 4 deletions equipment/humidifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
sys.path.append('/home/pi/oasis-cpu')

import rusty_pins
from peripherals import relays
from peripherals import digital_relays
from utils import concurrent_state as cs
from utils import error_handler as err
from networking import db_tools as dbt
Expand All @@ -29,12 +29,12 @@
while True:
if cs.structs["feature_toggles"]["hum_pid"] == "1":
print("Running humidifier in pulse mode with " + cs.structs["control_params"]["hum_feedback"] + "%" + " power...")
relays.actuate_slow_pwm(pin, float(cs.structs["control_params"]["hum_feedback"]), wattage=cs.structs["hardware_config"]["equipment_wattage"]["humidifier"], log="humidifier_kwh") #trigger appropriate response
digital_relays.actuate_slow_pwm(pin, float(cs.structs["control_params"]["hum_feedback"]), wattage=cs.structs["hardware_config"]["equipment_wattage"]["humidifier"], log="humidifier_kwh") #trigger appropriate response
else:
print("Running humidifier for " + cs.structs["control_params"]["humidifier_duration"] + " minute(s) on, " + cs.structs["control_params"]["humidifier_interval"] + " minute(s) off...")
if (time.time() - float(cs.structs["control_params"]["last_humidifier_run_time"])) > (float(cs.structs["control_params"]["humidifier_interval"])*60): #convert setting units (minutes) to base (seconds)
cs.write_state("/home/pi/oasis-cpu/configs/control_params.json", "last_humidifier_run_time", str(time.time()), db_writer = dbt.patch_firebase)
relays.actuate_interval_sleep(pin, float(cs.structs["control_params"]["humidifier_duration"]), float(cs.structs["control_params"]["humidifier_interval"]), duration_units= "minutes", sleep_units="minutes", wattage=cs.structs["hardware_config"]["equipment_wattage"]["humidifier"], log="humidifier_kwh")
digital_relays.actuate_interval_sleep(pin, float(cs.structs["control_params"]["humidifier_duration"]), float(cs.structs["control_params"]["humidifier_interval"]), duration_units= "minutes", sleep_units="minutes", wattage=cs.structs["hardware_config"]["equipment_wattage"]["humidifier"], log="humidifier_kwh")
cs.load_state()
time.sleep(1)
except SystemExit:
Expand All @@ -47,7 +47,7 @@
finally:
print("Shutting down humidifier...")
try:
relays.turn_off(pin)
digital_relays.turn_off(pin)
except:
print(resource_name + " has no relay objects remaining.")

Expand Down
8 changes: 4 additions & 4 deletions equipment/water_pump.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

#import libraries
import rusty_pins
from peripherals import relays
from peripherals import digital_relays
from utils import concurrent_state as cs
from utils import error_handler as err
from networking import db_tools as dbt
Expand All @@ -29,12 +29,12 @@
while True:
if cs.structs["feature_toggles"]["water_pid"] == "1":
print("Running water pump in pulse mode with " + cs.structs["control_params"]["moisture_feedback"] + "%" + " power...")
relays.actuate_slow_pwm(pin, intensity = float(cs.structs["control_params"]["moisture_feedback"]), wattage=cs.structs["hardware_config"]["equipment_wattage"]["water_pump"], log="water_pump_kwh") #trigger appropriate response
digital_relays.actuate_slow_pwm(pin, intensity = float(cs.structs["control_params"]["moisture_feedback"]), wattage=cs.structs["hardware_config"]["equipment_wattage"]["water_pump"], log="water_pump_kwh") #trigger appropriate response
else:
print("Running water pump for " + cs.structs["control_params"]["watering_duration"] + " minute(s) every " + cs.structs["control_params"]["watering_interval"] + " day(s)...")
if (time.time() - float(cs.structs["control_params"]["last_watering_run_time"])) > (float(cs.structs["control_params"]["watering_interval"])*60*60*24): #convert setting (days) to base units (seconds): days*(60*60*24)
cs.write_state("/home/pi/oasis-cpu/configs/control_params.json", "last_watering_run_time", str(time.time()), db_writer = dbt.patch_firebase)
relays.actuate_interval_sleep(pin, duration = float(cs.structs["control_params"]["watering_duration"]), sleep = float(cs.structs["control_params"]["watering_interval"]), duration_units="minutes", sleep_units="days", wattage=cs.structs["hardware_config"]["equipment_wattage"]["water_pump"], log="water_pump_kwh")
digital_relays.actuate_interval_sleep(pin, duration = float(cs.structs["control_params"]["watering_duration"]), sleep = float(cs.structs["control_params"]["watering_interval"]), duration_units="minutes", sleep_units="days", wattage=cs.structs["hardware_config"]["equipment_wattage"]["water_pump"], log="water_pump_kwh")
cs.load_state()
time.sleep(1)
except KeyboardInterrupt:
Expand All @@ -45,7 +45,7 @@
finally:
print("Shutting down water pump...")
try:
relays.turn_off(pin)
digital_relays.turn_off(pin)
except:
print(resource_name + " has no relay objects remaining.")

Expand Down
30 changes: 30 additions & 0 deletions imaging/camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,36 @@ def take_picture(image_path):
exit_status = still.exit_code()
return exit_status

def take_video(video_path, duration):
"""
Captures a video using the Raspberry Pi camera.
Args:
- video_path (str): Path to save the captured video.
- duration (int): Length of the video capture in seconds.
Returns:
- int: Exit status of the raspivid command.
"""
# Convert duration from seconds to milliseconds
duration_millis = duration * 1000

if cs.structs["hardware_config"]["camera_settings"]["awb_mode"] == "on":
# Take video and save to specified path
video_cmd = ["raspivid", "-e", "h264", "-o", str(video_path), "-t", str(duration_millis)]
video_process = rusty_pipes.Open(video_cmd, "raspivid")
video_process.wait()
else:
awb_values = "{},{}".format(cs.structs["hardware_config"]["camera_settings"]["awb_red"],
cs.structs["hardware_config"]["camera_settings"]["awb_blue"])
video_cmd = ["raspivid", "-e", "h264", "-o", str(video_path), "-t", str(duration_millis),
"-awb", "off", "-awbg", awb_values]
video_process = rusty_pipes.Open(video_cmd, "raspivid")
video_process.wait()

exit_status = video_process.exit_code()
return exit_status

def save_to_feed(image_path):
#timestamp image
timestamp = time.time()
Expand Down
File renamed without changes.
File renamed without changes.
13 changes: 13 additions & 0 deletions peripherals/digital_sensors.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#For setting up binary sensors (Water Level, PIR, Pressure Plate, Switch, etc.)
#Handle the high and low for each sensor case

import sys

sys.path.append("/home/pi/oasis-cpu")

import rusty_pins

def input(pin: int, debounce_count: int):
input = rusty_pins.GpioIn(pin, debounce_count)
return input

File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit e29f931

Please sign in to comment.