diff --git a/examples/mqtt.py b/examples/mqtt.py index b80ca55..3ce8e5b 100644 --- a/examples/mqtt.py +++ b/examples/mqtt.py @@ -66,13 +66,19 @@ def on_connect(client, userdata, flags, rc): print("Failed to connect, return code %d\n", rc) def on_message(client, userdata, msg): - drawblack.text((150, 0), '99', font = font10, fill = 0) - drawblack.text((150, 15), '99', font = font10, fill = 0) - drawblack.text((150, 30), '99', font = font10, fill = 0) - drawblack.text((150, 45), '99', font = font10, fill = 0) - drawblack.text((150, 60), '99', font = font10, fill = 0) + if msg.topic == "openWB/pv/W": + line = 0 + elif msg.topic == "openWB/global/WHouseConsumption": + line = 15 + elif msg.topic == "openWB/evu/W": + line = 30 + elif msg.topic == "openWB/housebattery/%Soc": + line = 45 + elif msg.topic == "openWB/housebattery/W": + line = 60 + drawblack.text((150, line), {msg.payload.decode()}, font = font10, fill = 0) epd.display(epd.getbuffer(HBlackimage), epd.getbuffer(HRedimage)) - print(f"`{msg.topic}`: `{msg.payload.decode()}`") + #print(f"`{msg.topic}`: `{msg.payload.decode()}`") Connected = False #global variable for the state of the connection