restructure

This commit is contained in:
Robert Borzutzki 2022-10-19 19:51:26 +02:00
parent 4598ef9f59
commit fbf3c5d488

View File

@ -32,33 +32,11 @@ pw = "phio6yiR9ohs1veeghu4WaeGhaiRi8he4EiWasheev4faeku8tohdiuthah7zahP"
client_id = "solarmonitor"
try:
logging.info("epd2in13bc Demo")
epd = epd2in13bc.EPD()
logging.info("init and Clear")
epd.init()
epd.Clear()
time.sleep(1)
# Drawing on the image
logging.info("Drawing")
font10 = ImageFont.truetype(os.path.join(picdir, 'Font.ttc'), 12)
# Drawing on the Horizontal image
logging.info("1.Drawing on the Horizontal image...")
HBlackimage = Image.new('1', (epd.height, epd.width), 255) # 298*126
HRedimage = Image.new('1', (epd.height, epd.width), 255) # 298*126 ryimage: red or yellow image
drawblack = ImageDraw.Draw(HBlackimage)
drawred = ImageDraw.Draw(HRedimage)
drawblack.text((5, 0), 'PV Produktion', font = font10, fill = 0)
drawblack.text((5, 15), 'Hausverbrauch', font = font10, fill = 0)
drawblack.text((5, 30), 'Strom Import/Export', font = font10, fill = 0)
drawblack.text((5, 45), 'Batterie %', font = font10, fill = 0)
drawblack.text((5, 60), 'Batterie Laden/Entladen', font = font10, fill = 0)
epd.display(epd.getbuffer(HBlackimage), epd.getbuffer(HRedimage))
#epd.display(epd.getbuffer(HBlackimage))
#time.sleep(1)
except IOError as e:
logging.info(e)
@ -68,7 +46,6 @@ except KeyboardInterrupt:
epd2in13bc.epdconfig.module_exit()
exit()
def on_connect(client, userdata, flags, rc):
if rc == 0:
print("Connected to MQTT Broker!")
@ -87,28 +64,14 @@ def on_message(client, userdata, msg):
if msg.topic == "openWB/pv/W":
value_pvProduction = ""+msg.payload.decode()
line = 0
elif msg.topic == "openWB/global/WHouseConsumption":
value_wHouseConsumption = ""+msg.payload.decode()
line = 15
elif msg.topic == "openWB/evu/W":
value_energyImportExport = ""+msg.payload.decode()
line = 30
elif msg.topic == "openWB/housebattery/%Soc":
value_houseBatterySoC = ""+msg.payload.decode()
line = 45
elif msg.topic == "openWB/housebattery/W":
value_houseBatteryLoadUnload = ""+msg.payload.decode()
line = 60
print(line)
print("PvP: "+value_pvProduction)
print("Hou: "+value_wHouseConsumption)
print("I/E: "+value_energyImportExport)
print("SoC: "+value_houseBatterySoC)
print("Bio: "+value_houseBatteryLoadUnload)
#print(f"`{msg.topic}`: `{msg.payload.decode()}`")
client = mqtt_client.Client(client_id, protocol=paho.MQTTv31)
client.username_pw_set(username, password=pw)
@ -138,7 +101,24 @@ client.subscribe(topic_houseBatteryLoadUnload)
try:
while True:
time.sleep(10)
# Drawing on the image
logging.info("Drawing")
font10 = ImageFont.truetype(os.path.join(picdir, 'Font.ttc'), 12)
# Drawing on the Horizontal image
logging.info("1.Drawing on the Horizontal image...")
HBlackimage = Image.new('1', (epd.height, epd.width), 255) # 298*126
HRedimage = Image.new('1', (epd.height, epd.width), 255) # 298*126 ryimage: red or yellow image
drawblack = ImageDraw.Draw(HBlackimage)
drawred = ImageDraw.Draw(HRedimage)
drawblack.text((5, 0), 'PV Produktion', font = font10, fill = 0)
drawblack.text((5, 15), 'Hausverbrauch', font = font10, fill = 0)
drawblack.text((5, 30), 'Strom Import/Export', font = font10, fill = 0)
drawblack.text((5, 45), 'Batterie %', font = font10, fill = 0)
drawblack.text((5, 60), 'Batterie Laden/Entladen', font = font10, fill = 0)
epd.display(epd.getbuffer(HBlackimage), epd.getbuffer(HRedimage))
#epd.display(epd.getbuffer(HBlackimage))
print("-----")
logging.info("test")
logging.info("PvP: "+value_pvProduction)
@ -146,18 +126,20 @@ try:
logging.info("I/E: "+value_energyImportExport)
logging.info("SoC: "+value_houseBatterySoC)
logging.info("Bio: "+value_houseBatteryLoadUnload)
drawblack.rectangle((150, 0, 220, 50), fill = 255)
#drawblack.rectangle((150, 0, 220, 50), fill = 255)
drawblack.text((150, 0), value_pvProduction, font = font10, fill = 0)
drawblack.rectangle((150, 15, 220, 50), fill = 255)
#drawblack.rectangle((150, 15, 220, 50), fill = 255)
drawblack.text((150, 15), value_wHouseConsumption, font = font10, fill = 0)
drawblack.rectangle((150, 30, 220, 50), fill = 255)
#drawblack.rectangle((150, 30, 220, 50), fill = 255)
drawblack.text((150, 30), value_energyImportExport, font = font10, fill = 0)
drawblack.rectangle((150, 45, 220, 50), fill = 255)
#drawblack.rectangle((150, 45, 220, 50), fill = 255)
drawred.text((150, 45), value_houseBatterySoC, font = font10, fill = 0)
drawblack.rectangle((150, 60, 220, 50), fill = 1)
#drawblack.rectangle((150, 60, 220, 50), fill = 255)
drawblack.text((150, 60), value_houseBatteryLoadUnload, font = font10, fill = 0)
epd.display(epd.getbuffer(HBlackimage), epd.getbuffer(HRedimage))
time.sleep(10)
except KeyboardInterrupt:
print("exiting")