From 74757ee7da9951e2671f1d5984983c303af45561 Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Thu, 27 Mar 2025 17:27:48 +0100 Subject: [PATCH] Fix telnet response if seriallog is 0 --- tasmota/tasmota_support/support.ino | 15 +++- tasmota/tasmota_support/support_tasmota.ino | 4 +- .../xdrv_08_serial_bridge.ino | 2 +- .../tasmota_xdrv_driver/xdrv_78_telnet.ino | 69 +++++++------------ 4 files changed, 41 insertions(+), 49 deletions(-) diff --git a/tasmota/tasmota_support/support.ino b/tasmota/tasmota_support/support.ino index b011545d0..d7cc80ac5 100755 --- a/tasmota/tasmota_support/support.ino +++ b/tasmota/tasmota_support/support.ino @@ -2398,6 +2398,10 @@ void SystemBusyDelayExecute(void) { * \*********************************************************************************************/ +void SetMinimumSeriallog(void) { + TasmotaGlobal.seriallog_level = (Settings->seriallog_level < LOG_LEVEL_INFO) ? (uint8_t)LOG_LEVEL_INFO : Settings->seriallog_level; +} + void SetTasConlog(uint32_t loglevel) { Settings->seriallog_level = loglevel; TasmotaGlobal.seriallog_level = loglevel; @@ -2608,7 +2612,8 @@ bool GetLog(uint32_t req_loglevel, uint32_t* index_p, char** entry_pp, size_t* l } uint32_t HighestLogLevel(void) { - uint32_t highest_loglevel = Settings->seriallog_level; + uint32_t highest_loglevel = TasmotaGlobal.seriallog_level; + if (Settings->seriallog_level > highest_loglevel) { highest_loglevel = Settings->seriallog_level; } if (Settings->mqttlog_level > highest_loglevel) { highest_loglevel = Settings->mqttlog_level; } #ifdef USE_WEBSERVER if (Settings->weblog_level > highest_loglevel) { highest_loglevel = Settings->weblog_level; } @@ -2703,11 +2708,15 @@ void AddLogData(uint32_t loglevel, const char* log_data, const char* log_data_pa // These calls fail to show initial logging log_line += 2; // Skip log_buffer_pointer and loglevel #ifdef USE_SERIAL_BRIDGE - SerialBridgeWrite(log_line, log_data_len); + if (loglevel <= TasmotaGlobal.seriallog_level) { + SerialBridgeWrite(log_line, log_data_len); + } #endif // USE_SERIAL_BRIDGE #ifdef USE_TELNET #ifdef ESP32 - TelnetWrite(log_line, log_data_len); // This uses too much heap on ESP8266 + if (loglevel <= TasmotaGlobal.seriallog_level) { + TelnetWrite(log_line, log_data_len); // This uses too much heap on ESP8266 + } #endif // ESP32 #endif // USE_TELNET diff --git a/tasmota/tasmota_support/support_tasmota.ino b/tasmota/tasmota_support/support_tasmota.ino index b42f79a8f..cdf000360 100644 --- a/tasmota/tasmota_support/support_tasmota.ino +++ b/tasmota/tasmota_support/support_tasmota.ino @@ -1870,7 +1870,7 @@ void SerialInput(void) if (!Settings->flag.mqtt_serial && (TasmotaGlobal.serial_in_byte == '\n')) { // CMND_SERIALSEND and CMND_SERIALLOG TasmotaGlobal.serial_in_buffer[TasmotaGlobal.serial_in_byte_counter] = 0; // Serial data completed - TasmotaGlobal.seriallog_level = (Settings->seriallog_level < LOG_LEVEL_INFO) ? (uint8_t)LOG_LEVEL_INFO : Settings->seriallog_level; + SetMinimumSeriallog(); if (serial_buffer_overrun) { AddLog(LOG_LEVEL_INFO, PSTR(D_LOG_COMMAND "Serial buffer overrun")); } else { @@ -1937,7 +1937,7 @@ void TasConsoleInput(void) { } } else if (console_in_byte == '\n') { - TasmotaGlobal.seriallog_level = (Settings->seriallog_level < LOG_LEVEL_INFO) ? (uint8_t)LOG_LEVEL_INFO : Settings->seriallog_level; + SetMinimumSeriallog(); if (console_buffer_overrun) { AddLog(LOG_LEVEL_INFO, PSTR(D_LOG_COMMAND "USB buffer overrun")); } else { diff --git a/tasmota/tasmota_xdrv_driver/xdrv_08_serial_bridge.ino b/tasmota/tasmota_xdrv_driver/xdrv_08_serial_bridge.ino index 783ca8fd8..c3d1842a5 100644 --- a/tasmota/tasmota_xdrv_driver/xdrv_08_serial_bridge.ino +++ b/tasmota/tasmota_xdrv_driver/xdrv_08_serial_bridge.ino @@ -156,7 +156,7 @@ void SerialBridgeLoop(void) { } else if (serial_in_byte == '\n') { serial_bridge_buffer[SBridge.in_byte_counter] = 0; // Serial data completed - TasmotaGlobal.seriallog_level = (Settings->seriallog_level < LOG_LEVEL_INFO) ? (uint8_t)LOG_LEVEL_INFO : Settings->seriallog_level; + SetMinimumSeriallog(); if (serial_bridge_overrun) { AddLog(LOG_LEVEL_INFO, PSTR(D_LOG_COMMAND "SSerial buffer overrun")); } else { diff --git a/tasmota/tasmota_xdrv_driver/xdrv_78_telnet.ino b/tasmota/tasmota_xdrv_driver/xdrv_78_telnet.ino index 867092b18..cf38bdc80 100644 --- a/tasmota/tasmota_xdrv_driver/xdrv_78_telnet.ino +++ b/tasmota/tasmota_xdrv_driver/xdrv_78_telnet.ino @@ -122,6 +122,18 @@ void TelnetWrite(char *line, uint32_t len) { } } +void TelnetGetLog(void) { + uint32_t index = Telnet.log_index; // Dump log buffer + char* line; + size_t len; + bool any_line = false; + while (GetLog(TasmotaGlobal.seriallog_level, &index, &line, &len)) { + any_line = true; + TelnetWrite(line, len -1); + } + Telnet.log_index = index; +} + /********************************************************************************************/ void TelnetLoop(void) { @@ -143,54 +155,28 @@ void TelnetLoop(void) { } Telnet.client = new_client; if (Telnet.client) { + SetMinimumSeriallog(); Telnet.client.printf("Tasmota %s %s (%s) %s\r\n", NetworkHostname(), TasmotaGlobal.version, GetBuildDateAndTime().c_str(), GetDeviceHardware().c_str()); - Telnet.prompt = 3; -#ifdef ESP32 - uint32_t index = 1; - char* line; - size_t len; - while (GetLog(Settings->seriallog_level, &index, &line, &len)) { - TelnetWrite(line, len -1); - } - Telnet.prompt = 0; -#else // ESP8266 - Telnet.log_index = 0; // Dump start of log buffer for restart messages -#endif // ESP32 - ESP8266 + Telnet.prompt = 3; // Print linefeed for non-requested data and use log color + Telnet.log_index = 1; // Dump start of log buffer for restart messages + TelnetGetLog(); + Telnet.prompt = 1; // Print prompt after requested data and use response color } } if (Telnet.client) { - // Output latest log buffer data -#ifdef ESP32 - if (0 == Telnet.prompt) { + // Output latest data +#ifdef ESP8266 + TelnetGetLog(); // As heap is low on ESP8266 it uses log output +#endif + if (1 == Telnet.prompt) { TelnetWriteColor(Telnet.color[0]); Telnet.client.printf("%s:# ", NetworkHostname()); TelnetWriteColor(0); - Telnet.prompt = 3; // Print linefeed for non-requested data + Telnet.prompt = 3; // Print linefeed for non-requested data and use log color while (Telnet.client.available()) { Telnet.client.read(); } // Flush input return; } -#else // ESP8266 - uint32_t index = Telnet.log_index; // Dump log buffer - char* line; - size_t len; - bool any_line = false; - while (GetLog(Settings->seriallog_level, &index, &line, &len)) { - any_line = true; - TelnetWrite(line, len -1); - } - if (any_line) { - if ((0 == Telnet.log_index) || (Telnet.prompt != 2)) { - TelnetWriteColor(Telnet.color[0]); - Telnet.client.printf("%s:# ", NetworkHostname()); - TelnetWriteColor(0); - Telnet.prompt = 3; // Print linefeed for non-requested data - while (Telnet.client.available()) { Telnet.client.read(); } // Flush input - } - Telnet.log_index = index; - return; - } -#endif // ESP32 - ESP8266 // Input keyboard data while (Telnet.client.available()) { @@ -202,10 +188,10 @@ void TelnetLoop(void) { } } else if (in_byte == '\n') { - Telnet.buffer[Telnet.in_byte_counter] = 0; // Telnet data completed - TasmotaGlobal.seriallog_level = (Settings->seriallog_level < LOG_LEVEL_INFO) ? (uint8_t)LOG_LEVEL_INFO : Settings->seriallog_level; Telnet.client.write("\r"); // Move cursor to begin of line (needed for non-buffered input) - Telnet.prompt = 1; // Do not print linefeed for requested data and use response color + Telnet.buffer[Telnet.in_byte_counter] = 0; // Telnet data completed + Telnet.prompt = 1; // Print prompt after requested data and use response color + SetMinimumSeriallog(); if (Telnet.in_byte_counter >= Telnet.buffer_size) { AddLog(LOG_LEVEL_INFO, PSTR(D_LOG_TELNET "Buffer overrun")); } else { @@ -219,9 +205,6 @@ void TelnetLoop(void) { } } Telnet.in_byte_counter = 0; -#ifdef ESP32 - Telnet.prompt = 0; // Print prompt -#endif // ESP32 return; } }