This commit is contained in:
xyj 2024-02-05 10:51:39 +08:00
parent fa44f490e2
commit 6f62fbca0d
2 changed files with 38 additions and 6 deletions

View File

@ -83,6 +83,38 @@ def rfid_deviceId(rfid, deviceId):
]
def is_warning(deviceId, v, t):
match t:
case 0:
temperature = v[1]
if 41.0 <= temperature or temperature <= 37.0:
return True
case 1:
air_temperature = v[1]
air_humidity = v[2]
if 40.0 <= air_temperature or air_temperature <= 0:
return True
if 80.0 <= air_humidity or air_humidity <= 30.0:
return True
case 2:
danqi = v[1]
if danqi >= 1.24:
return True
case 3:
jiawan = v[1]
if jiawan > 1000:
return True
case 4:
zaoyin = v[1]
if zaoyin >= 55:
return True
case 5:
yanwu = v[1]
if yanwu >= 200:
return True
return False
def insert_to_warning_sql(deviceId, v, t):
return {
"devices": ["root.warning." + deviceId],

View File

@ -254,9 +254,9 @@ async def message_publish(data):
r = requests.post(baseHost + insertUri, headers=headers, json=send_json)
r = r.json()
res.append(r)
# TODO 如果是报警数据,则发送到报警数据表
if is_warning(deviceId, v, t):
# 如果是报警数据,则发送到报警数据表
send_json = insert_to_warning_sql(deviceId, v, t)
print(send_json)
r = requests.post(baseHost + insertUri, headers=headers, json=send_json)
r = r.json()
res.append(r)