update
This commit is contained in:
parent
bf33dc04e1
commit
823fbfa21b
|
@ -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'
|
||||
|
|
10
xumu.py
10
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))
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue