Giter Site home page Giter Site logo

chunkysteveo / octoprintapi Goto Github PK

View Code? Open in Web Editor NEW
43.0 43.0 24.0 122 KB

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.

License: GNU General Public License v2.0

C++ 100.00%

octoprintapi's People

Contributors

agvxov avatar anfichtn avatar anon1efergwerfwer avatar chunkysteveo avatar fmatray avatar jcassel avatar larssimonsen avatar per1234 avatar ruedli avatar sidddy avatar witnessmenow avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

octoprintapi's Issues

Pushing Temperature of enclosure to Octoprint

Would it be possible to make a small arduino temperature and humidity reader, that pushes the temp to of the enclosure to octoprint. It seems that the latency of some sensors can be a bit of an issue on Raspberry GPIO, this way a local Arduino with LCD display can do the reading and push temperatures on a regular interval to Octoprint/Pi.

values not reset with printer not operational

Hello,
When the printer is not operational, the function getPrinterStatistics() does not reset printerStats.printerStat* and printerStats.printerTemp values.
At least printerStats.printerStateoperational should be false;

if(response == "Printer is not operational"){ String printerState = response; printerStats.printerState = printerState; return true; }

Infinite loop (or almost) with OctoprintApi::sendRequestToOctoprint()

Hello,
The the method OctoprintApi::sendRequestToOctoprint() seems, with some occasion, loop for ever or almost.

One of the occasion is with this answer (octoprint is down and Nginx is responding) :

HTTP/1.0 502 Bad Gateway
Cache-Control: no-cache
Connection: close
Content-Type: text/html

<html><body><h1>502 Bad Gateway</h1>
The server returned an invalid or incomplete response.
</body></html>

The code is waiting for a "Content-Length" that never happen.

What do you think about using ArduinoHttpClient instead of a custom code ?
https://github.com/arduino-libraries/ArduinoHttpClient

Filament length allways 0

Filament length is always reported as 0

Solution:
FILE OctoPrintAPI.h :
CHANGE:
long jobFilamentTool0Length;
TO:
float jobFilamentTool0Length;
AND
CHANGE:
long jobFilamentTool1Length;
TO:
float jobFilamentTool1Length;

FILE OctoPrintAPI.cpp:
CHANGE:
printJob.jobFilamentTool0Length = root["job"]["filament"]["tool0"]["length"] | 0;
TO:
printJob.jobFilamentTool0Length = root["job"]["filament"]["tool0"]["length"] | 0.0;
AND
CHANGE:
printJob.jobFilamentTool0Length = root["job"]["filament"]["tool1"]["length"] | 0;
TO:
printJob.jobFilamentTool0Length = root["job"]["filament"]["tool1"]["length"] | 0.0;

Library version issue

Hi, today I tried to compile the OctoPlugOut code, shared by Ruud Rademaker on the OctoPrint forum, using platformIO. I had an issue with the version of your library the platformIO downloaded 1.1.4 which appears to be the latest. However, it would not compile complaining of missing 'api.octoPrintCoreShutdown'. When I manually downloaded the library from Github as a zip file and then manually installed it in platformIO everything compiled correctly. I note that the most recent changes to the library include the missing item so I wondered if there is a versioning issue between what platformIO picks up and what is downloaded manually.

OctoPrint API can't get "job volume"

I can't get "job volume" from /api/job

OctoPrint Version 1.3.11

here is my json output:

{
  "job": {
    "averagePrintTime": null, 
    "estimatedPrintTime": 13998.720965267157, 
    "filament": {
      "tool0": {
        "length": 13039.22874999944, 
        "volume": 0.0
      }
    }, 
    "file": {
      "date": 1562264575, 
      "display": "AI3M_Apple_Watch_Dock_shell.gcode", 
      "name": "AI3M_Apple_Watch_Dock_shell.gcode", 
      "origin": "local", 
      "path": "AI3M_Apple_Watch_Dock_shell.gcode", 
      "size": 8588159
    }, 
    "lastPrintTime": null, 
    "user": "kayhanbelek"
  }, 
  "progress": {
    "completion": 54.590617150893465, 
    "filepos": 4688329, 
    "printTime": 10048, 
    "printTimeLeft": 8393, 
    "printTimeLeftOrigin": "estimate"
  }, 
  "state": "Printing"
}

New feature : octoPrintSetTemperatures()

Hello,
What do you think about adding a feature et set all temperatures at once.
This can be useful to quickly set all to 0°C and cool down tools and bed.

bool octoPrintSetTemperatures(uint16_t tool0, uint16_t tool1, uint16_t bed);

Question on Style

@chunkysteveo, I am working on an update to handle when a printer is disconnected from OctoPrint.

Right now when your printer is disconnected from OctoPrint, the values in the printerStats are not updated and will hold whatever they held prior to the disconnect. This can be handled at the client side by purposefully inspecting the return code and then parsing out the return body. Not really so good. It should be possible to just look at the printerState that is part of the printerStats struct.

This update would make the assumption that the existing values in printerStats are untrustworthy and therefor should be set to values that reflect the idea that they are not the true current state of the Printer. Also the State text should reflect the unknonw state of the printer. In the case of a 409, there is a JSON object that we can get that text from. In the even of some other error code, it may not have the JSON error at the root and we have to handle that too.

The bool flags are pretty obvious as to what they should be set to in this situation. but the tool and bed values are not as clear. My inclination is to set them to a negative value to make it clear that they cant be real trusted values. This would give some level of obvious feedback to a client developer that did not for some reason look at the State text or the Response code. I would set the float types values to -999.

That being the case, I also see that there is some level of this thinking in how printJob is populated. It is populating floats with 0.0 and ints with 0. And it also sets any strings to empty ("") where there is an issue. Note that the the call to OctoPrint has a response for the Jobs info call returns null as values in the case where the printer is offline and the Printer State just does not return any data. Making it necessary to handle it logically different.

For me 0(Zero) is a real value and is not the same as null. For example. it is possible that the progress values could actually be zero. But the reality is that they are unknown in this state. We can't set the values of the int and float types to null but setting them to 0(zero) is not so good either.

In any change I make, I don't want to break anything that is a well established use case. Thus the ask as to how you would want an update related to this to be handled. Preference wise, setting the printerStats float data to -999 would be preferred but this would also make me want to update the values set in printJob to -999 where needed. The other option would be to set the printerStats to 0(zero) as it is done currently for printJob.

Thoughts?

This may help; the main part of the change to how the printerStats would be populated would look something like this:

   if(isResponseUnexpected){ //All values in the Stats Struct are no lonber good and should not be trusted. 

	//seems approprate to set these to true. Given the state is really unknown/error at his time.
	printerStats.printerStateclosedOrError = true; 
	printerStats.printerStateerror         = true;
	printerStats.printerStatefinishing     = false;
	printerStats.printerStateoperational   = false;
	printerStats.printerStatepaused        = false;
	printerStats.printerStatepausing       = false;
	printerStats.printerStatePrinting      = false;
	printerStats.printerStateready         = false;
	printerStats.printerStateresuming      = false;
	printerStats.printerStatesdReady       = false;
	printerStats.printerStateCancelling  = false;
	
	printerStats.printerBedTempActual = -999;
	printerStats.printerBedTempTarget = -999;
	printerStats.printerBedTempOffset = -999;
	printerStats.printerBedAvailable  = false;
	printerStats.printerTool0TempActual = -999;
	printerStats.printerTool0TempTarget = -999;
	printerStats.printerTool0TempOffset = -999;
	printerStats.printerTool0Available  = false;
	printerStats.printerTool1TempActual = -999;
	printerStats.printerTool1TempTarget = -999;
	printerStats.printerTool1TempOffset = -999;
	printerStats.printerTool1Available  = false;
	
	if(root.containsKey("error")){ //at least we have a well known response message here for state text.
		printerStats.printerState = (const char *)root["error"]; 
		return true;
	}else{//no idea what was returned. This is a very unlikely code path. Other than timeout.
		printerStats.printerState = "Unknown, see (httpErrorBody)";
		return false;
	}

annoying debug messages

Hello,
I found two debug Serial.print to condition with _debug.
Sorry, for the poor correction code quality below, I quickly fixed this with vi.

  strcat(postData, ", \"absolute\": false");
  strcat(postData, " }");
  **if (_debug)** Serial.println(postData);
 if(**_debug &&** statusCodeInt != 200
    and statusCodeInt != 201
    and statusCodeInt != 202
    and statusCodeInt != 204){

      Serial.print("\nSERVER RESPONSE CODE: " + String(statusCodeALL));
      if(body!="") Serial.println(" - " + body);
      else Serial.println();
    }

extractHttpCode() not getting status code clean

Working on a local dev branch - extractHttpCode() function uses statusCode.indexOf(" ") and statusCode.lastIndexOf(" ") to try to get space between number, but some response have two words at end, such as "BAD REQUEST" "NO CONTENT" etc. Code ends up "400 BAD" or "204 NO" etc

Using toInt() works to strip out characters, but not sure how tidy this is?! Keeping it in for now.

....ponders...

New feature: begin()

As it is now of OctoPrintAPI (V1.1.15) it is only possible to initialize it before setup.
This makes problems for dynamic variables.

But i changed the source so that OctoPrintAPI will work from within setup now with success.

Here is what needs to be changed:

In OctoPrintAPI.h

class OctoprintApi {
public:
//OctoprintApi(Client &client, IPAddress octoPrintIp, int octoPrintPort, String apiKey);//DigiHzData removed.
//OctoprintApi(Client &client, char *octoPrintUrl, int octoPrintPort, String apiKey);//DigiHzData removed.
OctoprintApi(Client &client);//DigiHzData added.
void begin(IPAddress octoPrintIp, int octoPrintPort, String apiKey);//DigiHzData added.
void begin(char *octoPrintUrl, int octoPrintPort, String apiKey);//DigiHzData added.
...

In OctoPrintAPI.cpp

#include "OctoPrintAPI.h"

#include "Arduino.h"

OctoprintApi::OctoprintApi(Client &client){//DigiHzData added.
_client = &client;//DigiHzData added.
}//DigiHzData added.

/** OctoprintApi()

  • IP address version of the client connect function
  • */
    //OctoprintApi::OctoprintApi(Client &client, IPAddress octoPrintIp, int octoPrintPort, String apiKey) {//DigiHzData removed.
    void OctoprintApi::begin(IPAddress octoPrintIp, int octoPrintPort, String apiKey) {//DigiHzData added.
    //_client = &client;//DigiHzData removed.
    _apiKey = apiKey;
    _octoPrintIp = octoPrintIp;
    _octoPrintPort = octoPrintPort;
    _usingIpAddress = true;
    }

/** OctoprintApi()

  • Hostname version of the client connect function
  • */
    //OctoprintApi::OctoprintApi(Client &client, char *octoPrintUrl, int octoPrintPort, String apiKey) {//DigiHzData removed.
    void OctoprintApi::begin(char *octoPrintUrl, int octoPrintPort, String apiKey) {//DigiHzData added.
    //_client = &client;//DigiHzData removed.
    _apiKey = apiKey;
    _octoPrintUrl = octoPrintUrl;
    _octoPrintPort = octoPrintPort;
    _usingIpAddress = false;
    }

/** GET YOUR ASS TO OCTOPRINT...
*

  • **/
    ...

After these changes has been made, then you initiate OctoPrintApi before setup with:
OctoprintApi api(client);

And in setup you do either:
api.begin(ip, octoprint_httpPort, octoprint_apikey);//If using IP address
OR
api.begin(octoprint_host, octoprint_httpPort, octoprint_apikey);//If using hostname.

This way, we can pull ip, octoprint_host, octoprint_httpPort and octoprint_apikey from eeprom or sd card.

Unable to retrieve printer statistics

After upgrading the ESP8266 core packages to 2.4.2, an API call for the printerStatistics fails. It seems like the change I introduced a few weeks ago (which enforced connection closure by the server when all response data was sent) leads to "early connection closure" now: Although the response was is yet fully read, _client.available() is zero and _client.connected() is false... weird.

I'm wondering if OctoprintAPI should just consume the standard ESP8266HttpClient instead of implementing its own HTTP client... it should avoid weird issues like this one. What's your opinion on this? I'll probably do that change to fix my current project and I'll be happy to share the fix via pull request :-)

WPA2 or Ethernet access

Hi,
I was hoping to use the OctoPrintAPI for my Bachelors Thesis. However, to access the wireless network, I need to provide SSID, username, and password. Is this possible with the current library?
If not, is there a possibility of using Ethernet?

Thank you

Conflict OctoprintAPI and YoutubeApi

hello and already a big thank you for this bookstore.
As part of a lametric project I am trying to combine different displays from insta, youtube and octoprint on a led matrix. But I am encountering a conflict issue between the youtube api and octoprint.
During requests I receive this kind of message:

egametric_teste_octoprint:232:14: error: 'class YoutubeApi' has no member named 'printJob' subs = api.printJob.progressCompletion; ^ exit status 1 conflicting declaration 'OctoprintApi api' [13:47] egametric_teste_octoprint:200:14: error: 'class OctoprintApi' has no member named 'channelStats' subs = api.channelStats.subscriberCount; ^ exit status 1 conflicting declaration 'YoutubeApi api'`

the 2 libraries seem to come into conflict with each other and for the moment the only solution is to have to make a choice between displaying one or the other.
Is there a trick or a fix coming up to make the 2 work together?

Thanking you in advance for your response and your work.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.