From 77760dc2cc2ef531c33a35337bb7f55af5db1b59 Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Sun, 23 May 2021 16:50:17 +0200 Subject: [PATCH] Prep virtual mqtt_data prt2 --- tasmota/support.ino | 29 ++++++++++++++++++----------- tasmota/support_command.ino | 16 +++++++--------- tasmota/support_tasmota.ino | 25 +++++++++++++------------ tasmota/tasmota.ino | 4 ++-- tasmota/xdrv_01_webserver.ino | 15 +++++++-------- tasmota/xdrv_02_mqtt_9_impl.ino | 3 +-- tasmota/xdrv_05_irremote.ino | 2 +- tasmota/xdrv_05_irremote_full.ino | 2 +- tasmota/xdrv_10_rules.ino | 5 +---- tasmota/xdrv_10_scripter.ino | 8 ++++---- tasmota/xdrv_12_home_assistant.ino | 4 ++-- tasmota/xdrv_40_telegram.ino | 9 ++++++--- tasmota/xdrv_48_timeprop.ino | 3 +-- tasmota/xdrv_52_3_berry_tasmota.ino | 2 +- tasmota/xnrg_15_teleinfo.ino | 5 +---- tasmota/xsns_62_esp32_mi_ble.ino | 8 ++++---- tasmota/xsns_69_opentherm.ino | 6 +----- tasmota/xsns_87_esp32_sensors.ino | 2 +- 18 files changed, 72 insertions(+), 76 deletions(-) diff --git a/tasmota/support.ino b/tasmota/support.ino index 2165fff93..24fa920b9 100644 --- a/tasmota/support.ino +++ b/tasmota/support.ino @@ -1169,6 +1169,10 @@ char* ResponseGetTime(uint32_t format, char* time_str) return time_str; } +uint32_t ResponseSize(void) { + return sizeof(TasmotaGlobal.mqtt_data); +} + uint32_t ResponseLength(void) { return strlen(TasmotaGlobal.mqtt_data); } @@ -1186,7 +1190,7 @@ int Response_P(const char* format, ...) // Content send snprintf_P char d // This uses char strings. Be aware of sending %% if % is needed va_list args; va_start(args, format); - int len = ext_vsnprintf_P(TasmotaGlobal.mqtt_data, sizeof(TasmotaGlobal.mqtt_data), format, args); + int len = ext_vsnprintf_P(TasmotaGlobal.mqtt_data, ResponseSize(), format, args); va_end(args); return len; } @@ -1200,7 +1204,7 @@ int ResponseTime_P(const char* format, ...) // Content send snprintf_P char d ResponseGetTime(Settings.flag2.time_format, TasmotaGlobal.mqtt_data); int mlen = ResponseLength(); - int len = ext_vsnprintf_P(TasmotaGlobal.mqtt_data + mlen, sizeof(TasmotaGlobal.mqtt_data) - mlen, format, args); + int len = ext_vsnprintf_P(TasmotaGlobal.mqtt_data + mlen, ResponseSize() - mlen, format, args); va_end(args); return len + mlen; } @@ -1211,7 +1215,7 @@ int ResponseAppend_P(const char* format, ...) // Content send snprintf_P char d va_list args; va_start(args, format); int mlen = ResponseLength(); - int len = ext_vsnprintf_P(TasmotaGlobal.mqtt_data + mlen, sizeof(TasmotaGlobal.mqtt_data) - mlen, format, args); + int len = ext_vsnprintf_P(TasmotaGlobal.mqtt_data + mlen, ResponseSize() - mlen, format, args); va_end(args); return len + mlen; } @@ -1246,6 +1250,10 @@ int ResponseJsonEndEnd(void) return ResponseAppend_P(PSTR("}}")); } +bool ResponseContains_P(const char* needle) { + return (strstr_P(TasmotaGlobal.mqtt_data, needle) != nullptr); +} + /*********************************************************************************************\ * GPIO Module and Template management \*********************************************************************************************/ @@ -2025,9 +2033,8 @@ int8_t I2cWriteBuffer(uint8_t addr, uint8_t reg, uint8_t *reg_data, uint16_t len return 0; } -void I2cScan(char *devs, unsigned int devs_len, uint32_t bus = 0); -void I2cScan(char *devs, unsigned int devs_len, uint32_t bus) -{ +void I2cScan(uint32_t bus = 0); +void I2cScan(uint32_t bus) { // Return error codes defined in twi.h and core_esp8266_si2c.c // I2C_OK 0 // I2C_SCL_HELD_LOW 1 = SCL held low by another device, no procedure available to recover @@ -2039,7 +2046,7 @@ void I2cScan(char *devs, unsigned int devs_len, uint32_t bus) uint8_t address = 0; uint8_t any = 0; - snprintf_P(devs, devs_len, PSTR("{\"" D_CMND_I2CSCAN "\":\"" D_JSON_I2CSCAN_DEVICES_FOUND_AT)); + Response_P(PSTR("{\"" D_CMND_I2CSCAN "\":\"" D_JSON_I2CSCAN_DEVICES_FOUND_AT)); for (address = 1; address <= 127; address++) { #ifdef ESP32 TwoWire & myWire = (bus == 0) ? Wire : Wire1; @@ -2050,19 +2057,19 @@ void I2cScan(char *devs, unsigned int devs_len, uint32_t bus) error = myWire.endTransmission(); if (0 == error) { any = 1; - snprintf_P(devs, devs_len, PSTR("%s 0x%02x"), devs, address); + ResponseAppend_P(PSTR(" 0x%02x"), address); } else if (error != 2) { // Seems to happen anyway using this scan any = 2; - snprintf_P(devs, devs_len, PSTR("{\"" D_CMND_I2CSCAN "\":\"Error %d at 0x%02x"), error, address); + Response_P(PSTR("{\"" D_CMND_I2CSCAN "\":\"Error %d at 0x%02x"), error, address); break; } } if (any) { - strncat(devs, "\"}", devs_len - strlen(devs) -1); + ResponseAppend_P(PSTR("\"}")); } else { - snprintf_P(devs, devs_len, PSTR("{\"" D_CMND_I2CSCAN "\":\"" D_JSON_I2CSCAN_NO_DEVICES_FOUND "\"}")); + Response_P(PSTR("{\"" D_CMND_I2CSCAN "\":\"" D_JSON_I2CSCAN_NO_DEVICES_FOUND "\"}")); } } diff --git a/tasmota/support_command.ino b/tasmota/support_command.ino index 2e1313021..b4c088bad 100644 --- a/tasmota/support_command.ino +++ b/tasmota/support_command.ino @@ -311,8 +311,8 @@ void CommandHandler(char* topicBuf, char* dataBuf, uint32_t data_len) char json_command[TOPSZ]; snprintf_P(json_command, sizeof(json_command), PSTR("{\"" D_JSON_COMMAND "\":\"%s\","), type); uint32_t jc_len = strlen(json_command); - uint32_t mq_len = strlen(TasmotaGlobal.mqtt_data) +1; - if (mq_len < sizeof(TasmotaGlobal.mqtt_data) - jc_len) { + uint32_t mq_len = ResponseLength() +1; + if (mq_len < ResponseSize() - jc_len) { memmove(TasmotaGlobal.mqtt_data +jc_len -1, TasmotaGlobal.mqtt_data, mq_len); memmove(TasmotaGlobal.mqtt_data, json_command, jc_len); } @@ -2141,11 +2141,11 @@ void CmndWifi(void) void CmndI2cScan(void) { if ((1 == XdrvMailbox.index) && (TasmotaGlobal.i2c_enabled)) { - I2cScan(TasmotaGlobal.mqtt_data, sizeof(TasmotaGlobal.mqtt_data)); + I2cScan(); } #ifdef ESP32 if ((2 == XdrvMailbox.index) && (TasmotaGlobal.i2c_enabled_2)) { - I2cScan(TasmotaGlobal.mqtt_data, sizeof(TasmotaGlobal.mqtt_data), 1); + I2cScan(1); } #endif } @@ -2212,13 +2212,11 @@ void CmndDevGroupTie(void) if (XdrvMailbox.data_len > 0) { Settings.device_group_tie[XdrvMailbox.index - 1] = XdrvMailbox.payload; } - char * ptr = TasmotaGlobal.mqtt_data; - *ptr++ = '{'; + Response_P(PSTR("{")); for (uint32_t i = 0; i < MAX_DEV_GROUP_NAMES; i++) { - ptr += sprintf(ptr, PSTR("\"%s%u\":%u,"), D_CMND_DEVGROUP_TIE, i + 1, Settings.device_group_tie[i]); + ResponseAppend_P(PSTR("%s\"%s%u\":%u"), (i)?",":"", D_CMND_DEVGROUP_TIE, i + 1, Settings.device_group_tie[i]); } - *(ptr - 1) = '}'; - *ptr = 0; + ResponseJsonEnd(); } } #endif // USE_DEVICE_GROUPS diff --git a/tasmota/support_tasmota.ino b/tasmota/support_tasmota.ino index c16ad6f44..d04073805 100644 --- a/tasmota/support_tasmota.ino +++ b/tasmota/support_tasmota.ino @@ -837,13 +837,13 @@ bool MqttShowSensor(void) XdrvCall(FUNC_JSON_APPEND); bool json_data_available = (ResponseLength() - json_data_start); - if (strstr_P(TasmotaGlobal.mqtt_data, PSTR(D_JSON_PRESSURE)) != nullptr) { + if (ResponseContains_P(PSTR(D_JSON_PRESSURE))) { ResponseAppend_P(PSTR(",\"" D_JSON_PRESSURE_UNIT "\":\"%s\""), PressureUnit().c_str()); } - if (strstr_P(TasmotaGlobal.mqtt_data, PSTR(D_JSON_TEMPERATURE)) != nullptr) { + if (ResponseContains_P(PSTR(D_JSON_TEMPERATURE))) { ResponseAppend_P(PSTR(",\"" D_JSON_TEMPERATURE_UNIT "\":\"%c\""), TempUnit()); } - if ((strstr_P(TasmotaGlobal.mqtt_data, PSTR(D_JSON_SPEED)) != nullptr) && Settings.flag2.speed_conversion) { + if (ResponseContains_P(PSTR(D_JSON_SPEED)) && Settings.flag2.speed_conversion) { ResponseAppend_P(PSTR(",\"" D_JSON_SPEED_UNIT "\":\"%s\""), SpeedUnit().c_str()); } ResponseJsonEnd(); @@ -1109,10 +1109,11 @@ void Every250mSeconds(void) #endif // USE_ARILUX_RF TasmotaGlobal.ota_state_flag = 92; ota_result = 0; + char full_ota_url[200]; ota_retry_counter--; if (ota_retry_counter) { char ota_url[TOPSZ]; - strlcpy(TasmotaGlobal.mqtt_data, GetOtaUrl(ota_url, sizeof(ota_url)), sizeof(TasmotaGlobal.mqtt_data)); + strlcpy(full_ota_url, GetOtaUrl(ota_url, sizeof(ota_url)), sizeof(full_ota_url)); #ifdef ESP8266 #ifndef FIRMWARE_MINIMAL if (RtcSettings.ota_loader) { @@ -1132,10 +1133,10 @@ void Every250mSeconds(void) // Replace http://192.168.2.17:80/api/arduino/tasmota.bin with http://192.168.2.17:80/api/arduino/tasmota-minimal.bin // Replace http://192.168.2.17/api/arduino/tasmota.bin.gz with http://192.168.2.17/api/arduino/tasmota-minimal.bin.gz - char *bch = strrchr(TasmotaGlobal.mqtt_data, '/'); // Only consider filename after last backslash prevent change of urls having "-" in it - if (bch == nullptr) { bch = TasmotaGlobal.mqtt_data; } // No path found so use filename only + char *bch = strrchr(full_ota_url, '/'); // Only consider filename after last backslash prevent change of urls having "-" in it + if (bch == nullptr) { bch = full_ota_url; } // No path found so use filename only char *ech = strchr(bch, '.'); // Find file type in filename (none, .ino.bin, .ino.bin.gz, .bin, .bin.gz or .gz) - if (ech == nullptr) { ech = TasmotaGlobal.mqtt_data + strlen(TasmotaGlobal.mqtt_data); } // Point to '/0' at end of mqtt_data becoming an empty string + if (ech == nullptr) { ech = full_ota_url + strlen(full_ota_url); } // Point to '/0' at end of mqtt_data becoming an empty string //AddLog(LOG_LEVEL_DEBUG, PSTR("OTA: File type [%s]"), ech); @@ -1145,22 +1146,22 @@ void Every250mSeconds(void) char *pch = strrchr(bch, '-'); // Find last dash (-) and ignore remainder - handles tasmota-DE if (pch == nullptr) { pch = ech; } // No dash so ignore filetype *pch = '\0'; // mqtt_data = http://domus1:80/api/arduino/tasmota - snprintf_P(TasmotaGlobal.mqtt_data, sizeof(TasmotaGlobal.mqtt_data), PSTR("%s-" D_JSON_MINIMAL "%s"), TasmotaGlobal.mqtt_data, ota_url_type); // Minimal filename must be filename-minimal + snprintf_P(full_ota_url, sizeof(full_ota_url), PSTR("%s-" D_JSON_MINIMAL "%s"), full_ota_url, ota_url_type); // Minimal filename must be filename-minimal } #endif // FIRMWARE_MINIMAL if (ota_retry_counter < OTA_ATTEMPTS / 2) { - if (StrCaseStr_P(TasmotaGlobal.mqtt_data, PSTR(".gz"))) { + if (StrCaseStr_P(full_ota_url, PSTR(".gz"))) { ota_retry_counter = 1; } else { - strcat_P(TasmotaGlobal.mqtt_data, PSTR(".gz")); + strcat_P(full_ota_url, PSTR(".gz")); } } #endif // ESP8266 char version[50]; snprintf_P(version, sizeof(version), PSTR("%s%s"), TasmotaGlobal.version, TasmotaGlobal.image_name); - AddLog(LOG_LEVEL_DEBUG, PSTR(D_LOG_UPLOAD "%s %s"), TasmotaGlobal.mqtt_data, version); + AddLog(LOG_LEVEL_DEBUG, PSTR(D_LOG_UPLOAD "%s %s"), full_ota_url, version); WiFiClient OTAclient; - ota_result = (HTTP_UPDATE_FAILED != ESPhttpUpdate.update(OTAclient, TasmotaGlobal.mqtt_data, version)); + ota_result = (HTTP_UPDATE_FAILED != ESPhttpUpdate.update(OTAclient, full_ota_url, version)); if (!ota_result) { #ifndef FIRMWARE_MINIMAL int ota_error = ESPhttpUpdate.getLastError(); diff --git a/tasmota/tasmota.ino b/tasmota/tasmota.ino index 85a706371..163f65900 100644 --- a/tasmota/tasmota.ino +++ b/tasmota/tasmota.ino @@ -342,6 +342,8 @@ void setup(void) { } } + memcpy_P(TasmotaGlobal.version, VERSION_MARKER, 1); // Dummy for compiler saving VERSION_MARKER + snprintf_P(TasmotaGlobal.version, sizeof(TasmotaGlobal.version), PSTR("%d.%d.%d"), VERSION >> 24 & 0xff, VERSION >> 16 & 0xff, VERSION >> 8 & 0xff); // Release version 6.3.0 if (VERSION & 0xff) { // Development or patched version 6.3.0.10 snprintf_P(TasmotaGlobal.version, sizeof(TasmotaGlobal.version), PSTR("%s.%d"), TasmotaGlobal.version, VERSION & 0xff); @@ -378,8 +380,6 @@ void setup(void) { AddLog(LOG_LEVEL_INFO, PSTR(D_WARNING_MINIMAL_VERSION)); #endif // FIRMWARE_MINIMAL - memcpy_P(TasmotaGlobal.mqtt_data, VERSION_MARKER, 1); // Dummy for compiler saving VERSION_MARKER - #ifdef USE_ARDUINO_OTA ArduinoOTAInit(); #endif // USE_ARDUINO_OTA diff --git a/tasmota/xdrv_01_webserver.ino b/tasmota/xdrv_01_webserver.ino index 922d60f07..7f0ae150a 100644 --- a/tasmota/xdrv_01_webserver.ino +++ b/tasmota/xdrv_01_webserver.ino @@ -3029,16 +3029,15 @@ int WebSend(char *buffer) #ifdef USE_WEBSEND_RESPONSE // Return received data to the user - Adds 900+ bytes to the code const char* read = http.getString().c_str(); // File found at server - may need lot of ram or trigger out of memory! - uint32_t j = 0; - char text = '.'; - while (text != '\0') { - text = *read++; - if (text > 31) { // Remove control characters like linefeed - TasmotaGlobal.mqtt_data[j++] = text; - if (j == sizeof(TasmotaGlobal.mqtt_data) -2) { break; } + ResponseClear(); + char text[2] = { 0 }; + text[0] = '.'; + while (text[0] != '\0') { + text[0] = *read++; + if (text[0] > 31) { // Remove control characters like linefeed + if (ResponseAppend_P(text) == ResponseSize()) { break; }; } } - TasmotaGlobal.mqtt_data[j] = '\0'; #ifdef USE_SCRIPT extern uint8_t tasm_cmd_activ; // recursive call must be possible in this case diff --git a/tasmota/xdrv_02_mqtt_9_impl.ino b/tasmota/xdrv_02_mqtt_9_impl.ino index 6eee64262..aa9214f5a 100644 --- a/tasmota/xdrv_02_mqtt_9_impl.ino +++ b/tasmota/xdrv_02_mqtt_9_impl.ino @@ -1289,12 +1289,11 @@ void CmndPublish(void) { strlcpy(stemp1, mqtt_part, sizeof(stemp1)); ReplaceChar(stemp1, '#', ' '); if ((payload_part != nullptr) && strlen(payload_part)) { - strlcpy(TasmotaGlobal.mqtt_data, payload_part, sizeof(TasmotaGlobal.mqtt_data)); + Response_P(payload_part); } else { ResponseClear(); } MqttPublish(stemp1, (XdrvMailbox.index == 2)); -// ResponseCmndDone(); ResponseClear(); } } diff --git a/tasmota/xdrv_05_irremote.ino b/tasmota/xdrv_05_irremote.ino index fa4831746..f9a5b85d6 100644 --- a/tasmota/xdrv_05_irremote.ino +++ b/tasmota/xdrv_05_irremote.ino @@ -278,7 +278,7 @@ void IrReceiveCheck(void) prev_number = true; } ir_high = !ir_high; - if (strlen(TasmotaGlobal.mqtt_data) > sizeof(TasmotaGlobal.mqtt_data) - 40) { break; } // Quit if char string becomes too long + if (ResponseLength() > ResponseSize()) - 40) { break; } // Quit if char string becomes too long } uint16_t extended_length = getCorrectedRawLength(&results); ResponseAppend_P(PSTR("\",\"" D_JSON_IR_RAWDATA "Info\":[%d,%d,%d]"), extended_length, i -1, results.overflow); diff --git a/tasmota/xdrv_05_irremote_full.ino b/tasmota/xdrv_05_irremote_full.ino index 00b6cf7bd..c570f991d 100644 --- a/tasmota/xdrv_05_irremote_full.ino +++ b/tasmota/xdrv_05_irremote_full.ino @@ -307,7 +307,7 @@ void IrReceiveCheck(void) prev_number = true; } ir_high = !ir_high; - if (strlen(TasmotaGlobal.mqtt_data) > sizeof(TasmotaGlobal.mqtt_data) - 40) { break; } // Quit if char string becomes too long + if (ResponseLength() > ResponseSize()) - 40) { break; } // Quit if char string becomes too long } uint16_t extended_length = getCorrectedRawLength(&results); ResponseAppend_P(PSTR("\",\"" D_JSON_IR_RAWDATA "Info\":[%d,%d,%d]"), extended_length, i -1, results.overflow); diff --git a/tasmota/xdrv_10_rules.ino b/tasmota/xdrv_10_rules.ino index df7016da8..fc0b772f4 100644 --- a/tasmota/xdrv_10_rules.ino +++ b/tasmota/xdrv_10_rules.ino @@ -2139,10 +2139,7 @@ void CmndRule(void) rule = rule.substring(0, MAX_RULE_SIZE); rule += F("..."); } - // snprintf_P (TasmotaGlobal.mqtt_data, sizeof(TasmotaGlobal.mqtt_data), PSTR("{\"%s%d\":{\"State\":\"%s\",\"Once\":\"%s\",\"StopOnError\":\"%s\",\"Free\":%d,\"Rules\":\"%s\"}}"), - // XdrvMailbox.command, index, GetStateText(bitRead(Settings.rule_enabled, index -1)), GetStateText(bitRead(Settings.rule_once, index -1)), - // GetStateText(bitRead(Settings.rule_stop, index -1)), sizeof(Settings.rules[index -1]) - strlen(Settings.rules[index -1]) -1, Settings.rules[index -1]); - snprintf_P (TasmotaGlobal.mqtt_data, sizeof(TasmotaGlobal.mqtt_data), PSTR("{\"%s%d\":{\"State\":\"%s\",\"Once\":\"%s\",\"StopOnError\":\"%s\",\"Length\":%d,\"Free\":%d,\"Rules\":\"%s\"}}"), + Response_P(PSTR("{\"%s%d\":{\"State\":\"%s\",\"Once\":\"%s\",\"StopOnError\":\"%s\",\"Length\":%d,\"Free\":%d,\"Rules\":\"%s\"}}"), XdrvMailbox.command, index, GetStateText(bitRead(Settings.rule_enabled, index -1)), GetStateText(bitRead(Settings.rule_once, index -1)), GetStateText(bitRead(Settings.rule_stop, index -1)), rule_len, MAX_RULE_SIZE - GetRuleLenStorage(index - 1), diff --git a/tasmota/xdrv_10_scripter.ino b/tasmota/xdrv_10_scripter.ino index 00bf03e83..396a52888 100755 --- a/tasmota/xdrv_10_scripter.ino +++ b/tasmota/xdrv_10_scripter.ino @@ -6040,7 +6040,7 @@ bool ScriptCommand(void) { } else { if ('>' == XdrvMailbox.data[0]) { // execute script - snprintf_P (TasmotaGlobal.mqtt_data, sizeof(TasmotaGlobal.mqtt_data), PSTR("{\"%s\":\"%s\"}"), command,XdrvMailbox.data); + Response_P(PSTR("{\"%s\":\"%s\"}"), command, XdrvMailbox.data); if (bitRead(Settings.rule_enabled, 0)) { for (uint8_t count = 0; count, [, ] String result = ScriptSubscribe(XdrvMailbox.data, XdrvMailbox.data_len); diff --git a/tasmota/xdrv_12_home_assistant.ino b/tasmota/xdrv_12_home_assistant.ino index 9c2caab27..564e6f4ba 100644 --- a/tasmota/xdrv_12_home_assistant.ino +++ b/tasmota/xdrv_12_home_assistant.ino @@ -362,8 +362,8 @@ void TryResponseAppend_P(const char *format, ...) char dummy[2]; int dlen = vsnprintf_P(dummy, 1, format, args); - int mlen = strlen(TasmotaGlobal.mqtt_data); - int slen = sizeof(TasmotaGlobal.mqtt_data) - 1 - mlen; + int mlen = ResponseLength(); + int slen = ResponseSize() - 1 - mlen; if (dlen >= slen) { AddLog_P(LOG_LEVEL_ERROR, PSTR("%s (%u/%u):"), kHAssError1, dlen, slen); diff --git a/tasmota/xdrv_40_telegram.ino b/tasmota/xdrv_40_telegram.ino index 66191c43f..8abde2d60 100644 --- a/tasmota/xdrv_40_telegram.ino +++ b/tasmota/xdrv_40_telegram.ino @@ -299,7 +299,7 @@ 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 > sizeof(TasmotaGlobal.mqtt_data)) { JSONlen = sizeof(TasmotaGlobal.mqtt_data); } + if (JSONlen > ResponseSize()) { JSONlen = ResponseSize(); } char stemp[JSONlen]; strlcpy(stemp, JSON +1, JSONlen -2); if (cflg) { response += F(","); } @@ -401,8 +401,11 @@ void CmndTmState(void) { } } } - snprintf_P (TasmotaGlobal.mqtt_data, sizeof(TasmotaGlobal.mqtt_data), PSTR("{\"%s\":{\"Send\":\"%s\",\"Receive\":\"%s\",\"Echo\":\"%s\"}}"), - XdrvMailbox.command, GetStateText(Settings.sbflag1.telegram_send_enable), GetStateText(Settings.sbflag1.telegram_recv_enable), GetStateText(Settings.sbflag1.telegram_echo_enable)); + Response_P(PSTR("{\"%s\":{\"Send\":\"%s\",\"Receive\":\"%s\",\"Echo\":\"%s\"}}"), + XdrvMailbox.command, + GetStateText(Settings.sbflag1.telegram_send_enable), + GetStateText(Settings.sbflag1.telegram_recv_enable), + GetStateText(Settings.sbflag1.telegram_echo_enable)); } void CmndTmPoll(void) { diff --git a/tasmota/xdrv_48_timeprop.ino b/tasmota/xdrv_48_timeprop.ino index e2a699832..0defa6d33 100644 --- a/tasmota/xdrv_48_timeprop.ino +++ b/tasmota/xdrv_48_timeprop.ino @@ -208,8 +208,7 @@ bool TimepropCommand() if (XdrvMailbox.index >=0 && XdrvMailbox.index < TIMEPROP_NUM_OUTPUTS) { timeprops[XdrvMailbox.index].setPower( atof(XdrvMailbox.data), Tprop.current_time_secs ); } - snprintf_P(TasmotaGlobal.mqtt_data, sizeof(TasmotaGlobal.mqtt_data), PSTR("{\"" D_CMND_TIMEPROP D_CMND_TIMEPROP_SETPOWER "%d\":\"%s\"}"), - XdrvMailbox.index, XdrvMailbox.data); + Response_P(PSTR("{\"" D_CMND_TIMEPROP D_CMND_TIMEPROP_SETPOWER "%d\":\"%s\"}"), XdrvMailbox.index, XdrvMailbox.data); } else { serviced = false; diff --git a/tasmota/xdrv_52_3_berry_tasmota.ino b/tasmota/xdrv_52_3_berry_tasmota.ino index aa8c49df0..710ad2211 100644 --- a/tasmota/xdrv_52_3_berry_tasmota.ino +++ b/tasmota/xdrv_52_3_berry_tasmota.ino @@ -60,7 +60,7 @@ extern "C" { if (top == 4) { retain = be_tobool(vm, 4); } - strlcpy(TasmotaGlobal.mqtt_data, payload, sizeof(TasmotaGlobal.mqtt_data)); + Response_P(payload); MqttPublish(topic, retain); be_return(vm); // Return } diff --git a/tasmota/xnrg_15_teleinfo.ino b/tasmota/xnrg_15_teleinfo.ino index 75eef09a8..ca94ca1b0 100755 --- a/tasmota/xnrg_15_teleinfo.ino +++ b/tasmota/xnrg_15_teleinfo.ino @@ -206,10 +206,7 @@ void ADPSCallback(uint8_t phase, char * label) phase = 1; } - Response_P(PSTR("{")); - ResponseAppend_P(TasmotaGlobal.mqtt_data, sizeof(TasmotaGlobal.mqtt_data), PSTR("\"TIC\":{\"%s\":%i}"), label, phase ); - ResponseJsonEnd(); - + Response_P(PSTR("{\"TIC\":{\"%s\":%i}}"), label, phase ); // Publish adding ADCO serial number into the topic MqttPublishPrefixTopicRulesProcess_P(TELE, PSTR(D_RSLT_SENSOR), false); diff --git a/tasmota/xsns_62_esp32_mi_ble.ino b/tasmota/xsns_62_esp32_mi_ble.ino index 2599f64d6..c0afcc649 100644 --- a/tasmota/xsns_62_esp32_mi_ble.ino +++ b/tasmota/xsns_62_esp32_mi_ble.ino @@ -2691,10 +2691,10 @@ void MI32ShowSomeSensors(){ p = &MIBLEsensors[MI32.mqttCurrentSlot]; MI32GetOneSensorJson(MI32.mqttCurrentSlot, (maxcnt == 1)); - int mlen = strlen(TasmotaGlobal.mqtt_data); + int mlen = ResponseLength(); // if we ran out of room, leave here. - if (sizeof(TasmotaGlobal.mqtt_data) - mlen < 100){ + if (ResponseSize() - mlen < 100){ MI32.mqttCurrentSlot++; break; } @@ -3055,10 +3055,10 @@ void MI32ShowTriggeredSensors(){ ResponseAppend_P(PSTR(",")); // hide sensor name if HASS or option6 MI32GetOneSensorJson(sensor, (maxcnt == 1)); - int mlen = strlen(TasmotaGlobal.mqtt_data); + int mlen = ResponseLength(); // if we ran out of room, leave here. - if (sizeof(TasmotaGlobal.mqtt_data) - mlen < 100){ + if (ResponseSize() - mlen < 100){ sensor++; break; } diff --git a/tasmota/xsns_69_opentherm.ino b/tasmota/xsns_69_opentherm.ino index 9b425f3fa..9ea2ed9f2 100644 --- a/tasmota/xsns_69_opentherm.ino +++ b/tasmota/xsns_69_opentherm.ino @@ -518,11 +518,7 @@ void sns_opentherm_flags_cmd(void) int mode = Settings.ot_flags & (uint8_t)mask; if (mode > 0) { - if (addComma) - { - snprintf_P(TasmotaGlobal.mqtt_data, sizeof(TasmotaGlobal.mqtt_data), PSTR("%s,"), TasmotaGlobal.mqtt_data); - } - snprintf_P(TasmotaGlobal.mqtt_data, sizeof(TasmotaGlobal.mqtt_data), PSTR("%s%s"), TasmotaGlobal.mqtt_data, sns_opentherm_flag_text(mode)); + ResponseAppend_P(PSTR("%s%s"), (addComma)?",":"", sns_opentherm_flag_text(mode)); addComma = true; } } diff --git a/tasmota/xsns_87_esp32_sensors.ino b/tasmota/xsns_87_esp32_sensors.ino index 612c7feb3..792a904de 100644 --- a/tasmota/xsns_87_esp32_sensors.ino +++ b/tasmota/xsns_87_esp32_sensors.ino @@ -65,7 +65,7 @@ void Esp32SensorShow(bool json) { #endif // CONFIG_IDF_TARGET_ESP32 if (json) { - bool temperature_present = (strstr_P(TasmotaGlobal.mqtt_data, PSTR(D_JSON_TEMPERATURE)) != nullptr); + bool temperature_present = (ResponseContains_P(PSTR(D_JSON_TEMPERATURE))); ResponseAppend_P(PSTR(",\"ESP32\":{\"" D_JSON_TEMPERATURE "\":%*_f"), Settings.flag2.temperature_resolution, &t); #if CONFIG_IDF_TARGET_ESP32