From 6f62fbca0d51b9ad71ef729be80e602b8e638a58 Mon Sep 17 00:00:00 2001 From: xyj <10908227994@qq.com> Date: Mon, 5 Feb 2024 10:51:39 +0800 Subject: [PATCH] update --- config.py | 32 ++++++++++++++++++++++++++++++++ xumu.py | 12 ++++++------ 2 files changed, 38 insertions(+), 6 deletions(-) diff --git a/config.py b/config.py index c805644..0f7848a 100644 --- a/config.py +++ b/config.py @@ -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], diff --git a/xumu.py b/xumu.py index a6f35f1..ac578cc 100644 --- a/xumu.py +++ b/xumu.py @@ -254,12 +254,12 @@ async def message_publish(data): r = requests.post(baseHost + insertUri, headers=headers, json=send_json) r = r.json() res.append(r) - # TODO 如果是报警数据,则发送到报警数据表 - 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) + if is_warning(deviceId, v, t): + # 如果是报警数据,则发送到报警数据表 + send_json = insert_to_warning_sql(deviceId, v, t) + r = requests.post(baseHost + insertUri, headers=headers, json=send_json) + r = r.json() + res.append(r) return BaseResponse(data=res) except Exception as e: return BaseResponse(code=500, msg=str(e))