Add testasset

This commit is contained in:
Daniel Kluge
2023-10-31 14:02:46 +01:00
parent 5e58f84b38
commit 948aa78324
4 changed files with 48 additions and 0 deletions
+21
View File
@@ -0,0 +1,21 @@
from paho.mqtt import client as mqtt_client
import time
from datetime import datetime
from os import environ
is_docker = environ.get('AM_I_IN_A_DOCKER_CONTAINER', False)
broker = "mqttbroker" if is_docker else "localhost"
client = mqtt_client.Client("testasset")
# Wait for broker
if is_docker: time.sleep(3)
client.connect(broker, 1883, 60)
# Send the current datetime stamp to the topic "testopic/testparam1" and "testopic/testparam2" every 1 second
while True:
now = datetime.now()
client.publish("testopic/testparam1", str(now))
client.publish("testopic/testparam2", str(now))
time.sleep(1)