Temperature Sensor
Build, push image, and notify Watchtower / build-image (push) Successful in 45s
Build, push image, and notify Watchtower / notify (push) Successful in 10s

This commit is contained in:
2026-07-25 16:31:23 +02:00
parent 5a737c931c
commit a0af426c78
4 changed files with 82 additions and 984 deletions
+19 -14
View File
@@ -1,7 +1,7 @@
import _thread
import select
from machine import Pin
from sensors import temperature_gun
from machine import Pin, I2C
from sensors import temperature_sensor
from shared import get_mqtt_client, get_uart, config, payloads
import time
import ujson as json
@@ -16,14 +16,6 @@ def queue_publish(topic, payload):
with queue_lock:
msg_queue.append((topic, payload))
# --- INITIALIZE CAMERA ---
try:
# Pass your confirmed working SCL and SDA pins here
temperature_gun.init_camera(scl_pin=21, sda_pin=22, freq=100000)
except Exception as e:
print("[Main] Critical: Camera setup failed!")
sys.print_exception(e)
# --- READ DEVICE ID ---
try:
with open("device_id.txt", "r") as f:
@@ -161,7 +153,18 @@ def uart_background_thread():
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)
# Scan to verify the sensor is connected and detected
print("Scanning I2C bus...")
devices = temperature_sensor_i2c.scan()
if 0x5A in devices:
print("MLX90614 found at address 0x5A!")
else:
print("MLX90614 not found. Please check your wiring.")
temperature_sensor = temperature_sensor.MLX90614(temperature_sensor_i2c)
while True:
# MQTT HELLO sent every x seconds until we get a response from the orchestrator
@@ -172,9 +175,11 @@ while True:
pass
# Sensors
print(f"[Main] Reading temperature from the gun sensor...")
temp = temperature_gun.read_temperature()
print(f"[Main] Temperature read: {temp}°C")
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")