From abe05b4193c2928bc4845f9fb0a1f01ad055b55a Mon Sep 17 00:00:00 2001 From: WhatTheMike Date: Fri, 17 Mar 2023 23:15:36 -0400 Subject: [PATCH] Updated service and added delay when complete --- octomonitor.py | 36 +++++++++++++++++++++++++----------- octomonitor.service | 1 + 2 files changed, 26 insertions(+), 11 deletions(-) diff --git a/octomonitor.py b/octomonitor.py index 6e529b4..14086e2 100644 --- a/octomonitor.py +++ b/octomonitor.py @@ -34,8 +34,7 @@ import traceback from urllib3.exceptions import InsecureRequestWarning requests.packages.urllib3.disable_warnings(category=InsecureRequestWarning) -logging.basicConfig(level=logging.DEBUG) -#logging.basicConfig(level=logging.INFO) +logging.basicConfig(level=logging.INFO) logger=logging.getLogger('octopimonitor') formatter=logging.Formatter('[{asctime}] [{levelname:<8}] {name}: {message}', '%Y-%m-%d %H:%M:%S', style='{') handler=logging.handlers.RotatingFileHandler(filename='octopimonitor.log', encoding='utf-8', maxBytes=32*1024*1024, backupCount=5) @@ -50,6 +49,17 @@ def datestr(time): def getData(): jsondata=requests.get(fullurl, verify=False).json() jsondatatwo=requests.get(fullurltwo, verify=False).json() + state="" + if jsondatatwo["state"]["flags"]["paused"] == "true": + state="paused" + elif jsondatatwo["state"]["flags"]["printing"] == "true": + state="printing" + elif jsondatatwo["state"]["flags"]["error"] == "true": + state="error" + elif jsondatatwo["state"]["flags"]["cancelling"] == "true": + state="cancelling" + else: + state="unknown" jobdata={ "file":jsondata["currentFilename"].split('/')[-1], "layer":jsondata["layer"]["current"], @@ -62,6 +72,7 @@ def getData(): "bedtarget":jsondatatwo["temperature"]["bed"]["target"], "temp":jsondatatwo["temperature"]["tool0"]["actual"], "target":jsondatatwo["temperature"]["tool0"]["target"], + "state":state } return (jobdata,datetime.datetime.now()) @@ -90,6 +101,7 @@ try: # MONITOR LOOP while True: + epd.init() (jobdata,lastupdate)=getData() paper = Image.new('1', (epd.width, epd.height), 255) # 255: clear the frame draw = ImageDraw.Draw(paper) @@ -110,24 +122,26 @@ try: draw.text((117,250),timestr(lastupdate),font=font14,fill=0) draw.text((117,278),timestr(datetime.datetime.now()),font=font14,fill=0) # (240,82) under ETA + # (25,228) over last update + if jobdata['percent'] == "100": + draw.text((280,82),"Job complete.",font=font14,fill=0) + draw.text((250,96)," Refreshing every 5m.",font=font14,fill=0) + else: + draw.text((280,82),jobdata["state"],font=font18,fill=0) draw.text((25,228),f"{jobdata['bedtemp']}°c/{jobdata['bedtarget']}°c {jobdata['temp']}°c/{jobdata['target']}°c",font=font14,fill=0) # DISPLAY OUR MASTERPIECE epd.display(epd.getbuffer(paper)) epd.sleep() - #time.sleep(30) - sys.exit(0) -# logging.info("4.read bmp file on window") -# Himage2 = Image.new('1', (epd.height, epd.width), 255) # 255: clear the frame -# bmp = Image.open(os.path.join(imgdir, '100x100.bmp')) -# Himage2.paste(bmp, (50,10)) -# epd.display(epd.getbuffer(Himage2)) -# time.sleep(2) + if jobdata['percent'] == "100": + time.sleep(300) + else: + time.sleep(30) - except IOError as e: logging.info(e) except KeyboardInterrupt: logging.info("ctrl + c:") + epd.init() epd4in2.epdconfig.module_exit() exit() diff --git a/octomonitor.service b/octomonitor.service index 287a79e..1a27d4f 100644 --- a/octomonitor.service +++ b/octomonitor.service @@ -18,6 +18,7 @@ User=pi Group=pi WorkingDirectory=/home/pi/epaper/ ExecStart=/usr/bin/python3 /home/pi/epaper/octomonitor.py +KillSignal=SIGINT Restart=on-failure [Install]