@execute command not running before job

edited July 2023 in Repetier-Server
I am setting up a 2nd printer currently.  This works on the first printer (Duplicator i3)  but that printer display is powered via the USB cable even when the main power is unplugged, not sure if this is relevant here but the Kobra Max does not do this (no display, etc when only USB plugged in).  I have an execute command that I have set to run prior to a print job, this command pulls a pin low to turn a relay on and power the printer (As defined in repetier server) below.  I did test this command via GCODE when printer is on and it works as designed when the printer is already on. However since this command is run to turn on the printer, the printer will always be off prior to this command running.  If the printer is off this "run before print GCODE"option does not run prior to the print job starting.  The print job is in the print queue but the command never runs to turn on the printer so it'll never print obviously.   In this case would I be better off calling a program to set the pin low rather than trying to send GCODE prior to it connecting?

Thanks much,
Dave

«1

Comments

  • More important is the printer still communicating with the server when main power is off, meaning is the conected icon green and firmware runs just move/heat won't work due to missing main power? Actually if it is red it should even not start the print at all so neither before run or main gcode. In that case you would need to put it on a button in printer menu so you can enable it and then start print.

    Also does the command get execute with sync="true" and a delay so power get on before program executes? Normally programs are executed asynchronously so server would not wait for them to finish.
  • edited July 2023
    The printer is NOT communicating when off.  When the GPIO pin is high (printer OFF) the printer is red in Repetier server (Kobra Max).  Repetier host shows "offline" in the top right.  If I disconnect from the Kobra Max and connect to the connected Duplicator i3+ I can still send @execute Kobra_Max_ON command via GCODE and it'll work but I need to be able to have either that @execute command work before print to the Kobra Max via the Run before job area or run a script to pull that pin low via script before job starts to turn on printer.  I am trying to automate the proccess like I do on my Duplicator i3 so when I start a print it runs the @execute command to turn on the print.  The functioning duplicator i3 has some residual board power via USB even when mains power to it is off, unlike this Kobra Max.  

    I do not have sync on as the program @execute Kobra_Max_ON is what turns the printer on, it has to be the first step and is not dependent on any other process.  It has to be the first thing that happens.  Until I get that command to work, printer is off completely.  So if I could somehow get that @execute command to process either under the connected duplicator i3 printer or if there is a way for me to automate running of the script that @execute Kobra_Max_ON calls to run first that'd fix the problem.  

    I should be a bit more clear why this matters to me.  I slice w/ CURA and send right to repetier server.  I rarely (If ever) have server or host open so i'd have to open one of those to toggle the printer on w/ a button.  As an aside is there a way to have that power button in host be used to run a @gpio command?  I wanted to tie that to ;@gpio Power toggle.  I'm going to look into the replacement command for M80 and see if I can use ;@gpio Power toggle in the use instead field, hopefully that works.

    BTW, I'm working on integrating multiple pi cams via that multiplextor I discussed earlier into your system.  Perhaps you can integrate it into /usr/local/Repetier-Setup/bin/installWebcam2 when I am done.  Right now I'm just doing some reverse engineering of how web UI interfaces and sets up the cameras and runs the mjpgStart server and StartAllCams

  • Another observation.  if I go into printer console I can run that @execute command fine. 


  • edited July 2023
    An observation. In printer console I can use the @execute command fine, even w/ printer off.
  • Yes, unconnected printers can still run server commands. We changed that since you can do so many things still in scripts without gcode that it made sense. Just gcode does not get send to printer. Also putting fpio command con power on/off should work in server. Not sure about host since host does only execute when printer is online so it would not send it and probably send M80 anyway. So chances are that host can not do it.

    For starting a job you need to have the printer online or it will queue, which is what you already experienced.

    You could make a script that makes a api call to send the command and put that on your desktop to quickly enable it.

    Regarding webcam there is mainly startAllCams that checks cams and starts them. Then there is another script for communication that delivers list of webcams. For pi cam it just checks existens and always maps to port 9000. So if you extend the checks for second webcam and map that always to 9001 and also report it when queried it is included. And even if you do not report it, when it gets started you can enter url manually. So that is the most crucial part. Just for official solution it should be reported.
  • Is there a way to make gcode actually send to an unconnected printer?  So to be clear, I send my jobs right to repetier server via Cura.  There is no way that the @execute command can be  sent to an "offline" printer sort of like I do when I go into printer commands in server and manually run that @execute command while it's offline to turn on the GPIO pin which in turn turns on the printer?  We know unconnected printers can still receive server commands, I just need to find a way to allow sending at least one server command to an unconnected printer.  I really hope to automate this rather than have to go and turn on the printer before each print.

    Thanks
    Dave
  • Sure you can use console to send server commands. Also API send command would work. The main issue is that you can not start a job when printer is marked offline which is what cura plugin does when you send gcode. So you need a solution that sends a manual command with your execute command. It can be a simple batch script with a curl command to send it. Not sure if you can add such things in cura maybe via a plugin to trigger commands.
  • Repetier said:
    Sure you can use console to send server commands. Also API send command would work. The main issue is that you can not start a job when printer is marked offline which is what cura plugin does when you send gcode. So you need a solution that sends a manual command with your execute command. It can be a simple batch script with a curl command to send it. Not sure if you can add such things in cura maybe via a plugin to trigger commands.
    Thank you, i am going to look into an API send command.  Do you have documentation on that?  I did fine some posts regarding this but nothing in the server manual

    Dave
  • API is documented here
    https://prgdoc.repetier-server.com/v1/docs/index.html#/en/web-api/bridge
    in forum you might find some examples of curl and send call which is the most frequently used one. See api doc:
    https://prgdoc.repetier-server.com/v1/docs/index.html#/en/web-api/websocket/control?id=send-a-g-code

  • Repetier said:
    API is documented here
    https://prgdoc.repetier-server.com/v1/docs/index.html#/en/web-api/bridge
    in forum you might find some examples of curl and send call which is the most frequently used one. See api doc:
    https://prgdoc.repetier-server.com/v1/docs/index.html#/en/web-api/websocket/control?id=send-a-g-code

    Thanks much.  After much trial and error I have the API part working.  I can send a command and turn printer on / off using the command below but any suggestions on the best way to automate this before the print?  I don't think I can put this in start Gcode correct?   Any suggestions how to get this to run before a print job from a particular printer on the repetier side?  I will continue to look on the cura side per your previous suggestions as well.

  • On server side you can use a gpio button. But in upload there are no more ways to call code except the event "printJobAdded" which gets called after adding it. So if this is your only way you can add a event listener and check if no print is running, printer is offline and then enable printer and start next job in queue. This happens after soring so it would not have started when disabled and the event is triggered. But do not forget to add a delay for connection, so make the start in a @func block called with a timer after enabling power.
  • edited July 2023
    Yeah I do that now but that requires me opening server and using the button then sending the job.  It may be best just to keep this printer on at all times unfortunately.  

    With your way server would constantly be running a command to check for the event  "printJobAdded" and then start printer/print job?  Does that utilize a bunch of resources doing that constantly?  Can this be done in the "response to event field" in server?   if not, can you give me a little sample of how I could do this as I'm not exactly following.

    I saw this in a previous post of yours:

    "That is just a firmware message not triggering any scriptable events. So it is complicated and would require programming skills. You can create own events in printer config based on server responses. But it still does not trigger any scripts. So you would need a lua extension that listens for this special event and executes your sound script. Not sure if that is within your skills.

    Thinking about it I will add a script to these advanced events. There might be more such special cases where it might be useful to execute some operations on special messages. Then you can add an @execute in that script. I'm just at the edge of creating next update anyway to fix some minor but a bit annoying issues.'


    Thanks much,

    Dave
  • > With your way server would constantly be running a command to check for the event  "printJobAdded" and then start printer/print job? 
    No it does not, but the example is pasing communication which would. I mean add a event listener in "Run on activation.

    Like
    @func startFirstInQueue

    @func enableAndStart
      @if {{job.running==0 && state.online!=0 }}
        @gpio .... ; enable power
        @timedCall startQueue 4000 startFirstInQueue

    @callOnEvent "printJobAdded" enableAndStart

    But be aware that uploading with old print on bed can be fatal this way.
  • edited July 2023
    Sorry dumb question but where would I put this?   As an aside I have a curl script set up and I did create a shortcut to run the command in powershell to turn on/off the printer w/ an icon on my desktop but I hope to automate it w/ these commands you are referring to.  

    Also, on the topic of those buttons in host I think I found a bug.  I created a ticket on it recently, perhaps you could take a quick look at that when you are able?


    Dave


  • You put it in run on activate script, so it is active as soon as you activate it. Afterwards deactivate and activate to install new functions.
  • Repetier said:
    You put it in run on activate script, so it is active as soon as you activate it. Afterwards deactivate and activate to install new functions.
    Sorry if i'm a bit obtuse here.

    1.  I assume you mean to put this into the "run on printer activation" area of repetier server like in the attached image??
    2.  On the line where you say to start printer " @gpio .... ; enable power"  should I be using the GPIO command @gpio Power on which I have configured and tested to work (to power printer on/off by using @gpio power on/off) in global settings | GPIO pins ?  If so that isn't working.  I see the job in queue on repetier host under "waiting prints"
  • 1. Yes
    2. Yes whatever command you have to enable power
    Note that this command does not get triggered on activation. It gets triggered when you add a new file to print queue! So just adding it with gcode already there would not work. But you can test manually be triggering it:
    @call enableAndStart

    If you are unsure if something gets called add
    @echo Some message
    in the functions eventuelly with computed expressions to see why if does not trigger.
    @echo online: {{state.online}}
    for example.

    Remember changes in this code require deactivate/activate printer to reparse the content!
  • edited July 2023
    Repetier said:
    1. Yes
    2. Yes whatever command you have to enable power
    Note that this command does not get triggered on activation. It gets triggered when you add a new file to print queue! So just adding it with gcode already there would not work. But you can test manually be triggering it:
    @call enableAndStart

    If you are unsure if something gets called add
    @echo Some message
    in the functions eventuelly with computed expressions to see why if does not trigger.
    @echo online: {{state.online}}
    for example.

    Remember changes in this code require deactivate/activate printer to reparse the content!
    I did reboot to apply changes.  I was testing by sending a print job to the queue. When I try to run those echo commands to check the status of those parameters I can only run them when the printer is online.  When I try to run them from the console of the printer which is off (offline)  I get no response.  If i hit send it doesn't return anything unless printer is online.  The printer does say deactivated thought until I turn it on, i don't know if that makes a difference here.

    If I turn printer on manually and run @call enableAndStart I get this however since the printer is already on the print job I sent prior to running the command does start.

    Exec:12:07:04.110: @call enableAndStart
    Mesg:12:07:04.111: syntax error: @gpio name action
    Mesg:12:07:04.111: error: @_endfunc at place with unmatched function start - skipping all blocks



  • Makes sense, there is a 
    @endif
    missing in second function I see. So that would never run.

  • edited July 2023
    Repetier said:
    Makes sense, there is a 
    @endif
    missing in second function I see. So that would never run.

    I see, i just copied what you had stated above line for line. I'm not too knowledgeable on this language and the scripts.  Your post is below, where would i add the @endif?  Sorry for the handholding here I just don't quite grasp all of this side of repetier server it seems.  I just added @endif (maybe in wrong spot?) But now after reboot and attempt to print a job to this printer i am now getting Exec:11:59:35.014: @call enableAndStart printJobAdded "{}" but nothing else happens.  I checked state.online and job.running and both were 0 so I figured it'd run my next line @GPIO Power on but it doesn't seem to be.




    @func startFirstInQueue

    @func enableAndStart
      @if {{job.running==0 && state.online!=0 }}
        @gpio Power on ; enable power
        @timedCall startQueue 4000 startFirstInQueue
        @endif ;I just added this

    @callOnEvent "printJobAdded" enableAndStart





  • @func startFirstInQueue

    @func enableAndStart
      @if {{job.running==0 && state.online!=0 }}
        @gpio Power on
        @timedCall startQueue 4000 startFirstInQueue
      @endif

    @callOnEvent "printJobAdded" enableAndStart


    I also removed comment from @gpio - server commands should never have comments that was just a hint what to do there
  • edited July 2023
    Ok I "sort" of got this working by removing the if command and set delay a bit longer.  I'm not sure why that if statement is having issues since both variables return a 0 so I think it should proceed to the @gpio command but I'm no expert in this at all.

    However, what i am finding is that this only works on first print.  The ONLY way I can get it to work again is if I manually run a GPIO Power Off after the print.  Then the next @GPIO Power call works as designed.  if I do not do this I cannot turn the printer on via @GPIO Power on until I first run an @GPIO Power off.

    My current code (Which works only the first time until I manually type @gpio Power off after print)

    @func startFirstInQueue

    @func enableAndStart
      @gpio Power on 
      @timedCall startQueue 10000 startFirstInQueue
      @echo "10 second delay"

    @callOnEvent "printJobAdded" enableAndStart


  • I found out that in current version @timesCall only works when connected, so gets triggered only when power is on, but that shoul dnot be a problem as long as timeout is long enough to get it connected.

    You should add some @echo commands after @fun line to see if they get called. Should not matter reallt and removing @if is ok since @startNextPrintInQueue should ignore it if a job is running or printer is still offfline.

    Also please check if @startNextPrintInQueue works when you call it manually when it did not trigger. The question here is if a function does not get called or if something fails the second try for some reasons. Will also check @startNextPrintInQueue later to be sure. Just can't test the power part.
  • Repetier said:
    I found out that in current version @timesCall only works when connected, so gets triggered only when power is on, but that shoul dnot be a problem as long as timeout is long enough to get it connected.

    You should add some @echo commands after @fun line to see if they get called. Should not matter reallt and removing @if is ok since @startNextPrintInQueue should ignore it if a job is running or printer is still offfline.

    Also please check if @startNextPrintInQueue works when you call it manually when it did not trigger. The question here is if a function does not get called or if something fails the second try for some reasons. Will also check @startNextPrintInQueue later to be sure. Just can't test the power part.

    NextPrintInQueue  but it did nothing.  Nothing shows up in logs either.  After a successful print w/ the run on activate script powering up printer i shut off the printer w/ a command from extcommands.xml using the repetier server dropdown and the printer shuts down.  I then tried to power it back on w/ @gpio Power On but nothing.   Then I ran @startNextPrintInQueue but nothing happened.  Also tried this again w/o the @gpio Power On first but the result was the same.


    Another side questions.  I see you do not use /etc/rc.local on startup.  What would you recommend as the best way to initiate startup scripts with your image?  

    Thanks again, 
    Dave
  • I just tested @startNextPrintInQueue several times and it did it's job. Of course at the moment it gets called there must be a print in queue and printer must be connected and there must be no job running. So that seems to work.

    I also tested this script
    @func startFirstInQueue
      @echo start first print

    @func enableAndStart
      @echo Power on 
      @timedCall startQueue 10000 startFirstInQueue
      @echo "10 second delay"

    @callOnEvent "printJobAdded" enableAndStart

    It does anything but enable power as it has no such function and it got triggered when I e.g. move a model into queue and started it after 10 seconds. Only difference is the power on and connect.

    I checked if restarting deletes the timer or events, but it does not. So your version should work as far as I can say. Please try my version and check if it works with power already on. Remember do disable/activate printer first. Then move a model to queue as test ans see if it starts. Stop and do it again. On every event this command gets executed

    @call enableAndStart printJobAdded "{}"

    you can try also with jobs in queue to start them with 10s delay.

  • edited July 2023
    Repetier said:
    I just tested @startNextPrintInQueue several times and it did it's job. Of course at the moment it gets called there must be a print in queue and printer must be connected and there must be no job running. So that seems to work.

    I also tested this script
    @func startFirstInQueue
      @echo start first print

    @func enableAndStart
      @echo Power on 
      @timedCall startQueue 10000 startFirstInQueue
      @echo "10 second delay"

    @callOnEvent "printJobAdded" enableAndStart

    It does anything but enable power as it has no such function and it got triggered when I e.g. move a model into queue and started it after 10 seconds. Only difference is the power on and connect.

    I checked if restarting deletes the timer or events, but it does not. So your version should work as far as I can say. Please try my version and check if it works with power already on. Remember do disable/activate printer first. Then move a model to queue as test ans see if it starts. Stop and do it again. On every event this command gets executed

    @call enableAndStart printJobAdded "{}"

    you can try also with jobs in queue to start them with 10s delay.



    Thank you for the continued support/replies! 
    I think there is a bit of confusion.  If the printer is on and I run  @startNextPrintInQueue it works just fine to start the print.  The issue is after the the first job runs where it turns on printer properly  (using @gpio Power on) and the printer is turned off after the print @gpio Power ON will not work again to power on printer (Either running that command manually or with the run on printer activation). I have to manually type @gpio Power off one time and then the @gpio Power on command will work again.  It's like repetier thinks that the gpio state is still on so it doesn't even try to run the @gpio Power on command. 

    I did some more testing and found that if i change my repetier server gode (via run after job gcode) that powers off the printer from the ext command I was using @execute Kobra_Max_OFF (Would just send the pin high to turn off the relay powering the printer) to @gpio Power off my next print would work fine.  So there has to be some logic in there somewhere that has repetier server still thinking the printer is on so it doesn't run that @gpio Power on until it sees a @gpio Power off?

    On the topic of the GPIO power commands is there a way to specify this for different printers?  Right now @GPIO power On/off/toggle will only work for one printer.  It would be nice if I could do something like @GPIO Power (blob or GPIO Pin #) On/Off/toggle so the GPIO power command could be used for multiple printers.  I know you can specify the printer for the server UI power switching but to use via CLI it'd be nice to be able to opt for what printer you want the power command to function for.

    Another side questions.  I see you do not use /etc/rc.local on startup.  What would you recommend as the best way to initiate startup scripts with your image?  


    Dave
  • /etc/rc.local is fine I think. We just use services to run our scripts, but that is complicted for a personal image so no need to add an own service just for that.

    Are you sure a print is stopped with @execute ... My thinking is that it looses connection during end of print and that triggers something preventing it from working again and one is not marking job as finished.

    You can use @gpio for any number of pins. It also works cross printer. The printer association is just to define in which menu it should appear, but does not prevent from being used as server command.
  • edited July 2023
    /etc/rc.local does NOT execute on boot.  I verified this by creating a test text document from rc.local when it runs and it does not create that test text document on boot.  It is set to +x and if i run it manually it does execute the commands in it just fine. 



    I just now realized that I the display name is different than the name you use for the GPIO and cannot change it.  I thought it "had" to always be power but it is just dependent on the name you create when first setting it up.  

    I'm not sure I understand what you mean by "print is stopped with @execute".  After the print finishes it certainly does run that run after job gcode @execute command as the printer does shut off.  The print is no longer in queue so I assume print is stopped/finished as far as repetier is concerned?  I did find if I put in @GPIO Power off instead of that @execute command it seems to be working as designed.  Not sure why the method matters but it seems to.  HOWEVER, I feel like I'm going backwards here because after realizing that I can name each GPIO pin command individually and control by that I deleted the "Power" GPIO pin and created two new ones.  One is called Kobra and one is called Duplicator.  So now the commands are @GPIO Kobra on|off|toggle and @GPIO Duplicator on|off|toggle and all work when using console.  HOWEVER (Just when I thought I had it) i updated the script to reflect the new @gpio name and it doesn't want to power it on even after rebooting.  I do see the echo of it running the commands however.  

    Current code:
    @func startFirstInQueue

    @func enableAndStart
      @gpio Kobra on
      @echo "Powering on Kobra Max"
      @timedCall startQueue 10000 startFirstInQueue
      @echo "10 second delay to start print"

    @callOnEvent "printJobAdded" enableAndStart


    What I see when sending print:



  • edited July 2023
    LOL you will hate me sooner than later but at least I resolved the @gpio Kobra on issue.  It seems I hadn't rebooted when I thought I had so that is resolved, it does power up as designed.  I did confirm that if i have @gpio Kobra off in run after job area INSTEAD of my extcommand of @execute <command namd> the next print powers on printer as designed.  So there just so happens to be something weird that happens when the printer is shut off w/ anything other than a @gpio command

    I also figured out the rc.local thing as well.
  • For power off I think it would be a good idea to move that in a @func like in start here and call it with a delay, so server can finish and after being finished storing everything etc. it gets shut down with a delay. Also helps head cooling faster when fan is on. Some printers control it by temperature to prevent heat rising when hot.

    But I still wonder what @execute does different as I assume it just switches off power in a script and exits.
Sign In or Register to comment.