Use of GCODE system commands

Hi all !

I have
OctoPrint version : 1.9.0
OctoPi version : 1.0.0
and plugin
GCODE System Commands 1.0.1)
Installed manually (I don't have this plugins in the GUI menu)

GCODE System Commands comes without useful guide,
however the local community has provided some hints in discussions.

My goal was to somehow turn on and off the LED, which would
illuminate the pad in the evening,
allowing the camera to capture the printing progress.

Raspberry PI4 has a GPIO interface that can control via pins LED.
I made an LED with power supply and regulator. It works (via ssh and a small python program) fine.
But how to glue this with Octoprint?

Then I discovered GCODE System Commands.

The first attempts were very disappointing and
led to the feeling that the path was not there.

But on this portal I found some discussions about this plugin
(the feeling that I am not the only one disappointed), and I got down to work again.

So I have Installed GCODE System Commands.

Now I need to edit ~/.octoprint/octoprint.yaml ( I have the configuration file here, but it may differ for other versions. ).

Here i find controls: and plugin: sections (or if not exist, create them )

and wrote :

controls:
 - children:
  - command: OCTO301
    name: ON
    type: command
  - command: OCTO302
    name: OFF
    type: command
  layout: horizontal
  name: LED
  type: section
~~~
plugins:
  gcodesystemcommands:
    command_definitions:
    - command: /home/octo/scripts/ledON.py
      id: '301'
    - command: /home/octo/scripts/leOFF.py
      id: '302'


scripts must be runnable:
( my scripts ) :

#! /bin/python3
import sys, os
import RPi.GPIO as GPIO
from time import sleep
import logging

def setLogger(logFileName: str):
    logging.basicConfig(
        filename=logFileName,
        format="%(asctime)s [%(levelname)s] %(module)s: %(lineno)d\
        %(funcName)s:  %(message)s",
        level=logging.DEBUG,
        datefmt='%d %H:%M:%S',
        filemode="w"
    )
    logger = logging.getLogger("svit")
    pass

GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
GPIO.setup( 17, GPIO.OUT )


pname=os.path.basename(__file__)
setLogger( '/home/milan/scripts/svit.log')
logging.info(pname)
if pname == "ledON.py":
        print( 'ON' )
        GPIO.output( 17, 1 )
        exit()
elif pname == 'ledOFF.py':
    print( 'OFF' )
    GPIO.output( 17, 0 )
    exit ()


In fact, there is only one script LedON.py which has one link ledOFF.py and script detect, if script is called via link or not.

For action must wait a while ( when printer does all commands in cache ), it is maybe second. But it works greatly.

Excuse me, some parts of topic I wrote with auto translator, so maybe its are unclear.

I hope my article helps someone.

Milan

type or paste code here

Use one of the PlugIns made for this exact thing... that is unless you really want to cobble together your code and make it work the hard way.

A little looking there is this... OctoLight
Looks like exactly what you need.

You see, I was digging through this plugin... well, it's a shame I didn't know about OctoLight before. Thanks for the insight :D.