From 201f835aa799f934a40f2c183a88c8bff5078664 Mon Sep 17 00:00:00 2001 From: Robert Borzutzki Date: Wed, 19 Oct 2022 17:46:36 +0200 Subject: [PATCH] fix --- examples/mqtt.py | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/examples/mqtt.py b/examples/mqtt.py index b21c88d..b49335e 100644 --- a/examples/mqtt.py +++ b/examples/mqtt.py @@ -94,16 +94,7 @@ def on_connect(client, userdata, flags, rc): print("Failed to connect, return code %d\n", rc) def on_message(client, userdata, msg): - global value_pvProduction - global value_wHouseConsumption - global value_energyImportExport - global value_houseBatterySoC - global value_houseBatteryLoadUnload - value_pvProduction = "" - value_wHouseConsumption = "" - value_energyImportExport = "" - value_houseBatterySoC = "" - value_houseBatteryLoadUnload = "" + if msg.topic == "openWB/pv/W": value_pvProduction = ""+msg.payload.decode() @@ -133,6 +124,18 @@ def on_message(client, userdata, msg): client = mqtt_client.Client(client_id, protocol=paho.MQTTv31) client.username_pw_set(username, password=pw) client.on_connect = on_connect + +global value_pvProduction +global value_wHouseConsumption +global value_energyImportExport +global value_houseBatterySoC +global value_houseBatteryLoadUnload +value_pvProduction = "" +value_wHouseConsumption = "" +value_energyImportExport = "" +value_houseBatterySoC = "" +value_houseBatteryLoadUnload = "" + client.on_message = on_message client.connect(broker, port=port)