Executing program from event hook trigger

I can't seem to figure out how to execute a compiled program from the event hook triggers in configure.yaml.

I have a custom built LED panel that I want to turn on and off with the prints using the RPi's GPIO, which requires a custom library (so enclosure won't work, hence the scripts). I am relatively newer to Linux, so I'm guessing it's a misunderstanding on how to run the shell commands from the octoprint instance due to file permissions?

I have verified that executing the programs from the command line do turn on/off the LEDs (but they do require super user permissions or I get "Can't open /dev/mem: Permission denied") and that all users (chmod a+x) have executable permissions to these executables.

config.yaml snippet

events:
  subscriptions:
  - command: ~/LED_on
    event: PrintStarted
    type: system
  - command: ~/LED_off
    event:
    - PrintFailed
    - PrintDone
    - PrintCancelled
    type: system
ls -l
-rwxr-xr-x  1 pi pi 8516 Jul 20 16:54 LED_off
-rwxr-xr-x  1 pi pi 8636 Jul 20 17:03 LED_on

Running latest version of octopi install

if it requires sudo then you will have to adjust the sudoers for the executable to allow running it without.

and you'll probably want to use the full path /home/pi/LED_on and /home/pi/LED_off instead of the tilde shortcut, just to be safe.

  • Create a file /etc/sudoers.d/LED_on (as root) with the following contents:
    pi ALL=NOPASSWD: /home/pi/LED_on
  • Create a file /etc/sudoers.d/LED_off (as root) with the following contents:
    pi ALL=NOPASSWD: /home/pi/LED_off

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.