Custom button to run python script in windows

OctoPrint 1.8.1
Python 3.9.0
Windows 10 21H2

I am using an android device as a webcam, my goal is through the octoprint server I can turn on, turn off the device's camera, control the led light, and activate the autofocus, this through some commands sent in adb, I have tested all these features through individual scripts and they work perfectly, the problem is in the integration with octoprint

Options I have tried
I have consulted 3 different ways that I found to be able to execute system commands in octoprint

Custom control editor
One of them is through the "Custom Control Editor" plugin, adding an option based on script, where I added the script for example to turn on the camera on the device I added .py file in C:\Users\User\AppData\Roaming\OctoPrint\scripts\, and i add the script in custom control editor as "", but this doesnt works, i saw that this type of system commands is not possible to run from control button section

In this second way i tried adding custom G-CODE "OCTO901" to run the file with the following command "C:\Users\User\AppData\Roaming\OctoPrint\scripts\", but when i run this code im getting the following error image


I tried using "start "" C:\Users\User\AppData\Roaming\OctoPrint\scripts\" same error
And finally using "start "" "C:\Users\User\AppData\Local\Programs\Python\Python39\python.exe" "C:\Users\User\AppData\Roaming\OctoPrint\scripts\", not error, but doesnt run the script

system commands
In the config.yaml the System Buttons I confiured the script and it works perfectly, so the problem is implementing this GCodeSystemCommands for using as custom button in Control Tab

another option is using built in event manager and react to print start/stop events to automate it and not have to use a button.

You might have better luck with the other options by creating a batch file (.bat) with the command to run in it and set the system command setting to that batch file.

This method works, however there are still some actions that I want to perform, and that are only possible through the buttons, for example, turning the light on and off at convenience and manual focus

I have tried executing a .bat file and even executing the command directly, this did not work.

I found an option in the events section called GcodeScript${ScriptName}Running, I created an empty G-CODE script and executed it according to the configuration, the file is executed, I can see it in the octoprint terminal, but since it is not G -CODE "Unknown command" errors are thrown, however I expected the gcode script detection event to be fired to execute my actual script, it didn't work

command: start "" "C:\Users\User\Documents\Scripts octoprint\"
enabled: true
event: GcodeScript${camera_on}Running
type: system

Well, that makes sense to me since since it's not a gcode script, they are not the same as batch file. When you tried gcode system commands with the batch file were you still using start? That shouldn't be necessary and the command should just be the path to your batch file. Any errors in log?

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