strawberry-pi-greenhouse/main.py

32 lines
938 B
Python

import time
import os
from datetime import datetime
try:
import paho.mqtt.client as mqtt
import gpiozero
except ImportError:
print('Some modules are missing. Try to install them with "pip3 install -r requirements.txt"')
exit()
def debug_print(message: str):
now = datetime.now()
current_time = now.strftime("%H:%M:%S")
print('[DEBUG]['+current_time+'] '+message)
def error_print(message: str):
now = datetime.now()
current_time = now.strftime("%H:%M:%S")
print('[ERROR]['+current_time+'] '+message)
def relay_controller(pin: int, status: str):
if status == "ON":
relay = gpiozero.OutputDevice(pin, active_high=False, initial_value=False)
relay.on()
elif status == "OFF":
relay = gpiozero.OutputDevice(pin, active_high=False, initial_value=False)
relay.off()
else:
error_print("Unknown status for relay ("+status+")")
def get_water_lvl():