De echte 'clean' versie!!!!

This commit is contained in:
Atilla
2024-03-12 20:57:53 +01:00
parent 925f73469b
commit 380764d1a6
8 changed files with 64 additions and 124 deletions

View File

@@ -1,24 +1,13 @@
import sys
import uuid
import json
from os.path import dirname, abspath, join
from paho.mqtt import subscribe
root_dir = dirname(dirname(abspath(__file__)))
sys.path.append(root_dir)
def on_message(client, userdata, message):
payload_str = message.payload.decode("utf-8")
data = json.loads(payload_str)
from mqtt.mqtt_client import create_client, start_loop
mqtt_topic = "goodgarden/soil_temperature"
def on_connect(client, userdata, flags, rc):
client.subscribe(mqtt_topic)
print(f"Subscribed to {mqtt_topic}")
def on_message(client, userdata, msg):
message = msg.payload.decode()
print(f"Message received on topic {msg.topic}: {message}")
print(f"Message received on topic {message.topic}: {data}")
if __name__ == "__main__":
unique_client_id = f"subscriber_{uuid.uuid4()}"
client = create_client(unique_client_id, on_connect, on_message)
start_loop(client)
topic = "goodgarden/soil_temperature"
subscribe.callback(on_message, topic)