from time import sleep
from sensors import read_data
from control import (
control_heater
)
from thermal_model import (
update_temperature
)
from fan import control_fan
from motor import turn_eggs
from history import add_data
from graphs import draw_graph
from wifi import connect_wifi
from dashboard import (
start_server,
send_dashboard
)
import state
# =========================
# WIFI
# =========================
wlan = connect_wifi()
server = start_server()
# =========================
# CONTADORES
# =========================
counter = 0
turn_counter = 0
# =========================
# LOOP
# =========================
while True:
data = read_data()
hum = data["hum"]
temp = update_temperature(0)
heater, pid_output, pwm = (
control_heater(temp)
)
temp = update_temperature(
pid_output / 100
)
fan_speed = control_fan(
temp,
state.setpoint,
pid_output
)
add_data(
temp,
hum,
pid_output,
fan_speed
)
print("\n=================")
print(
"TEMP:",
round(temp,1)
)
print(
"HUM:",
hum
)
print(
"PWM:",
round(pid_output,1)
)
print(
"FAN:",
fan_speed
)
print(
"SETPOINT:",
state.setpoint
)
draw_graph()
# Volteo automático
turn_counter += 1
if turn_counter >= 15:
turn_eggs()
print(
"VOLTEO HUEVOS"
)
turn_counter = 0
# Dashboard web
try:
client, addr = server.accept()
request = client.recv(1024)
send_dashboard(
client,
temp,
hum,
pid_output,
fan_speed
)
except:
pass
sleep(2)