awx-perfermance-arm32/main.py

50 lines
1.4 KiB
Python
Raw Normal View History

2023-09-06 05:49:19 +00:00
import paho.mqtt.client as mqtt
import json
2023-09-08 04:44:49 +00:00
import argparse
2023-09-06 05:49:19 +00:00
from datetime import datetime
import time
import yaml
2023-09-08 04:44:49 +00:00
parser = argparse.ArgumentParser()
parser.add_argument('-config',help='')
args = parser.parse_args()
with open(f'/usr/local/sdt/app/{args.config}/config.yaml', encoding='UTF-8') as f:
2023-09-06 05:49:19 +00:00
yamlData = yaml.load(f, Loader=yaml.FullLoader)
mqttc = mqtt.Client() # puclisher 이름
mqttc.username_pw_set("sdt", "251327")
mqttc.connect("13.209.39.139", 32259)
while True:
dataList = []
for n in range(10):
data = {
"timestamp": datetime.now().timestamp(),
2023-09-08 04:44:49 +00:00
"current": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
"voltage": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
"do": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
"er1": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
"er2": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
2023-09-06 05:49:19 +00:00
}
dataList.append(data)
time.sleep(0.1)
2023-09-08 04:44:49 +00:00
dataBody = {
"slot": 1,
"chamber": 1,
"channel": 1,
"list": dataList,
}
2023-09-06 05:49:19 +00:00
datas = json.dumps({
2023-09-08 04:44:49 +00:00
"modeCode": "test1",
"assetCode": "perfermance",
"dataType":"DATA",
"data": dataBody
2023-09-06 05:49:19 +00:00
})
mqttc.publish(f"/device-data/{yamlData['topic']}", datas) # topic, message
2023-09-08 04:44:49 +00:00
# mqttc.publish(f"/device-data/perfermance", datas) # topic, message