#Nombre del Proyecto: UEBO
#FSE, comision 08
#Integrantes: Tobias Simcic, Thiago Luna Gauna, Lautaro Quevedo
#Tenes huevos y no sabes ni como hacer un huevo duro?¿Hacer huevos es demasiado complicado?
#Excelente, presentamos Ultimate Egg Boiling Option(U.E.B.O). Para usted, si, para usted.
#Esta herramienta permite cocinar 3 tipos de huevos(huevo duro, huevo pasado por agua y pollet),
#y solo recibir una señal cuando estén listos. Se terminaron sus huevo problemas,
#ahora podrá disfrutar el manjar aviar en sus distintos tipos.
#Ultimate Egg Boiling Option (U.E.B.O) tiene un sistemas de 3 opciones, intercambiables con los botones,
#al darle al boton de iniciar, empieza la cocción. Al comenzar,
#un relay que se encarga de encender la hornalla electrica que calentara el agua.
#Mientras tanto hay un sensor de temperatura NTC que detecta y compara la temperatura del agua con la deseada.
#Al llegar a la temperatura de agua necesaria empieza un contador,
#este contador varia en función a la opción seleccionada. Una vez alcanzado el tiempo de cocción,
#el huevo está listo.
import time
import machine
import micropython
import network
import math
from machine import Pin,PWM, ADC, Timer
from umqtt.simple import MQTTClient
#Indicamos red WIFI y clave
ssid = 'Wokwi-GUEST'
wifipassword = ''
#Datos Server MQTT (Broker)
#Indicamos datos MQTT Broker (server y puerto)
mqtt_server = 'io.adafruit.com'
port = 1883
user = 'tobias_sim' #definido en adafruit
password = 'aio_YwNN246c5N8EHnBCNmyL90XqOGVn' #key adafruit
#Indicamos ID(unico) y topicos
client_id = 'HuevoProject'
topic_TEMP = 'tobias_sim/feeds/temperatura'
topic_TOGGLE = 'tobias_sim/feeds/toggle'
TOGGLE = True
#Definimos modo Station (conectarse a Access Point remoto)
sta_if = network.WLAN(network.STA_IF)
sta_if.active(True)
#Conectamos al wifi
sta_if.connect(ssid, wifipassword)
print("Conectando")
while not sta_if.isconnected():
print(".", end="")
time.sleep(0.1)
print("Conectado a Wifi!")
#Vemos cuales son las IP
print(sta_if.ifconfig())
#Antes de conectarnos al broker, vamos a definir una funcion
#que sera llamada cada vez que se produzca un publish sobre
#un topico donde estamos suscriptos
def callback_toggle(topic, msg):
global TOGGLE
#Cuando se ejecuta esta funcion quere decir que
#hubo un mensaje nuevo en algun topico, verificamos esto
#Dado que lo que llega viene en UTF-8, lo decodificamos
#para que sea una cadena de texto regular
dato = msg.decode('utf-8')
topicrec = topic.decode('utf-8')
print("Cambio en: "+topicrec+":"+dato)
#Nos fijamos si es el topico esperado y el valor del dato
if topicrec == topic_TOGGLE and "ON" in dato:
TOGGLE=True
else:
TOGGLE=False
#Intentamos conectarnos al broker MQTT
try:
conexionMQTT = MQTTClient(client_id, mqtt_server,user=user,password=password,port=int(port))
conexionMQTT.set_callback(callback_toggle)
conexionMQTT.connect()
conexionMQTT.subscribe(topic_TOGGLE)
print("Conectado con Broker MQTT")
except OSError as e:
#Si fallo la conexion, reiniciamos todo
print("Fallo la conexion al Broker, reiniciando...")
time.sleep(5)
machine.reset()
Relay = Pin(4,Pin.OUT)
BotonAdelante = Pin(18, Pin.IN, Pin.PULL_UP)
BotonAtras = Pin(19, Pin.IN, Pin.PULL_UP)
BotonInicio = Pin(5, Pin.IN, Pin.PULL_UP)
BotonReset = Pin(16, Pin.IN, Pin.PULL_UP)
sensor_tmp = ADC(Pin(34))
parlante = PWM(Pin(14), freq=440, duty_u16=32768)
parlante.duty(0)
R_SERIE = 10000 # Resistencia fija (10 kΩ)
BETA = 3950 # Constante beta del NTC
R_25 = 10000 # Resistencia del NTC a 25 °C (10 kΩ)
T0 = 298.15 # Temperatura en Kelvin (25 °C)
contador = 0
Tiempos = [180, 360, 600]
Coccion = ["Pasado por agua","Mollet","Huevo duro"]
EstadoActual = 0
def leer_temperatura():
valor_adc = sensor_tmp.read() # Valor entre 0 y 4095
voltaje = (valor_adc/4095 ) *3.3 # Convertir a voltaje
resistencia_ntc = R_SERIE / ((3.3/ voltaje) - 1) # Calcular resistencia del NTC
temperatura_kelvin = 1 / ((1 / T0 ) + (1 / BETA) * math.log(resistencia_ntc/R_25))
temperatura_celsius = temperatura_kelvin - 273.15
return temperatura_celsius
def Temporizador(EstadoActual):
global contador
contador = contador + 1
if contador == Tiempos[EstadoActual-1]:
eltimer.deinit()
Relay.value(0)
print("Huevo listo!")
parlante.duty(50)
time.sleep(5)
parlante.duty(0)
time.sleep(5)
def Cocinar(EstadoActual):
Relay.value(1)
eltimer = Timer(1)
while True:
time.sleep(5)
conexionMQTT.publish(topic_TEMP,str(leer_temperatura()))
if leer_temperatura()>=100:
continue
print("Hierve!")
eltimer.init(mode=Timer.PERIODIC, period=1000,callback=lambda t: Temporizador(EstadoActual, eltimer))
EstadoActual=4
if TOGGLE:
while True:
time.sleep_ms(3)
if EstadoActual == 0:
if not BotonAdelante.value():
EstadoActual = 1
if not BotonAtras.value():
EstadoActual = 3
elif EstadoActual == 1:
if not BotonAdelante.value():
EstadoActual = 2
if not BotonAtras.value():
EstadoActual = 3
elif EstadoActual == 2:
if not BotonAdelante.value():
EstadoActual = 3
if not BotonAtras.value():
EstadoActual = 1
elif EstadoActual == 3:
if not BotonAdelante.value():
EstadoActual = 1
if not BotonAtras.value():
EstadoActual = 2
if not BotonInicio.value() and (EstadoActual==1 or EstadoActual==2 or EstadoActual==3):
print(f"Coccion elegida: {Coccion[EstadoActual-1]}")
Cocinar(EstadoActual)
if not BotonReset.value() and EstadoActual==4:
EstadoActual = 0