Compare commits

...

2 Commits

Author SHA1 Message Date
YujinChu a47ea039de new 2023-09-08 08:15:58 +00:00
YujinChu 10d67c039b check ok 2023-09-08 08:12:39 +00:00
9 changed files with 165 additions and 3 deletions

View File

@ -7,6 +7,7 @@ import minimalmodbus
import serial.rs485 import serial.rs485
import subprocess import subprocess
import json import json
import yaml
import queue import queue
import paho.mqtt.client as mqtt import paho.mqtt.client as mqtt
import numpy as np import numpy as np
@ -38,6 +39,7 @@ parser.add_argument('-config',help='')
args = parser.parse_args() args = parser.parse_args()
ROOT_PATH = f"/usr/local/sdt/app/{args.config}" ROOT_PATH = f"/usr/local/sdt/app/{args.config}"
DEVICE_PATH = f"/etc/sdt/device-control"
############################################################################### ###############################################################################
# JSON FILE READ # # JSON FILE READ #
@ -47,6 +49,10 @@ with open(f"{ROOT_PATH}/connect_info.json","r") as f:
#with open(f"{args.config}/connect_info.json","r") as f: #with open(f"{args.config}/connect_info.json","r") as f:
info = json.load(f) info = json.load(f)
with open(f"{DEVICE_PATH}/config.yaml","r") as f:
#with open(f"{args.config}/connect_info.json","r") as f:
dev_info = yaml.load(f, Loader=yaml.FullLoader)
############################################################################### ###############################################################################
# Shared memory setting # # Shared memory setting #
@ -65,8 +71,6 @@ a = [ data[str(n+1)] for n in range(64)]
a = np.array(a) a = np.array(a)
############################################################################### ###############################################################################
# Get Data from Shared Memory # # Get Data from Shared Memory #
############################################################################### ###############################################################################
@ -80,7 +84,8 @@ b[:] = a[:]
# MQTT Broker Setting # # MQTT Broker Setting #
############################################################################### ###############################################################################
MQTT_TOPIC = info['mqtt']['topic'] #MQTT_TOPIC = info['mqtt']['topic']
MQTT_TOPIC = dev_info['assetcode']
MQTT_ID = info['mqtt']['id'] MQTT_ID = info['mqtt']['id']
MQTT_PW = info['mqtt']['pw'] MQTT_PW = info['mqtt']['pw']
MQTT_HOST_IP = info['mqtt']['host_ip'] MQTT_HOST_IP = info['mqtt']['host_ip']

23
AWX_shm_updater.py Normal file
View File

@ -0,0 +1,23 @@
import numpy as np
from multiprocessing import shared_memory
import time
import json
import argparse
existing_shm = shared_memory.SharedMemory(name="DO-shm")
c = np.ndarray((64,), dtype=np.int32, buffer=existing_shm.buf)
parser = argparse.ArgumentParser()
parser.add_argument('-config',help='')
args = parser.parse_args()
ROOT_PATH = f"/usr/local/sdt/app/{args.config}"
while True:
with open(f"{ROOT_PATH}/config.json", 'r') as file:
jsonData = json.load(file)
for n in range(64):
c[n]=jsonData[str(n+1)]
time.sleep(2)

18
AWX_shm_updater.py~ Normal file
View File

@ -0,0 +1,18 @@
import numpy as np
from multiprocessing import shared_memory
import time
import json
existing_shm = shared_memory.SharedMemory(name="DO-shm")
c = np.ndarray((64,), dtype=np.int32, buffer=existing_shm.buf)
file_path = "./config.json"
while True:
with open(file_path, 'r') as file:
jsonData = json.load(file)
for n in range(64):
c[n]=jsonData[str(n+1)]
time.sleep(2)

10
AWX_shm_updater.service Normal file
View File

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

10
AWX_shm_updater.service~ Normal file
View File

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

66
config.json~ Normal file
View File

@ -0,0 +1,66 @@
{
"1": 1,
"2": 1,
"3": 1,
"4": 1,
"5": 1,
"6": 1,
"7": 1,
"8": 1,
"9": 1,
"10": 0,
"11": 0,
"12": 0,
"13": 0,
"14": 0,
"15": 0,
"16": 1,
"17": 0,
"18": 0,
"19": 0,
"20": 0,
"21": 0,
"22": 0,
"23": 0,
"24": 0,
"25": 0,
"26": 0,
"27": 0,
"28": 0,
"29": 0,
"30": 0,
"31": 0,
"32": 0,
"33": 0,
"34": 0,
"35": 0,
"36": 1,
"37": 0,
"38": 0,
"39": 0,
"40": 0,
"41": 0,
"42": 0,
"43": 0,
"44": 0,
"45": 0,
"46": 1,
"47": 0,
"48": 0,
"49": 0,
"50": 0,
"51": 0,
"52": 0,
"53": 0,
"54": 0,
"55": 0,
"56": 1,
"57": 0,
"58": 0,
"59": 0,
"60": 0,
"61": 0,
"62": 0,
"63": 0,
"64": 0
}

View File

@ -7,3 +7,6 @@ sudo cp /usr/local/sdt/app/$1/AWX_collector.service /etc/systemd/system/$1.servi
sudo cp /usr/local/sdt/app/$1/AWX_shm_updater.service /etc/systemd/system/AWX_shm_updater.service sudo cp /usr/local/sdt/app/$1/AWX_shm_updater.service /etc/systemd/system/AWX_shm_updater.service
sudo systemctl start $1 sudo systemctl start $1
sudo systemctl enable $1 sudo systemctl enable $1
sudo systemctl start AWX_shm_updater
sudo systemctl enable AWX_shm_updater

9
install.sh~ Normal file
View File

@ -0,0 +1,9 @@
#!/bin/bash
pip install -r requirements.txt
sudo sed -i "s/appName/$1/g" /usr/local/sdt/app/$1/AWX_collector.service
sudo cp /usr/local/sdt/app/$1/AWX_collector.service /etc/systemd/system/$1.service
sudo cp /usr/local/sdt/app/$1/AWX_shm_updater.service /etc/systemd/system/AWX_shm_updater.service
sudo systemctl start $1
sudo systemctl enable $1

18
shm_updater.py~ Normal file
View File

@ -0,0 +1,18 @@
import numpy as np
from multiprocessing import shared_memory
import time
import json
existing_shm = shared_memory.SharedMemory(name="do_shm2")
c = np.ndarray((32,), dtype=np.int32, buffer=existing_shm.buf)
file_path = "./config.json"
while True:
with open(file_path, 'r') as file:
jsonData = json.load(file)
for n in range(32):
c[n]=jsonData[str(n+1)]
time.sleep(2)