@execute command not running before job
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
Thanks much,
Dave
Comments
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.
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
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.
Thanks
Dave
Dave
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
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
No it does not, but the example is pasing communication which would. I mean add a event listener in "Run on activation.
Like
But be aware that uploading with old print on bed can be fatal this way.
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
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"
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!
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.
@endif
missing in second function I see. So that would never run.
@endif ;I just added this
@endif
I also removed comment from @gpio - server commands should never have comments that was just a hint what to do there
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)
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.
I also tested this script
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
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.
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:
What I see when sending print:
I also figured out the rc.local thing as well.
But I still wonder what @execute does different as I assume it just switches off power in a script and exits.