OctoPrint Network with Processing

I have set up an OctoPrint (https://octoprint.org/) instance running on a Raspberry Pi. OctoPrint allows for remote control of 3D printers but I wanted to add automation to the mix by using Processing to control OctoPrint.

I know my OctoPrint instance is working, I can connect to it via web browser and submit jobs to the printer that it is connected to. The difficult part seems to be connecting Processing to the OctoPrint. I know there is a library to achieve this via Arduino (GitHub - chunkysteveo/OctoPrintAPI: Library for use with Arduino compatible micro controllers (web enabled) to access the Octoprint API on Raspberry Pi's running the Octoprint 3D printer web server by the brilliant Gina Häußge, aka @foosel.) but, if possible, I want to avoid using an Arduino as a middle man between the Raspberry Pi and my PC as this seems very redundant.

I was hoping to use Processing’s native Network library to create a client to interface with OctoPrint’s API. What I need to understand is:

  • Is this at all feasible or should I use the Arduino as intermediary?
  • OctoPrint requires an API key to communicate with it, how do I transmit this when creating a new Client?
  • The Client class asks for a port, but whenever I try to use any of the ports that I believe are open on OctoPrint I get an error (either “java.net.ConnectException: Connection refused: connect” or “Client SocketException: Socket closed”) is this being caused by the API key not being sent?

Here is the code I have tried to use, with the IP address censored. Please let me know if you have any questions and thanks in advance!

import processing.net.*;

Client myClient;
Client myClient2;
int dataIn;

void setup()
{
size(200, 200);
//use either statement to check port 80 or 5000
myClient = new Client(this, “xxx.xxx.xxx.xxx”, 80);
//myClient2 = new Client(this, “xxx.xxx.xxx.xxx”, 5000);
}