Updates to survivability of klipper or moonraker restarts
This commit is contained in:
parent
2c135f1aa8
commit
85031a0e51
@ -91,7 +91,7 @@ class KlippyWebsocket(threading.Thread):
|
|||||||
GLib.PRIORITY_HIGH_IDLE,
|
GLib.PRIORITY_HIGH_IDLE,
|
||||||
self._callback,
|
self._callback,
|
||||||
response['method'],
|
response['method'],
|
||||||
response['params'][0]
|
response['params'][0] if "params" in response else {}
|
||||||
)
|
)
|
||||||
return
|
return
|
||||||
|
|
||||||
@ -109,12 +109,10 @@ class KlippyWebsocket(threading.Thread):
|
|||||||
self.ws.send(json.dumps(data))
|
self.ws.send(json.dumps(data))
|
||||||
|
|
||||||
def on_open(self, ws):
|
def on_open(self, ws):
|
||||||
print("### ws open ###")
|
|
||||||
logger.info("### ws open ###")
|
logger.info("### ws open ###")
|
||||||
self.connected = True
|
self.connected = True
|
||||||
|
|
||||||
def on_close(self, ws):
|
def on_close(self, ws):
|
||||||
print("### ws closed ###")
|
|
||||||
logger.info("### ws closed ###")
|
logger.info("### ws closed ###")
|
||||||
self.connected = False
|
self.connected = False
|
||||||
|
|
||||||
@ -130,14 +128,18 @@ class KlippyWebsocket(threading.Thread):
|
|||||||
info = self._screen.apiclient.get_info()
|
info = self._screen.apiclient.get_info()
|
||||||
except Exception:
|
except Exception:
|
||||||
continue
|
continue
|
||||||
print(info)
|
|
||||||
if info != False:
|
if info != False:
|
||||||
self.connect()
|
self.connect()
|
||||||
if self.is_connected():
|
if self.is_connected():
|
||||||
break
|
break
|
||||||
print ("### Waiting for websocket")
|
logger.info("### Waiting for websocket")
|
||||||
time.sleep(.5)
|
time.sleep(.5)
|
||||||
|
|
||||||
|
Gdk.threads_add_idle(
|
||||||
|
GLib.PRIORITY_HIGH_IDLE,
|
||||||
|
self._screen.printer_ready
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def on_error(self, ws, error):
|
def on_error(self, ws, error):
|
||||||
print(error)
|
print(error)
|
||||||
|
70
screen.py
70
screen.py
@ -76,6 +76,17 @@ class KlipperScreen(Gtk.Window):
|
|||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.read_config()
|
self.read_config()
|
||||||
self.init_style()
|
self.init_style()
|
||||||
|
self.printer = Printer({
|
||||||
|
'configfile': {
|
||||||
|
'config': {}
|
||||||
|
},
|
||||||
|
'print_stats': {
|
||||||
|
'state': 'disconnected'
|
||||||
|
},
|
||||||
|
'virtual_sdcard': {
|
||||||
|
'is_active': False
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
self.apiclient = KlippyRest("127.0.0.1",7125)
|
self.apiclient = KlippyRest("127.0.0.1",7125)
|
||||||
Gtk.Window.__init__(self)
|
Gtk.Window.__init__(self)
|
||||||
@ -104,9 +115,14 @@ class KlipperScreen(Gtk.Window):
|
|||||||
if not hasattr(self, "_ws"):
|
if not hasattr(self, "_ws"):
|
||||||
self.create_websocket()
|
self.create_websocket()
|
||||||
|
|
||||||
|
print(info)
|
||||||
|
if info['result']['klippy_state'] == "disconnected":
|
||||||
|
self.printer_initializing("Klipper is not connected to moonraker")
|
||||||
|
return
|
||||||
if info['result']['klippy_state'] == "error":
|
if info['result']['klippy_state'] == "error":
|
||||||
logger.warning("Printer is emergency stopped")
|
logger.warning("Printer is emergency stopped")
|
||||||
self.printer_initializing("Shutdown due to Emergency Stop")
|
self.printer_initializing("Shutdown due to Emergency Stop")
|
||||||
|
return
|
||||||
|
|
||||||
status_objects = [
|
status_objects = [
|
||||||
'idle_timeout',
|
'idle_timeout',
|
||||||
@ -120,25 +136,20 @@ class KlipperScreen(Gtk.Window):
|
|||||||
]
|
]
|
||||||
r = requests.get("http://127.0.0.1:7125/printer/objects/query?" + "&".join(status_objects))
|
r = requests.get("http://127.0.0.1:7125/printer/objects/query?" + "&".join(status_objects))
|
||||||
|
|
||||||
requested_updates = {
|
|
||||||
"toolhead": [],
|
|
||||||
"virtual_sdcard": [],
|
|
||||||
"print_stats": [],
|
|
||||||
"heater_bed": [],
|
|
||||||
"extruder": [],
|
|
||||||
"configfile": []
|
|
||||||
}
|
|
||||||
|
|
||||||
#TODO: Check that we get good data
|
#TODO: Check that we get good data
|
||||||
print (r.content)
|
#print (r.content)
|
||||||
data = json.loads(r.content)
|
try:
|
||||||
|
data = json.loads(r.content)
|
||||||
|
except:
|
||||||
|
logger.info("Not able to load data. Klippy is most likely offline")
|
||||||
|
return
|
||||||
data = data['result']['status']
|
data = data['result']['status']
|
||||||
for x in data:
|
for x in data:
|
||||||
self.last_update[x] = data[x]
|
self.last_update[x] = data[x]
|
||||||
|
|
||||||
self.printer_config = data['configfile']['config']
|
self.printer_config = data['configfile']['config']
|
||||||
#logger.debug("Printer config: %s" % json.dumps(self.printer_config, indent=2))
|
#logger.debug("Printer config: %s" % json.dumps(self.printer_config, indent=2))
|
||||||
self.printer = Printer(data)
|
self.printer.__init__(data)
|
||||||
|
|
||||||
# Initialize target values. TODO: methodize this
|
# Initialize target values. TODO: methodize this
|
||||||
self.printer.set_dev_stat("heater_bed", "target", data['heater_bed']['target'])
|
self.printer.set_dev_stat("heater_bed", "target", data['heater_bed']['target'])
|
||||||
@ -150,12 +161,17 @@ class KlipperScreen(Gtk.Window):
|
|||||||
elif info['result']['klippy_state'] == "ready":
|
elif info['result']['klippy_state'] == "ready":
|
||||||
self.printer_ready()
|
self.printer_ready()
|
||||||
|
|
||||||
while (self._ws.is_connected() == False):
|
|
||||||
logger.warning("### Main: Waiting for websocket")
|
|
||||||
continue
|
|
||||||
|
|
||||||
self.files = KlippyFiles(self)
|
self.files = KlippyFiles(self)
|
||||||
|
|
||||||
|
def ws_subscribe(self):
|
||||||
|
requested_updates = {
|
||||||
|
"toolhead": [],
|
||||||
|
"virtual_sdcard": [],
|
||||||
|
"print_stats": [],
|
||||||
|
"heater_bed": [],
|
||||||
|
"extruder": [],
|
||||||
|
"configfile": []
|
||||||
|
}
|
||||||
self._ws.klippy.object_subscription(requested_updates)
|
self._ws.klippy.object_subscription(requested_updates)
|
||||||
|
|
||||||
def show_panel(self, panel_name, type, remove=None, pop=True, **kwargs):
|
def show_panel(self, panel_name, type, remove=None, pop=True, **kwargs):
|
||||||
@ -315,13 +331,17 @@ class KlipperScreen(Gtk.Window):
|
|||||||
def _websocket_callback(self, action, data):
|
def _websocket_callback(self, action, data):
|
||||||
#print(json.dumps([action, data], indent=2))
|
#print(json.dumps([action, data], indent=2))
|
||||||
|
|
||||||
if action == "notify_status_update":
|
if action == "notify_klippy_disconnected":
|
||||||
|
logger.info("### Going to disconnected state")
|
||||||
|
self.printer_initializing("Klipper has shutdown")
|
||||||
|
return
|
||||||
|
elif action == "notify_status_update":
|
||||||
self.printer.process_update(data)
|
self.printer.process_update(data)
|
||||||
if "webhooks" in data and "klippy_state" in data['webhooks']:
|
if "webhooks" in data and "state" in data['webhooks']:
|
||||||
if data['webhooks']['klippy_state'] == "shutdown":
|
#if data['webhooks']['state'] == "shutdown":
|
||||||
logger.info("### Going to disconnected state")
|
# logger.info("### Going to disconnected state")
|
||||||
self.printer_initializing("Klipper has shutdown")
|
# self.printer_initializing("Klipper has shutdown")
|
||||||
elif data['webhooks']['state'] == "ready":
|
if data['webhooks']['state'] == "ready":
|
||||||
logger.info("### Going to ready state")
|
logger.info("### Going to ready state")
|
||||||
self.printer_ready()
|
self.printer_ready()
|
||||||
else:
|
else:
|
||||||
@ -333,12 +353,13 @@ class KlipperScreen(Gtk.Window):
|
|||||||
else:
|
else:
|
||||||
if active == True or paused == True:
|
if active == True or paused == True:
|
||||||
self.printer_printing()
|
self.printer_printing()
|
||||||
|
elif action == "notify_filelist_changed":
|
||||||
if action == "notify_filelist_changed":
|
|
||||||
logger.debug("Filelist changed: %s", json.dumps(data,indent=2))
|
logger.debug("Filelist changed: %s", json.dumps(data,indent=2))
|
||||||
#self.files.add_file()
|
#self.files.add_file()
|
||||||
elif action == "notify_metadata_update":
|
elif action == "notify_metadata_update":
|
||||||
self.files.update_metadata(data['filename'])
|
self.files.update_metadata(data['filename'])
|
||||||
|
else:
|
||||||
|
logger.debug(json.dumps([action, data], indent=2))
|
||||||
|
|
||||||
for sub in self.subscriptions:
|
for sub in self.subscriptions:
|
||||||
self.panels[sub].process_update(data)
|
self.panels[sub].process_update(data)
|
||||||
@ -376,6 +397,7 @@ class KlipperScreen(Gtk.Window):
|
|||||||
|
|
||||||
# Reinitialize printer, in case the printer was shut down and anything has changed.
|
# Reinitialize printer, in case the printer was shut down and anything has changed.
|
||||||
self.printer.__init__(data['result']['status'])
|
self.printer.__init__(data['result']['status'])
|
||||||
|
self.ws_subscribe()
|
||||||
|
|
||||||
#logger.debug("Config sections: %s", self.printer.get_config_section_list())
|
#logger.debug("Config sections: %s", self.printer.get_config_section_list())
|
||||||
#logger.debug("Bed_screws: %s", self.printer.get_config_section("bed_screws"))
|
#logger.debug("Bed_screws: %s", self.printer.get_config_section("bed_screws"))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user