-
Notifications
You must be signed in to change notification settings - Fork 24
/
OctoPrintAPI.h
153 lines (131 loc) · 4.35 KB
/
OctoPrintAPI.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
/* ___ _ ____ _ _ _ ____ ___
/ _ \ ___| |_ ___ | _ \ _ __(_)_ __ | |_ / \ | _ \_ _|
| | | |/ __| __/ _ \| |_) | '__| | '_ \| __| / _ \ | |_) | |
| |_| | (__| || (_) | __/| | | | | | | |_ / ___ \| __/| |
\___/ \___|\__\___/|_| |_| |_|_| |_|\__/_/ \_\_| |___|
.......By Stephen Ludgate https://www.chunkymedia.co.uk.......
*/
#ifndef OctoprintApi_h
#define OctoprintApi_h
#include <Arduino.h>
#include <ArduinoJson.h>
#include <Client.h>
#define OPAPI_TIMEOUT 3000
#define POSTDATA_SIZE 256
#define POSTDATA_GCODE_SIZE 50
#define JSONDOCUMENT_SIZE 1024
#define USER_AGENT "OctoPrintAPI/1.1.6 (Arduino)"
struct printerStatistics {
String printerState;
bool printerStateclosedOrError;
bool printerStateerror;
bool printerStatefinishing;
bool printerStateoperational;
bool printerStatepaused;
bool printerStatepausing;
bool printerStatePrinting;
bool printerStateready;
bool printerStateresuming;
bool printerStatesdReady;
float printerBedTempActual;
float printerBedTempTarget;
float printerBedTempOffset;
bool printerBedAvailable;
float printerTool0TempActual;
float printerTool0TempTarget;
float printerTool0TempOffset;
bool printerTool0Available;
float printerTool1TempTarget;
float printerTool1TempActual;
float printerTool1TempOffset;
bool printerTool1Available;
};
struct octoprintVersion {
String octoprintApi;
String octoprintServer;
};
struct printJobCall {
String printerState;
long estimatedPrintTime;
long jobFileDate;
String jobFileName;
String jobFileOrigin;
long jobFileSize;
String jobFilePath;
float progressCompletion;
long progressFilepos;
long progressPrintTime;
long progressPrintTimeLeft;
String progressprintTimeLeftOrigin;
long jobFilamentTool0Length;
float jobFilamentTool0Volume;
long jobFilamentTool1Length;
float jobFilamentTool1Volume;
};
struct printerBedCall {
float printerBedTempActual;
float printerBedTempOffset;
float printerBedTempTarget;
long printerBedTempHistoryTimestamp;
float printerBedTempHistoryActual;
};
class OctoprintApi {
public:
OctoprintApi(void);
OctoprintApi(Client &client, IPAddress octoPrintIp, int octoPrintPort, String apiKey);
OctoprintApi(Client &client, char *octoPrintUrl, int octoPrintPort, String apiKey);
void init(Client &client, char *octoPrintUrl, int octoPrintPort, String apiKey);
void init(Client &client, IPAddress octoPrintIp, int octoPrintPort, String apiKey);
String sendGetToOctoprint(String command);
String getOctoprintEndpointResults(String command);
bool getPrinterStatistics();
bool getOctoprintVersion();
printerStatistics printerStats;
octoprintVersion octoprintVer;
bool getPrintJob();
printJobCall printJob;
bool _debug = false;
int httpStatusCode = 0;
String httpErrorBody = "";
String sendPostToOctoPrint(String command, const char *postData);
bool octoPrintConnectionDisconnect();
bool octoPrintConnectionAutoConnect();
bool octoPrintConnectionFakeAck();
bool octoPrintPrintHeadHome();
bool octoPrintPrintHeadRelativeJog(double x, double y, double z, double f);
bool octoPrintPrintHeadAbsoluteJog(double x, double y, double z, double f);
bool octoPrintPrintHeadJog(double x, double y, double z, double f,bool absolute);
bool octoPrintExtrude(double amount);
bool octoPrintSetBedTemperature(uint16_t t);
bool octoPrintSetTool0Temperature(uint16_t t);
bool octoPrintSetTool1Temperature(uint16_t t);
bool octoPrintGetPrinterSD();
bool octoPrintPrinterSDInit();
bool octoPrintPrinterSDRefresh();
bool octoPrintPrinterSDRelease();
bool octoPrintGetPrinterBed();
printerBedCall printerBed;
bool octoPrintJobStart();
bool octoPrintJobCancel();
bool octoPrintJobRestart();
bool octoPrintJobPauseResume();
bool octoPrintJobPause();
bool octoPrintJobResume();
bool octoPrintFileSelect(String &path);
bool octoPrintCoreShutdown();
bool octoPrintCoreReboot();
bool octoPrintCoreRestart();
bool octoPrintPrinterCommand(char *gcodeCommand);
private:
Client *_client;
String _apiKey;
IPAddress _octoPrintIp;
bool _usingIpAddress;
char *_octoPrintUrl;
int _octoPrintPort;
const int maxMessageLength = 1000;
void closeClient();
int extractHttpCode(String statusCode, String body);
String sendRequestToOctoprint(String type, String command, const char *data);
};
#endif