Skip to content

Instantly share code, notes, and snippets.

@bigwheel
Forked from foosel/octoprint_ackackack.py
Last active February 5, 2024 02:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save bigwheel/4ed84496d88faac7aeefeeb823fea300 to your computer and use it in GitHub Desktop.
Save bigwheel/4ed84496d88faac7aeefeeb823fea300 to your computer and use it in GitHub Desktop.
OctoPrint-AckAckAck. Install by placing octoprint_ackackack.py in ~/.octoprint/plugins or (OctoPrint 1.4.1+) by pasting "https://gist.githubusercontent.com/bigwheel/4ed84496d88faac7aeefeeb823fea300/raw/octoprint_ackackack.py" into Plugin Manager > Get More > from URL
# coding=utf-8
from __future__ import absolute_import
import octoprint.plugin
import logging
from collections import deque
class AckAckAckPlugin(octoprint.plugin.StartupPlugin):
def __init__(self):
super(AckAckAckPlugin, self).__init__()
self._comm_tail = deque(maxlen=10) # Buffer 10 lines
def on_startup(self, host, port):
from octoprint.logging.handlers import CleaningTimedRotatingFileHandler
path = self._settings.get_plugin_logfile_path()
logging_handler = CleaningTimedRotatingFileHandler(path,
when="D",
backupCount=10)
formatter = logging.Formatter("%(asctime)s %(message)s")
logging_handler.setFormatter(formatter)
logging_handler.setLevel(logging.DEBUG)
self._logger.addHandler(logging_handler)
self._logger.setLevel(logging.DEBUG)
self._logger.propagate = False
def on_gcode_received(self, comm, line, *args, **kwargs):
self._comm_tail.append("Recv: {}".format(line))
if "o\\x00k" in line or "o\x00k" in line:
self._logger.error("Garbled OK detected:")
self._logger.error("-" * 80)
for l in self._comm_tail:
self._logger.error(l)
self._logger.error("-" * 80)
return "ok"
elif line == 'k\n':
self._logger.error("Garbled OK detected: k")
self._logger.error("-" * 80)
for l in self._comm_tail:
self._logger.error(l)
self._logger.error("-" * 80)
return "ok"
elif "\x00" in line:
self._logger.error("Potential garble detected:")
self._logger.error("-" * 80)
for l in self._comm_tail:
self._logger.error(l)
self._logger.error("-" * 80)
return line
def on_gcode_sent(self, comm_instance, phase, cmd, cmd_type, gcode,
*args, **kwargs):
self._comm_tail.append("Send: {}".format(cmd))
__plugin_name__ = "OctoPrint-AckAckAck"
__plugin_pythoncompat__ = ">=2.7,<4"
__plugin_implementation__ = AckAckAckPlugin()
__plugin_hooks__ = {
"octoprint.comm.protocol.gcode.received": __plugin_implementation__.on_gcode_received,
"octoprint.comm.protocol.gcode.sent": __plugin_implementation__.on_gcode_sent
}
@nbergen
Copy link

nbergen commented Feb 5, 2024

https://gist.github.com/bigwheel/4ed84496d88faac7aeefeeb823fea300#file-octoprint_ackackack-py-L44
elif line == 'k\n':

This seems to be the issue for me as well.

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment