Browse Source

ws: don't flood the log with actions

also, clean-up PGM_P usage and just use `const char*` instead
mcspr-patch-1
Maxim Prokhorov 3 years ago
parent
commit
aece6a99b1
2 changed files with 8 additions and 17 deletions
  1. +6
    -15
      code/espurna/ws.cpp
  2. +2
    -2
      code/espurna/ws.h

+ 6
- 15
code/espurna/ws.cpp View File

@ -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);


+ 2
- 2
code/espurna/ws.h View File

@ -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


Loading…
Cancel
Save