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 <ESP8266WebServer.h>
|
||||
#include <ArduinoJson.h>
|
||||
|
||||
class WebAPI {
|
||||
private:
|
||||
void handleNotFound();
|
||||
void handlePutCommand();
|
||||
|
||||
String getStatusJson();
|
||||
public:
|
||||
WebAPI();
|
||||
void init();
|
||||
|
||||
@@ -16,4 +16,6 @@ monitor_speed = 115200
|
||||
board_build.f_cpu = 80000000L
|
||||
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() {}
|
||||
|
||||
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() {
|
||||
server.send(404, "text/plain", "File Not Found\n\n");
|
||||
}
|
||||
|
||||
void WebAPI::handlePutCommand() {
|
||||
queueManager.putCommand(server.arg("plain").c_str());
|
||||
server.send(200, "text/plain", String(queueManager.execQueueSize()));
|
||||
server.send(200, "text/plain", getStatusJson());
|
||||
}
|
||||
|
||||
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.begin();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user