mirror of
https://github.com/usatiuk/EggbotWireless.git
synced 2025-10-26 16:57:48 +01:00
webapi returns an actual status message
This commit is contained in:
@@ -3,12 +3,13 @@
|
|||||||
|
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
#include <ESP8266WebServer.h>
|
#include <ESP8266WebServer.h>
|
||||||
|
#include <ArduinoJson.h>
|
||||||
|
|
||||||
class WebAPI {
|
class WebAPI {
|
||||||
private:
|
private:
|
||||||
void handleNotFound();
|
void handleNotFound();
|
||||||
void handlePutCommand();
|
void handlePutCommand();
|
||||||
|
String getStatusJson();
|
||||||
public:
|
public:
|
||||||
WebAPI();
|
WebAPI();
|
||||||
void init();
|
void init();
|
||||||
|
|||||||
@@ -17,3 +17,5 @@ board_build.f_cpu = 80000000L
|
|||||||
upload_resetmethod = nodemcu
|
upload_resetmethod = nodemcu
|
||||||
|
|
||||||
upload_port=/dev/ttyUSB0
|
upload_port=/dev/ttyUSB0
|
||||||
|
|
||||||
|
lib_deps = ArduinoJson@6.11
|
||||||
@@ -5,17 +5,36 @@ ESP8266WebServer server(80);
|
|||||||
|
|
||||||
WebAPI::WebAPI() {}
|
WebAPI::WebAPI() {}
|
||||||
|
|
||||||
|
String WebAPI::getStatusJson() {
|
||||||
|
StaticJsonDocument<256> doc;
|
||||||
|
Status status = executor.status();
|
||||||
|
|
||||||
|
doc["commandQueue"] = queueManager.execQueueSize();
|
||||||
|
doc["eggDia"] = status.eggDia;
|
||||||
|
doc["eggLen"] = status.eggLen;
|
||||||
|
doc["feedrate"] = status.feedrate;
|
||||||
|
doc["mmE"] = status.mmE;
|
||||||
|
doc["mmS"] = status.mmS;
|
||||||
|
doc["pEng"] = status.pEng;
|
||||||
|
doc["xLim"] = status.xLim;
|
||||||
|
|
||||||
|
String out;
|
||||||
|
serializeJson(doc, out);
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
void WebAPI::handleNotFound() {
|
void WebAPI::handleNotFound() {
|
||||||
server.send(404, "text/plain", "File Not Found\n\n");
|
server.send(404, "text/plain", "File Not Found\n\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
void WebAPI::handlePutCommand() {
|
void WebAPI::handlePutCommand() {
|
||||||
queueManager.putCommand(server.arg("plain").c_str());
|
queueManager.putCommand(server.arg("plain").c_str());
|
||||||
server.send(200, "text/plain", String(queueManager.execQueueSize()));
|
server.send(200, "text/plain", getStatusJson());
|
||||||
}
|
}
|
||||||
|
|
||||||
void WebAPI::init() {
|
void WebAPI::init() {
|
||||||
server.on("/putCommand", HTTP_POST, std::bind(&WebAPI::handlePutCommand, this));
|
server.on("/putCommand", HTTP_POST,
|
||||||
|
std::bind(&WebAPI::handlePutCommand, this));
|
||||||
server.onNotFound(std::bind(&WebAPI::handleNotFound, this));
|
server.onNotFound(std::bind(&WebAPI::handleNotFound, this));
|
||||||
server.begin();
|
server.begin();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user