forked from chunkysteveo/OctoPrintAPI
-
Notifications
You must be signed in to change notification settings - Fork 0
/
OctoPrintAPI.h
163 lines (138 loc) · 4.67 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
154
155
156
157
158
159
160
161
162
163
/* ___ _ ____ _ _ _ ____ ___
/ _ \ ___| |_ ___ | _ \ _ __(_)_ __ | |_ / \ | _ \_ _|
| | | |/ __| __/ _ \| |_) | '__| | '_ \| __| / _ \ | |_) | |
| |_| | (__| || (_) | __/| | | | | | | |_ / ___ \| __/| |
\___/ \___|\__\___/|_| |_| |_|_| |_|\__/_/ \_\_| |___|
.......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 // 3s timetout
#define OPAPI_RUN_TIMEOUT (millis() - start_waiting < OPAPI_TIMEOUT) && (start_waiting <= millis())
#define POSTDATA_SIZE 128
#define TEMPDATA_SIZE 24
#define JSONDOCUMENT_SIZE 1024
#define USER_AGENT "OctoPrintAPI/1.1.4 (Arduino)"
#define USER_AGENT_SIZE 64
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;
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;
float printerBedTempHistoryTarget;
};
struct printerChamberCall {
float printerChamberTempActual;
float printerChamberTempOffset;
float printerChamberTempTarget;
long printerChamberTempHistoryTimestamp;
float printerChamberTempHistoryActual;
float printerChamberTempHistoryTarget;
};
class OctoprintApi {
public:
OctoprintApi(Client &client, IPAddress octoPrintIp, uint16_t octoPrintPort, String apiKey);
OctoprintApi(Client &client, char *octoPrintUrl, uint16_t 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;
uint16_t httpStatusCode = 0;
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 octoPrintExtrude(double amount);
bool octoPrintSetBedTemperature(uint16_t t);
bool octoPrintSetTool0Temperature(uint16_t t);
bool octoPrintSetTool1Temperature(uint16_t t);
bool octoPrintSetTemperatures(uint16_t tool0 = 0, uint16_t tool1 = 0, uint16_t bed = 0);
bool octoPrintCoolDown() { return octoPrintSetTemperatures(); };
bool octoPrintSetChamberTemperature(uint16_t t);
bool octoPrintGetPrinterSD();
bool octoPrintPrinterSDInit();
bool octoPrintPrinterSDRefresh();
bool octoPrintPrinterSDRelease();
bool octoPrintGetPrinterBed();
printerBedCall printerBed;
bool octoPrintGetPrinterChamber();
printerChamberCall printerChamber;
bool octoPrintJobStart();
bool octoPrintJobCancel();
bool octoPrintJobRestart();
bool octoPrintJobPauseResume();
bool octoPrintJobPause();
bool octoPrintJobResume();
bool octoPrintFileSelect(String &path);
bool octoPrintPrinterCommand(const char *gcodeCommand);
private:
Client *_client;
String _apiKey;
IPAddress _octoPrintIp;
bool _usingIpAddress;
char *_octoPrintUrl;
uint16_t _octoPrintPort;
char _useragent[USER_AGENT_SIZE];
void closeClient();
void sendHeader(const String type, const String command, const char *data);
int extractHttpCode(const String statusCode);
String sendRequestToOctoprint(const String type, const String command, const char *data);
};
#endif