I am using the Psu Control plugin. i love the functionality, but it only allows for one gpio to be controlled/triggered. One relay controles the board power another relay controles my ventilators.
I got the gpio control but its very limited and cant be triggered by starting of finishing prints.
Does anyone have a solution?
fork the GPIO control plugin and add in the gcode options or event options the way they are in PSU Control to power off/on etc. This is how I started my many IoT power related plugins. that support multiple devices.
or use GCodeSystemCommands and write a basic python script for flipping the relays.
do you mean physically forking the gpio wire?
My coding skills are not great. Do you maybe have an example for me?
No, I meant fork the plugin repository and adjust the code to include those other bits.
After some struggling, I managed to get a working python script to do what I want.
Unfortunately when I define the scripts in GCODE System Commands and test the OCTO1 command in octoprint terminal, it just says "ERROR" but no explanation whats going wrong.
I am trying to find more documentation on de GCODE System Commands plugin, but so far no luck.
Enable debug logging and see what it says. Can share here as well.
Seems to be a permission issue. Do I need to place the scripts in a different folder? If I try to move them to the folder shown in the plugin screenshot i cant.
octoprint.log (132.5 KB)
I don't think it has to, but assuming you are using an octopi image, it should be able to execute from the /home/pi/scripts/
folder without issue. Did you chmod +X /home/pi/scripts/FanOn.py
(not even sure that's a thing with python scripts)? I wonder if it's because you're using python instead of bash? Otherwise a permissions error is bubbling up from the python script related to GPIO access?
I changed permissions but now Im getting different error in the log.
2021-05-16 11:33:42,627 - octoprint.plugins.gcodesystemcommands - INFO - Command ID 1 returned: 2
2021-05-16 11:33:51,709 - octoprint.plugins.gcodesystemcommands - DEBUG - Command ID=2, Line=/home/pi/scripts/FanOff.py, Args=None
2021-05-16 11:33:51,710 - octoprint.plugins.gcodesystemcommands - INFO - Executing command ID: 2
2021-05-16 11:33:51,944 - octoprint.plugins.gcodesystemcommands - DEBUG - Command ID 2 returned: 2, output=import-im6.q16: unable to open X server `' @ error/import.c/ImportImageCommand/358.
import-im6.q16: unable to open X server `' @ error/import.c/ImportImageCommand/358.
/home/pi/scripts/FanOff.py: 6: /home/pi/scripts/FanOff.py: Syntax error: word unexpected (expecting ")")
2021-05-16 11:33:51,945 - octoprint.plugins.gcodesystemcommands - INFO - Command ID 2 returned: 2
2021-05-16 11:33:57,582 - octoprint.plugins.gcodesystemcommands - DEBUG - Command ID=1, Line=/home/pi/scripts/FanOn.py, Args=None
2021-05-16 11:33:57,583 - octoprint.plugins.gcodesystemcommands - INFO - Executing command ID: 1
2021-05-16 11:33:57,788 - octoprint.plugins.gcodesystemcommands - DEBUG - Command ID 1 returned: 2, output=import-im6.q16: unable to open X server `' @ error/import.c/ImportImageCommand/358.
import-im6.q16: unable to open X server `' @ error/import.c/ImportImageCommand/358.
/home/pi/scripts/FanOn.py: 4: /home/pi/scripts/FanOn.py: Syntax error: word unexpected (expecting ")")
2021-05-16 11:33:57,789 - octoprint.plugins.gcodesystemcommands - INFO - Command ID 1
In both files, you have a syntax error. In the first one, the issue is on line 6, on the second, the issue is on line 4. Try running the files manually from the command line first to make sure they work.
Ive tried running both from terminal and both work. This is what's in them.
FanOn.py
import RPi.GPIO as GPIO
import time
# turn ventilators on
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
pins = [27]
GPIO.setup(pins, GPIO.OUT)
GPIO.output(27, GPIO.HIGH)
GPIO.cleanup()
FanOff.py
import RPi.GPIO as GPIO
import time
# turn ventilators off after 5 min
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
pins = [27]
GPIO.setup(pins, GPIO.OUT)
time.sleep(3)
GPIO.output(27, GPIO.LOW)
delay is currently set to 3 sec instead of 5 min.
it its 4 and 6 it would be the GPIO.setmode(GPIO.BCM) but that should be valid code.
Don't know why it would trip in that.
Line=/home/pi/scripts/FanOff.py, Args=None
You're calling the py file directly but there is no shebang in the source provided. Add a shebang to tell the shell what interpreter to use or call with python
. Might not fix the issue but that's one issue that stands out.
Also make sure exec is set.
Think I found it. (facepalm moment)
forgot the "#!/usr/bin/python" in the first line.
now everything seems to work.
Also the exec calls are blocking. You're script will run but further GCODE will not exec until the script completes.
dont understand.
What should I add to resolve that?
If I do a cleanup at the end of the on script it switches the relay.
You'd have to fork and background the script with a wrapper script.
Im going to try and figure out what that means. I have no clue how to do that.
Okey, The scripts do work but, the terminal show a lot of comments about the script.
I aslo notice that the PSU_control plugin no longer turns off the power relay automatically.
Probably because the script does not compleet.
I've read about the wrapper script you mentioned. That, is way to complex for my current knowledge.
For now, I would be helped by knowing how to roundoff the scripts so they compleet without effecting the altered relay state the script switched.