2026年5月19日 星期二

[水井USR] 自動更新水井USR網站上即時魚溫資料

 


Python測試程式(由ChatGPT產生):

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import requests

url = "https://shuijingusr.pythonanywhere.com/api/pond/sensor-reading/"

payload = {
    "token": "abc123",
    "farm_name": "蛤之美生態養殖場",
    "pond_code": "1",
    "water_temperature": 28.9,
    "salinity": 18.4,
    "ph": 7.6,
    "dissolved_oxygen": 6.8,
    "water_source": "直流變頻水車運轉中",
    "recorded_at": "2026-05-19T10:30:00+08:00"
}

response = requests.post(url, json=payload)

print("狀態碼:", response.status_code)

try:
    print("回傳資料:", response.json())
except Exception:
    print("伺服器回傳不是 JSON:")
    print(response.text)

執行結果:
狀態碼: 201
回傳資料: {'ok': True, 'message': '魚塭感測資料已成功寫入', 'data': {'id': 7, 'farm': '蛤之美生態養殖場', 'pond_id': 1, 'pond_code': '1', 'pond_name': '文蛤', 'water_temperature': 28.9, 'salinity': 18.4, 'ph': 7.6, 'dissolved_oxygen': 6.8, 'water_source': '直流變頻水車運轉中', 'status': 'normal', 'status_display': '正常', 'alert_message': '目前水質穩定', 'recorded_at': '2026-05-19T10:30:00+08:00'}}

沒有留言:

張貼留言