|
|
|
@ -18,7 +18,7 @@ fullurltwo=f"{octoprint}/{printerpath}?apikey={apikey}"
|
|
|
|
|
|
|
|
|
|
import sys
|
|
|
|
|
import os
|
|
|
|
|
import requests,datetime
|
|
|
|
|
import requests,datetime,signal
|
|
|
|
|
imgdir = "/home/pi/epaper/img"#os.path.join(os.path.dirname(os.path.dirname(os.path.realpath(__file__))), 'img')#dontask
|
|
|
|
|
libdir = "/home/pi/epaper/lib"#os.path.join(os.path.dirname(os.path.dirname(os.path.realpath(__file__))), 'lib')
|
|
|
|
|
if os.path.exists(libdir):
|
|
|
|
@ -41,14 +41,35 @@ handler=logging.handlers.RotatingFileHandler(filename='octopimonitor.log', encod
|
|
|
|
|
handler.setFormatter(formatter)
|
|
|
|
|
logger.addHandler(handler)
|
|
|
|
|
|
|
|
|
|
def debug(a):
|
|
|
|
|
logger.debug(a)
|
|
|
|
|
def info(a):
|
|
|
|
|
logger.info(a)
|
|
|
|
|
def warn(a):
|
|
|
|
|
logger.warning(a)
|
|
|
|
|
def error(a):
|
|
|
|
|
logger.error(a)
|
|
|
|
|
def critical(a):
|
|
|
|
|
logger.critical(a)
|
|
|
|
|
def timestr(time):
|
|
|
|
|
return f"{datestr(time)} {time.hour:02}:{time.minute:02}"
|
|
|
|
|
def datestr(time):
|
|
|
|
|
return f"{time.year}-{time.month:02}-{time.day:02}"
|
|
|
|
|
|
|
|
|
|
def trapsignal(signalnum, frame):
|
|
|
|
|
# https://stackabuse.com/handling-unix-signals-in-python/
|
|
|
|
|
info(f"Caught signal {signalnum}")
|
|
|
|
|
if signalnum == 1:
|
|
|
|
|
info(f"Caught hup - reloading (signal {signalnum})")
|
|
|
|
|
(jobdata,lastupdate)=getData()
|
|
|
|
|
drawData(jobdata,lastupdate)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def getData():
|
|
|
|
|
info(f"requesting data from {octoprint}...")
|
|
|
|
|
jsondata=requests.get(fullurl, verify=False).json()
|
|
|
|
|
jsondatatwo=requests.get(fullurltwo, verify=False).json()
|
|
|
|
|
info(f"Data received. Porgcessing.")
|
|
|
|
|
state=""
|
|
|
|
|
if jsondatatwo["state"]["flags"]["paused"]:
|
|
|
|
|
state="paused"
|
|
|
|
@ -78,20 +99,21 @@ def getData():
|
|
|
|
|
}
|
|
|
|
|
return (jobdata,datetime.datetime.now())
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
logging.info("Octopi print monitor starting...")
|
|
|
|
|
# INIT
|
|
|
|
|
epd = epd4in2.EPD()
|
|
|
|
|
logging.info("init and Clear")
|
|
|
|
|
epd.init()
|
|
|
|
|
epd.Clear()
|
|
|
|
|
|
|
|
|
|
def drawData(jobdata,lastupdate):
|
|
|
|
|
info(f"Loading fonts and images")
|
|
|
|
|
font14 = ImageFont.truetype(os.path.join(imgdir, 'Font.ttc'), 14)
|
|
|
|
|
font16 = ImageFont.truetype(os.path.join(imgdir, 'Font.ttc'), 16)
|
|
|
|
|
font18 = ImageFont.truetype(os.path.join(imgdir, 'Font.ttc'), 18)
|
|
|
|
|
font20 = ImageFont.truetype(os.path.join(imgdir, 'Font.ttc'), 20)
|
|
|
|
|
font24 = ImageFont.truetype(os.path.join(imgdir, 'Font.ttc'), 24)
|
|
|
|
|
# LOCS
|
|
|
|
|
# LOAD OUR BACKGROUND
|
|
|
|
|
bg = Image.open(os.path.join(imgdir, 'backgroundv2.bmp'))
|
|
|
|
|
info(f"Initializing ePaper display")
|
|
|
|
|
epd.init()
|
|
|
|
|
paper = Image.new('1', (epd.width, epd.height), 255) # Blank canvas
|
|
|
|
|
draw = ImageDraw.Draw(paper)
|
|
|
|
|
paper.paste(bg, (0, 0))
|
|
|
|
|
# ADD OUR TEXT
|
|
|
|
|
# filename (60,6) file
|
|
|
|
|
# percent (125,45) percent
|
|
|
|
|
# eta (265,45) eta
|
|
|
|
@ -100,17 +122,7 @@ try:
|
|
|
|
|
# lastlayer (125,162) lastlayertime
|
|
|
|
|
# lastupdate (117,250)
|
|
|
|
|
# lastrefresh (117,278)
|
|
|
|
|
|
|
|
|
|
# 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)
|
|
|
|
|
# LOAD OUR BACKGROUND
|
|
|
|
|
bg = Image.open(os.path.join(imgdir, 'backgroundv2.bmp'))
|
|
|
|
|
paper.paste(bg, (0, 0))
|
|
|
|
|
# ADD OUR TEXT
|
|
|
|
|
info(f"Preparing job data on canvas...")
|
|
|
|
|
if len(jobdata['file']) < 20:
|
|
|
|
|
draw.text((60, 6), jobdata['file'], font = font18, fill = 0)
|
|
|
|
|
else:
|
|
|
|
@ -132,18 +144,36 @@ try:
|
|
|
|
|
draw.text((288,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
|
|
|
|
|
info("Drawing canvas on ePaper display")
|
|
|
|
|
epd.display(epd.getbuffer(paper))
|
|
|
|
|
epd.sleep()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
signal.signal(signal.SIGHUP, trapsignal)
|
|
|
|
|
info("Octopi print monitor starting...")
|
|
|
|
|
# INIT
|
|
|
|
|
epd = epd4in2.EPD()
|
|
|
|
|
info("init and Clear")
|
|
|
|
|
epd.init()
|
|
|
|
|
epd.Clear()
|
|
|
|
|
|
|
|
|
|
# MONITOR LOOP
|
|
|
|
|
while True:
|
|
|
|
|
(jobdata,lastupdate)=getData()
|
|
|
|
|
drawData(jobdata,lastupdate)
|
|
|
|
|
if jobdata['percent'] == "100" or jobdata['bedtarget'] == jobdata['target']:
|
|
|
|
|
info("Jobs idle - sleeping for 5 minutes")
|
|
|
|
|
time.sleep(300)
|
|
|
|
|
else:
|
|
|
|
|
info("Print in progress - sleeping for 30 seconds")
|
|
|
|
|
time.sleep(30)
|
|
|
|
|
|
|
|
|
|
except IOError as e:
|
|
|
|
|
logging.info(e)
|
|
|
|
|
error(e)
|
|
|
|
|
|
|
|
|
|
except KeyboardInterrupt:
|
|
|
|
|
logging.info("ctrl + c:")
|
|
|
|
|
critical("ctrl + c:")
|
|
|
|
|
epd.init()
|
|
|
|
|
epd4in2.epdconfig.module_exit()
|
|
|
|
|
exit()
|
|
|
|
|