Library for use with Arduino compatible micro controllers (web enabled) to access the Octoprint API on Raspberry Pi's (or any Linux based box) running the OctoPrint 3D printer web server by the brilliant Gina Häußge, aka @foosel.
You can connect to the OctoPrint server via it's awesome REST API and pull back information about the state of the 3D printer, the temperatures of it's print bed, hotend(s), and any current print job progress. In fact, you can do most things via the REST API with some GET and POST commands.
Crucially I use this to keep track of current print job completion percentage. Using something simple like a Neopixel stick - you can have a portable progress bar sat next to you, while your 3D printer is printing away in your garage, basement, shed etc. Saves you time opening up a browser in your laptop or phone, and logging in and viewing the current status - just glace up at some LEDs and see how far it's gone.
This library will make it easy for you to get the information, I leave it up to you what and how you process this data in the most useful or pointless way!
You will of course need a 3D printer which is running on OctoPrint, and an Arduino compatible microcontroller that can connect to the internet/your network - basically an ESP8266! Your OctoPi installation will need a valid API key, and you will also need to enable CORS.
In your OctoPrint server settings, go to Api and enable it, and copy the API Key.
You need to enable this to access the API.
You can check if your server is ready to accept request to the REST API by going to it in a browser on a PC/laptop and adding in the API key as a parameter. The URL would look something like this:
http://192.168.1.2/api/version?apikey=ABC123DEF456ETCYOUGETHEIDEA
where 192.168.1.2 is the local IP of your OctoPrint server, and ABC123DEF456ETCYOUGETHEIDEA is your API key.
Your browser should give you something like this:
{
"api": "0.1",
"server": "1.3.6"
}
Hooray, you can now talk to your OctoPrint server via it's API. And so can your Arduino.
It works if you use your hostname and custom port that forwards... more instructions to follow :)
Available in the official Arduino Library Manager - Sketch -> Include Library -> Manage Libraries... and then search for "octoprint" and click Install!
Also available via GitHub if you clone it or download as a ZIP. The downloaded ZIP code can be included as a new library into the IDE selecting the menu:
Sketch / include Library / Add .Zip library
You will also have to install the awesome ArduinoJson library written by Benoît Blanchon. Search ArduinoJson on the Arduino Library manager or get it from here. If you've not got it already, what have you been doing?!
Include OctoPrint API in your project:
#include <OctoPrintAPI.h>
This is the first sketch to try out. Enter your WiFi credentials, your OctoPrint network info, API key, compile and upload. Open the serial monitor and you should start to see printer information coming back. Works on both ESP8266 and ESP32 boards.
Uses the getPrintJob() function of the class to get the current print job and returns most of the useful API variables. Gives a "real world" example of using the variables to print more human readable info once collected from the API.
See the LICENSE.md file for details
1.1.0
It's a big update to this new library, but needed to allow it to work across all (probably) Arduino clients, and not just ESP8266. Big up to Brian Lough @witnessmenow for this update which swapped out HTTPClient to passing the (whatever) client TO the library instead. If you are using the library already - you will need to update your scripts to the new call staring call - Sorry!
Added ESP32 example too as proof of concept for that platform, thanks again to Brian for confirming this works.
Stephen Ludgate:
Email - info@chunkymedia.co.uk
https://github.com/chunkysteveo/OctoPrintAPI
git checkout -b feature/fooBar
)git commit -am 'Add some fooBar'
)git push origin feature/fooBar
)