Updated service and added delay when complete

main
parent 2cc80506b5
commit abe05b4193

@ -34,8 +34,7 @@ import traceback
from urllib3.exceptions import InsecureRequestWarning from urllib3.exceptions import InsecureRequestWarning
requests.packages.urllib3.disable_warnings(category=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') logger=logging.getLogger('octopimonitor')
formatter=logging.Formatter('[{asctime}] [{levelname:<8}] {name}: {message}', '%Y-%m-%d %H:%M:%S', style='{') 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) 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(): def getData():
jsondata=requests.get(fullurl, verify=False).json() jsondata=requests.get(fullurl, verify=False).json()
jsondatatwo=requests.get(fullurltwo, 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={ jobdata={
"file":jsondata["currentFilename"].split('/')[-1], "file":jsondata["currentFilename"].split('/')[-1],
"layer":jsondata["layer"]["current"], "layer":jsondata["layer"]["current"],
@ -62,6 +72,7 @@ def getData():
"bedtarget":jsondatatwo["temperature"]["bed"]["target"], "bedtarget":jsondatatwo["temperature"]["bed"]["target"],
"temp":jsondatatwo["temperature"]["tool0"]["actual"], "temp":jsondatatwo["temperature"]["tool0"]["actual"],
"target":jsondatatwo["temperature"]["tool0"]["target"], "target":jsondatatwo["temperature"]["tool0"]["target"],
"state":state
} }
return (jobdata,datetime.datetime.now()) return (jobdata,datetime.datetime.now())
@ -90,6 +101,7 @@ try:
# MONITOR LOOP # MONITOR LOOP
while True: while True:
epd.init()
(jobdata,lastupdate)=getData() (jobdata,lastupdate)=getData()
paper = Image.new('1', (epd.width, epd.height), 255) # 255: clear the frame paper = Image.new('1', (epd.width, epd.height), 255) # 255: clear the frame
draw = ImageDraw.Draw(paper) draw = ImageDraw.Draw(paper)
@ -110,24 +122,26 @@ try:
draw.text((117,250),timestr(lastupdate),font=font14,fill=0) draw.text((117,250),timestr(lastupdate),font=font14,fill=0)
draw.text((117,278),timestr(datetime.datetime.now()),font=font14,fill=0) draw.text((117,278),timestr(datetime.datetime.now()),font=font14,fill=0)
# (240,82) under ETA # (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) draw.text((25,228),f"{jobdata['bedtemp']}°c/{jobdata['bedtarget']}°c {jobdata['temp']}°c/{jobdata['target']}°c",font=font14,fill=0)
# DISPLAY OUR MASTERPIECE # DISPLAY OUR MASTERPIECE
epd.display(epd.getbuffer(paper)) epd.display(epd.getbuffer(paper))
epd.sleep() epd.sleep()
#time.sleep(30) if jobdata['percent'] == "100":
sys.exit(0) time.sleep(300)
# logging.info("4.read bmp file on window") else:
# Himage2 = Image.new('1', (epd.height, epd.width), 255) # 255: clear the frame time.sleep(30)
# bmp = Image.open(os.path.join(imgdir, '100x100.bmp'))
# Himage2.paste(bmp, (50,10))
# epd.display(epd.getbuffer(Himage2))
# time.sleep(2)
except IOError as e: except IOError as e:
logging.info(e) logging.info(e)
except KeyboardInterrupt: except KeyboardInterrupt:
logging.info("ctrl + c:") logging.info("ctrl + c:")
epd.init()
epd4in2.epdconfig.module_exit() epd4in2.epdconfig.module_exit()
exit() exit()

@ -18,6 +18,7 @@ User=pi
Group=pi Group=pi
WorkingDirectory=/home/pi/epaper/ WorkingDirectory=/home/pi/epaper/
ExecStart=/usr/bin/python3 /home/pi/epaper/octomonitor.py ExecStart=/usr/bin/python3 /home/pi/epaper/octomonitor.py
KillSignal=SIGINT
Restart=on-failure Restart=on-failure
[Install] [Install]

Loading…
Cancel
Save