From 0a0dcd94870a67d55262bd3ba65c00d797be6b13 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EC=88=98=EC=A4=80?= Date: Mon, 11 Sep 2023 11:23:00 +0900 Subject: [PATCH] first commit --- awx-perfermance.service | 10 ++++++++++ config.yaml | 1 + install.sh | 7 +++++++ main.py | 38 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 56 insertions(+) create mode 100644 awx-perfermance.service create mode 100644 config.yaml create mode 100755 install.sh create mode 100644 main.py diff --git a/awx-perfermance.service b/awx-perfermance.service new file mode 100644 index 0000000..a7afeb0 --- /dev/null +++ b/awx-perfermance.service @@ -0,0 +1,10 @@ +[Unit] +Description=awx-perfermance + +[Service] +ExecStart=/home/sdt/miniconda3/bin/python3 /usr/local/sdt/app/appName/main.py -config appName +Restart=always +RestartSec=10 + +[Install] +WantedBy=multi-user.target diff --git a/config.yaml b/config.yaml new file mode 100644 index 0000000..6b4aef8 --- /dev/null +++ b/config.yaml @@ -0,0 +1 @@ +topic: perfermance \ No newline at end of file diff --git a/install.sh b/install.sh new file mode 100755 index 0000000..5447c1a --- /dev/null +++ b/install.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +sudo sed -i "s/appName/$1/g" /usr/local/sdt/app/$1/awx-perfermance.service +sudo cp /usr/local/sdt/app/$1/awx-perfermance.service /etc/systemd/system/$1.service +sudo systemctl start $1 +sudo systemctl enable $1 + diff --git a/main.py b/main.py new file mode 100644 index 0000000..0e1bc42 --- /dev/null +++ b/main.py @@ -0,0 +1,38 @@ +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