Compare commits

..

1 Commits
test2 ... main

Author SHA1 Message Date
이수준 259fc53ba2 first commit 2023-09-08 13:44:49 +09:00
4 changed files with 28 additions and 20 deletions

View File

@ -2,7 +2,7 @@
Description=awx-perfermance-arm32 Description=awx-perfermance-arm32
[Service] [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 Restart=always
RestartSec=10 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 #!/bin/bash
sudo cp /usr/local/sdt/app/awx-perfermance-arm32/awx-perfermance-arm32.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-arm32 sudo cp /usr/local/sdt/app/$1/awx-perfermance.service /etc/systemd/system/$1.service
sudo systemctl enable awx-perfermance-arm32 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-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) 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