This commit is contained in:
xyj 2024-01-24 15:46:31 +08:00
parent d255c1b465
commit 90a3636ebd
1 changed files with 26 additions and 26 deletions

52
main.py
View File

@ -116,32 +116,32 @@ async def process_data(request: Request):
r = await request.body() r = await request.body()
print(r) print(r)
return 200 return 200
try: # try:
data = await request.body() # data = await request.body()
data = data.decode("utf-8") # data = data.decode("utf-8")
data = json.loads(data) # data = json.loads(data)
payload = data["payload"] # payload = data["payload"]
receive_len = len(payload) # receive_len = len(payload)
payload = json.loads(payload) # payload = json.loads(payload)
send_len = payload["l"] # send_len = payload["l"]
if receive_len != send_len: # if receive_len != send_len:
return 301 # return 301
m = payload["m"] # m = payload["m"]
v = payload["v"] # v = payload["v"]
t = payload["t"] # t = payload["t"]
cid = v[0] # cid = v[0]
send_json = { # send_json = {
"devices": ["root.farm." + cid], # "devices": ["root.farm." + cid],
"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]],
"values_list": [v], # "values_list": [v],
"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()) # return BaseResponse(data=r.json())
except Exception as e: # except Exception as e:
return BaseResponse(code=500, msg=str(e)) # return BaseResponse(code=500, msg=str(e))
if __name__ == '__main__': if __name__ == '__main__':