How to acquire and analysis the original data from OctoPrint?

Hi everyone:

I am doing a research project, and currently using OctoPrinter to connect a 3D printer. What I want is to acquire the data from the 3D printer via OctoPrint, then output the data to a cloud platform.

Therefore, I need to find the database or calling APIs to get the result of a JSON file to help me find the required data. I have tried access the data from the front-end and found that communication is generally used JSON for data transfer. It is temporarily determined that the front-end communication logic is implemented in 'client.js' file.

Now I need to see how the plugin source code is obtained, which is equivalent to our source code, and I need to know how to collect the corresponding data. Changing the corresponding text or interface, and modify the existing developed plugin seems to be a good idea.

I want to figure out three questions:

  1. Am I in the right direction? To acquire the data via JSON.
  2. How could I obtain the needed data, then use, demonstrate, analysing it in my cloud platform?
  3. Which solution is much quicker to finish this task for a beginner level programmer?

Can anyone help me with that? I do not have a strong computer science background and codings are not looking straight to me.

I appreciate your help and time.

Jacky

Could you be more specific in what you want to do with "the data"? What is "the data"? Just temperatures, or more?

Am I in the right direction? To acquire the data via JSON.

Acquiring any data from OctoPrint through an external application is best done via the REST API, which does indeed serve up data in JSON.

How could I obtain the needed data, then use, demonstrate, analysing it in my cloud platform?

This is very well documented in the OctoPrint developer documentation here:
https://docs.octoprint.org/en/master/api/index.html

Which solution is much quicker to finish this task for a beginner level programmer?

I don't know if there is a quicker way for a beginner level programmer. The advantage of using the REST API is that you can use just about any language and framework you are comfortable with.

If you are worried about performance issues, or not if you need information that you can not easily get by polling the REST API (eg you need to respond to events in a timing critical way), you may have to look into creating a plugin for OctoPrint. In that case, you would need to use Python:
https://docs.octoprint.org/en/master/plugins/index.html

It is temporarily determined that the front-end communication logic is implemented in 'client.js' file.

I am not quite sure what you mean by that. client.js is documented here:
https://docs.octoprint.org/en/master/jsclientlib/index.html
It will help you consume data from OctoPrint in applications written in Javascript. You don't have to use it. The REST API uses HTTP requests, which can be made in many different ways from many different languages and frameworks.

2 Likes

Hi there:

Thank you so much for your reply. It is beneficial and solving my urgent needs.

  1. For the needed data type, I made a detailed classification. Because in my research project, I am acquiring the data to determine which 3D printer is available or not, and how long it will going to be available or not. Therefore, this data will help me to analysis the 3D printer's status:

Printer's capability related data: Equipment ID (model), technology type (such as maximum supported print size), name, component, supported material type, feedstock type, user information, baud rate, port type, printer's layer resolution and positioning accuracy.

Printer's feasibility related data: Model size, estimated layer height, printer status, and layer information.

Printer's availability related data: Estimated total printing time, printing time left, nozzle/tool temperature (actual and target), bed temperature (actual and target), filament usage/storage, failure detection, real-time command status (pause, cancel, restart, print, repair).

The data should be found and accessed via OctoPrint. A demonstration is enough for this project, and we do not need a mature product. Therefore, to acquire 5-6 different types of data is sufficient for the project, say, considering the data of supported material type, maximum supported print size, nozzle/tool temperature, printer status, total printing time and printing time left.

  1. In terms of data analysation, did you mean that I could follow the instructions under the 'REST API' developing website? If I am choosing to create a plug-in to achieve the functions I mentioned, how long does it usually take in your point of view?

  2. The last website address you attached is the right place of client.js, I fount it in the frontend of http://octopi.local/

I was wondering this file should be the part of OctoPrint software, right? In my opinion, the communication logic should consist of this file, but I am not sure how to use it, does this file helpful for my research project?

Again, I appreciate your reply and help, hope you have a nice day!

Cheers
Jacky

All of the data you list can be accessed by polling the REST API.

Yes. That's why I posted that link.

This file is what the OctoPrint web interface uses to communicate with the OctoPrint backend. You can use it too if your application uses javascript (either in a browser, which I don't think is applicable to you, or on a server in a node.js application). But it is very possible to communicate with the OctoPrint backend using the REST API without using client.js. You dont have to use it. I don't know how useful it is for you to use it, because I don't know what language/framework you will be using.

This is impossible to tell, because I don't know your experience in writing software.

This wouldn't be a school- or work-related project, would it?

And what if it is? We're not supposed to be helpful for school or work related projects?

1 Like

Mostly curious. I do like to hear where these research projects are coming from. If this were a work-related project I tend to encourage the person to support foosel's Patron site, for example. Some of the bigger players (Amazon) in theory are spinning up cloud-based projects with printer farms and presumably have deep pockets and intend to sell Printing-as-a-Service in the future.

When I engage with students as a former instructor I usually try to help them by pointing at the existing resources, teaching them how to farm for answers rather than the Chegg approach.

Hi there:

Sorry for the late reply, a little bit busy yesterday. Thanks for your help again. I've tried using Postman to find data I need with the REST API information website you provided, and I think that should be useful. I should do more research of course.

Again, I appreciate your help.

Hi~ Sorry for the late reply. I knew it's quiet confusing, but it is a school related project. I'm a research master, and trying to propose a IoT gateway framework to support smart manufacturing system. I do not need a mature product but do need to finish a demo. I found OctoPrint and explored it by myself, and I thought it's quiet useful and helpful for my project. Maybe it's a little confusing sometime, but feel free to ask me anything. I appreciate your reply. Cheers.

Fortunately for you, I taught at Origin Code Academy and I also thought that OctoPrint has a mature-enough REST API to be useful for our students.

There are literally a hundred or more projects within this space.

Awesome! That should be helpful, I do need to watch and learn it carefully. Appreciate.

If it's a younger audience, they might enjoy this one.

Hi there:

I am trying to learn PlugIn development tutorials. I have already set up my local development environment by using PyCharm. The python coding which provided in the tutorial website can run in Pycharm and demonstrate the ideal results, but can not be shown in OctoPrint software of course. I was wondering do you know how to find the ~/.octoprint/plugins folder?

In my understanding, this folder should locate in the sd card of the Raspberry Pi I am using, because I tried to do the Hello World PlugIn coding via the Raspberry Pi directly. The path of this folder is ~/oprint/lib/python2.7/site-packages/octoprint/plugins. But I fell this way is not straightforward, how could I edit and save the py file in the folder directly? Maybe there is something I did wrong in the local development environment building?

I appreciate your help.

Cheers
Jacky

No, it isn't, it's literally ~/.octoprint/plugins. On Windows its %APPDATA%\OctoPrint\plugins.

And you can develop on your desktop as well, you don't have to develop on your Pi. You can even develop under Windows or MacOS with OctoPrint installed on the same machine. OctoPrint is platform agnostic. There are guides on how to get things running at https://docs.octoprint.org/en/master/development/environment.html

Hi, foosel!

It is nice to hear from you, and I have to say the OctoPrint is incredible, it helps a lot on my master's research.

The path I mentioned is used for writing py code in the Raspberry Pi directly, by using a keyboard and connected to a screen, and turns out it can work, and I can find this output in the log: octoprint.plugins.helloworld - INFO - Hello World!. I am currently following the tutorial of the website you provided, but I still can not open ~/.octoprint/plugins in the terminal of my Mac laptop. It shows something like this:

-bash: cd: octoprint: No such file or directory
or
-bash: dir: command not found

Sorry for my weak programming background and I appreciate your help.

Cheers
Jacky

It's .octoprint, not octoprint. The dot is important.

If you put stuff in the folder you mentioned you are messing with the installation in way you shouldn't and your stuff will also be overwritten and/or vanish on next update, so you really should use the folder stated.

Hi foosel, thanks for your reply. But it still can not work in my Mac's terminal, and I am confused about that. It looks like this:

(venv) (Octoprint) wifi-172-23-59-25:octoprint myusername$ ~/.octoprint/plugins
-bash: /Users/suziwei/.octoprint/plugins: No such file or directory

When you wish to change directories, you need to use the Linux/macOS/Windows cd command:

cd ~/.octoprint/plugins

If you wanted to verify that any of the directory structure exists:

ls -l ~/.octoprint
ls -l ~/.octoprint/plugins

For a typical macOS installation, however, they decide to store things slightly differently:

cd "~/Library/Application Support/OctoPrint"
ls -l "Library/Application Support/OctoPrint"