Sorry - I have tried every permutation of path and Python version I can think of entering into GCode Command, all without success. Would be nice if I can find out the reason it is failing instead of just a simple "error" response from Octoprint.
In OctoPrint Settings, Logging, I set octoprint.plugins.gcodesystemcommands
to DEBUG
.
I created two scripts, success:
#!/bin/bash
echo ID: $OCTOPRINT_GCODESYSTEMCOMMAND_ID >>/home/pi/gcsyscmd.txt
echo ARGS: $OCTOPRINT_GCODESYSTEMCOMMAND_ARGS >>/home/pi/gcsyscmd.txt
echo LINE: $OCTOPRINT_GCODESYSTEMCOMMAND_LINE >>/home/pi/gcsyscmd.txt
exit 0
and fail:
#!/bin/bash
echo ID: $OCTOPRINT_GCODESYSTEMCOMMAND_ID >>/home/pi/gcsyscmd.txt
echo ARGS: $OCTOPRINT_GCODESYSTEMCOMMAND_ARGS >>/home/pi/gcsyscmd.txt
echo LINE: $OCTOPRINT_GCODESYSTEMCOMMAND_LINE >>/home/pi/gcsyscmd.txt
exit 1
I set OCTO10 to be /home/pi/success 10
and OCTO11 to be /home/pi/fail 11
.
After typing OCTO10
and OCTO11
into the terminal, the terminal output was:
Exec(GCodeSystemCommands): OCTO10
Return(GCodeSystemCommands): ok
[...]
Exec(GCodeSystemCommands): OCTO11
Return(GCodeSystemCommands): error
and octoprint.log contained:
2022-08-15 14:31:48,052 - octoprint.plugins.gcodesystemcommands - INFO - Add command definition OCTO10 = /home/pi/success 10
2022-08-15 14:31:48,054 - octoprint.plugins.gcodesystemcommands - INFO - Add command definition OCTO11 = /home/pi/fail 11
2022-08-15 14:32:10,256 - octoprint.plugins.gcodesystemcommands - DEBUG - Command ID=10, Line=/home/pi/success 10, Args=None
2022-08-15 14:32:10,257 - octoprint.plugins.gcodesystemcommands - INFO - Executing command ID: 10
2022-08-15 14:32:10,314 - octoprint.plugins.gcodesystemcommands - DEBUG - Command ID 10 returned: 0, output=b''
2022-08-15 14:32:10,314 - octoprint.plugins.gcodesystemcommands - INFO - Command ID 10 returned: 0
2022-08-15 14:32:18,301 - octoprint.plugins.gcodesystemcommands - DEBUG - Command ID=11, Line=/home/pi/fail 11, Args=None
2022-08-15 14:32:18,301 - octoprint.plugins.gcodesystemcommands - INFO - Executing command ID: 11
2022-08-15 14:32:18,362 - octoprint.plugins.gcodesystemcommands - DEBUG - Command ID 11 returned: 1, output=b''
2022-08-15 14:32:18,363 - octoprint.plugins.gcodesystemcommands - INFO - Command ID 11 returned: 1
I'd suggest you enable debug for the plugin and see what output appears in octoprint.log. The issue could be as simple as the script isn't returning the correct status. Probably not but I think the debug output in the log will be useful.
Created the scripts as provided by copy/paste. Set the two shell scripts (success.sh and fail.sh) to executable. Created the OCTO commands 10 and 11 in GCode Command, then executed and then behind them executed OCTO15 (deploy brush) in the Octoprint terminal. OCTO10 & 11 returned Success in the terminal. OCTO15 returned error. Here are the entries from octoprint.log:
2022-08-15 17:23:21,264 - octoprint.plugins.gcodesystemcommands - INFO - Executing command ID: 10
2022-08-15 17:23:21,315 - octoprint.plugins.gcodesystemcommands - INFO - Command ID 10 returned: 127
2022-08-15 17:23:27,172 - octoprint.plugins.gcodesystemcommands - INFO - Executing command ID: 11
2022-08-15 17:23:27,219 - octoprint.plugins.gcodesystemcommands - INFO - Command ID 11 returned: 127
2022-08-15 17:23:47,258 - octoprint.plugins.gcodesystemcommands - INFO - Add command definition OCTO15 = python3 ./OCTO15.py
2022-08-15 17:23:47,258 - octoprint.plugins.gcodesystemcommands - INFO - Add command definition OCTO10 = /home/pi/success.sh
2022-08-15 17:23:47,258 - octoprint.plugins.gcodesystemcommands - INFO - Add command definition OCTO11 = /home/pi/success.sh
2022-08-15 17:24:02,700 - octoprint.plugins.gcodesystemcommands - INFO - Executing command ID: 10
2022-08-15 17:24:02,743 - octoprint.plugins.gcodesystemcommands - INFO - Command ID 10 returned: 126
2022-08-15 17:24:02,744 - octoprint.plugins.gcodesystemcommands - INFO - Executing command ID: 10
2022-08-15 17:24:02,779 - octoprint.plugins.gcodesystemcommands - INFO - Command ID 10 returned: 126
2022-08-15 17:24:09,110 - octoprint.plugins.gcodesystemcommands - INFO - Executing command ID: 11
2022-08-15 17:24:09,157 - octoprint.plugins.gcodesystemcommands - INFO - Command ID 11 returned: 126
2022-08-15 17:25:00,909 - octoprint.plugins.gcodesystemcommands - INFO - Executing command ID: 15
2022-08-15 17:25:01,001 - octoprint.plugins.gcodesystemcommands - INFO - Command ID 15 returned: 2
2022-08-15 17:27:50,418 - octoprint.plugins.gcodesystemcommands - INFO - Executing command ID: 10
2022-08-15 17:27:50,464 - octoprint.plugins.gcodesystemcommands - INFO - Command ID 10 returned: 0
2022-08-15 17:27:56,428 - octoprint.plugins.gcodesystemcommands - INFO - Executing command ID: 11
2022-08-15 17:27:56,476 - octoprint.plugins.gcodesystemcommands - INFO - Command ID 11 returned: 0
2022-08-15 17:28:02,561 - octoprint.plugins.gcodesystemcommands - INFO - Executing command ID: 15
2022-08-15 17:28:02,656 - octoprint.plugins.gcodesystemcommands - INFO - Command ID 15 returned: 2
Here is the python script for OCTO15:
#Below will import all the extra functionality desired and create the initialising statement for access to all 16 PWM signals.
from time import *
from adafruit_servokit import ServoKit
kit = ServoKit(channels=16)
#Below decides the angle of all servos
kit.servo[0].angle = 90
Here is the shell script I'm attempting to run from GCode Commands:
#!/usr/bin/bash
/usr/bin/python3.7 /home/pi/OCTO15.py
NOTE: I have tried calling python3 as well, and absolutel paths to both python and teh script as well as relative paths to the script which sites in /home/pi.
For readability, please enclose scripts and logs with the </>
icon. This keeps that text from being scanned for markdown.
It doesn't look like you added the logging debug for the plugin but from what was output by the plugin, I see some unexpected results.
The plugin will return success or failure based on the status returned by the script. This status returned by the scripts I posted is the parameter to the exit
with zero (0) for success, non-zero (1-255) for failure. See this for a more detailed explanation.
It also looks like OCTO10 and OCTO11 were both set to /home/pi/success.sh
which explains why they both succeed. Your script is returning a 2 which is a failure.
I have an Adafruit DC & Stepper Motor HAT attached to my RPi 3B and use the following script called from a plugin I authored, https://github.com/b-morgan/OctoPrint-FanSpeedMirror.
#!/usr/bin/python3
import time
import board
import sys
from adafruit_motorkit import MotorKit
kit = MotorKit(i2c=board.I2C())
# get the speed from 0 (off) to 255 (max speed)
s = int(float(sys.argv[1])+0.5)
# fans won't run at really low speeds so don't try
if s < 32:
kit.motor3.throttle = 0
kit.motor4.throttle = 0
else:
# make sure speed is in range
s = min(s,255)
if s < 80:
# for low speeds, goose the fan to get it started
kit.motor3.throttle = 0.75
kit.motor4.throttle = 0.75
time.sleep(0.05)
# set the fan speed
t = float(s)/255.0
# do both fans
kit.motor3.throttle = t
kit.motor4.throttle = t
I added OCTO15 as python3 /home/pi/cpfan2.py 50
and OCTO16 as python3 /home/pi/cpfan2.py 0
and both commands execute successfully. If I leave off the parameter (OCTO17 as python3 /home/pi/cpfan2.py
) then I get an error and the debug output in octoprint.log shows me exactly what went wrong:
2022-08-16 07:52:56,753 - octoprint.plugins.gcodesystemcommands - DEBUG - Command ID=17, Line=python3 /home/pi/cpfan2.py, Args=None
2022-08-16 07:52:56,754 - octoprint.plugins.gcodesystemcommands - INFO - Executing command ID: 17
2022-08-16 07:52:57,022 - octoprint.plugins.gcodesystemcommands - DEBUG - Command ID 17 returned: 1, output=b'Traceback (most recent call last):\n File "/home/pi/cpfan2.py", line 9, in <module>\n s = int(float(sys.argv[1])+0.5)\nIndexError: list index out of range\n'
2022-08-16 07:52:57,023 - octoprint.plugins.gcodesystemcommands - INFO - Command ID 17 returned: 1
From my experiments, I believe what you are attempting to do will work as soon as we can narrow down exactly what is causing the error.
I see a number after the python command line OCTO15 (50 in that one, and 0 in the python line after OCTO16) in what you posted. and I have seen it a couple other times too - I have no number - what is that number and could that be the problem?
I GOT IT!!! I went in and started playing with both the python and shell scripts. NOT sure what I did that made it work - but IT'S WORKING!!! Thank you!!!
Applications, shell scripts, and Python scripts all can be passed parameters. In my script, I get the first parameter with sys.argv[1]
and use that to set the speed. My plugin captures the parameter on the gcode command M106 and passes it on to the script.
The fans (red boxes) are attached to the frame of the printer and provide additional cooling for PLA. The gcode sets the tool head fan speed and the plugin mirrors that speed to these two fans.
I had a need and solved the problem before the GpioFanController plugin existed. My solution used an "off the shelf" RPi HAT and left the actual fan control to code running on the RPi.
If you are willing to do the wiring, the GpioFanController plugin has some additional functionality.