def init(): file_logger.info('Init temperature control') GPIO.setwarnings(False) GPIO.setmode(GPIO.BCM) GPIO.setup(RELAY_GPIO_PIN, GPIO.OUT) # GPIO Assign mode time.sleep(1)
def captureImage(timestamp): file_logger.info("Capturing image...") file_name = timestamp.strftime("%Y-%m-%d_%H%M") + ".jpg" bash_command = "fswebcam --no-banner -q -r 1600x1200 -p YUYV -S 1 --jpeg 95 /home/pi/gb_data/gb_cam_images/{}" \ .format(file_name) GPIO.setmode(GPIO.BCM) GPIO.setup(RELAY_GPIO_PIN, GPIO.OUT) # GPIO Assign mode time.sleep(1) GPIO.output(RELAY_GPIO_PIN, GPIO.LOW) # on process = subprocess.Popen(bash_command.split(), stdout=subprocess.PIPE) output, error = process.communicate() time.sleep(20) GPIO.output(RELAY_GPIO_PIN, GPIO.HIGH) # off time.sleep(5) GPIO.cleanup() file_logger.info("Image captured: {}".format(file_name))
def init(): file_logger.info("Init air pump control") GPIO.setwarnings(False) GPIO.setmode(GPIO.BCM) GPIO.setup(RELAY_GPIO_PIN, GPIO.OUT) # GPIO Assign mode time.sleep(1)
def write_data(ph, ec): # voc, co2, humidity, temperature, waterTemperature file_full_path = fileFolder + fileName with open(file_full_path) as file: lines = file.read().splitlines() if lines: last_line = lines[-1] cells = last_line.split(',') if float(cells[ph_cell_number]) < 0 <= float(ph): file_logger.info("Writing pH value: {}".format(float(ph))) cells[ph_cell_number] = float(ph) if float(cells[ec_cell_number]) < 0 <= float(ec): file_logger.info("Writing EC value: {}".format(float(ec))) cells[ec_cell_number] = float(ec) with open(file_full_path, "w") as file: writer = csv.writer(file, delimiter=',') for line in lines[:-1]: writer.writerow(line.split(',')) writer.writerow(cells)
def run_day_hours(): file_logger.info("air pump ON (for {} minutes)".format( settings.air_pump_on_interval_day_seconds / 60)) GPIO.output(RELAY_GPIO_PIN, GPIO.LOW) # on time.sleep(settings.air_pump_on_interval_day_seconds) file_logger.info("air pump OFF (for {} minutes)".format( settings.air_pump_off_interval_day_seconds / 60)) GPIO.output(RELAY_GPIO_PIN, GPIO.HIGH) # off time.sleep(settings.air_pump_off_interval_day_seconds)
def start_monitoring(): while True: try: fan_running = not GPIO.input(RELAY_GPIO_PIN) # negation because of inverted connection to relays humidity, temperature = dht_data_collect.get_read_data(3) if temperature > settings.fan_enable_temperature_limit_celsius and not fan_running: GPIO.output(RELAY_GPIO_PIN, GPIO.LOW) # on file_logger.info('Temperature: {} *C - FAN on'.format(temperature)) elif temperature <= settings.fan_enable_temperature_limit_celsius and fan_running: GPIO.output(RELAY_GPIO_PIN, GPIO.HIGH) # off file_logger.info('Temperature: {} *C - FAN off'.format(temperature)) time.sleep(settings.fan_monitoring_interval_seconds) except Exception as e: file_logger.error('Error in: ' + os.path.basename(__file__)) file_logger.error(e)
def write_data(readings): # voc, co2, humidity, temperature, waterTemperature file_logger.info("Writing data to CSV...") current_datetime = datetime.now() readings.insert(0, current_datetime.strftime("%Y-%m-%d %H:%M:%S")) readings.insert(6, -1.0) readings.insert(7, -1.0) with open(csv_file_full_path, 'a') as file: writer = csv.writer(file) if os.stat(csv_file_full_path).st_size == 0: writer.writerow([ "datetime", "VOC", "CO2", "humidity", "temperature", "water_temperature", "pH", "EC" ]) writer.writerow(readings)
def start(): while True: try: now = datetime.now() if settings.data_save_night_hour_end <= now.hour <= settings.data_save_night_hour_begin: file_logger.info("Getting sensors readings...") voc, co2, humidity, temperature, water_temperature = get_sensors_data( ) write_data( [voc, co2, humidity, temperature, water_temperature]) # write_html_file() file_logger.info("Data saving done.") time.sleep(settings.data_save_delay_seconds) except Exception as e: file_logger.error('Error in: ' + os.path.basename(__file__)) file_logger.error(e)
def get_sensors_data(): voc, co2 = co2_data_collect.get_data() file_logger.info("VOC: {} :: CO2: {} ".format(voc, co2)) humidity, temperature = dht_data_collect.get_read_data(3) file_logger.info("Humidity: {} :: Temperature: {} ".format( humidity, temperature)) water_temperature = water_data_collect.get_water_temperature_data() file_logger.info("Water temperature: {} ".format(water_temperature)) return voc, co2, humidity, temperature, water_temperature
import subprocess from datetime import datetime import RPi.GPIO as GPIO import time import file_logger import os import settings RELAY_GPIO_PIN = 8 # relay IN1, GPIO 8 for FAN logs_name = 'image_capture.log' file_logger.init(logs_name) file_logger.info("Init image capture") def captureImage(timestamp): file_logger.info("Capturing image...") file_name = timestamp.strftime("%Y-%m-%d_%H%M") + ".jpg" bash_command = "fswebcam --no-banner -q -r 1600x1200 -p YUYV -S 1 --jpeg 95 /home/pi/gb_data/gb_cam_images/{}" \ .format(file_name) GPIO.setmode(GPIO.BCM) GPIO.setup(RELAY_GPIO_PIN, GPIO.OUT) # GPIO Assign mode time.sleep(1) GPIO.output(RELAY_GPIO_PIN, GPIO.LOW) # on process = subprocess.Popen(bash_command.split(), stdout=subprocess.PIPE) output, error = process.communicate()
def get_meters_data(): file_logger.info("Waiting for meters readings...") water_temperature, ph, ec = water_data_collect.get_all_meters_data() file_logger.info("T: {} :: pH: {} :: EC: {} ".format(water_temperature, ph, ec)) return water_temperature, ph, ec
import csv import time import water_data_collect import file_logger import os logs_name = 'meters_data_save.log' file_logger.init(logs_name) file_logger.info("Init meters data save") fileName = 'grow_data.csv' fileFolder = '/home/pi/gb_data/gb_csv/' ph_cell_number = 6 ec_cell_number = 7 def get_meters_data(): file_logger.info("Waiting for meters readings...") water_temperature, ph, ec = water_data_collect.get_all_meters_data() file_logger.info("T: {} :: pH: {} :: EC: {} ".format(water_temperature, ph, ec)) return water_temperature, ph, ec def write_data(ph, ec): # voc, co2, humidity, temperature, waterTemperature file_full_path = fileFolder + fileName with open(file_full_path) as file:
def init(): file_logger.info('Init data save')