Modifiying shutdown button to add extra features
I have my server running a custom command that shuts down the printer and then using a webaction shuts off the power to the printer and the server though a smart plug. I have a small delay in the ifttt program to allow the server to properly shutdown before removing power.
I have this gcode in a quick command
@pushmessage Hard Shutdown of MK2.5S Initiated
M104 S0 T0
M140 S0
M109 R38
@syncMotion
@webAction Hard_Shutdown
@syncMotion
@pushmessage Hard Shutdown of Mk2.5s Completed
G4 S1
@syncMotion
@execute shutdown
M104 S0 T0
M140 S0
M109 R38
@syncMotion
@webAction Hard_Shutdown
@syncMotion
@pushmessage Hard Shutdown of Mk2.5s Completed
G4 S1
@syncMotion
@execute shutdown
would there be an easy way to modify the action of the current shutdown button in the extcommands.xml to achieve the same result?
in my mind the easiest would be to be able to call my custom quick command from within the shutdown script.
so change the current execute to something else
<execute>sudo /sbin/shutdown -h now</execute>
I am not a programmer so any help on this would be much appreciated.
Comments
https://prgdoc.repetier-server.com/v1/docs/index.html#/en/web-api/unixsockets
on how to do this when you activate unix sockets. There is a sample script (put it in /var/lib/Repetier-Server/scripts) and adjust the included gcode command and printer slug name (see url in browser when inside a printer tab) it is the one looking like printer name.
#!/bin/bash
Server runs script as user repetierserver already. I set execute permission with
chmod 755 myshutdown
And in extcommands you call it without sudo just full path /var/lib/Repetier-Server/scripts/myshutdown
As a test on console run
sudo -i
sudo -u repetierserver var/lib/Repetier-Server/scripts/myshutdown
which should work as it simulates user and path server would use then.
If some parts do not get shown it is probably a xml error. Copy xml file to
https://xmllint.com/
and verify that it is at least valid xml.
<name>Shutdown Server</name>
<icon>
<svg aria-hidden="true" focusable="false" data-prefix="far" data-icon="power-off" class="svg-inline--fa fa-power-off fa-w-16" role="img" viewBox="0 0 512 512"><path fill="currentColor" d="M388.5 46.3C457.9 90.3 504 167.8 504 256c0 136.8-110.8 247.7-247.5 248C120 504.3 8.2 393 8 256.4 7.9 168 54 90.3 123.5 46.3c5.8-3.7 13.5-1.8 16.9 4.2l11.8 20.9c3.1 5.5 1.4 12.5-3.9 15.9C92.8 122.9 56 185.1 56 256c0 110.5 89.5 200 200 200s200-89.5 200-200c0-70.9-36.8-133.1-92.3-168.6-5.3-3.4-7-10.4-3.9-15.9l11.8-20.9c3.3-6.1 11.1-7.9 16.9-4.3zM280 276V12c0-6.6-5.4-12-12-12h-24c-6.6 0-12 5.4-12 12v264c0 6.6 5.4 12 12 12h24c6.6 0 12-5.4 12-12z"></path></svg>
</icon>
<execute>/var/lib/Repetier-Server/scripts/hard-shutdown.sh</execute>
<confirm>Really shut down the server?</confirm>
<!--
Define if command should show up in local printer interface, default true.
-->
<local>true</local>
<!--
Define if command should show up in remote printer interface, default true.
-->
<remote>true</remote>
<!--
Define if command should show up only for users with print permission, default true.
-->
<print-permission>true</print-permission>
<!--
Define if command should show up only for users with add files permission, default false.
-->
<add-permission>true</add-permission>
<!--
Define if command should show up only for users with del files permission, default false.
-->
<del-permission>true</del-permission>
<!--
Define if command should show up only for users with configuration permission, default false.
-->
<config-permission>true</config-permission>
</command>
The shutdown command on home screen only appears if the command contains "shutdown -h"
So as solution for you rename hard-shutdown.sh into hard-shutdown and make the execute
<execute>/var/lib/Repetier-Server/scripts/hard-shutdown -h now</execute>
Also you don't use the parameter the check to show it is happy and will put it on home screen as well then.
M104 S0 T0
M140 S0
M109 R38
@syncMotion
@webAction Hard_Shutdown
@syncMotion
@pushmessage Hard Shutdown of Mk2.5s Completed
G4 S1
@syncMotion
@execute shutdown
#!/bin/bash
nc -N -U /tmp/repetier-server.sock <<EOF
{
"action": "send",
"data": {
"cmd": "@quickCommand Hard Shutdown"
},
"printer": "MK2.5S"
}
EOF
<name>Shutdown Server</name>
<icon>
<svg aria-hidden="true" focusable="false" data-prefix="far" data-icon="power-off" class="svg-inline--fa fa-power-off fa-w-16" role="img" viewBox="0 0 512 512"><path fill="currentColor" d="M388.5 46.3C457.9 90.3 504 167.8 504 256c0 136.8-110.8 247.7-247.5 248C120 504.3 8.2 393 8 256.4 7.9 168 54 90.3 123.5 46.3c5.8-3.7 13.5-1.8 16.9 4.2l11.8 20.9c3.1 5.5 1.4 12.5-3.9 15.9C92.8 122.9 56 185.1 56 256c0 110.5 89.5 200 200 200s200-89.5 200-200c0-70.9-36.8-133.1-92.3-168.6-5.3-3.4-7-10.4-3.9-15.9l11.8-20.9c3.3-6.1 11.1-7.9 16.9-4.3zM280 276V12c0-6.6-5.4-12-12-12h-24c-6.6 0-12 5.4-12 12v264c0 6.6 5.4 12 12 12h24c6.6 0 12-5.4 12-12z"></path></svg>
</icon>
<execute>/var/lib/Repetier-Server/scripts/hard-shutdown -h now</execute>
<confirm>Really shut down the server?</confirm>
<!--
Define if command should show up in local printer interface, default true.
-->
<local>true</local>
<!--
Define if command should show up in remote printer interface, default true.
-->
<remote>true</remote>
<!--
Define if command should show up only for users with print permission, default true.
-->
<print-permission>true</print-permission>
<!--
Define if command should show up only for users with add files permission, default false.
-->
<add-permission>true</add-permission>
<!--
Define if command should show up only for users with del files permission, default false.
-->
<del-permission>true</del-permission>
<!--
Define if command should show up only for users with configuration permission, default false.
-->
<config-permission>true</config-permission>
</command>
<execute name="reboot" allowParams="false" sync="false">sudo /sbin/shutdown -r now</execute>
Remember it is a printer shutdown function to disable a printer for power saving when it is not used. You are misusing it to also shutdown the pi and probably expect it to first shutdown when it had printed. You can do this easily with global variables and changing the shutdown code. For this add in run on connect
@set global.had_job 0
and in "Run before job"
@set global.had_job 1
then you have variable set to 1 after a print. The put your idle shutdown script inside
@if {{global.had_job==1}}
....
@endif
and it will only run after a print on idle.
@set global.boottime {{time()}}
@if {{global.elapsed>=global.shutdowntime}}
@quickCommand Hard Shutdown
@endif
@echo {{state.idle_seconds}}
I registered that after shutdown value was set to very high time. Maybe that is related to the issue, also I can not reproduce it. But I revised the logic, so now idle stays untouched. But it still gets reset on next M code being send.