Thuta Learning
ရှာဖွေရန်
ProjectsHardwarebeginner

Mini Project Part 3: Temperature Monitor — Web Dashboard

စိတ်လျှော့ပါ။ ဒီခန်းကို စာအုပ်လိုမဟုတ်ဘဲ စကားပြောသလိုပဲ၊ နားလည်လွယ်အောင် ရှင်းပါမယ်။

ဒီခန်းပြီးရင် ဘာတတ်သွားမလဲ

  • Mini Project Part 3: Temperature Monitor — Web Dashboard ကို ကြောက်စရာမလိုအောင် နားလည်မယ်
  • ကိုယ်တိုင် hardware wiring/code ကို run ကြည့်တတ်မယ်
  • Real project ထဲမှာ ဒီ concept ကို ချက်ချင်း အသုံးချတတ်မယ်

ခဏလေး ဒီလိုပဲ စဉ်းစားကြည့်

'Setting Up a Web Server on Pi' lesson ကို ဒီနေရာမှာ ပေါင်းစပ် အသုံးချမှာပါ — Flask route တစ်ခုက temp_log.csv ဖိုင်ကို ဖတ်ပြီး, latest reading (current temp/humidity) + history table (last N readings) ကို HTML page အဖြစ် render ပါတယ်။ Auto-refresh (HTML meta refresh tag ဒါမှမဟုတ် simple JavaScript setInterval) ကို ထည့်ရင် page ကို manual reload မလိုဘဲ latest data ကို ပုံမှန် ပြသနေပါလိမ့်မယ်။

လက်တွေ့ scenario နဲ့ ချိတ်ကြည့်မယ်

Flask route ထဲမှာ csv.reader ဖြင့် temp_log.csv ကို ဖတ်, last 20 row ကို list အဖြစ် ယူပြီး HTML template ထဲ loop ဖြင့် table row အဖြစ် render ပါ — dashboard ကို phone browser ကနေ http://raspberrypi.local:5000 ဖြင့် ဝင်ကြည့်ရင် Temperature Monitor project တစ်ခုလုံး (hardware → data collection → web display) ပြီးစီးသွားပါလိမ့်မယ်။

အတူတူ ကြည့်မယ်

python
from flask import Flask
import csv

app = Flask(__name__)

@app.route('/')
def dashboard():
    with open('temp_log.csv') as f:
        rows = list(csv.reader(f))[-20:]  # last 20 readings
    latest = rows[-1] if rows else ['--', '--', '--']
    rows_html = ''.join(f'<tr><td>{r[0]}</td><td>{r[1]}°C</td><td>{r[2]}%</td></tr>' for r in rows)
    return f'''
    <meta http-equiv="refresh" content="10">
    <h1>Current: {latest[1]}°C, {latest[2]}%</h1>
    <table border="1"><tr><th>Time</th><th>Temp</th><th>Humidity</th></tr>{rows_html}</table>
    '''

if __name__ == '__main__':
    app.run(host='0.0.0.0', port=5000)
You should see
http://raspberrypi.local:5000 ကို ဝင်ကြည့်ရင် current temperature/humidity ကို header မှာ ပြပြီး, history table ကို ၁၀ စက္ကန့်တစ်ခါ auto-refresh ဖြင့် ပြသမည်။

၅ မိနစ် စမ်းကြည့်

Part 1-2 ရဲ့ hardware + logging script ကို ဒီ dashboard code နဲ့ ပေါင်းစပ်ပြီး Temperature Monitor project ကို end-to-end run ကြည့်ပါ — ဒါက tutorial တစ်ခုလုံးရဲ့ capstone project ဖြစ်ပါတယ်။

သတိလေးတစ်ချက်

Production-ready project ဖြစ်ချင်ရင် logging script + dashboard script ကို ယခင်အခန်း 'Running Services on Boot' lesson အတိုင်း systemd service ၂ ခု (log-service, dashboard-service) အဖြစ် register ထားရင် Pi restart ဖြစ်လည်း auto-run ဆက်ဖြစ်နေပါလိမ့်မယ်။

ဒီနေရာမှာ လူအများမှားတတ်တယ်

  • Logging script (Part 2) ကို background မှာ run မထားဘဲ Dashboard script (Part 3) ကိုပဲ run ခြင်း — log file ထဲ data အသစ် ဆက်မထည့်ဘူး, dashboard ထဲ old data ချည်း ကျန်နေခြင်း
  • Both script (logging + dashboard) ကို terminal window တစ်ခုတည်းမှာ run ကြိုးစားခြင်း — separate process/terminal (ဒါမှမဟုတ် systemd service ၂ ခု) လိုအပ်

အခု ကိုယ်တိုင် စမ်းကြည့်

Part 1-2 ရဲ့ hardware + logging script ကို ဒီ dashboard code နဲ့ ပေါင်းစပ်ပြီး Temperature Monitor project ကို end-to-end run ကြည့်ပါ — ဒါက tutorial တစ်ခုလုံးရဲ့ capstone project ဖြစ်ပါတယ်။

You'll know it worked when: http://raspberrypi.local:5000 ကို ဝင်ကြည့်ရင် current temperature/humidity ကို header မှာ ပြပြီး, history table ကို ၁၀ စက္ကန့်တစ်ခါ auto-refresh ဖြင့် ပြသမည်။

Mini Project Part 3: Temperature Monitor — Web Dashboard | Thuta Learning