Compare commits

...

2 Commits
test1 ... main

Author SHA1 Message Date
이수준 259fc53ba2 first commit 2023-09-08 13:44:49 +09:00
이수준 931a38fd0a first commit 2023-09-06 14:54:44 +09:00
4 changed files with 37 additions and 19 deletions

View File

@ -0,0 +1,10 @@
[Unit]
Description=awx-perfermance-arm32
[Service]
ExecStart=/usr/bin/python3 /usr/local/sdt/app/appName/main.py -config appName
Restart=always
RestartSec=10
[Install]
WantedBy=multi-user.target

View File

@ -1,10 +0,0 @@
[Unit]
Description=awx-perfermance
[Service]
ExecStart=/home/sdt/miniconda3/bin/python3 /usr/local/sdt/app/awx-perfermance/main.py
Restart=always
RestartSec=10
[Install]
WantedBy=multi-user.target

View File

@ -1,5 +1,7 @@
#!/bin/bash #!/bin/bash
sudo cp /usr/local/sdt/app/awx-perfermance/awx-perfermance.service /etc/systemd/system/ sudo sed -i "s/appName/$1/g" /usr/local/sdt/app/$1/awx-perfermance-arm32.service
sudo systemctl start awx-perfermance sudo cp /usr/local/sdt/app/$1/awx-perfermance.service /etc/systemd/system/$1.service
sudo systemctl enable awx-perfermance sudo systemctl start $1
sudo systemctl enable $1

28
main.py
View File

@ -1,11 +1,16 @@
import paho.mqtt.client as mqtt import paho.mqtt.client as mqtt
import json import json
import argparse
from datetime import datetime from datetime import datetime
import time import time
import yaml import yaml
with open('/usr/local/sdt/app/awx-perfermance/config.yaml', encoding='UTF-8') as f: 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) yamlData = yaml.load(f, Loader=yaml.FullLoader)
@ -18,16 +23,27 @@ while True:
for n in range(10): for n in range(10):
data = { data = {
"timestamp": datetime.now().timestamp(), "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], "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],
} }
dataList.append(data) dataList.append(data)
time.sleep(0.1) time.sleep(0.1)
dataBody = {
"slot": 1,
"chamber": 1,
"channel": 1,
"list": dataList,
}
datas = json.dumps({ datas = json.dumps({
"assetCode":"", "modeCode": "test1",
"timestamp":0, "assetCode": "perfermance",
"dataType":"", "dataType":"DATA",
"data": dataList "data": dataBody
}) })
mqttc.publish(f"/device-data/{yamlData['topic']}", datas) # topic, message mqttc.publish(f"/device-data/{yamlData['topic']}", datas) # topic, message
# mqttc.publish(f"/device-data/perfermance", datas) # topic, message