Add support for longer (logging) text strings

This commit is contained in:
Theo Arends 2021-05-30 16:40:52 +02:00
parent 36d5fc3851
commit 0c8e10ffc4
3 changed files with 13 additions and 16 deletions

View File

@ -2843,15 +2843,15 @@ void HandleHttpCommand(void)
uint32_t index = curridx;
char* line;
size_t len;
WSContentFlush();
while (GetLog(TasmotaGlobal.templog_level, &index, &line, &len)) {
// [14:49:36.123 MQTT: stat/wemos5/RESULT = {"POWER":"OFF"}] > [{"POWER":"OFF"}]
char* JSON = (char*)memchr(line, '{', len);
if (JSON) { // Is it a JSON message (and not only [15:26:08 MQT: stat/wemos5/POWER = O])
size_t JSONlen = len - (JSON - line);
if (JSONlen > sizeof(TasmotaGlobal.mqtt_data)) { JSONlen = sizeof(TasmotaGlobal.mqtt_data); }
char stemp[JSONlen];
strlcpy(stemp, JSON +1, JSONlen -2);
WSContentSend_P(PSTR("%s%s"), (cflg) ? "," : "", stemp);
String stemp = (cflg) ? "," : ""; // Add a comma
stemp.concat(JSON +1, JSONlen -3); // Add a terminating '\0'
Webserver->sendContent(stemp);
cflg = true;
}
}
@ -2928,11 +2928,11 @@ void HandleConsoleRefresh(void)
bool cflg = (index);
char* line;
size_t len;
WSContentFlush();
while (GetLog(Settings.weblog_level, &index, &line, &len)) {
if (len > sizeof(TasmotaGlobal.mqtt_data) -2) { len = sizeof(TasmotaGlobal.mqtt_data); }
char stemp[len +1];
strlcpy(stemp, line, len);
WSContentSend_P(PSTR("%s%s"), (cflg) ? PSTR("\n") : "", stemp);
String stemp = (cflg) ? "\n" : ""; // Add a newline
stemp.concat(line, len -1); // Add a terminating '\0'
Webserver->sendContent(stemp);
cflg = true;
}
WSContentSend_P(PSTR("}1"));

View File

@ -299,11 +299,8 @@ String TelegramExecuteCommand(const char *svalue) {
char* JSON = (char*)memchr(line, '{', len);
if (JSON) { // Is it a JSON message (and not only [15:26:08 MQT: stat/wemos5/POWER = O])
size_t JSONlen = len - (JSON - line);
if (JSONlen > ResponseSize()) { JSONlen = ResponseSize(); }
char stemp[JSONlen];
strlcpy(stemp, JSON +1, JSONlen -2);
if (cflg) { response += F(","); }
response += stemp;
response.concat(JSON +1, JSONlen -3);
cflg = true;
}
}

View File

@ -673,11 +673,11 @@ void HandleBerryConsole(void)
// bool cflg = (index);
// char* line;
// size_t len;
// WSContentFlush();
// while (GetLog(Settings.weblog_level, &index, &line, &len)) {
// if (len > sizeof(TasmotaGlobal.mqtt_data) -2) { len = sizeof(TasmotaGlobal.mqtt_data); }
// char stemp[len +1];
// strlcpy(stemp, line, len);
// WSContentSend_P(PSTR("%s%s"), (cflg) ? PSTR("\n") : "", stemp);
// String stemp = (cflg) ? "\n" : ""; // Add a newline
// stemp.concat(line, len -1); // Add a terminating '\0'
// Webserver->sendContent(stemp);
// cflg = true;
// }
// WSContentSend_P(PSTR("}1"));