How to get axes from REST API?

What is the problem?
I don't know how to get axes current postion from rest api. I only found in documentation how to set axes postion.

I don't think OctoPrint itself natively knows what the current position is since that's happening in a lagged fashion on the printer board within the firmware. OctoPrint pushes lots of commands into a queue until the firmware says "whoa, too much".

A gcode M114 will query the current position from Marlin/reprap, though. If it's implemented in your firmware then that might be a mechanism for finding out.

Knowing this, there is a way of sending in a gcode command from the REST API. And yet, the expected response is a 204 with no content. So the answer is yes and no.

Another approach would be to write a plugin which uses the Simple API plugin, listen for your own REST API call, inject the M114 into the serial stream, interpret the response and then return that to your client in json.

It doesn't look like the position is directly available through the REST API, but there is already an event that gets fired when OctoPrint receives the response to an M114 command, which includes the parsed coordinates:
https://docs.octoprint.org/en/master/events/index.html#gcode-processing

1 Like