update
This commit is contained in:
parent
8c43382caf
commit
62fb24d7a4
37
config.py
37
config.py
|
@ -43,3 +43,40 @@ send3 = {
|
||||||
"v": ["test1", 10.62, 2],
|
"v": ["test1", 10.62, 2],
|
||||||
"l": 50
|
"l": 50
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def RFID_template(deviceId):
|
||||||
|
return [
|
||||||
|
f"CREATE TIMESERIES root.farm.{deviceId}.iccid(cid) WITH datatype=TEXT,ENCODING=PLAIN",
|
||||||
|
f"CREATE TIMESERIES root.farm.{deviceId}.temperature(v) WITH datatype=FLOAT,ENCODING=PLAIN",
|
||||||
|
f"CREATE TIMESERIES root.farm.{deviceId}.RFID(r) WITH datatype=TEXT,ENCODING=PLAIN",
|
||||||
|
f"CREATE TIMESERIES root.farm.{deviceId}.type(t) WITH datatype=INT32,ENCODING=PLAIN",
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
def common_template(deviceId):
|
||||||
|
return [
|
||||||
|
f"CREATE TIMESERIES root.farm.{deviceId}.iccid(cid) WITH datatype=TEXT,ENCODING=PLAIN",
|
||||||
|
f"CREATE TIMESERIES root.farm.{deviceId}.value(v) WITH datatype=FLOAT,ENCODING=PLAIN",
|
||||||
|
f"CREATE TIMESERIES root.farm.{deviceId}.type(t) WITH datatype=INT32,ENCODING=PLAIN",
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
def air_template(deviceId):
|
||||||
|
return [
|
||||||
|
f"CREATE TIMESERIES root.farm.{deviceId}.iccid(cid) WITH datatype=TEXT,ENCODING=PLAIN",
|
||||||
|
f"CREATE TIMESERIES root.farm.{deviceId}.air_temperature(at) WITH datatype=FLOAT,ENCODING=PLAIN",
|
||||||
|
f"CREATE TIMESERIES root.farm.{deviceId}.air_humidity(ah) WITH datatype=FLOAT,ENCODING=PLAIN",
|
||||||
|
f"CREATE TIMESERIES root.farm.{deviceId}.type(t) WITH datatype=INT32,ENCODING=PLAIN",
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
# 数据库创建字段sql语句
|
||||||
|
def get_sql(deviceId, type):
|
||||||
|
match type:
|
||||||
|
case 0:
|
||||||
|
return RFID_template(deviceId)
|
||||||
|
case 1:
|
||||||
|
return air_template(deviceId)
|
||||||
|
case _:
|
||||||
|
return common_template(deviceId)
|
||||||
|
|
14
main.py
14
main.py
|
@ -91,7 +91,7 @@ async def register(request: Request):
|
||||||
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 BaseResponse(code=301, msg="data valid error")
|
return BaseResponse(code=301, msg=f"data valid error, receive_len:{receive_len}")
|
||||||
deviceId = payload["d"]
|
deviceId = payload["d"]
|
||||||
iccid = payload["cid"]
|
iccid = payload["cid"]
|
||||||
type = payload["t"]
|
type = payload["t"]
|
||||||
|
@ -103,8 +103,18 @@ async def register(request: Request):
|
||||||
"values_list": [[iccid, deviceId, type]],
|
"values_list": [[iccid, deviceId, type]],
|
||||||
"is_aligned": False
|
"is_aligned": False
|
||||||
}
|
}
|
||||||
|
res = []
|
||||||
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())
|
res.append(r.json())
|
||||||
|
# 创建相应的数据库和字段
|
||||||
|
sql_list = get_sql(deviceId, type)
|
||||||
|
for sql in sql_list:
|
||||||
|
send_json = {
|
||||||
|
"sql": sql
|
||||||
|
}
|
||||||
|
r = requests.post(baseHost + insertUri, headers=headers, json=send_json)
|
||||||
|
res.append(r.json())
|
||||||
|
return BaseResponse(data=json.dumps(res))
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
return BaseResponse(code=500, msg=str(e))
|
return BaseResponse(code=500, msg=str(e))
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue