Browse Source

Use arduinojson to print to weblog

pull/931/head
Maxim Prokhorov 6 years ago
parent
commit
2357b290a5
2 changed files with 12 additions and 9 deletions
  1. +11
    -8
      code/espurna/debug.ino
  2. +1
    -1
      code/html/custom.js

+ 11
- 8
code/espurna/debug.ino View File

@ -68,17 +68,20 @@ void _debugSend(char * message) {
#if DEBUG_WEB_SUPPORT
if (wsConnected() && (getFreeHeap() > 10000)) {
String m = String(message);
m.replace("\"", """);
m.replace("{", "&#123");
m.replace("}", "&#125");
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["weblog"] = buffer;
#else
snprintf_P(buffer, sizeof(buffer), PSTR("{\"weblog\": \"%s\"}"), m.c_str());
root["weblog"] = message;
#endif
wsSend(buffer);
String out;
root.printTo(out);
jsonBuffer.clear();
wsSend(out.c_str());
pause = true;
}
#endif


+ 1
- 1
code/html/custom.js View File

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


Loading…
Cancel
Save