Jump to content
HaryPlotter

Trying to find a command that changes the current state of the printer from "printing" to "pause" and vice versa

Recommended Posts

Posted · Trying to find a command that changes the current state of the printer from "printing" to "pause" and vice versa

Hi, I am trying to build an interruptor to save filament and or to "pause" prints, when no filament is available anymore.

 

An important step to complete this task is to be able to change the state of the printer from "Printing" to "pause".

I asked some pros in the exibition "formnext" and they told me in the api of the Ultimaker there should be a code. So I looked it up.

 

I found someting promising, but I don´  t get too far. I will add some screenshots so you will see, what I am talking about.

 

1. The api asks me an authorisation. Somehow it lets me go forward if I use "ultimaker" and "admin", so I guess it´ s the same PW as the PW I used to change the extruders...

 

2. There is a command that gives out the current state of the printer. But somehow I can not change the state.

 

3. There is a command that starts with "Curl -x...." But I cannot use that command, as I would like to change the state directly in the command line instead of only getting the current state of the printer.  I think that has to do with programming JSON-Files and I cannot yet program json or python-Files

 

4. Then I looked at the printer connection of Cura and there is a button that allows the printer to be paused. So I tried to find out, what command this button triggers (see screenshot) but still those command lead to nowhere.

 

Maybe someone can help me out here. Without me having to program anything in json or python or something else to be able to stop the print with that command line...

A tech in the exibition told me that should be possible so maybe I overlooked something...

 

Once I have that command ready I will implement that command to be executed when the filament runs out. This I am trying to get done with a raspbery pi.

 

I would appreciate any help here.

 

Thank you

 

 

Daniel1161125013_printstate.thumb.jpg.6951fc5b91b5986b4a28a97617b4b2b8.jpg

Pausing printing command screenshot.jpg

Passphrase.jpg

current state of printer.jpg

Share this post


Link to post
Share on other sites
Posted · Trying to find a command that changes the current state of the printer from "printing" to "pause" and vice versa
5 hours ago, HaryPlotter said:

1. The api asks me an authorisation.

...

So I tried to find out, what command this button triggers (see screenshot) but still those command lead to nowhere.

 

It doesn't lead to nowhere, it just needs a proper authorization (like all PUT and POST commands), that's all.

 

Some explanations about authorization (why and how) from the developer, in the link below.
 

https://community.ultimaker.com/topic/15604-inside-the-ultimaker-3-day-3-remote-access-part-2/

 

...and a second link about the correct syntax for the rest of the curl command:

 

https://community.ultimaker.com/topic/21062-api-print_jobstate-error-code-400/?do=findComment&comment=196861

 

 

Once you have an id/key combination, add the digest authorization to the (corrected) curl command line

curl -X PUT --digest --user YOUR_ID:YOUR_KEY ...

...and i guess you want to store id/key somewhere to use it for subsequent calls.

The Python script from the first link does this for you, but it's a bit crumbled since the last forum migration (as well as the links to other parts of the "Inside..." serie). Since you don't want to use Python anyway, i guess this part is not that important for you?

 

Share this post


Link to post
Share on other sites
Posted · Trying to find a command that changes the current state of the printer from "printing" to "pause" and vice versa

Hi tinkergnome,

 

thank you for your help so far. Slowly I am understanding better now (slowly).

 

So first of all it is not that I am not thinking about programming python. It is just that I haven´t had any experience in it without getting to run a program (timelapse.py) that I found somewhere and it helped alot understanding where a print failed. This I could get to run with some time but I did not programm it.  So I litterally have had to look up what "put" or "get" means.

 

 

So I used the code that was displayed in your links and tried to start it (adding the correct ip-Adress of my printer).. and probabbly I miss out to change some other syntaxes of the code itself.

With  that other program (timelapse.py) I had no big problems to implement that but here I see that I still need some more time with that...

 

Anyhow I am not giving up! There was another problem.. when I "copy/pasted" the lines for python. The editor did put the programme in only one line, which makes the overwiev very nasty. Is there a better way to copy the lines the way I see them in the link into a pyhton program?

 

Anyhow, all theses lines lead to beeing able to set the value "print", "pause" or "abort" pyhsically remotedly. Once I have this figured out correctly I still would like to know if there is a way to putting the "pause"-command into a shell that if executed pauses the print with no further personal handling. Because if it isn´  t, the idea to stop any print with the lack of filament would could not be stopped automatically (e.G. if every time the printer would demand an authorisation). So this remains for me the biggest question.

 

I have added the lines I copied from the remote-access-part an a screenshot of the result of on of the programms...

 

Greetings

 

 

Daniel

 

PS: Please feel free to help me understand, what changes I have to make to get those programms to work propperly (please leave out bad comments as I know that I don´  t know anything about programming)

 

PPS: I changed that extensions from .py to .log to be able to upload the files here...

Syntax error.jpg

test.log Test2.log Test3.log

Share this post


Link to post
Share on other sites
Posted · Trying to find a command that changes the current state of the printer from "printing" to "pause" and vice versa
1 hour ago, HaryPlotter said:

The editor did put the programme in only one line, which makes the overwiev very nasty. Is there a better way to copy the lines the way I see them in the link into a pyhton program?

 

A (the) crucial point with the Python language is that is relies on correct indentations. I'll add the (slightly modified) original script below.

GET, PUT and POST are not part of python - those things are related to the http protocol (AFAIK).

I'm nearly clueless too, most of the time i only combine parts that i found somewhere. 🙂

 

Authorization is only needed once - the printer will ask for confirmation (the same as during the first connection from Cura). You can use the confirmed credentials without further inquiry from this point on.

 

Here is a working example (put all scripts in the same directory).

"UM3_API.py" contains the main class from @Daid.

All other scripts are short examples.

The credentials are stored in a *.data file and re-used if available.

 

um3_api.zip

  • Like 1

Share this post


Link to post
Share on other sites
Posted (edited) · Trying to find a command that changes the current state of the printer from "printing" to "pause" and vice versa

tinkergnome, you are my hero!!!

 

Great job. You even thougt about adapting my IP-Adress. This just brings me so much further...

 

So to say I will have to authorise the PC for once and then it will be executed without asking me that authoristaion again. GREAT!

 

Once I advance with the Raspberry project. I will most certainly keep you uptdated.

 

Just to be sure (I will test it tomorrow):

So for example if I run a print and I want to pause it. I ´  ll go into the command mode (CMD) and I start the pausing python-file throughout python and it should first ask me to authorise this and then pause the printer. Is this right?

Afterwards I could even implement an Icon, when I interlink it with that special command. I hope I got it right.. at least I could do this in Windows..

Because in the end I´ ll have to solve it as a selfexecuting version over Linux that keeps running in the rasp and executes the pausing just if the signal of my fotocell dropps below a certain value... but this I´  ll figure out once I hav the last device ready (still waiting on the laser-diode to drop in)...

 

Greetings

 

 

Daniel

Edited by HaryPlotter

Share this post


Link to post
Share on other sites
Posted · Trying to find a command that changes the current state of the printer from "printing" to "pause" and vice versa
12 hours ago, HaryPlotter said:

So for example if I run a print and I want to pause it. I ´  ll go into the command mode (CMD) and I start the pausing python-file throughout python and it should first ask me to authorise this and then pause the printer. Is this right?

 

Yep.

And if the *.py extension is associated with python.exe (which is usually the case on Windows) - a double click on the pause script should be sufficient (that's how i switch the lights on and off).

 

Good luck!

 

  • Like 1

Share this post


Link to post
Share on other sites
Posted · Trying to find a command that changes the current state of the printer from "printing" to "pause" and vice versa

Yep, all worked out for me. Testing worked great and all of the scripts are doing just what they are supposed to do..

 

Thanks again for the forwarding. So I guess I close the subject for now.

 

I wish to all of you that you will have a great christmas in the upcomming days and weeks and that all your wishes (for filaments and stuff YEAH) are going to come true... ;O)

For myself I had a wish for a new kind of filament (Ultrafuse 316L from BASF) which I will test in January .. the only thing I have to figure out is the shrinkage of the printed objects to after the sintering-process. I was at the formnext one month ago and they tolkd me that the probably will make a software for it once there is enough demand for it.... would be great! And it gets better. Next year they´  ll bring out 2 new filaments based on the same process. On that goes where the PVC gets in. This in order to separate the fiament and make overhangs printable (ceramic based filament) and another Filament in the metall direction ---> Steel or even Titanium. That would make things available that were restricted to people that can afford a Markforged or similar printers... Nice things to come! So happy Christmas!!!

 

Greetings

 

 

Daniel

 

PS: I saw that something is creating a file (I left it here for you as a .log-File). I had been part of a .py File. So I guess this is the Token that the Ultimker creates to allow the program (API) to be executed? Is this a "general-key" or does it create itself again every time at a new "handshake". If not, is it swapable to other PC´  s (e.G. the Rasp) to avoid the authorisation process with another PC? If you don´  t know it doesn´  t matter because the result is there anyhow...

UM3_API.cpython-36.log

Share this post


Link to post
Share on other sites
Posted · Trying to find a command that changes the current state of the printer from "printing" to "pause" and vice versa
7 hours ago, HaryPlotter said:

I saw that something is creating a file (I left it here for you as a .log-File).

 

That's only the python script in a binary form, google found this link:

https://indianpythonista.wordpress.com/2018/01/05/demystifying-pyc-files/

 

Only user and password ("id" and "key") are needed for authorization. Those are currently stored in a *.data file in the same directory (and loaded in the function "initAPI").

  • Like 1

Share this post


Link to post
Share on other sites
Posted · Trying to find a command that changes the current state of the printer from "printing" to "pause" and vice versa

Great! Thanks again...

 

You´  re a great teacher. Now I even know that... so instead of Compiling the whole program each time, running the .pyc-code is much easier for the interpreter to understand and thus saves time. I can even decompile those files back to the original scripts. That is wild!

Understood the ID and KEY, log as well. Now I´ m starting to draw again because today I got myself a small touchscreen I want to implement ontop of my rasp... makes programming and testing the code later much easier..

 

Greetings

 

 

Daniel

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...