import time
import dht
from machine import Pin
import ujson
# === Configuration ===
AUTHOR_NAME = "Nishika Agrawal 0901EO231037" # <-- Replace with your name
sensor = dht.DHT22(Pin(15))
def read_sensor():
try:
sensor.measure()
temperature = sensor.temperature()
humidity = sensor.humidity()
return temperature, humidity
except OSError as e:
print("Failed to read sensor:", e)
return None, None
def display_dashboard(temp, hum):
print("\n" + "="*40)
print(f"🌤️ Smart Weather Monitoring Dashboard")
print(f"👨💻 Developer: {AUTHOR_NAME}")
print("="*40)
print(f"🌡️ Temperature : {temp:.2f} °C")
print(f"💧 Humidity : {hum:.2f} %")
print("-"*40)
# Simulated ThingSpeak feed (textual chart)
print("📊 ThingSpeak Simulated Feed")
print("Temp: " + "|" * int(temp))
print("Humidity: " + "|" * int(hum / 2))
print("="*40)
# === Main Loop ===
while True:
temp, hum = read_sensor()
if temp is not None:
# Simulate dashboard view
display_dashboard(temp, hum)
# Also output JSON (like Wokwi dashboard expects)
print(ujson.dumps({
"temperature": temp,
"humidity": hum
}))
time.sleep(3)