Run GPIO command when job is added to queue

Hi, I'm trying to implement a system to automatically turn my printers on when they receive a job. I'll be using a Raspberry Pi relay hat which works via GPIO, so I've set up a GPIO command using the "set output on/off" function for the relevant pin.

When I run the command in the console or via the menu, I can see on the Pi that it correctly controls the pin state. However I'm struggling to get it to work when I send a job to the printer. If I put the command in the "Run before job" field of the Event Dependent G-codes for the printer, it seems like it only runs when the printer actually starts the job, which only happens when the printer is already powered on.

Is there a way to run a server command as soon as the job is added to the queue, please? 

Comments

  • Good question, but the answer is no.

    There is a event "jobsChanged" that gets triggered every time a job gets modified so clients should reload job list. For 1.2.1 I added "printJobAdded" event that gets triggered when a printjob got added. This also triggers when it was uploaded with autostart! You can start with jobsChanged since it is after upload and last will be send when job gets removed.

    But be aware that this is dangerous - if some objects are on bed or something else goes wrong bad things can happen and you might have forgotten this before you added a print to jobs!

    Your script should then look like this with adjustments

    @func startNext
      @startNextPrintInQueue
    @endfunc

    @if {{job.running == 0 }}
      ...activate code
     ; Start after a delay so printer is up and connected! 5 seconds here
      @timedCall startNextTimer 5000 startNext
    @endif
  • edited November 2021
    Okay, I understand this is all at my own risk :smile:

    I see what that script does but sorry I'm not quite clear on where exactly it goes? I can only find reference to jobsChanged in the API docs - am I going to need to write my own client for this, or is there an easier way that I'm just not seeing?

    Thanks for your help!
  • You are right this way it is useless.

    @func startNext
      @startNextPrintInQueue
    @endfunc

    @func startOnUpload
    @if {{job.running == 0 }}
      ...activate code
     ; Start after a delay so printer is up and connected! 5 seconds here
      @timedCall startNextTimer 5000 startNext
    @endif
    @endfunc

    @callOnEvent jobsChanged startOnUpload

    is what you need. You can add this e.g. in "Run in Printer Activation" event dependent g-code. Because of @callOnEvent it will listen all the time on the event, so no client needed. Needs 1.2.0 to work. In 1.2.1 you should change event into printJobAdded as it is better suited.
  • edited July 2023
    wrong ports sorry.
Sign In or Register to comment.