Setup: Make Docker Compose, Scheduler, and Simclient fully operational
This commit is contained in:
6
simclient/Dockerfile
Normal file
6
simclient/Dockerfile
Normal file
@@ -0,0 +1,6 @@
|
||||
FROM python:3.13-slim
|
||||
WORKDIR /app
|
||||
COPY requirements.txt .
|
||||
RUN pip install --no-cache-dir -r requirements.txt
|
||||
COPY . .
|
||||
CMD ["python", "simclient.py"]
|
||||
1
simclient/requirements.txt
Normal file
1
simclient/requirements.txt
Normal file
@@ -0,0 +1 @@
|
||||
paho-mqtt
|
||||
24
simclient/simclient.py
Normal file
24
simclient/simclient.py
Normal file
@@ -0,0 +1,24 @@
|
||||
# simclient/simclient.py
|
||||
import time
|
||||
import paho.mqtt.client as mqtt
|
||||
|
||||
|
||||
def on_message(client, userdata, msg):
|
||||
print(f"Empfangen: {msg.topic} {msg.payload.decode()}")
|
||||
|
||||
|
||||
def main():
|
||||
client = mqtt.Client()
|
||||
client.on_message = on_message
|
||||
# Im Docker-Netzwerk: Hostname des MQTT-Brokers ist "mqtt"
|
||||
client.connect("mqtt", 1883)
|
||||
client.subscribe("infoscreen/+/now")
|
||||
while True:
|
||||
# Heartbeat senden
|
||||
client.publish("infoscreen/client1/heartbeat", "alive")
|
||||
client.loop(timeout=1.0)
|
||||
time.sleep(5)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user