From 823fbfa21b34f1e256062dc209cb803678acfa6f Mon Sep 17 00:00:00 2001 From: xyj <10908227994@qq.com> Date: Thu, 25 Jan 2024 09:42:51 +0800 Subject: [PATCH] update --- config.py | 1 + xumu.py | 10 +++------- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/config.py b/config.py index c044429..d6d42a7 100644 --- a/config.py +++ b/config.py @@ -16,6 +16,7 @@ baseHost = "https://iot.lihaink.cn/iotdb_restapi" # 注意这里前面不能加/ insertUri = "rest/v2/insertRecords" queryUri = "rest/v2/query" +nonQueryUri = "rest/v2/nonQuery" # 鉴权 username = 'root' password = 'root' diff --git a/xumu.py b/xumu.py index 0b62893..d59d6a7 100644 --- a/xumu.py +++ b/xumu.py @@ -58,7 +58,7 @@ async def rest_query(request: Request): @app.post("/api/xumu/device/query") async def get_device(device: Device): try: - sql = "SELECT * FROM root.device where 1=1" + sql = "SELECT * FROM root.device where time>=0" # 检查iccid是否有值,如果有,添加到SQL语句中 if device.iccid: sql += f" and iccid = '{device.iccid}'" @@ -89,19 +89,16 @@ async def register(request: Request): payload = json.loads(payload) send_len = payload["l"] if receive_len != send_len: - print(receive_len) return BaseResponse(code=301, msg=f"data valid error, receive_len:{receive_len}") deviceId = payload["d"] iccid = payload["cid"] type = payload["t"] - # TODO 检测该设备是否已经创建 + # 该设备是否已经创建 device = Device(iccid=iccid, deviceId=deviceId, type=type) a_device = await get_device(device) - print(a_device) if a_device.code == 200: v = a_device.data["values"] if len(v) != 0: - print("该设备已经注册过了") return BaseResponse(code=302, msg="该设备已经注册过了") # 创建该设备 send_json = { @@ -121,11 +118,10 @@ async def register(request: Request): send_json = { "sql": sql } - r = requests.post(baseHost + insertUri, headers=headers, json=send_json) + r = requests.post(baseHost + nonQueryUri, headers=headers, json=send_json) res.append(r.json()) return BaseResponse(data=res) except Exception as e: - print(e) return BaseResponse(code=500, msg=str(e))