🌡️ 溫度監控與警報系統
📌 功能簡介
此專案透過 Flask 網站 + SQLite 資料庫,定時從 210.62.179.209/Data.txt 抓取冷凍冷藏室的即時溫度,並具備 超標警報與 Gmail API 通知功能。
同時支援歷史查詢、Excel 匯出與排程紀錄。
🔧 系統架構
-
語言:Python + Flask
-
資料庫:SQLite (
temperatures.db) -
功能模組:
-
requests:抓取即時溫度 -
schedule+threading:背景定時任務 -
pandas:Excel 匯出 -
googleapiclient:Gmail API 寄送通知
-
-
服務監控點:
-
1F前室
-
魚翅保存庫
-
原物料保存庫
-
成品保存庫
-
急速冷凍室
-
製成品預冷室
-
2F冷藏室
-
3F冷藏室
-
📑 功能說明
1. 定時紀錄與警報
-
每 10 分鐘自動抓取一次溫度數據並存入資料庫。
-
若溫度高於設定值(排除除霜時段),會透過 Gmail API 發送異常警報。
-
記錄冷卻時間 (
alert_cooldown_hours),避免重複通知。
2. 設定檔 (config.json)
{
"notifications": {
"enabled": true,
"sender": "zfuntw@gmail.com",
"recipients": ["example@mail.com"],
"alert_cooldown_hours": 3
},
"temperature_settings": {
"1F前室": {"enabled": true, "threshold": 10, "defrost_hours": [3, 15]},
"魚翅保存庫": {"enabled": true, "threshold": -5, "defrost_hours": []}
}
}
3. 前端介面
-
/即時監控頁面,顯示當前溫度 -
/history歷史紀錄查詢,可篩選日期區間 -
/export_excel將指定日期區間匯出 Excel -
/settings設定通知收件人、警報值與除霜時段
4. Gmail API 通知
-
使用
token.json儲存授權憑證。 -
異常時寄送 Email 通知指定人員。
5. 簡易版資料採集程式
另附加 get_temperature_data 腳本:
-
每 10 秒抓取一次溫度資料
-
僅儲存前 4 筆溫度數據至資料庫
📂 資料表結構
temperatures
| 欄位 | 說明 |
|---|---|
| id | 主鍵 |
| timestamp | 紀錄時間 |
| temp_front_room | 1F前室 |
| temp_shark_fin | 魚翅保存庫 |
| temp_raw_material | 原物料保存庫 |
| temp_finished_product | 成品保存庫 |
| temp_blast_freezer | 急速冷凍室 |
| temp_precooling_room | 製成品預冷室 |
| temp_2f | 2F冷藏室 |
| temp_3f | 3F冷藏室 |
▶️ 啟動方式
python app.py
網站預設服務於
👉 https://temp.zfun.com.tw/login
⚠️ 注意事項
-
需先完成 Gmail API OAuth 授權並放置
token.json。 -
除霜時間需在設定檔中明確設定,避免誤報。
-
若無法連線
210.62.179.209,會回傳空值並略過紀錄。
No comments to display
No comments to display