From f689b03a13779ece0e174e635e4c4917f9762a25 Mon Sep 17 00:00:00 2001 From: Julian Date: Sat, 6 Jul 2024 21:23:57 +0200 Subject: [PATCH] Paint X if email sent --- src/program.py | 78 ++++++++++++++++++++++++++------------------------ 1 file changed, 40 insertions(+), 38 deletions(-) diff --git a/src/program.py b/src/program.py index 449896b..b446c87 100644 --- a/src/program.py +++ b/src/program.py @@ -159,8 +159,7 @@ def shutdown(epd): epd.sleep() epd2in13_V4.epdconfig.module_exit(cleanup=True) print("Linux shutdown...") - #check_call(['sudo', 'poweroff']) - #TODO + #check_call(['sudo', 'poweroff']) #TODO sys.exit(1) pause() @@ -220,12 +219,11 @@ Die aktuelle Hoehe betraegt {3:.0f} cm. Gruesse vom Tank-Computer""".format(meas, sender_email, receiver_email, val) context = ssl.create_default_context() with smtplib.SMTP(smtp_server, smtp_port) as server: - #TODO - #server.set_debuglevel(1) - #server.ehlo() + server.set_debuglevel(1) + server.ehlo() server.starttls(context=context) - #server.login(sender_email, smtp_password.strip()) - #server.sendmail(sender_email, receiver_email, message) + server.login(sender_email, smtp_password.strip()) + server.sendmail(sender_email, receiver_email, message) def display_site_measure(epd, titel, titel_pos, val): dp = Image.new('1', (epd.height, epd.width), 255) @@ -247,32 +245,32 @@ def display_site_main(epd, cl, ph, clm, phm): draw = ImageDraw.Draw(dp) draw.text((19, 31), f"Chlor: {cl:.0f} %", font = font_label, fill = 0) draw.text((149, 31), f"pH-: {ph:.0f} %", font = font_label, fill = 0) - if cl < 80: - draw.rectangle((10, 54, 114, 61), outline = 1, fill = 1) - if cl < 60: - draw.rectangle((10, 66, 114, 73), outline = 1, fill = 1) - if cl < 40: - draw.rectangle((10, 78, 114, 85), outline = 1, fill = 1) - if cl < 20: - draw.rectangle((10, 90, 114, 97), outline = 1, fill = 1) - if cl < ALARM_LEVEL_CM: - if clm == 1: - draw.text((37, 53), "X", font = font_huge, fill = 0) - else: - draw.rectangle((10, 54, 114, 109), outline = 1, fill = 1) - if ph < 80: - draw.rectangle((135, 54, 239, 61), outline = 1, fill = 1) - if ph < 60: - draw.rectangle((135, 66, 239, 73), outline = 1, fill = 1) - if ph < 40: - draw.rectangle((135, 78, 239, 85), outline = 1, fill = 1) - if ph < 20: - draw.rectangle((135, 90, 239, 97), outline = 1, fill = 1) - if ph < ALARM_LEVEL_CM: - if phm == 1: - draw.text((164, 53), "X", font = font_huge, fill = 0) - else: - draw.rectangle((135, 54, 239, 109), outline = 1, fill = 1) + if clm == 1: # wenn mail gesendet (cl < alarm) + # alle Balken ausblenden + draw.rectangle((10, 54, 114, 109), outline = 1, fill = 1) + draw.text((37, 53), "X", font = font_huge, fill = 0) + else: + if cl < 80: #100-80 + draw.rectangle((10, 54, 114, 61), outline = 1, fill = 1) + if cl < 60: #80-60 + draw.rectangle((10, 66, 114, 73), outline = 1, fill = 1) + if cl < 40: #60-40 + draw.rectangle((10, 78, 114, 85), outline = 1, fill = 1) + if cl < 20: #40-20 + draw.rectangle((10, 90, 114, 97), outline = 1, fill = 1) + if phm == 1: # wenn mail gesendet (ph- < alarm) + # alle Balken ausblenden + draw.rectangle((135, 54, 239, 109), outline = 1, fill = 1) + draw.text((164, 53), "X", font = font_huge, fill = 0) + else: + if ph < 80: #100-80 + draw.rectangle((135, 54, 239, 61), outline = 1, fill = 1) + if ph < 60: #80-60 + draw.rectangle((135, 66, 239, 73), outline = 1, fill = 1) + if ph < 40: #60-40 + draw.rectangle((135, 78, 239, 85), outline = 1, fill = 1) + if ph < 20: #40-20 + draw.rectangle((135, 90, 239, 97), outline = 1, fill = 1) epd.display(epd.getbuffer(dp)) if __name__ == '__main__': @@ -324,6 +322,7 @@ if __name__ == '__main__': mavg_ph = MovingAverage(AVG_WINDOWSIZE) clp_prev = -1 php_prev = -1 + force_update = False while True: try: state = buttons.get_state() @@ -414,12 +413,13 @@ if __name__ == '__main__': php = get_percent(ph_leer, ph_voll, ph) print("Chlor: {:10.2f} cm, pH-Minus: {:10.2f} cm".format(cl, ph)) print("Chlor: {:10.2f} %, pH-Minus: {:10.2f} %".format(clp, php)) - clp = round(clp, 0) - php = round(php, 0) - if clp != clp_prev or php != php_prev: + clp_now = round(clp, 0) + php_now = round(php, 0) + if clp_now != clp_prev or php_now != php_prev or force_update: display_site_main(epd, clp, php, cl_mail, ph_mail) - clp_prev = clp - php_prev = php + force_update = False + clp_prev = clp_now + php_prev = php_now if cl_status and abs(cl_leer - ALARM_LEVEL_CM) < cl: print(f"{Fore.RED}Chlor-Tank fast leer!{Style.RESET_ALL}") if cl_mail == 0: @@ -430,6 +430,7 @@ if __name__ == '__main__': config.set('Chlor', 'datum_mail', str(datetime.datetime.now())) with open(FILE, 'w') as configfile: config.write(configfile) + force_update = True if ph_status and abs(ph_leer - ALARM_LEVEL_CM) < ph: print(f"{Fore.RED}pH-Minus-Tank fast leer!{Style.RESET_ALL}") if ph_mail == 0: @@ -440,6 +441,7 @@ if __name__ == '__main__': config.set('pH-', 'datum_mail', str(datetime.datetime.now())) with open(FILE, 'w') as configfile: config.write(configfile) + force_update = True time.sleep(0.5) except KeyboardInterrupt: shutdown(epd) \ No newline at end of file