This commit is contained in:
xyj 2024-01-25 14:10:42 +08:00
parent 3dde96f179
commit 6ae16e0e66
2 changed files with 56 additions and 14 deletions

View File

@ -28,20 +28,23 @@ headers = {
} }
# RFID # RFID
send1 = { send1 = {
"m": ["cid", "r", "v", "t"], "m": ["cid", "r", "v"],
"v": ["abcd", "rfid", 10.62, 0], "v": ["abcd", "rfid", 10.62],
"t": 0,
"l": 63 "l": 63
} }
# 空气 # 空气
send2 = { send2 = {
"m": ["cid", "at", "ah", "t"], "m": ["cid", "at", "ah"],
"v": ["test2", 10.62, 50.22, 1], "v": ["test2", 10.62, 50.22],
"t": 1,
"l": 65 "l": 65
} }
# 普通 # 普通
send3 = { send3 = {
"m": ["cid", "v", "t"], "m": ["cid", "v"],
"v": ["test1", 10.62, 2], "v": ["test1", 10.62],
"t": 2,
"l": 50 "l": 50
} }
@ -72,6 +75,12 @@ def air_template(deviceId):
] ]
def rfid_deviceId(rfid, deviceId):
return [
f"insert into root.rfid(timestamp, rfid, deviceId) values(0, '{rfid}', '{deviceId}')"
]
# 数据库创建字段sql语句 # 数据库创建字段sql语句
def get_sql(deviceId, type): def get_sql(deviceId, type):
match type: match type:

49
xumu.py
View File

@ -63,10 +63,25 @@ async def rest_query(request: Request):
# RFID查询接口 # RFID查询接口
@app.post("/api/xumu/rfid/query") @app.post("/api/xumu/rfid/query")
async def rest_query(rfid_query: RFIDQuery): async def rfid_query(rfid_entity: RFIDQuery):
rfid = rfid_query.rfid try:
rfid = rfid_entity.rfid
pass sql = f"select deviceId from root.rfid where rfid='{rfid}'"
send_json = {
"sql": sql
}
r = requests.post(baseHost + queryUri, headers=headers, json=send_json)
if r.status_code != 200:
return BaseResponse(data=r.json(), code=404, msg="404")
r = r.json()
values = r["values"]
if len(values) == 0:
return BaseResponse(msg="No Such RFID", code=500)
deviceId = values[0][0]
send_json = DataQuery(deviceId=deviceId)
return await data_query(send_json)
except Exception as e:
return BaseResponse(code=500, msg=str(e))
# 设备查询接口 # 设备查询接口
@ -157,12 +172,28 @@ async def process_data(request: Request):
m = payload["m"] m = payload["m"]
v = payload["v"] v = payload["v"]
t = payload["t"] t = payload["t"]
# TODO 判断t是否为00 则代表是RFID设备需要做一个映射 res = []
cid = v[0] # 判断t是否为00 则代表是RFID设备需要做一个映射
if t == 0:
rfid = v[1]
deviceId = v[0]
sql_list = rfid_deviceId(rfid, deviceId)
sql = sql_list[0]
send_json = {
"sql": sql
}
r = requests.post(baseHost + nonQueryUri, headers=headers, json=send_json)
if r.status_code != 200:
return BaseResponse(code=r.status_code, msg=r.json())
r = r.json()
if r["code"] != 200:
return BaseResponse(code=500, msg=r)
res.append(r)
deviceId = v[0]
m.append("t") m.append("t")
v.append(t) v.append(t)
send_json = { send_json = {
"devices": ["root.farm." + cid], "devices": ["root.farm." + deviceId],
"timestamps": [int(time.time() * 1000)], "timestamps": [int(time.time() * 1000)],
"measurements_list": [m], "measurements_list": [m],
"data_types_list": [dataTypes[t]], "data_types_list": [dataTypes[t]],
@ -170,7 +201,9 @@ async def process_data(request: Request):
"is_aligned": False "is_aligned": False
} }
r = requests.post(baseHost + insertUri, headers=headers, json=send_json) r = requests.post(baseHost + insertUri, headers=headers, json=send_json)
return BaseResponse(data=r.json()) r = r.json()
res.append(r)
return BaseResponse(data=res)
except Exception as e: except Exception as e:
return BaseResponse(code=500, msg=str(e)) return BaseResponse(code=500, msg=str(e))