From 04cdb224abced58d0dd50905fa04317ce4725f41 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Xose=20P=C3=A9rez?= Date: Sat, 24 Mar 2018 00:11:45 +0100 Subject: [PATCH] Check free heap when DEBUG_WEB_SUPPORT is enabled to prevent resets --- code/espurna/debug.ino | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) 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); }