I was wondering if anyone could assist me with understanding how to write a script for the Resume GCODE function that uses the 'last_temperature' template variable.
Reading the 'Context' section of the GCODE Scripts docs page, I attempted the following GCODE, however this is not working.
{% if last_temperature[0]['target'] is not none %}
M109 S{{last_temperature[0]['target']}}
{% endif %}
{% if last_temperature[b]['target'] is not none %}
M190 S{{last_temperature[b]['target']}}
{% endif %}
As I am new to OctoPrint, GCODE and 3D Printing any assistance would be greatly appreciated.
OctoPrint Version : 1.3.6
OctoPi Version : 0.14
Printer : Creality-CR10
I have tried converting the GCODE to the following, but all that happens now is that the print starts immediately without pre heating either the extruder or the heated bed.
{% if last_temperature[0]['target'] is not none %}
M109 S{{last_temperature[0]['target']}}
{% else %}
M109 S205
{% endif %}
{% if last_temperature['b']['target'] is not none %}
M190 S{{last_temperature['b']['target']}}
{% else %}
M190 S60
{% endif %}
It would make sense to share what is actually generated and going over the line to your printer (see the Terminal tab).
This works for me:
{% if pause_temperature[0] and pause_temperature[0]['target'] is not none %}
M109 S{{ pause_temperature[0]['target'] }}
{% else %}
M104 S0
{% endif %}
{% if pause_temperature['b'] and pause_temperature['b']['target'] is not none %}
M190 S{{ pause_temperature['b']['target'] }}
{% else %}
M140 S0
{% endif %}
A more complex example that also takes care of ensuring to iterate over all defined tools and send the corresponding T parameter with the temperature command (but only if there are more than one extruders defined) would be this:
{% for tool in range(printer_profile.extruder.count) %}
{% if pause_temperature[tool] and pause_temperature[tool]['target'] is not none %}
{% if tool == 0 and printer_profile.extruder.count == 1 %}
M109 T{{ tool }} S{{ pause_temperature[tool]['target'] }}
{% else %}
M109 S{{ pause_temperature[tool]['target'] }}
{% endif %}
{% else %}
{% if tool == 0 and printer_profile.extruder.count == 1 %}
M104 T{{ tool }} S0
{% else %}
M104 S0
{% endif %}
{% endif %}
{% endfor %}
{% if printer_profile.heatedBed %}
{% if pause_temperature['b'] and pause_temperature['b']['target'] is not none %}
M190 S{{ pause_temperature['b']['target'] }}
{% else %}
M140 S0
{% endif %}
{% endif %}
Note that in both cases I use pause_temperature instead of last_temperature. last_temperature is always the last temperature reported by your printer (hence the name), so if you use that, you are basically doing a non operation (e.g. the last temperature of the hotend reported by your printer was 24Β°C because you shut off the heater after pausing, now you issue a M109 S24.0 which does nothing). pause_temperature on the other hand is recorded when you pause the print (as is cancel_temperature when you cancel the print), so is probably rather what you want.
I can see that I was using the wrong template variables, however I could only find a small amount of variables available thus I wasn't aware of the pause_temperature variable. If I may ask, where could I find a list of all available variables, currently I am looking at the following URL
Sorry to revive this ancient topic, but I just stumbled onto it trying to improve my Octoprint pause functionality. Looking at the code below from the post by foosel, I have two questions.
{% for tool in range(printer_profile.extruder.count) %}
{% if pause_temperature[tool] and pause_temperature[tool]['target'] is not none %}
{% if tool == 0 and printer_profile.extruder.count == 1 %}
M109 T{{ tool }} S{{ pause_temperature[tool]['target'] }}
{% else %}
M109 S{{ pause_temperature[tool]['target'] }}
{% endif %}
{% else %}
{% if tool == 0 and printer_profile.extruder.count == 1 %}
M104 T{{ tool }} S0
{% else %}
M104 S0
{% endif %}
{% endif %}
{% endfor %}
{% if printer_profile.heatedBed %}
{% if pause_temperature['b'] and pause_temperature['b']['target'] is not none %}
M190 S{{ pause_temperature['b']['target'] }}
{% else %}
M140 S0
{% endif %}
{% endif %}
First, unless I'm mistaken, the "if" statements checking for the number of extruders are backwards - i.e. I think it should be like below? i.e. if there's only one extruder, don't use the "T" in the M109 statement.
Second question is whether there is a concept of global variables in GCODE script. The current script would not re-set the fan speed to its prior value after resume if I turn it off at pause (which I'd like to do). Is there a clever way to extract the fan speed via a plug-in and store in a global variable that could be used in the resume script?
Welcome to the nightmare that is 3d printer communication. Believe it or not, the fan speed is a "write-only" value. I have absolutely no way to extract it from the printer again. Same goes for the current tool and feedrate btw, and for the feedrate and flowrate modifier. So if I want to be able to track the current value I'll have to do it myself and pray to the deities that the user doesn't fiddle around with the controller on the printer and modifies it outside of my control or knowledge. Which is what is done for the current tool and the feedrate, but currently not for anything else because frankly it is just messy.
In a nutshell: nope, currently not. Could be changed, though I'm not completely sure if I want to open that can of worms.