This E-Stop code I pasted into the printer.cfg file is getting errors when I hit SAVE & RESTART.

I edited and trimmed the code down to this: [gcode_button e-stop] pin: rpi:gpio26 press_gcode: {% do call_method("printer.emergency_stop") %} release_gcode: {% if event.elapsed_time > 1.0 %} {% do call_method("machine.reboot") %} {% endif %} Resulting error: Error loading template 'gcode_button e-stop:press_gcode': jinja2.exceptions.TemplateSyntaxError: Encountered unknown tag 'do'.
19 Replies
ctbjdm_04135
ctbjdm_041354mo ago
Just a guess, but try getting rid of the spaces in “gcode_button e-stop”
millenford - VC4 300h
The docs show a space in there when you add an optional name (e-stop in my case), but I tried it anyway and got a new error. lol thanks though!
TheTik
TheTik4mo ago
Take a look at this, maybe you're not importing something you should? https://stackoverflow.com/a/67045035
Stack Overflow
jinja2.exceptions.TemplateSyntaxError: Encountered unknown tag 'do'
I'm not very familiar with Jinja and I'm having some issues using "do" statement in my template. I was reading other posts and I was trying to fix it but still no luck. Here is how partial
millenford - VC4 300h
The first few lines are fairly straightforward, but it's not evident to me how to integrate the rest. I will try though. Thanks.
CrashTestCharlie / VC4 400h
Isn't this supposed to be in moonraker.cfg and not printer.cfg?
miklschmidt
miklschmidt4mo ago
[gcode_button] is a klipper section. do is not a thing in klipper's jinja environment though. You're totally correct however that the jinja syntax used here is moonraker and not klipper.
CrashTestCharlie / VC4 400h
Ok, the snip helge posted had "# moonraker.conf" at the top of it, so I'm all turned around
millenford - VC4 300h
Yes it does have moonraker.conf at the top, but when Helge gave me the code he said to put it in printer.cfg. So should I put the code in moonraker.conf?
CrashTestCharlie / VC4 400h
Someone else got this working., might be worth some time to search some
millenford - VC4 300h
When I searched I found some discussions about just interrupting the power, using M112, or using this code or something similar. I didn't find a final solution that somebody implemented and it just worked. Then Mikl said the E-Stop functionality is part of the Klipper configuration. Then Helge pasted in some code, and here I am.
CrashTestCharlie / VC4 400h
Check https://discord.com/channels/582187371529764864/1223286652949106748/12660306623188215291266030662318821529 That might not point to the message Here, I am using a latching e-stop button so I did only the reset function. Since I am going 3v3 to GPIO I had to use the ~ in front of the pin to enable the built in pull down resistor. Also it looks like pin format has to be gpiochip0/gpio22 in my case to work. Going to do some more testing but so far so good. Here is my current moonraker.conf file
# Emergency Stop
[button estop]
type: gpio
pin: ~gpiochip0/gpio22
on_press:
# Executes immediately after a press is detected
{% do call_method("printer.emergency_stop") %}
# Emergency Stop
[button estop]
type: gpio
pin: ~gpiochip0/gpio22
on_press:
# Executes immediately after a press is detected
{% do call_method("printer.emergency_stop") %}
millenford - VC4 300h
My moonraker.conf has a bunch of IP addresses in it. Should the E-Stop code go above or below the IP stuff or does it matter?
CrashTestCharlie / VC4 400h
I don't know, but I'd put it after
millenford - VC4 300h
This is my moonraker file. Load the RatOS moonraker defaults [include RatOS/moonraker.conf] If you use a non standard ip range in your local network, you can specify it under trusted_clients here. [authorization] cors_domains: http://app.fluidd.xyz https://app.fluidd.xyz https://my.mainsail.xyz http://my.mainsail.xyz http://*.local http://*.lan trusted_clients: 127.0.0.1 10.0.0.0/8 127.0.0.0/8 169.254.0.0/16 172.16.0.0/12 192.168.0.0/16 FE80::/10 ::1/128 FD00::/8 Okay I'll try it.
TheTik
TheTik4mo ago
Try putting your code within a code block. Start and stop it with triple backtick (same button as tilde ~)
miklschmidt
miklschmidt4mo ago
@millenford - VC4 300h either you use the moonraker syntax and put it in moonraker.conf or you use the klipper syntax and put it in printer.cfg. for klipper it would look like this in printer.cfg:
[gcode_button e-stop]
pin: rpi:gpio26
press_gcode:
m112
[gcode_button e-stop]
pin: rpi:gpio26
press_gcode:
m112
If you want the long press stuff, you need to use moonraker.
millenford - VC4 300h
The code below that I put in the moonraker.conf file is what I got working and I'm going to use unless I discover some weird side affects. I wired my E-Stop pushbutton to pull the input to ground when pressed, but that caused the E-Stop to occur when I released it (instead of when I pressed it), so I added the "!" inversion symbol to the pin definition. I also wired in a 4.7kOhm pullup resistor to 3v3 (versus using the software pullup). When I release the E-Stop, the last instruction apparently reboots the machine using "machine.reboot", but I still have to do a "FIRMWARE RESTART" in Mainsail after that. I'm still learning the difference between the two functions. Thanks to everybody! this code runs in moonraker.conf [button e-stop] type: gpio pin: !gpiochip0/gpio26 on_press: {% do call_method("printer.emergency_stop") %} on_release: {% do call_method("machine.reboot") %}
Godzilla_Bill_K4IBC
Reason you had to invert it is because most ESTOP buttons come with NC contacts that open with Press. Look at your ESTOP button and see if it has another set of contacts. On some ESTOPs the contacts have a clear cover so you can actually see them.
millenford - VC4 300h
In this case they are N.O. contacts. I think the true state to the Raspberry Pi is HIGH, as opposed to LOW as I was originally told.
Want results from more Discord servers?
Add your server