|
@ -52,11 +52,11 @@ std::vector<web_api_t> _apis; |
|
|
void _wsMQTTCallback(unsigned int type, const char * topic, const char * payload) { |
|
|
void _wsMQTTCallback(unsigned int type, const char * topic, const char * payload) { |
|
|
|
|
|
|
|
|
if (type == MQTT_CONNECT_EVENT) { |
|
|
if (type == MQTT_CONNECT_EVENT) { |
|
|
wsSend("{\"mqttStatus\": true}"); |
|
|
|
|
|
|
|
|
wsSend_P(PSTR("{\"mqttStatus\": true}")); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if (type == MQTT_DISCONNECT_EVENT) { |
|
|
if (type == MQTT_DISCONNECT_EVENT) { |
|
|
wsSend("{\"mqttStatus\": false}"); |
|
|
|
|
|
|
|
|
wsSend_P(PSTR("{\"mqttStatus\": false}")); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
@ -68,7 +68,7 @@ void _wsParse(uint32_t client_id, uint8_t * payload, size_t length) { |
|
|
JsonObject& root = jsonBuffer.parseObject((char *) payload); |
|
|
JsonObject& root = jsonBuffer.parseObject((char *) payload); |
|
|
if (!root.success()) { |
|
|
if (!root.success()) { |
|
|
DEBUG_MSG_P(PSTR("[WEBSOCKET] Error parsing data\n")); |
|
|
DEBUG_MSG_P(PSTR("[WEBSOCKET] Error parsing data\n")); |
|
|
wsSend(client_id, "{\"message\": \"Error parsing data!\"}"); |
|
|
|
|
|
|
|
|
wsSend_P(client_id, PSTR("{\"message\": \"Error parsing data!\"}")); |
|
|
return; |
|
|
return; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -103,7 +103,7 @@ void _wsParse(uint32_t client_id, uint8_t * payload, size_t length) { |
|
|
|
|
|
|
|
|
JsonObject& data = root["data"]; |
|
|
JsonObject& data = root["data"]; |
|
|
if (!data.containsKey("app") || (data["app"] != APP_NAME)) { |
|
|
if (!data.containsKey("app") || (data["app"] != APP_NAME)) { |
|
|
wsSend(client_id, "{\"message\": \"The file does not look like a valid configuration backup.\"}"); |
|
|
|
|
|
|
|
|
wsSend_P(client_id, PSTR("{\"message\": \"The file does not look like a valid configuration backup.\"}")); |
|
|
return; |
|
|
return; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -119,7 +119,7 @@ void _wsParse(uint32_t client_id, uint8_t * payload, size_t length) { |
|
|
|
|
|
|
|
|
saveSettings(); |
|
|
saveSettings(); |
|
|
|
|
|
|
|
|
wsSend(client_id, "{\"message\": \"Changes saved. You should reboot your board now.\"}"); |
|
|
|
|
|
|
|
|
wsSend_P(client_id, PSTR("{\"message\": \"Changes saved. You should reboot your board now.\"}")); |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -264,11 +264,11 @@ void _wsParse(uint32_t client_id, uint8_t * payload, size_t length) { |
|
|
} |
|
|
} |
|
|
if (key == "adminPass2") { |
|
|
if (key == "adminPass2") { |
|
|
if (!value.equals(adminPass)) { |
|
|
if (!value.equals(adminPass)) { |
|
|
wsSend(client_id, "{\"message\": \"Passwords do not match!\"}"); |
|
|
|
|
|
|
|
|
wsSend_P(client_id, PSTR("{\"message\": \"Passwords do not match!\"}")); |
|
|
return; |
|
|
return; |
|
|
} |
|
|
} |
|
|
if (value.length() == 0) continue; |
|
|
if (value.length() == 0) continue; |
|
|
wsSend(client_id, "{\"action\": \"reload\"}"); |
|
|
|
|
|
|
|
|
wsSend_P(client_id, PSTR("{\"action\": \"reload\"}")); |
|
|
key = String("adminPass"); |
|
|
key = String("adminPass"); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -371,9 +371,9 @@ void _wsParse(uint32_t client_id, uint8_t * payload, size_t length) { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if (changed) { |
|
|
if (changed) { |
|
|
wsSend(client_id, "{\"message\": \"Changes saved\"}"); |
|
|
|
|
|
|
|
|
wsSend_P(client_id, PSTR("{\"message\": \"Changes saved\"}")); |
|
|
} else { |
|
|
} else { |
|
|
wsSend(client_id, "{\"message\": \"No changes detected\"}"); |
|
|
|
|
|
|
|
|
wsSend_P(client_id, PSTR("{\"message\": \"No changes detected\"}")); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
@ -608,7 +608,7 @@ bool _wsAuth(AsyncWebSocketClient * client) { |
|
|
|
|
|
|
|
|
if (index == WS_BUFFER_SIZE) { |
|
|
if (index == WS_BUFFER_SIZE) { |
|
|
DEBUG_MSG_P(PSTR("[WEBSOCKET] Validation check failed\n")); |
|
|
DEBUG_MSG_P(PSTR("[WEBSOCKET] Validation check failed\n")); |
|
|
wsSend(client->id(), "{\"message\": \"Session expired, please reload page...\"}"); |
|
|
|
|
|
|
|
|
wsSend_P(client->id(), PSTR("{\"message\": \"Session expired, please reload page...\"}")); |
|
|
return false; |
|
|
return false; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -663,16 +663,30 @@ bool wsConnected() { |
|
|
return (_ws.count() > 0); |
|
|
return (_ws.count() > 0); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
bool wsSend(const char * payload) { |
|
|
|
|
|
|
|
|
void wsSend(const char * payload) { |
|
|
if (_ws.count() > 0) { |
|
|
if (_ws.count() > 0) { |
|
|
_ws.textAll(payload); |
|
|
_ws.textAll(payload); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
bool wsSend(uint32_t client_id, const char * payload) { |
|
|
|
|
|
|
|
|
void wsSend_P(PGM_P payload) { |
|
|
|
|
|
if (_ws.count() > 0) { |
|
|
|
|
|
char buffer[strlen_P(payload)]; |
|
|
|
|
|
strcpy_P(buffer, payload); |
|
|
|
|
|
_ws.textAll(buffer); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void wsSend(uint32_t client_id, const char * payload) { |
|
|
_ws.text(client_id, payload); |
|
|
_ws.text(client_id, payload); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void wsSend_P(uint32_t client_id, PGM_P payload) { |
|
|
|
|
|
char buffer[strlen_P(payload)]; |
|
|
|
|
|
strcpy_P(buffer, payload); |
|
|
|
|
|
_ws.text(client_id, buffer); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
void wsSetup() { |
|
|
void wsSetup() { |
|
|
_ws.onEvent(_wsEvent); |
|
|
_ws.onEvent(_wsEvent); |
|
|
mqttRegister(_wsMQTTCallback); |
|
|
mqttRegister(_wsMQTTCallback); |
|
|