Skip to content

Commit

Permalink
fix long websocket message issue
Browse files Browse the repository at this point in the history
  • Loading branch information
Pako2 committed Dec 31, 2018
1 parent 61f1105 commit 4b66b9a
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 47 deletions.
3 changes: 1 addition & 2 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ lib_deps =
ArduinoJson
ESPAsyncTCP
ESPAsyncUDP
ESP Async WebServer
;https://github.com/me-no-dev/ESPAsyncWebServer#e4950444c41f082c1e040aca97034c3f53c8562c
https://github.com/me-no-dev/ESPAsyncWebServer#e4950444c41f082c1e040aca97034c3f53c8562c
AsyncMqttClient
MFRC522
https://github.com/monkeyboard/Wiegand-Protocol-Library-for-Arduino.git
Expand Down
45 changes: 0 additions & 45 deletions src/webserver.esp
Original file line number Diff line number Diff line change
@@ -1,51 +1,6 @@
void ICACHE_FLASH_ATTR setupWebServer() {
server.addHandler(&ws);
ws.onEvent(onWsEvent);

AsyncCallbackJsonWebHandler *handler = new AsyncCallbackJsonWebHandler("/commit", [](AsyncWebServerRequest *request, JsonVariant &json) {
bool failed = true;
JsonObject &root = json.as<JsonObject>();
if (!root.success())
{
#ifdef DEBUG
Serial.println(F("[ WARN ] Couldn't parse JSON message"));
#endif
}
else
{
// Web Browser sends some commands, check which command is given
if (root.containsKey("command"))
{
const char *command = root["command"];
// Check whatever the command is and act accordingly
if (strcmp(command, "configfile") == 0)
{
File f = SPIFFS.open("/config.json", "w+");
if (f)
{
size_t len = root.measurePrettyLength();
root.prettyPrintTo(f);
f.close();
shouldReboot = true;
//ESP.restart();
writeEvent("INFO", "sys", "Config stored in the SPIFFS", String(len)+" bytes");
#ifdef DEBUG
Serial.print(F("[ INFO ] Config stored in the SPIFFS ("));
Serial.print(len);
Serial.println(F(" bytes)"));
#endif
failed = false;
request->send(202, "text/plain", "Config Success");
}
}
}
}
if (failed) {request->send(405, "text/plain", "Config Failed");}
});
server.addHandler(handler);



server.onNotFound([](AsyncWebServerRequest *request) {
AsyncWebServerResponse *response = request->beginResponse(404, "text/plain", "Not found");
request->send(response);
Expand Down

0 comments on commit 4b66b9a

Please sign in to comment.