diff --git a/code/espurna/debug.ino b/code/espurna/debug.ino index 08318ab5..554e3fdc 100644 --- a/code/espurna/debug.ino +++ b/code/espurna/debug.ino @@ -61,12 +61,16 @@ void _debugSend(char * message) { #endif #if DEBUG_WEB_SUPPORT - if (wsConnected()) { - char buffer[strlen(message) + 24]; + if (wsConnected() && (getFreeHeap() > 10000)) { + String m = String(message); + m.replace("\"", """); + m.replace("{", "{"); + m.replace("}", "}"); + char buffer[m.length() + 24]; #if DEBUG_ADD_TIMESTAMP - snprintf_P(buffer, sizeof(buffer), PSTR("{\"weblog\": \"%s%s\"}"), timestamp, message); + snprintf_P(buffer, sizeof(buffer), PSTR("{\"weblog\": \"%s%s\"}"), timestamp, m.c_str()); #else - snprintf_P(buffer, sizeof(buffer), PSTR("{\"weblog\": \"%s\"}"), message); + snprintf_P(buffer, sizeof(buffer), PSTR("{\"weblog\": \"%s\"}"), m.c_str()); #endif wsSend(buffer); }