Retrieivng GCODE from Octoprint

Hello, I was wondering what the best approach was to access gcode information (line by line) to a Unity project in real time? I have tried downloading the gcode from the octoprint api but I would prefer to access the current gcode line being printed (like from the terminal on the website). Is there any plugins or something in the API to pull from? Thank you!

You can use logs from this api Push updates β€” OctoPrint master documentation

But it's only pushed every 0.5 seconds afaik.

It also gives you "just" the terminal output. That means the line was just transmitted - not the printer is executing it right now. There are buffers on the printer side and long running commands and stuff like that.

If you need it more real time then you need to write a custom plugin.

Hope that's what you're looking for.

May I ask on what kind of project you're working on?

1 Like

Thank you so much, I am working on a digital twin in Unity VR of two 3D printers (both run octoprint and I currently have a system to send a web request to print a gcode file). I want to interpret the gcode file to create a basic model (I have a rough code for that), but that 0.5 sec buffer means I'll probably just download the gcode file from octoprint and interpret the code through there.

Sorry maybe I worded it badly.

The "update rate" is 0.5 seconds. It doesn't give you the output in realtime - it sends it in blocks every half a second.

That doesn't mean that there's only 0.5 seconds worth of data in there. As far as I understand it you get the whole cached log every time. I'm not 100% sure tho and can't really test it. I'll ask foosel for more details tomorrow.

The buffer which I was referring to is inside the printer. It buffers multiple gcodes and processes them after the last one was executed. That means if you print a slow line for example, the last send gcode could take some time until it's executed.

I just mentioned it so you're aware of that.

I for example maxed out my gcode buffer which means the gcode commands in the terminal are sometimes for the next layer or even the next 2-3 layers.

Your project sounds interesting :slight_smile:
It would be nice if you could share some pictures or clips with us :tentacle:

1 Like

Alrighty I asked foosel again how it works :slight_smile:

When you connect to the logs via the api the first time, you also get the transmission logs of the past, but from then you only get updates in 0.5s intervals. That means as long as you're connected you won't miss anything.

1 Like

Ok then that should go along with my project great! Once I get further along I will try to show some pictures (right now it's a work in progress). Thank you again!

1 Like