awx-perfermance/main.py

41 lines
1.2 KiB
Python
Raw Normal View History

2023-10-16 06:41:52 +00:00
import paho.mqtt.client as mqtt
2023-09-11 02:23:00 +00:00
import json
import argparse
from datetime import datetime
import time
import yaml
parser = argparse.ArgumentParser()
parser.add_argument('-config',help='')
args = parser.parse_args()
2023-10-18 07:09:00 +00:00
iwith open(f'/usr/local/sdt/app/{args.config}/config.json', encoding='UTF-8') as f:
2023-10-17 08:40:08 +00:00
# with open(f'./config.json', encoding='UTF-8') as f:
jsonData = json.load(f)
2023-09-11 02:23:00 +00:00
2023-10-16 06:39:08 +00:00
mqttc = mqtt.Client() # puclisher 이름
mqttc.username_pw_set("sdt", "251327")
mqttc.connect("13.209.39.139", 32259)
2023-10-12 00:53:29 +00:00
# f = open(f'/usr/local/sdt/app/{args.config}/text.txt')
2023-09-11 02:23:00 +00:00
while True:
2023-10-16 06:39:08 +00:00
# print(f"Config value: {yamlData['topic']}", flush=True)
dataList = []
for n in range(10):
data = {
"timestamp": datetime.now().timestamp(),
"data": [1 ,2 ,3 ,4 ,5 ,6 ,1, 1, 2, 3, 1 ,2 ,3 ,4 ,5 ,6 ,1, 1, 2, 3, 1 ,2 ,3 ,4 ,5 ,6 ,1, 1, 2, 3, 1 ,2 ,3 ,4 ,5 ,6 ,1, 1, 2, 3, 1 ,2 ,3 ,4 ,5 ,6 ,1, 1, 2, 3, 1 ,2 ,3 ,4 ,5 ,6 ,1, 1, 2, 3, 4, 5, 6, 1],
}
dataList.append(data)
datas = json.dumps({
"assetCode":"",
"timestamp":0,
"dataType":"",
"data": dataList
})
2023-10-17 08:40:08 +00:00
mqttc.publish(f"/sdt-cloud/{jsonData['topic']}", datas) # topic, message
2023-09-25 01:20:46 +00:00
time.sleep(2)