39 lines
1.1 KiB
Python
39 lines
1.1 KiB
Python
|
import paho.mqtt.client as mqtt
|
||
|
import json
|
||
|
import argparse
|
||
|
|
||
|
from datetime import datetime
|
||
|
import time
|
||
|
import yaml
|
||
|
|
||
|
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:
|
||
|
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(),
|
||
|
"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)
|
||
|
time.sleep(0.1)
|
||
|
|
||
|
|
||
|
datas = json.dumps({
|
||
|
"assetCode":"",
|
||
|
"timestamp":0,
|
||
|
"dataType":"",
|
||
|
"data": dataList
|
||
|
})
|
||
|
mqttc.publish(f"/device-data/{yamlData['topic']}", datas) # topic, message
|