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

View File

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

View File

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