PSU 2 commands at the same time


I am running Octoprint on OrangePI Zero 2, am using PSU to control my printer send "gpio write 2 1" to power ON, send "gpio write 2 0" to power OFF. All works as expected. However I want also to turn off web cam when the printer is off, and turn it on once the printer is on, the OrangePi itself is running 24/7. Camera is controlled by a service "mjpg-streamer" and is working fine also.

What did you already try to solve it?

First I tired changing the

  1. ON command to "gpio write 2 1 && systemctl start mjpg-streamer"
  2. OFF command to "gpio write 2 0 && systemctl stop mjpg-streamer"
    In this case only the first command is beeing executed - the printer starts (GPIO pin state changes) but the mjpg-streamer service state does not change.

Then I created a script ON and script OFF each containing 2 commands, same effect GPIO pin is written, but mjpg-streamer service state is not changed.
When I use any of the above approaches in the terminal all works as expected.

Any suggestions how to use 2 commands at once?


Don't you usually need sudo in front of systemctl stop mjpg-streamer? When you run it from the command line do you need to enter a password sometimes?

Thanks, issue solved.

  1. created file octoprint in /etc/sudoers.d
    octoprint ALL = NOPASSWD: /bin/systemctl stop mjpg-streamer.service
    octoprint ALL = NOPASSWD: /bin/systemctl start mjpg-streamer.service
  2. added sudo to the commands
1 Like