first commit

This commit is contained in:
이수준 2023-09-08 13:44:49 +09:00
parent 931a38fd0a
commit 259fc53ba2
4 changed files with 28 additions and 20 deletions

View File

@ -2,7 +2,7 @@
Description=awx-perfermance-arm32
[Service]
ExecStart=/usr/bin/python3 /usr/local/sdt/app/awx-perfermance-arm32/main.py
ExecStart=/usr/bin/python3 /usr/local/sdt/app/appName/main.py -config appName
Restart=always
RestartSec=10

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
sudo cp /usr/local/sdt/app/awx-perfermance-arm32/awx-perfermance-arm32.service /etc/systemd/system/
sudo systemctl start awx-perfermance-arm32
sudo systemctl enable awx-perfermance-arm32
sudo sed -i "s/appName/$1/g" /usr/local/sdt/app/$1/awx-perfermance-arm32.service
sudo cp /usr/local/sdt/app/$1/awx-perfermance.service /etc/systemd/system/$1.service
sudo systemctl start $1
sudo systemctl enable $1

28
main.py
View File

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