System commands through the web ui

I've moved over from octoprint and the only thing I miss so far is being able to invoke system commands. Ie I used to use the gpio command to turn on/off a relay. I could run this command through a button in the octoprint webui.

I also would use things like curl commands to connect to other web services to do something when a print was done or canceled.

So is there anything like this in repetier server?


  • Sure. Chech in the manual the "Advanced Setup" chapter which describes how to add new external commands.
  • Thanks @Repetier, that seemed to work for the default reboot/shutdown in the example.  But soon as I added the following, the menu doesn't show.  So I assume there's a syntax error?
                    <name>Power Off Printer</name>
                    <execute>gpio -g mode 26 out && gpio -g write 26 1</execute>
                    <confirm>Really poweroff the printer</confirm>

    here's the full extcommands.xml file:
  • looking at the server log the problem is the "&&".  I tried pre-pending a \ but still got a parsing error in the server.log.  How can I escape these characters so that I don't get this error?
  • It's XML and in xml a & should be &amp;

    Also you should use absolute path for commands. Nut sure if it will work without full path.

  • @Repetier, the &amp; works fine.
    however the command fails.  This is what I have:
                    <name>Power Off Printer</name>
                    <execute>gpio -g mode 26 out &amp;&amp; gpio -g write 26 1</execute>

    I can run that same command via ssh or console on the pi with && istead of the &amp;&amp; and it works fine.

    Only thing the log tells me is: Starting external command gpio with 10 parameters.

    So I don't think the command is being parsed right.  I'll keep playing with this, but an ideas are appriciated!
  • That is no command, it's 2 commands and no absolute paths. What you have is something you could execute in bash, but we are really just invoking 1 program. So you'd better move this into a bash script and invoke that script.
  • Just wanted to follow up on this thread. I found the discussion useful and I was able to get added commands to turn the printer on/off with a sainsmart relay board. I made a script called that contains the following:
    #!/bin bash

    gpio -g mode 2 out
    gpio -g write 2 0
    I also made a similar one for turning the printer off (just wrote 1 to pin 2 instead of 0). I then made the extcommands.xml file and put it in /var/lib/Repetier-Server/database/ 
    Initially I tried just creating it from scratch because I didn't know how to paste text into vi (I'm really new to Linux), but it didn't work. The commands didn't show up in the tool menu. Then I discovered the nano text editor (SOOO much easier, why the hell is vi so complicated??) and pasted the sample extcommands.xml text from the manual into my file and added these commands:

                    <name>Printer On</name>
                    <execute>bash /home/pi/scripts/</execute>
                    <confirm>Really turn on the printer?</confirm>
                    <name>Printer Off</name>
                    <execute>bash /home/pi/scripts/</execute>
                    <confirm>Really turn off the printer?</confirm>

    Restarted the Pi and hallelujah, I had four new commands.
    Thanks Repetier for the help and feedback. Now I need to finish building the relay box.
  • edited November 2016
    Note: I am running Repetier-Server Pro on Raspberry Pi 2 Model B.
    I have my printer connected to a Z-wave breaker and I can turn on and off my printer by calling the Domoticz API (Domoticz running on other Pi 3) using curl or wget. My printer does not have PS_ON. The board on my printer will stay on with the LCD on and dim text, powered by the Raspberry Pi's USB-port. Because of that I kill the power supply to the USB-devices with "
    sudo hub-ctrl -h 0 -P 2 -p 0" (-p 1 for power on). This works good but it kills power to all USB-devices (except ethernet), the usb camera too so I call killall for mjpeg_streamer before hub-ctrl to get rid of the segfault errors in dmesg when camera looses power. Will the system try to restart mjpeg_streamer all the time or is there any command that I can run to make repetier-server to not try to restart the webcam service when printer is off? Also, how do I send gcodes using the extcommands.xml? I want to home all before I kill power and usb. :)

    Power on script:
    sleep 10
    sudo hub-ctrl -h 0 -P 2 -p 1

    Power off script:
    sudo killall -9 mjpg_streamer
    sudo hub-ctrl -h 0 -P 2 -p 0
    sleep 5

    Get hub-ctrl here:

    "Install" hub-ctrl:
    sudo apt-get install libusb-dev build-essential
    cd /tmp
    gcc -o hub-ctrl hub-ctrl.c -lusb
    chmod +x hub-ctrl
    sudo mv hub-ctrl /usr/bin/

  • Regarding mjpg_streamer this depends on how you installed it. We changed it a few times and currently I'm changing the scripts again to also include selection of resolution in server interface. If started through service I would suggest stopping the mjpg_streamer service first. Especially the systemd versions might have the option to restart on fault.

    Regarding gcodes you might simply use our web api and use curl to send commands, see
    and especially "User websocket commands directly" whcih shows how to send websocket commands allowing you to use the "send" command to send gcode from shell using curl.
  • edited November 2016
    Thanks! I used the Raspberry Pi image v4 so I haven't touched mjpg_streamer.

    Edit: My profile tells me that my location is Norway? It's Sweden and I can't find where to change it..
  • NiklasO said:
    Thanks! I used the Raspberry Pi image v4 so I haven't touched mjpg_streamer.

    Edit: My profile tells me that my location is Norway? It's Sweden and I can't find where to change it..
    So it uses in deed systemd and stopping it would be good also I don't think it stops the processes as it is more a hack to start them on startup. They also start by plugging them in usb port so that is only one part of it.

    Not sure what you mean with profile norway - do you mean the wlan setup? You can change the region in wlan setup in server.
  • Ok thanks, I will look in to it.

    By profile I mean the profile here on the forum. ;)
  • I guess forum uses some kind of geoip mapping for autosetting and that might be not as accurate as it should be.
Sign In or Register to comment.