Need to add item to shutdown menu

What is the problem?

I need to add an item to the shutdown menu for my Geekworm x735 power control board of my raspberry pi.

What did you already try to solve it?

Looked through the various octoprint directories, but could not really find a way to add my shutdown script or add a menu item to the shutdown menu. I saw on the Internet mention of a menu.cfg file, but I could not find such a file.

Have you tried running in safe mode and if so did it solve the issue?

NA

Complete Logs

octoprint.log, serial.log or output on terminal tab at a minimum, browser error console if UI issue ... no logs, no support! Not log excerpts, complete logs.)

NA

Additional information about your setup

OctoPrint version, OctoPi version, printer, firmware, browser, operating system, ... as much data as possible

using Raspberry pi 3B with Geekworm x735 power management board as well as Waveshare Pan-Tilt hat with raspberry pi camera v2.

You're looking for system controls...

https://docs.octoprint.org/en/master/configuration/config_yaml.html#system

Yes, that looks like what I was looking for. Thanks, I will give it a try.

I'm curious if the Easy Servo plugin would work for you to control the pan/tilt?

I tried it, but Easy Servo uses Gpio and I could never get it to work. Probably something I was doing. The board I have though is based on I2C and I have some python scripts that work though I have yet to figure out how to get them to work without going through an ssh connection.

ZK36

Yeah, I looked at the python code on that waveshare's wiki pages as the example. You'd definitely have to make a separate control interface for OctoPrint if you wanted to. There was one other plugin that controls that same chip it appears but is used to control an LED strip. Merging the two together would probably get you what you needed.

Thanks. Yea, I looked at that one, but you are right that I probably need to create my own plugin and combine the two. Now, I just need to figure out how to do that as I am fairly new to python. Sounds like a good project though.

The PCA9685 LED Strip Control plugin does not have issues enabled and is not Python 3 compatible. @ZK36, you would be doing the community a solid if you started with that plugin, added what you need to it, and published it. There are numerous people on these forums (and the discord) that would help you over any hurdle you encounter.

Okay, I added

system:
actions:

  • name Shutdown x735
    action shutdown_x735
    command: x735off
    confirm: You are about to shutdown the system and turn power off to Raspberry Pi 3B.

to the config.yaml file in the .octoprint directory, but that stopped the server from even starting until I removed it from the config.yaml file.

Okay, so I was able to get it to add the menu entry using the system command. I had a couple of typos that I fixed. But it won't run the command that I can use when I ssh over to it. The command is x730off and is in /usr/local/bin.

You have to use the full path to the file. so change it to this.

system:
    actions:
    -   name: Shutdown x735
        action: shutdown_x735
        command: /usr/local/bin/x735off
        confirm: You are about to shutdown the system and turn power off to Raspberry Pi 3B.

I am thinking about it though I will do it in Python 2.7 initially as that is what my octoprint is based on. Several of the plugins I use are not Python 3 compatible so I have resisted converting my version of octoprint to Python 3. Once I get it working though I can certainly convert it to Python 3 once I install another copy of octoprint. This probably won't happen right away though, only as time allows.

okay, I was wondering about that. I did not do that as I don't normally have to use the full path.

Well, I am having a lot of trouble getting that script to work. I specified the command as /usr/local/bin/x730off and it fails saying permission denied for gpio. If I add sudo then I get

command: /usr/local/bin/x730off

Command for custom:shutdown_x735 failed with return code 1:
STDOUT: X730 Shutting down...

STDERR: /usr/local/bin/x730off: line 6: /sys/class/gpio/gpio18/direction: Permission denied
/usr/local/bin/x730off: line 7: /sys/class/gpio/gpio18/value: Permission denied
/usr/local/bin/x730off: line 20: echo: write error: Operation not permitted

command: sudo /usr/local/bin/x730off

Command for custom:shutdown_x735 failed with return code 1:
STDOUT: 
STDERR: sudo: no tty present and no askpass program specified

Any ideas?

Haven't personally done much with gpio, but think there are options in raspi-config related to that. You also might have to add the pi user to the dialout and gpio rules or something like that.

I was in the same boat as you when I added Python 3 compatibility to my plugin, FanSpeedMirror. I was able to create a virtual environment with Python 3 and switch back and forth with a couple of renames. I did the changes, updated my plugin, and then switched back to Python 2 so all the other plugins I use would work again :smile:

pi is already a member of the dialout and gpio groups. Like I said before though, when I connect remotely to the pi through ssh using the pi user account the script runs fine. It is only in the Octoprint web interface that I get permission errors.

Okay, looks like I was mistaken. I do have to use the password when I connect via ssh. Maybe it was remembering my password those times I did not have to use my password.

Do you know how I can get the script to execute without asking for a password? I tried adding it to the sudoers file pi ALL=NOPASSWD: /usr/local/bin/x730off, but that did not work either.