Better cook parameter estimation + Defrost mode + Removed esp-wifi debugs + Orchestrator and microwave exchange
This commit is contained in:
@@ -55,6 +55,21 @@ def on_mqtt_message(message):
|
||||
# Unsubscribe from the hello topic since we got a response
|
||||
mqtt_client.unsubscribe(config.MQTT_TOPIC_HELLO)
|
||||
print("[MQTT Thread] Unsubscribed from topic:", config.MQTT_TOPIC_HELLO)
|
||||
|
||||
# Handle cooking messages
|
||||
elif message['topic'] == config.MQTT_TOPIC_COOKING and payload_data and payload_data["id_microwave"] == DEVICE_ID:
|
||||
# Cooking sensors init request
|
||||
if not "cook_time_seconds" in payload_data:
|
||||
print("[MQTT Thread] Cooking sensors init received from the orchestrator")
|
||||
obj_temp = temperature_sensor.read_object_temp()
|
||||
amb_temp = temperature_sensor.read_ambient_temp()
|
||||
queue_publish(config.MQTT_TOPIC_SENSOR, payloads.mqtt_sensor_data(DEVICE_ID, obj_temp, amb_temp))
|
||||
# Received cooking parameters from the orchestrator
|
||||
else:
|
||||
print("[MQTT Thread] Cooking parameters received from the orchestrator:", payload_data)
|
||||
# Here you would handle the cooking parameters, e.g., start a cooking process
|
||||
# For now, we just print them
|
||||
|
||||
print("[MQTT Thread] Message processing complete.")
|
||||
|
||||
mqtt_client.set_callback(on_mqtt_message)
|
||||
@@ -86,7 +101,6 @@ def mqtt_background_thread():
|
||||
mqtt_client.publish(topic, payload, qos=config.MQTT_QOS)
|
||||
|
||||
# 2. Check for incoming messages (non-blocking poll)
|
||||
# Shortened timeout to keep the queue responsive
|
||||
events = poller.poll(200)
|
||||
if events:
|
||||
mqtt_client.wait()
|
||||
@@ -145,18 +159,18 @@ def uart_background_thread():
|
||||
time.sleep(5)
|
||||
|
||||
# --- Launch background worker ---
|
||||
# _thread.start_new_thread(mqtt_background_thread, ())
|
||||
# _thread.start_new_thread(uart_background_thread, ())
|
||||
_thread.start_new_thread(mqtt_background_thread, ())
|
||||
_thread.start_new_thread(uart_background_thread, ())
|
||||
|
||||
|
||||
# --- MAIN APPLICATION THREAD (Core 0) ---
|
||||
print("[Main] Main execution path active.")
|
||||
time.sleep(2) # Give the thread a moment to initial connect
|
||||
mqtt_hello_sent_timestamp = -config.MQTT_HELLO_INTERVAL
|
||||
# mqtt_client.subscribe(config.MQTT_TOPIC_HELLO, qos=config.MQTT_QOS)
|
||||
mqtt_client.subscribe(config.MQTT_TOPIC_HELLO, qos=config.MQTT_QOS)
|
||||
|
||||
# Temperature sensor setup
|
||||
temperature_sensor_i2c = I2C(scl=Pin(25, Pin.IN, Pin.PULL_UP), sda=Pin(26, Pin.IN, Pin.PULL_UP), freq=100000)
|
||||
temperature_sensor_i2c = I2C(0, scl=Pin(25, Pin.IN, Pin.PULL_UP), sda=Pin(26, Pin.IN, Pin.PULL_UP), freq=100000)
|
||||
# Scan to verify the sensor is connected and detected
|
||||
print("Scanning I2C bus...")
|
||||
devices = temperature_sensor_i2c.scan()
|
||||
@@ -174,13 +188,6 @@ while True:
|
||||
mqtt_hello_sent_timestamp = time.time()
|
||||
pass
|
||||
|
||||
# Sensors
|
||||
print(f"[Main] Reading temperature from sensor...")
|
||||
obj_temp = temperature_sensor.read_object_temp()
|
||||
amb_temp = temperature_sensor.read_ambient_temp()
|
||||
if obj_temp is not None and amb_temp is not None:
|
||||
print(f"Object: {obj_temp:.2f}°C | Ambient: {amb_temp:.2f}°C")
|
||||
|
||||
# 2. Example: Send data to the Heltec board every 5 seconds
|
||||
# uart_device.send("Status Check: WiFi Active")
|
||||
time.sleep(1)
|
||||
Reference in New Issue
Block a user