mirror of
https://github.com/arendst/Tasmota.git
synced 2025-07-23 18:56:38 +00:00
Prep virtual mqtt_data prt2
This commit is contained in:
parent
408ae6a4ef
commit
77760dc2cc
@ -1169,6 +1169,10 @@ char* ResponseGetTime(uint32_t format, char* time_str)
|
|||||||
return time_str;
|
return time_str;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint32_t ResponseSize(void) {
|
||||||
|
return sizeof(TasmotaGlobal.mqtt_data);
|
||||||
|
}
|
||||||
|
|
||||||
uint32_t ResponseLength(void) {
|
uint32_t ResponseLength(void) {
|
||||||
return strlen(TasmotaGlobal.mqtt_data);
|
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
|
// This uses char strings. Be aware of sending %% if % is needed
|
||||||
va_list args;
|
va_list args;
|
||||||
va_start(args, format);
|
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);
|
va_end(args);
|
||||||
return len;
|
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);
|
ResponseGetTime(Settings.flag2.time_format, TasmotaGlobal.mqtt_data);
|
||||||
|
|
||||||
int mlen = ResponseLength();
|
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);
|
va_end(args);
|
||||||
return len + mlen;
|
return len + mlen;
|
||||||
}
|
}
|
||||||
@ -1211,7 +1215,7 @@ int ResponseAppend_P(const char* format, ...) // Content send snprintf_P char d
|
|||||||
va_list args;
|
va_list args;
|
||||||
va_start(args, format);
|
va_start(args, format);
|
||||||
int mlen = ResponseLength();
|
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);
|
va_end(args);
|
||||||
return len + mlen;
|
return len + mlen;
|
||||||
}
|
}
|
||||||
@ -1246,6 +1250,10 @@ int ResponseJsonEndEnd(void)
|
|||||||
return ResponseAppend_P(PSTR("}}"));
|
return ResponseAppend_P(PSTR("}}"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool ResponseContains_P(const char* needle) {
|
||||||
|
return (strstr_P(TasmotaGlobal.mqtt_data, needle) != nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
/*********************************************************************************************\
|
/*********************************************************************************************\
|
||||||
* GPIO Module and Template management
|
* 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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void I2cScan(char *devs, unsigned int devs_len, uint32_t bus = 0);
|
void I2cScan(uint32_t bus = 0);
|
||||||
void I2cScan(char *devs, unsigned int devs_len, uint32_t bus)
|
void I2cScan(uint32_t bus) {
|
||||||
{
|
|
||||||
// Return error codes defined in twi.h and core_esp8266_si2c.c
|
// Return error codes defined in twi.h and core_esp8266_si2c.c
|
||||||
// I2C_OK 0
|
// I2C_OK 0
|
||||||
// I2C_SCL_HELD_LOW 1 = SCL held low by another device, no procedure available to recover
|
// 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 address = 0;
|
||||||
uint8_t any = 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++) {
|
for (address = 1; address <= 127; address++) {
|
||||||
#ifdef ESP32
|
#ifdef ESP32
|
||||||
TwoWire & myWire = (bus == 0) ? Wire : Wire1;
|
TwoWire & myWire = (bus == 0) ? Wire : Wire1;
|
||||||
@ -2050,19 +2057,19 @@ void I2cScan(char *devs, unsigned int devs_len, uint32_t bus)
|
|||||||
error = myWire.endTransmission();
|
error = myWire.endTransmission();
|
||||||
if (0 == error) {
|
if (0 == error) {
|
||||||
any = 1;
|
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
|
else if (error != 2) { // Seems to happen anyway using this scan
|
||||||
any = 2;
|
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;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (any) {
|
if (any) {
|
||||||
strncat(devs, "\"}", devs_len - strlen(devs) -1);
|
ResponseAppend_P(PSTR("\"}"));
|
||||||
}
|
}
|
||||||
else {
|
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 "\"}"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -311,8 +311,8 @@ void CommandHandler(char* topicBuf, char* dataBuf, uint32_t data_len)
|
|||||||
char json_command[TOPSZ];
|
char json_command[TOPSZ];
|
||||||
snprintf_P(json_command, sizeof(json_command), PSTR("{\"" D_JSON_COMMAND "\":\"%s\","), type);
|
snprintf_P(json_command, sizeof(json_command), PSTR("{\"" D_JSON_COMMAND "\":\"%s\","), type);
|
||||||
uint32_t jc_len = strlen(json_command);
|
uint32_t jc_len = strlen(json_command);
|
||||||
uint32_t mq_len = strlen(TasmotaGlobal.mqtt_data) +1;
|
uint32_t mq_len = ResponseLength() +1;
|
||||||
if (mq_len < sizeof(TasmotaGlobal.mqtt_data) - jc_len) {
|
if (mq_len < ResponseSize() - jc_len) {
|
||||||
memmove(TasmotaGlobal.mqtt_data +jc_len -1, TasmotaGlobal.mqtt_data, mq_len);
|
memmove(TasmotaGlobal.mqtt_data +jc_len -1, TasmotaGlobal.mqtt_data, mq_len);
|
||||||
memmove(TasmotaGlobal.mqtt_data, json_command, jc_len);
|
memmove(TasmotaGlobal.mqtt_data, json_command, jc_len);
|
||||||
}
|
}
|
||||||
@ -2141,11 +2141,11 @@ void CmndWifi(void)
|
|||||||
void CmndI2cScan(void)
|
void CmndI2cScan(void)
|
||||||
{
|
{
|
||||||
if ((1 == XdrvMailbox.index) && (TasmotaGlobal.i2c_enabled)) {
|
if ((1 == XdrvMailbox.index) && (TasmotaGlobal.i2c_enabled)) {
|
||||||
I2cScan(TasmotaGlobal.mqtt_data, sizeof(TasmotaGlobal.mqtt_data));
|
I2cScan();
|
||||||
}
|
}
|
||||||
#ifdef ESP32
|
#ifdef ESP32
|
||||||
if ((2 == XdrvMailbox.index) && (TasmotaGlobal.i2c_enabled_2)) {
|
if ((2 == XdrvMailbox.index) && (TasmotaGlobal.i2c_enabled_2)) {
|
||||||
I2cScan(TasmotaGlobal.mqtt_data, sizeof(TasmotaGlobal.mqtt_data), 1);
|
I2cScan(1);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
@ -2212,13 +2212,11 @@ void CmndDevGroupTie(void)
|
|||||||
if (XdrvMailbox.data_len > 0) {
|
if (XdrvMailbox.data_len > 0) {
|
||||||
Settings.device_group_tie[XdrvMailbox.index - 1] = XdrvMailbox.payload;
|
Settings.device_group_tie[XdrvMailbox.index - 1] = XdrvMailbox.payload;
|
||||||
}
|
}
|
||||||
char * ptr = TasmotaGlobal.mqtt_data;
|
Response_P(PSTR("{"));
|
||||||
*ptr++ = '{';
|
|
||||||
for (uint32_t i = 0; i < MAX_DEV_GROUP_NAMES; i++) {
|
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) = '}';
|
ResponseJsonEnd();
|
||||||
*ptr = 0;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif // USE_DEVICE_GROUPS
|
#endif // USE_DEVICE_GROUPS
|
||||||
|
@ -837,13 +837,13 @@ bool MqttShowSensor(void)
|
|||||||
XdrvCall(FUNC_JSON_APPEND);
|
XdrvCall(FUNC_JSON_APPEND);
|
||||||
|
|
||||||
bool json_data_available = (ResponseLength() - json_data_start);
|
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());
|
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());
|
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());
|
ResponseAppend_P(PSTR(",\"" D_JSON_SPEED_UNIT "\":\"%s\""), SpeedUnit().c_str());
|
||||||
}
|
}
|
||||||
ResponseJsonEnd();
|
ResponseJsonEnd();
|
||||||
@ -1109,10 +1109,11 @@ void Every250mSeconds(void)
|
|||||||
#endif // USE_ARILUX_RF
|
#endif // USE_ARILUX_RF
|
||||||
TasmotaGlobal.ota_state_flag = 92;
|
TasmotaGlobal.ota_state_flag = 92;
|
||||||
ota_result = 0;
|
ota_result = 0;
|
||||||
|
char full_ota_url[200];
|
||||||
ota_retry_counter--;
|
ota_retry_counter--;
|
||||||
if (ota_retry_counter) {
|
if (ota_retry_counter) {
|
||||||
char ota_url[TOPSZ];
|
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
|
#ifdef ESP8266
|
||||||
#ifndef FIRMWARE_MINIMAL
|
#ifndef FIRMWARE_MINIMAL
|
||||||
if (RtcSettings.ota_loader) {
|
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: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
|
// 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
|
char *bch = strrchr(full_ota_url, '/'); // 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
|
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)
|
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);
|
//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
|
char *pch = strrchr(bch, '-'); // Find last dash (-) and ignore remainder - handles tasmota-DE
|
||||||
if (pch == nullptr) { pch = ech; } // No dash so ignore filetype
|
if (pch == nullptr) { pch = ech; } // No dash so ignore filetype
|
||||||
*pch = '\0'; // mqtt_data = http://domus1:80/api/arduino/tasmota
|
*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
|
#endif // FIRMWARE_MINIMAL
|
||||||
if (ota_retry_counter < OTA_ATTEMPTS / 2) {
|
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;
|
ota_retry_counter = 1;
|
||||||
} else {
|
} else {
|
||||||
strcat_P(TasmotaGlobal.mqtt_data, PSTR(".gz"));
|
strcat_P(full_ota_url, PSTR(".gz"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif // ESP8266
|
#endif // ESP8266
|
||||||
char version[50];
|
char version[50];
|
||||||
snprintf_P(version, sizeof(version), PSTR("%s%s"), TasmotaGlobal.version, TasmotaGlobal.image_name);
|
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;
|
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) {
|
if (!ota_result) {
|
||||||
#ifndef FIRMWARE_MINIMAL
|
#ifndef FIRMWARE_MINIMAL
|
||||||
int ota_error = ESPhttpUpdate.getLastError();
|
int ota_error = ESPhttpUpdate.getLastError();
|
||||||
|
@ -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
|
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
|
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);
|
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));
|
AddLog(LOG_LEVEL_INFO, PSTR(D_WARNING_MINIMAL_VERSION));
|
||||||
#endif // FIRMWARE_MINIMAL
|
#endif // FIRMWARE_MINIMAL
|
||||||
|
|
||||||
memcpy_P(TasmotaGlobal.mqtt_data, VERSION_MARKER, 1); // Dummy for compiler saving VERSION_MARKER
|
|
||||||
|
|
||||||
#ifdef USE_ARDUINO_OTA
|
#ifdef USE_ARDUINO_OTA
|
||||||
ArduinoOTAInit();
|
ArduinoOTAInit();
|
||||||
#endif // USE_ARDUINO_OTA
|
#endif // USE_ARDUINO_OTA
|
||||||
|
@ -3029,16 +3029,15 @@ int WebSend(char *buffer)
|
|||||||
#ifdef USE_WEBSEND_RESPONSE
|
#ifdef USE_WEBSEND_RESPONSE
|
||||||
// Return received data to the user - Adds 900+ bytes to the code
|
// 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!
|
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;
|
ResponseClear();
|
||||||
char text = '.';
|
char text[2] = { 0 };
|
||||||
while (text != '\0') {
|
text[0] = '.';
|
||||||
text = *read++;
|
while (text[0] != '\0') {
|
||||||
if (text > 31) { // Remove control characters like linefeed
|
text[0] = *read++;
|
||||||
TasmotaGlobal.mqtt_data[j++] = text;
|
if (text[0] > 31) { // Remove control characters like linefeed
|
||||||
if (j == sizeof(TasmotaGlobal.mqtt_data) -2) { break; }
|
if (ResponseAppend_P(text) == ResponseSize()) { break; };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
TasmotaGlobal.mqtt_data[j] = '\0';
|
|
||||||
#ifdef USE_SCRIPT
|
#ifdef USE_SCRIPT
|
||||||
extern uint8_t tasm_cmd_activ;
|
extern uint8_t tasm_cmd_activ;
|
||||||
// recursive call must be possible in this case
|
// recursive call must be possible in this case
|
||||||
|
@ -1289,12 +1289,11 @@ void CmndPublish(void) {
|
|||||||
strlcpy(stemp1, mqtt_part, sizeof(stemp1));
|
strlcpy(stemp1, mqtt_part, sizeof(stemp1));
|
||||||
ReplaceChar(stemp1, '#', ' ');
|
ReplaceChar(stemp1, '#', ' ');
|
||||||
if ((payload_part != nullptr) && strlen(payload_part)) {
|
if ((payload_part != nullptr) && strlen(payload_part)) {
|
||||||
strlcpy(TasmotaGlobal.mqtt_data, payload_part, sizeof(TasmotaGlobal.mqtt_data));
|
Response_P(payload_part);
|
||||||
} else {
|
} else {
|
||||||
ResponseClear();
|
ResponseClear();
|
||||||
}
|
}
|
||||||
MqttPublish(stemp1, (XdrvMailbox.index == 2));
|
MqttPublish(stemp1, (XdrvMailbox.index == 2));
|
||||||
// ResponseCmndDone();
|
|
||||||
ResponseClear();
|
ResponseClear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -278,7 +278,7 @@ void IrReceiveCheck(void)
|
|||||||
prev_number = true;
|
prev_number = true;
|
||||||
}
|
}
|
||||||
ir_high = !ir_high;
|
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);
|
uint16_t extended_length = getCorrectedRawLength(&results);
|
||||||
ResponseAppend_P(PSTR("\",\"" D_JSON_IR_RAWDATA "Info\":[%d,%d,%d]"), extended_length, i -1, results.overflow);
|
ResponseAppend_P(PSTR("\",\"" D_JSON_IR_RAWDATA "Info\":[%d,%d,%d]"), extended_length, i -1, results.overflow);
|
||||||
|
@ -307,7 +307,7 @@ void IrReceiveCheck(void)
|
|||||||
prev_number = true;
|
prev_number = true;
|
||||||
}
|
}
|
||||||
ir_high = !ir_high;
|
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);
|
uint16_t extended_length = getCorrectedRawLength(&results);
|
||||||
ResponseAppend_P(PSTR("\",\"" D_JSON_IR_RAWDATA "Info\":[%d,%d,%d]"), extended_length, i -1, results.overflow);
|
ResponseAppend_P(PSTR("\",\"" D_JSON_IR_RAWDATA "Info\":[%d,%d,%d]"), extended_length, i -1, results.overflow);
|
||||||
|
@ -2139,10 +2139,7 @@ void CmndRule(void)
|
|||||||
rule = rule.substring(0, MAX_RULE_SIZE);
|
rule = rule.substring(0, MAX_RULE_SIZE);
|
||||||
rule += F("...");
|
rule += F("...");
|
||||||
}
|
}
|
||||||
// snprintf_P (TasmotaGlobal.mqtt_data, sizeof(TasmotaGlobal.mqtt_data), PSTR("{\"%s%d\":{\"State\":\"%s\",\"Once\":\"%s\",\"StopOnError\":\"%s\",\"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)), 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\"}}"),
|
|
||||||
XdrvMailbox.command, index, GetStateText(bitRead(Settings.rule_enabled, index -1)), GetStateText(bitRead(Settings.rule_once, index -1)),
|
XdrvMailbox.command, index, GetStateText(bitRead(Settings.rule_enabled, index -1)), GetStateText(bitRead(Settings.rule_once, index -1)),
|
||||||
GetStateText(bitRead(Settings.rule_stop, index -1)),
|
GetStateText(bitRead(Settings.rule_stop, index -1)),
|
||||||
rule_len, MAX_RULE_SIZE - GetRuleLenStorage(index - 1),
|
rule_len, MAX_RULE_SIZE - GetRuleLenStorage(index - 1),
|
||||||
|
@ -6040,7 +6040,7 @@ bool ScriptCommand(void) {
|
|||||||
} else {
|
} else {
|
||||||
if ('>' == XdrvMailbox.data[0]) {
|
if ('>' == XdrvMailbox.data[0]) {
|
||||||
// execute script
|
// 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)) {
|
if (bitRead(Settings.rule_enabled, 0)) {
|
||||||
for (uint8_t count = 0; count<XdrvMailbox.data_len; count++) {
|
for (uint8_t count = 0; count<XdrvMailbox.data_len; count++) {
|
||||||
if (XdrvMailbox.data[count]==';') XdrvMailbox.data[count] = '\n';
|
if (XdrvMailbox.data[count]==';') XdrvMailbox.data[count] = '\n';
|
||||||
@ -6059,15 +6059,15 @@ bool ScriptCommand(void) {
|
|||||||
if (glob_script_mem.glob_error==1) {
|
if (glob_script_mem.glob_error==1) {
|
||||||
// was string, not number
|
// was string, not number
|
||||||
GetStringArgument(lp, OPER_EQU, str, 0);
|
GetStringArgument(lp, OPER_EQU, str, 0);
|
||||||
snprintf_P (TasmotaGlobal.mqtt_data, sizeof(TasmotaGlobal.mqtt_data), PSTR("{\"script\":{\"%s\":\"%s\"}}"), lp, str);
|
Response_P(PSTR("{\"script\":{\"%s\":\"%s\"}}"), lp, str);
|
||||||
} else {
|
} else {
|
||||||
dtostrfd(fvar, 6, str);
|
dtostrfd(fvar, 6, str);
|
||||||
snprintf_P (TasmotaGlobal.mqtt_data, sizeof(TasmotaGlobal.mqtt_data), PSTR("{\"script\":{\"%s\":%s}}"), lp, str);
|
Response_P(PSTR("{\"script\":{\"%s\":%s}}"), lp, str);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return serviced;
|
return serviced;
|
||||||
}
|
}
|
||||||
snprintf_P (TasmotaGlobal.mqtt_data, sizeof(TasmotaGlobal.mqtt_data), PSTR("{\"%s\":\"%s\",\"Free\":%d}"),command, GetStateText(bitRead(Settings.rule_enabled, 0)), glob_script_mem.script_size - strlen(glob_script_mem.script_ram));
|
Response_P(PSTR("{\"%s\":\"%s\",\"Free\":%d}"), command, GetStateText(bitRead(Settings.rule_enabled, 0)), glob_script_mem.script_size - strlen(glob_script_mem.script_ram));
|
||||||
#ifdef SUPPORT_MQTT_EVENT
|
#ifdef SUPPORT_MQTT_EVENT
|
||||||
} else if (CMND_SUBSCRIBE == command_code) { //MQTT Subscribe command. Subscribe <Event>, <Topic> [, <Key>]
|
} else if (CMND_SUBSCRIBE == command_code) { //MQTT Subscribe command. Subscribe <Event>, <Topic> [, <Key>]
|
||||||
String result = ScriptSubscribe(XdrvMailbox.data, XdrvMailbox.data_len);
|
String result = ScriptSubscribe(XdrvMailbox.data, XdrvMailbox.data_len);
|
||||||
|
@ -362,8 +362,8 @@ void TryResponseAppend_P(const char *format, ...)
|
|||||||
char dummy[2];
|
char dummy[2];
|
||||||
int dlen = vsnprintf_P(dummy, 1, format, args);
|
int dlen = vsnprintf_P(dummy, 1, format, args);
|
||||||
|
|
||||||
int mlen = strlen(TasmotaGlobal.mqtt_data);
|
int mlen = ResponseLength();
|
||||||
int slen = sizeof(TasmotaGlobal.mqtt_data) - 1 - mlen;
|
int slen = ResponseSize() - 1 - mlen;
|
||||||
if (dlen >= slen)
|
if (dlen >= slen)
|
||||||
{
|
{
|
||||||
AddLog_P(LOG_LEVEL_ERROR, PSTR("%s (%u/%u):"), kHAssError1, dlen, slen);
|
AddLog_P(LOG_LEVEL_ERROR, PSTR("%s (%u/%u):"), kHAssError1, dlen, slen);
|
||||||
|
@ -299,7 +299,7 @@ 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 > sizeof(TasmotaGlobal.mqtt_data)) { JSONlen = sizeof(TasmotaGlobal.mqtt_data); }
|
if (JSONlen > ResponseSize()) { JSONlen = ResponseSize(); }
|
||||||
char stemp[JSONlen];
|
char stemp[JSONlen];
|
||||||
strlcpy(stemp, JSON +1, JSONlen -2);
|
strlcpy(stemp, JSON +1, JSONlen -2);
|
||||||
if (cflg) { response += F(","); }
|
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\"}}"),
|
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));
|
XdrvMailbox.command,
|
||||||
|
GetStateText(Settings.sbflag1.telegram_send_enable),
|
||||||
|
GetStateText(Settings.sbflag1.telegram_recv_enable),
|
||||||
|
GetStateText(Settings.sbflag1.telegram_echo_enable));
|
||||||
}
|
}
|
||||||
|
|
||||||
void CmndTmPoll(void) {
|
void CmndTmPoll(void) {
|
||||||
|
@ -208,8 +208,7 @@ bool TimepropCommand()
|
|||||||
if (XdrvMailbox.index >=0 && XdrvMailbox.index < TIMEPROP_NUM_OUTPUTS) {
|
if (XdrvMailbox.index >=0 && XdrvMailbox.index < TIMEPROP_NUM_OUTPUTS) {
|
||||||
timeprops[XdrvMailbox.index].setPower( atof(XdrvMailbox.data), Tprop.current_time_secs );
|
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\"}"),
|
Response_P(PSTR("{\"" D_CMND_TIMEPROP D_CMND_TIMEPROP_SETPOWER "%d\":\"%s\"}"), XdrvMailbox.index, XdrvMailbox.data);
|
||||||
XdrvMailbox.index, XdrvMailbox.data);
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
serviced = false;
|
serviced = false;
|
||||||
|
@ -60,7 +60,7 @@ extern "C" {
|
|||||||
if (top == 4) {
|
if (top == 4) {
|
||||||
retain = be_tobool(vm, 4);
|
retain = be_tobool(vm, 4);
|
||||||
}
|
}
|
||||||
strlcpy(TasmotaGlobal.mqtt_data, payload, sizeof(TasmotaGlobal.mqtt_data));
|
Response_P(payload);
|
||||||
MqttPublish(topic, retain);
|
MqttPublish(topic, retain);
|
||||||
be_return(vm); // Return
|
be_return(vm); // Return
|
||||||
}
|
}
|
||||||
|
@ -206,10 +206,7 @@ void ADPSCallback(uint8_t phase, char * label)
|
|||||||
phase = 1;
|
phase = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
Response_P(PSTR("{"));
|
Response_P(PSTR("{\"TIC\":{\"%s\":%i}}"), label, phase );
|
||||||
ResponseAppend_P(TasmotaGlobal.mqtt_data, sizeof(TasmotaGlobal.mqtt_data), PSTR("\"TIC\":{\"%s\":%i}"), label, phase );
|
|
||||||
ResponseJsonEnd();
|
|
||||||
|
|
||||||
// Publish adding ADCO serial number into the topic
|
// Publish adding ADCO serial number into the topic
|
||||||
MqttPublishPrefixTopicRulesProcess_P(TELE, PSTR(D_RSLT_SENSOR), false);
|
MqttPublishPrefixTopicRulesProcess_P(TELE, PSTR(D_RSLT_SENSOR), false);
|
||||||
|
|
||||||
|
@ -2691,10 +2691,10 @@ void MI32ShowSomeSensors(){
|
|||||||
p = &MIBLEsensors[MI32.mqttCurrentSlot];
|
p = &MIBLEsensors[MI32.mqttCurrentSlot];
|
||||||
|
|
||||||
MI32GetOneSensorJson(MI32.mqttCurrentSlot, (maxcnt == 1));
|
MI32GetOneSensorJson(MI32.mqttCurrentSlot, (maxcnt == 1));
|
||||||
int mlen = strlen(TasmotaGlobal.mqtt_data);
|
int mlen = ResponseLength();
|
||||||
|
|
||||||
// if we ran out of room, leave here.
|
// if we ran out of room, leave here.
|
||||||
if (sizeof(TasmotaGlobal.mqtt_data) - mlen < 100){
|
if (ResponseSize() - mlen < 100){
|
||||||
MI32.mqttCurrentSlot++;
|
MI32.mqttCurrentSlot++;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -3055,10 +3055,10 @@ void MI32ShowTriggeredSensors(){
|
|||||||
ResponseAppend_P(PSTR(","));
|
ResponseAppend_P(PSTR(","));
|
||||||
// hide sensor name if HASS or option6
|
// hide sensor name if HASS or option6
|
||||||
MI32GetOneSensorJson(sensor, (maxcnt == 1));
|
MI32GetOneSensorJson(sensor, (maxcnt == 1));
|
||||||
int mlen = strlen(TasmotaGlobal.mqtt_data);
|
int mlen = ResponseLength();
|
||||||
|
|
||||||
// if we ran out of room, leave here.
|
// if we ran out of room, leave here.
|
||||||
if (sizeof(TasmotaGlobal.mqtt_data) - mlen < 100){
|
if (ResponseSize() - mlen < 100){
|
||||||
sensor++;
|
sensor++;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -518,11 +518,7 @@ void sns_opentherm_flags_cmd(void)
|
|||||||
int mode = Settings.ot_flags & (uint8_t)mask;
|
int mode = Settings.ot_flags & (uint8_t)mask;
|
||||||
if (mode > 0)
|
if (mode > 0)
|
||||||
{
|
{
|
||||||
if (addComma)
|
ResponseAppend_P(PSTR("%s%s"), (addComma)?",":"", sns_opentherm_flag_text(mode));
|
||||||
{
|
|
||||||
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));
|
|
||||||
addComma = true;
|
addComma = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -65,7 +65,7 @@ void Esp32SensorShow(bool json) {
|
|||||||
#endif // CONFIG_IDF_TARGET_ESP32
|
#endif // CONFIG_IDF_TARGET_ESP32
|
||||||
|
|
||||||
if (json) {
|
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);
|
ResponseAppend_P(PSTR(",\"ESP32\":{\"" D_JSON_TEMPERATURE "\":%*_f"), Settings.flag2.temperature_resolution, &t);
|
||||||
|
|
||||||
#if CONFIG_IDF_TARGET_ESP32
|
#if CONFIG_IDF_TARGET_ESP32
|
||||||
|
Loading…
x
Reference in New Issue
Block a user