From aece6a99b11a3b9107e68c324a86acb9c07105e7 Mon Sep 17 00:00:00 2001 From: Maxim Prokhorov Date: Sat, 6 Feb 2021 00:30:24 +0300 Subject: [PATCH] ws: don't flood the log with actions also, clean-up PGM_P usage and just use `const char*` instead --- code/espurna/ws.cpp | 21 ++++++--------------- code/espurna/ws.h | 4 ++-- 2 files changed, 8 insertions(+), 17 deletions(-) diff --git a/code/espurna/ws.cpp b/code/espurna/ws.cpp index 08049a0a..85bf05d5 100644 --- a/code/espurna/ws.cpp +++ b/code/espurna/ws.cpp @@ -338,14 +338,11 @@ void _wsParse(AsyncWebSocketClient *client, uint8_t * payload, size_t length) { const char* action = root["action"]; if (action) { - if (strcmp(action, "ping") == 0) { wsSend_P(client_id, PSTR("{\"pong\": 1}")); return; } - DEBUG_MSG_P(PSTR("[WEBSOCKET] Requested action: %s\n"), action); - if (strcmp(action, "reboot") == 0) { deferredReset(100, CustomResetReason::Web); return; @@ -367,25 +364,19 @@ void _wsParse(AsyncWebSocketClient *client, uint8_t * payload, size_t length) { JsonObject& data = root["data"]; if (data.success()) { - - // Callbacks - for (auto& callback : _ws_callbacks.on_action) { - callback(client_id, action, data); - } - - // Restore configuration via websockets if (strcmp(action, "restore") == 0) { if (settingsRestoreJson(data)) { wsSend_P(client_id, PSTR("{\"message\": 5}")); } else { wsSend_P(client_id, PSTR("{\"message\": 4}")); } + return; } - return; - + for (auto& callback : _ws_callbacks.on_action) { + callback(client_id, action, data); + } } - }; // Check configuration ----------------------------------------------------- @@ -689,7 +680,7 @@ void wsSend(const char * payload) { } } -void wsSend_P(PGM_P payload) { +void wsSend_P(const char* payload) { if (_ws.count() > 0) { char buffer[strlen_P(payload)]; strcpy_P(buffer, payload); @@ -711,7 +702,7 @@ void wsSend(uint32_t client_id, const char * payload) { _ws.text(client_id, payload); } -void wsSend_P(uint32_t client_id, PGM_P payload) { +void wsSend_P(uint32_t client_id, const char* payload) { char buffer[strlen_P(payload)]; strcpy_P(buffer, payload); _ws.text(client_id, buffer); diff --git a/code/espurna/ws.h b/code/espurna/ws.h index c39802a0..019b2fe5 100644 --- a/code/espurna/ws.h +++ b/code/espurna/ws.h @@ -100,8 +100,8 @@ void wsSend(const char* data); // Immediatly try to serialize and send raw char data // (also, see above) -void wsSend_P(PGM_P data); -void wsSend_P(uint32_t client_id, PGM_P data); +void wsSend_P(const char* data); +void wsSend_P(uint32_t client_id, const char* data); // Check if any or specific client_id is connected // Server will try to set unique ID for each client