From d5710eaa20c33b22fcd109bc9d368bb210cfd20e Mon Sep 17 00:00:00 2001 From: robert Date: Wed, 31 Jan 2024 23:33:08 +0000 Subject: [PATCH] add try --- examples/solar-monitoring.py | 101 ++++++++++++++++++----------------- 1 file changed, 51 insertions(+), 50 deletions(-) diff --git a/examples/solar-monitoring.py b/examples/solar-monitoring.py index e177927..ade1056 100644 --- a/examples/solar-monitoring.py +++ b/examples/solar-monitoring.py @@ -62,61 +62,62 @@ def subscribe(client: mqtt_client, topic): def run(): - client = connect_mqtt() - house_battery_soc = subscribe(client, topic_house_battery_soc) - house_battery_power = subscribe(client, topic_house_battery_power) - power_import_export = subscribe(client, topic_power_import_export) - pv_power = subscribe(client, topic_pv_power) - house_power = subscribe(client, topic_house_power) - car_soc = subscribe(client, topic_car_soc) - charge_point_power = subscribe(client, topic_charge_point_power) + try: + client = connect_mqtt() + house_battery_soc = subscribe(client, topic_house_battery_soc) + house_battery_power = subscribe(client, topic_house_battery_power) + power_import_export = subscribe(client, topic_power_import_export) + pv_power = subscribe(client, topic_pv_power) + house_power = subscribe(client, topic_house_power) + car_soc = subscribe(client, topic_car_soc) + charge_point_power = subscribe(client, topic_charge_point_power) - logging.info("epd2in13b_V3 Demo") - - epd = epd2in13b_V3.EPD() - #logging.info("init and Clear") - #epd.init() - #epd.Clear() - - # Drawing on the image - logging.info("Drawing") - font16 = ImageFont.truetype(os.path.join(picdir, 'Font.ttc'), 16) - font18 = ImageFont.truetype(os.path.join(picdir, 'Font.ttc'), 18) - - # Drawing on the Horizontal image - logging.info("1.Drawing on the Horizontal image...") - HBlackimage = Image.new('1', (epd.height, epd.width), 255) # 298*126 - HRYimage = Image.new('1', (epd.height, epd.width), 255) # 298*126 ryimage: red or yellow image - drawblack = ImageDraw.Draw(HBlackimage) - drawry = ImageDraw.Draw(HRYimage) - drawblack.text((2, 0), 'PV Production', font = font16, fill = 0) - drawblack.text((2, 16), 'Hausverbrauch', font = font16, fill = 0) - drawblack.text((2, 32), 'Strom Import', font = font16, fill = 0) - drawblack.text((2, 48), 'Batterie', font = font16, fill = 0) - drawblack.text((2, 64), 'Batterie Entladen', font = font16, fill = 0) - drawblack.text((2, 80), 'Auto Laden', font = font16, fill = 0) + logging.info("epd2in13b_V3 Demo") + + epd = epd2in13b_V3.EPD() + #logging.info("init and Clear") + #epd.init() + #epd.Clear() + + # Drawing on the image + logging.info("Drawing") + font16 = ImageFont.truetype(os.path.join(picdir, 'Font.ttc'), 16) + font18 = ImageFont.truetype(os.path.join(picdir, 'Font.ttc'), 18) + + # Drawing on the Horizontal image + logging.info("1.Drawing on the Horizontal image...") + HBlackimage = Image.new('1', (epd.height, epd.width), 255) # 298*126 + HRYimage = Image.new('1', (epd.height, epd.width), 255) # 298*126 ryimage: red or yellow image + drawblack = ImageDraw.Draw(HBlackimage) + drawry = ImageDraw.Draw(HRYimage) + drawblack.text((2, 0), 'PV Production', font = font16, fill = 0) + drawblack.text((2, 16), 'Hausverbrauch', font = font16, fill = 0) + drawblack.text((2, 32), 'Strom Import', font = font16, fill = 0) + drawblack.text((2, 48), 'Batterie', font = font16, fill = 0) + drawblack.text((2, 64), 'Batterie Entladen', font = font16, fill = 0) + drawblack.text((2, 80), 'Auto Laden', font = font16, fill = 0) - drawblack.text((100, 80), str(charge_point_power), font = font16, fill = 0) - epd.display(epd.getbuffer(HBlackimage), epd.getbuffer(HRYimage)) + drawblack.text((100, 80), str(charge_point_power), font = font16, fill = 0) + epd.display(epd.getbuffer(HBlackimage), epd.getbuffer(HRYimage)) - #logging.info("Clear...") - #epd.init() - #epd.Clear() + #logging.info("Clear...") + #epd.init() + #epd.Clear() + + logging.info("Goto Sleep...") + epd.sleep() + + client.loop_forever() - logging.info("Goto Sleep...") - epd.sleep() + except IOError as e: + logging.info(e) + + except KeyboardInterrupt: + logging.info("ctrl + c:") + epd2in13b_V3.epdconfig.module_exit() + exit() - client.loop_forever() if __name__ == '__main__': - run() - - -#except IOError as e: -# logging.info(e) - -#except KeyboardInterrupt: -# logging.info("ctrl + c:") -# epd2in13b_V3.epdconfig.module_exit() -# exit() + run() \ No newline at end of file