I am using the event hooks to call a custom script to alert me when a print start/stops/fails etc...
I would like to get an event trigger when a M600 command is sent to the printer so I know when it needs a filament change instead of listening for the beeps.
What did you already try to solve it?
Looked in the event documentation and don't see any reference to the M600 command generating an event.
Additional information about your setup (OctoPrint version, OctoPi version, printer, firmware, octoprint.log, serial.log or output on terminal tab, ...)
I'm no software developer, but as I had a simular issue and I wrote a small plug-in inspired by the GCODE Systems Command Plugin.
I put a .py file with the following code into my octoprint/plugins folder. Everytime a M600 gcode is sent to the printer a specified shell script gets fired up. The shell script sends out a pushbullet notification to my phone in my case.
Here is my code:
# coding=utf-8
from __future__ import absolute_import
import octoprint.plugin
import time
import os
import sys
class M600ActionPlugin(octoprint.plugin.StartupPlugin):
def hook_gcode_sent(self, comm_instance, phase, cmd, cmd_type, gcode, *args, **kwargs):
script_path= *** insert path to your script here ***
if gcode and cmd[:4] == "M600":
self._logger.info("M600 registered")
try:
r = os.system(script_path)
except:
self._logger.error("Script could not be run")
def __plugin_load__():
global __plugin_implementation__
__plugin_implementation__ = M600ActionPlugin()
global __plugin_hooks__
__plugin_hooks__ = {
"octoprint.comm.protocol.gcode.sent": __plugin_implementation__.hook_gcode_sent
}
__plugin_name__ = "M600 Shell Action"
__plugin_version__ = "0.1.0"
__plugin_description__ = "Plugin fires up a shell script, if a M600 gcode is sent to the printer."
As I said, I am no software developer. If someone wants to take it and make it better, instalable plugin, feel free.
Just add the compatibility flag to the end, like this. I don't see anything glaringly wrong that would be incompatible.
# coding=utf-8
from __future__ import absolute_import
import octoprint.plugin
import time
import os
import sys
class M600ActionPlugin(octoprint.plugin.StartupPlugin):
def hook_gcode_sent(self, comm_instance, phase, cmd, cmd_type, gcode, *args, **kwargs):
script_path= *** insert path to your script here ***
if gcode and cmd[:4] == "M600":
self._logger.info("M600 registered")
try:
r = os.system(script_path)
except:
self._logger.error("Script could not be run")
def __plugin_load__():
global __plugin_implementation__
__plugin_implementation__ = M600ActionPlugin()
global __plugin_hooks__
__plugin_hooks__ = {
"octoprint.comm.protocol.gcode.sent": __plugin_implementation__.hook_gcode_sent
}
__plugin_name__ = "M600 Shell Action"
__plugin_version__ = "0.1.0"
__plugin_pythoncompat__ = ">=2.7,<4"
__plugin_description__ = "Plugin fires up a shell script, if a M600 gcode is sent to the printer."
There is also the FilamentChange event now as well, so you could use the Event Manager in OctoPrint's settings to make this work now. It fires on M600, M701 or M702. Quite new, in 1.7.0.
Big thanks to @tierra for the original plugin, and thanks to @jneilliii for showing how to easily fix it, (and it works!) but huge thanks to @Charlie_Powell for pointing out the new functionality!!
So, if anyone is wanting to use this, you don't need the plugin anymore - Just add this to your config.yaml:
Just like @tech-rat I have it sending alerts to Slack so I don't have to be at the printer when running multi-color prints. This is so cool, thanks all!