diff --git a/code/espurna/debug.ino b/code/espurna/debug.ino index 641d28a7..7eea7ccb 100644 --- a/code/espurna/debug.ino +++ b/code/espurna/debug.ino @@ -68,17 +68,20 @@ void _debugSend(char * message) { #if DEBUG_WEB_SUPPORT if (wsConnected() && (getFreeHeap() > 10000)) { - String m = String(message); - m.replace("\"", """); - m.replace("{", "{"); - m.replace("}", "}"); - char buffer[m.length() + 24]; + DynamicJsonBuffer jsonBuffer(JSON_OBJECT_SIZE(1) + strlen(message) + 17); + JsonObject &root = jsonBuffer.createObject(); #if DEBUG_ADD_TIMESTAMP - snprintf_P(buffer, sizeof(buffer), PSTR("{\"weblog\": \"%s%s\"}"), timestamp, m.c_str()); + char buffer[strlen(timestamp) + strlen(message) + 1]; + snprintf_P(buffer, sizeof(buffer), "%s%s", timestamp, message); + root.set("weblog", buffer); #else - snprintf_P(buffer, sizeof(buffer), PSTR("{\"weblog\": \"%s\"}"), m.c_str()); + root.set("weblog", message); #endif - wsSend(buffer); + String out; + root.printTo(out); + jsonBuffer.clear(); + + wsSend(out.c_str()); pause = true; } #endif diff --git a/code/html/custom.js b/code/html/custom.js index 49d2ab34..78e7a077 100644 --- a/code/html/custom.js +++ b/code/html/custom.js @@ -1217,7 +1217,7 @@ function processData(data) { // Web log if ("weblog" === key) { - $("#weblog").append(value); + $("#weblog").append(new Text(value)); $("#weblog").scrollTop($("#weblog")[0].scrollHeight - $("#weblog").height()); return; }