Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Printing progress #6

Open
dragondgold opened this issue Sep 1, 2015 · 15 comments
Open

Printing progress #6

dragondgold opened this issue Sep 1, 2015 · 15 comments

Comments

@dragondgold
Copy link

Would it be possible to get the printing progress (0.0% to 100.0%) using octocmd status?

@vishnubob
Copy link
Owner

Maybe, does OctoPrint provide this information via the API?

@dragondgold
Copy link
Author

Yes, it should be possible !http://docs.octoprint.org/en/master/api/datamodel.html#progress-information I would do it myself but I am new at python and I still don't understand how you use the rest API to communicate with octoprint

@vishnubob
Copy link
Owner

Sounds to me like a perfect project for you to get to know python! Good luck, and I look forward to your pull request.

@dragondgold
Copy link
Author

@vishnubob I'm slowly understanding your code and I successfully done some GET request to obtain print progress and some other data. The problem is with POST request. Apparently I have to specify the Content-Type to application/json otherwise I get Response [500]. I tried to add it to the post method inside OctoPrint_API so I call self.session.post(self.url + url, args=args, headers={'content-type': 'application/json'}) but I get Response [400] on that way.

Can you give me some hint about what I'm doing wrong?

@vishnubob vishnubob reopened this Sep 16, 2015
@vishnubob
Copy link
Owner

ok, i've updated the code a bunch. the problem is octocmd and octoprint have drifted somewhat. there are still some problems, but check out the new code and see if you have you still get a 400.

@dragondgold
Copy link
Author

When trying to run a POST now I get:

Traceback (most recent call last):
  File "/Applications/PyCharm.app/Contents/helpers/pydev/pydevd.py", line 2358, in <module>
    globals = debugger.run(setup['file'], None, None, is_module)
  File "/Applications/PyCharm.app/Contents/helpers/pydev/pydevd.py", line 1778, in run
    pydev_imports.execfile(file, globals, locals)  # execute the script
  File "/Users/andrestorti/Copy/Impresora 3D/Control Externo/octocmd/scripts/octocmd", line 514, in <module>
    process(args)
  File "/Users/andrestorti/Copy/Impresora 3D/Control Externo/octocmd/scripts/octocmd", line 504, in process
    op.pause_job()
  File "/Users/andrestorti/Copy/Impresora 3D/Control Externo/octocmd/scripts/octocmd", line 307, in pause_job
    res = self.post("control/job", data={"command": "pause"})
  File "/Users/andrestorti/Copy/Impresora 3D/Control Externo/octocmd/scripts/octocmd", line 243, in post
    return self.session.post(self.url + url, **kw)
  File "/Users/andrestorti/Copy/Impresora 3D/Control Externo/octocmd/scripts/octocmd", line 221, in session
    self._session.headers["X-Api-Key"] = self.key
  File "/Users/andrestorti/Copy/Impresora 3D/Control Externo/octocmd/scripts/octocmd", line 211, in key
    return self.config["OctoAPI_KEY"]
TypeError: string indices must be integers, not str

When I debugged the code self.config was just a string containing the path to the config file. Also if I run octocmd init:

Traceback (most recent call last):
  File "/Users/andrestorti/Copy/Impresora 3D/Control Externo/octocmd/scripts/octocmd", line 514, in <module>
    process(args)
  File "/Users/andrestorti/Copy/Impresora 3D/Control Externo/octocmd/scripts/octocmd", line 509, in process
    process_init(args)
  File "/Users/andrestorti/Copy/Impresora 3D/Control Externo/octocmd/scripts/octocmd", line 475, in process_init
    if test_config(cache):
  File "/Users/andrestorti/Copy/Impresora 3D/Control Externo/octocmd/scripts/octocmd", line 461, in test_config
    op = OctoPrint_API(config=config)
  File "/Users/andrestorti/Copy/Impresora 3D/Control Externo/octocmd/scripts/octocmd", line 207, in __init__
    self.location = "sdcard" if kw["sdcard"] else "local"
KeyError: 'sdcard'

There seems to be a problem with the new sdcard option

@vishnubob
Copy link
Owner

I'm not sure why you got these errors, but I pushed some changes that might address them. Please try it again, and let me know if it works.

@dragondgold
Copy link
Author

GET works great but still having issues with POST. I'm just adding this inside OctoPrint_API

    def pause_job(self):
        res = self.post("control/job", data={'command': 'pause'})
        return self.check_response(res, 204)

I'm getting this error:

Traceback (most recent call last):
  File "/Users/andrestorti/Copy/Impresora 3D/Control Externo/octocmd/scripts/octocmd", line 514, in <module>
    process(args)
  File "/Users/andrestorti/Copy/Impresora 3D/Control Externo/octocmd/scripts/octocmd", line 504, in process
    res = op.pause_job()
  File "/Users/andrestorti/Copy/Impresora 3D/Control Externo/octocmd/scripts/octocmd", line 309, in pause_job
    res = self.post("control/job", data={'command': 'pause'})
  File "/Users/andrestorti/Copy/Impresora 3D/Control Externo/octocmd/scripts/octocmd", line 245, in post
    return self.session.post(self.url + url, **kw)
  File "/Users/andrestorti/Copy/Impresora 3D/Control Externo/octocmd/scripts/octocmd", line 223, in session
    self._session.headers["X-Api-Key"] = self.key
  File "/Users/andrestorti/Copy/Impresora 3D/Control Externo/octocmd/scripts/octocmd", line 211, in key
    return self.config["OctoAPI_KEY"]
TypeError: string indices must be integers, not str

I'm running this with Python 2.7.10 on OS X Yosemite. The errors with the init command are fixed however.

@vishnubob
Copy link
Owner

What is the command line you are executing?

@dragondgold
Copy link
Author

I added a pause command. I'm just running this:

op = OctoPrint_API(**args.__dict__)
res = op.pause_job()

Here is the complete code if you want to see: http://pastebin.com/LXYRhGHk.

@vishnubob
Copy link
Owner

Thanks for the code, but I was asking how you were executing the command from the shell.

@dragondgold
Copy link
Author

Hooo, I'm running it inside PyCharm!

@vishnubob
Copy link
Owner

I've never used PyCharm, and since this is written as a command line tool, I can't really help you without an analogous command line example that replicates your results.

@vishnubob
Copy link
Owner

Reading your code further, it doesn't seem like you execute load_config(), which is why you are getting the error. Notice that the status command loads the config. If you model your command based on this, it should work. Good luck.

@e77
Copy link

e77 commented Jan 30, 2021

status command should have a -continuous switch where it just polls every couple of seconds.

octoprint-cli does this, so it shouldn't be too hard to achieve.

progress %age, current layer number, Z height would also be useful additions to the output

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants