5 Commits

Author SHA1 Message Date
93bbccf5c3 fix typo in configuration
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/tag/woodpecker Pipeline was successful
2024-01-11 15:32:32 +01:00
012bb46b2a fix configuration
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/tag/woodpecker Pipeline was successful
2024-01-11 15:27:28 +01:00
ae1828a06e fix use of modbus module
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/tag/woodpecker Pipeline was successful
2024-01-11 15:23:07 +01:00
51dec2b281 fix ci script
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/tag/woodpecker Pipeline was successful
2024-01-11 15:16:47 +01:00
4ea85f3c7e change config to env, add ci-script
All checks were successful
ci/woodpecker/tag/woodpecker Pipeline was successful
2024-01-11 14:52:36 +01:00
5 changed files with 107 additions and 14 deletions

30
.woodpecker.yml Normal file
View File

@ -0,0 +1,30 @@
steps:
build:
image: plugins/kaniko
settings:
repo: gitea.hottis.de/wn/digitaltwin1
registry:
from_secret: container_registry
tags: latest,${CI_COMMIT_SHA},${CI_COMMIT_TAG}
username:
from_secret: container_registry_username
password:
from_secret: container_registry_password
dockerfile: Dockerfile
when:
- event: [push, tag]
deploy:
image: portainer/kubectl-shell:latest
secrets:
- source: kube_config
target: KUBE_CONFIG_CONTENT
commands:
- export IMAGE_TAG=$CI_COMMIT_TAG
- printf "$KUBE_CONFIG_CONTENT" > /tmp/kubeconfig
- export KUBECONFIG=/tmp/kubeconfig
- cat ./deployment/install-yml.tmpl | sed -e 's,%IMAGETAG%,'$IMAGE_TAG','g | kubectl apply -f -
when:
- event: tag

View File

@ -0,0 +1,44 @@
apiVersion: v1
kind: Namespace
metadata:
name: homea
---
apiVersion: v1
kind: ConfigMap
metadata:
name: digitaltwin1
namespace: homea
data:
MQTT__BROKER: "emqx01-anonymous-cluster-internal.broker.svc.cluster.local"
MQTT__DIGITALOUTPUTTOPICPREFIX: "dt1/coil"
MQTT__DIGITALINPUTTOPICPREFIX: "dt1/di"
MQTT__ANALOGINPUTEVENTTOPICPREFIX: "dt1/ai/event"
MQTT__ANALOGINPUTPERIODICTOPICPREFIX: "dt1/ai/periodic"
MQTT__ANALOGINPUTPUBLISHPERIOD: "60.0"
MQTT__DISABLEANALOGINPUTEVENTPUBLISHING: "true"
MODBUS__CLIENT: "172.16.2.31"
MODBUS__SCANRATE: "0.25"
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: digitaltwin1
namespace: homea
labels:
app: digitaltwin1
spec:
replicas: 1
selector:
matchLabels:
app: digitaltwin1
template:
metadata:
labels:
app: digitaltwin1
spec:
containers:
- name: digitaltwin1
image: gitea.hottis.de/wn/digitaltwin1:%IMAGETAG%
envFrom:
- configMapRef:
name: digitaltwin1

View File

@ -1,4 +1,4 @@
from pymodbus.client.sync import ModbusTcpClient as ModbusClient
from pymodbus.client import ModbusTcpClient as ModbusClient
from pymodbus.exceptions import ModbusIOException
from time import sleep
import threading

30
src/config.py Normal file
View File

@ -0,0 +1,30 @@
import os
from loguru import logger
class Config:
OPTIONS = {
'mqtt': [ 'broker',
'digitalOutputTopicPrefix',
'digitalInputTopicPrefix',
'analogInputEventTopicPrefix',
'analogInputPeriodicTopicPrefix',
'analogInputPublishPeriod',
'disableAnalogInputEventPublishing' ],
'modbus': [ 'client', 'scanrate' ]
}
def __init__(self):
self.values = {}
for section, keys in Config.OPTIONS.items():
self.values[section] = {}
for key in keys:
varname = f"{section}__{key}".upper()
try:
self.values[section][key] = os.environ[varname]
logger.info(f"Config: {section} {key} -> {self.values[section][key]}")
except KeyError:
pass
def __getitem__(self, section):
return self.values[section]

View File

@ -8,7 +8,7 @@ from ModbusHandler import ModbusHandler
from MqttEventPublisher import MqttEventPublisher, mqttEventPublisherStart
from MqttPeriodPublisher import MqttPeriodPublisher
from MqttCoilSubscriber import MqttCoilSubscriber
from config import Config
deathBell = threading.Event()
@ -21,18 +21,7 @@ def exceptHook(args):
logger.info("DigitalTwin1 starting")
parser = argparse.ArgumentParser(description="DigitalTwin1")
parser.add_argument('--config', '-f',
help='Config file, default is $pwd/config/config.ini',
required=False,
default='./config/config.ini')
args = parser.parse_args()
config = configparser.ConfigParser()
config.read(args.config)
config = Config()
processImage = ProcessImage()