additions and corrections for
deployment instructions
This commit is contained in:
@@ -3,9 +3,11 @@ FROM python:3.13-slim
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
COPY requirements.txt ./
|
||||
COPY listener/requirements.txt ./
|
||||
RUN pip install --no-cache-dir -r requirements.txt
|
||||
|
||||
COPY . .
|
||||
COPY listener/ ./listener
|
||||
COPY models/ ./models
|
||||
|
||||
CMD ["python", "listener.py"]
|
||||
ENV PYTHONPATH=/app
|
||||
CMD ["python", "listener/listener.py"]
|
||||
|
||||
@@ -1,18 +1,17 @@
|
||||
|
||||
import os
|
||||
import json
|
||||
import logging
|
||||
import threading
|
||||
import time
|
||||
# ...requests entfernt...
|
||||
import datetime
|
||||
import paho.mqtt.client as mqtt
|
||||
from sqlalchemy import create_engine
|
||||
from sqlalchemy.orm import sessionmaker
|
||||
from models.models import Client
|
||||
from dotenv import load_dotenv
|
||||
|
||||
load_dotenv("/workspace/.env")
|
||||
if os.getenv("ENV", "development") == "development":
|
||||
from dotenv import load_dotenv
|
||||
load_dotenv(".env")
|
||||
|
||||
# ENV-abhängige Konfiguration
|
||||
ENV = os.getenv("ENV", "development")
|
||||
@@ -28,8 +27,6 @@ logging.basicConfig(level=logging.DEBUG,
|
||||
engine = create_engine(DB_URL)
|
||||
Session = sessionmaker(bind=engine)
|
||||
|
||||
# ...externe Zeitsynchronisation entfernt...
|
||||
|
||||
# MQTT-Callback
|
||||
|
||||
|
||||
@@ -82,6 +79,16 @@ def on_message(client, userdata, msg):
|
||||
except Exception as e:
|
||||
logging.error(f"Fehler bei Verarbeitung: {e}")
|
||||
|
||||
topic_parts = msg.topic.split('/')
|
||||
if len(topic_parts) == 3 and topic_parts[0] == "infoscreen" and topic_parts[1] == "request_group_id":
|
||||
client_id = topic_parts[2]
|
||||
session = Session()
|
||||
client_obj = session.query(Client).filter_by(uuid=client_id).first()
|
||||
group_id = client_obj.group_id if client_obj else None
|
||||
session.close()
|
||||
response_topic = f"infoscreen/response_group_id/{client_id}"
|
||||
client.publish(response_topic, json.dumps({"group_id": group_id}))
|
||||
|
||||
|
||||
def main():
|
||||
mqtt_client = mqtt.Client(protocol=mqtt.MQTTv311, callback_api_version=2)
|
||||
@@ -89,8 +96,9 @@ def main():
|
||||
mqtt_client.connect("mqtt", 1883)
|
||||
mqtt_client.subscribe("infoscreen/discovery")
|
||||
mqtt_client.subscribe("infoscreen/+/heartbeat")
|
||||
mqtt_client.subscribe("infoscreen/request_group_id/#")
|
||||
logging.info(
|
||||
"Listener gestartet und abonniert auf infoscreen/discovery und infoscreen/+/heartbeat")
|
||||
"Listener gestartet und abonniert auf infoscreen/discovery, infoscreen/+/heartbeat und infoscreen/request_group_id/#")
|
||||
mqtt_client.loop_forever()
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user