mirror of https://github.com/arendst/Tasmota.git
Merge branch 'globalstruct' into development
This commit is contained in:
commit
524012a752
|
@ -526,12 +526,12 @@ void SettingsSave(uint8_t rotate)
|
|||
UpdateBackwardCompatibility();
|
||||
if ((GetSettingsCrc32() != settings_crc32) || rotate) {
|
||||
if (1 == rotate) { // Use eeprom flash slot only and disable flash rotate from now on (upgrade)
|
||||
stop_flash_rotate = 1;
|
||||
TasmotaGlobal.stop_flash_rotate = 1;
|
||||
}
|
||||
if (2 == rotate) { // Use eeprom flash slot and erase next flash slots if stop_flash_rotate is off (default)
|
||||
settings_location = SETTINGS_LOCATION +1;
|
||||
}
|
||||
if (stop_flash_rotate) {
|
||||
if (TasmotaGlobal.stop_flash_rotate) {
|
||||
settings_location = SETTINGS_LOCATION;
|
||||
} else {
|
||||
settings_location--;
|
||||
|
@ -555,7 +555,7 @@ void SettingsSave(uint8_t rotate)
|
|||
ESP.flashWrite(settings_location * SPI_FLASH_SEC_SIZE, (uint32*)&Settings, sizeof(Settings));
|
||||
}
|
||||
|
||||
if (!stop_flash_rotate && rotate) {
|
||||
if (!TasmotaGlobal.stop_flash_rotate && rotate) {
|
||||
for (uint32_t i = 1; i < CFG_ROTATES; i++) {
|
||||
ESP.flashEraseSector(settings_location -i); // Delete previous configurations by resetting to 0xFF
|
||||
delay(1);
|
||||
|
@ -615,7 +615,7 @@ void SettingsLoad(void) {
|
|||
|
||||
void EspErase(uint32_t start_sector, uint32_t end_sector)
|
||||
{
|
||||
bool serial_output = (LOG_LEVEL_DEBUG_MORE <= seriallog_level);
|
||||
bool serial_output = (LOG_LEVEL_DEBUG_MORE <= TasmotaGlobal.seriallog_level);
|
||||
for (uint32_t sector = start_sector; sector < end_sector; sector++) {
|
||||
|
||||
bool result = ESP.flashEraseSector(sector); // Arduino core - erases flash as seen by SDK
|
||||
|
|
|
@ -607,7 +607,7 @@ bool NewerVersion(char* version_str)
|
|||
char* GetPowerDevice(char* dest, uint32_t idx, size_t size, uint32_t option)
|
||||
{
|
||||
strncpy_P(dest, S_RSLT_POWER, size); // POWER
|
||||
if ((devices_present + option) > 1) {
|
||||
if ((TasmotaGlobal.devices_present + option) > 1) {
|
||||
char sidx[8];
|
||||
snprintf_P(sidx, sizeof(sidx), PSTR("%d"), idx); // x
|
||||
strncat(dest, sidx, size - strlen(dest) -1); // POWERx
|
||||
|
@ -629,12 +629,12 @@ void GetEspHardwareType(void)
|
|||
// uint32_t efuse3 = *(uint32_t*)(0x3FF00058);
|
||||
// uint32_t efuse4 = *(uint32_t*)(0x3FF0005C);
|
||||
|
||||
is_8285 = ( (efuse1 & (1 << 4)) || (efuse2 & (1 << 16)) );
|
||||
if (is_8285 && (ESP.getFlashChipRealSize() > 1048576)) {
|
||||
is_8285 = false; // ESP8285 can only have 1M flash
|
||||
TasmotaGlobal.is_8285 = ( (efuse1 & (1 << 4)) || (efuse2 & (1 << 16)) );
|
||||
if (TasmotaGlobal.is_8285 && (ESP.getFlashChipRealSize() > 1048576)) {
|
||||
TasmotaGlobal.is_8285 = false; // ESP8285 can only have 1M flash
|
||||
}
|
||||
#else
|
||||
is_8285 = false; // ESP8285 can only have 1M flash
|
||||
TasmotaGlobal.is_8285 = false; // ESP8285 can only have 1M flash
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -642,7 +642,7 @@ String GetDeviceHardware(void)
|
|||
{
|
||||
char buff[10];
|
||||
#ifdef ESP8266
|
||||
if (is_8285) {
|
||||
if (TasmotaGlobal.is_8285) {
|
||||
strcpy_P(buff, PSTR("ESP8285"));
|
||||
} else {
|
||||
strcpy_P(buff, PSTR("ESP8266EX"));
|
||||
|
@ -944,7 +944,7 @@ void SetSerial(uint32_t baudrate, uint32_t serial_config) {
|
|||
}
|
||||
|
||||
void ClaimSerial(void) {
|
||||
serial_local = true;
|
||||
TasmotaGlobal.serial_local = true;
|
||||
AddLog_P(LOG_LEVEL_INFO, PSTR("SNS: Hardware Serial"));
|
||||
SetSeriallog(LOG_LEVEL_NONE);
|
||||
TasmotaGlobal.baudrate = Serial.baudRate();
|
||||
|
@ -1081,12 +1081,16 @@ char* ResponseGetTime(uint32_t format, char* time_str)
|
|||
return time_str;
|
||||
}
|
||||
|
||||
void ResponseClear(void) {
|
||||
TasmotaGlobal.mqtt_data[0] = '\0';
|
||||
}
|
||||
|
||||
int Response_P(const char* format, ...) // Content send snprintf_P char data
|
||||
{
|
||||
// This uses char strings. Be aware of sending %% if % is needed
|
||||
va_list args;
|
||||
va_start(args, format);
|
||||
int len = vsnprintf_P(mqtt_data, sizeof(mqtt_data), format, args);
|
||||
int len = vsnprintf_P(TasmotaGlobal.mqtt_data, sizeof(TasmotaGlobal.mqtt_data), format, args);
|
||||
va_end(args);
|
||||
return len;
|
||||
}
|
||||
|
@ -1097,10 +1101,10 @@ int ResponseTime_P(const char* format, ...) // Content send snprintf_P char d
|
|||
va_list args;
|
||||
va_start(args, format);
|
||||
|
||||
ResponseGetTime(Settings.flag2.time_format, mqtt_data);
|
||||
ResponseGetTime(Settings.flag2.time_format, TasmotaGlobal.mqtt_data);
|
||||
|
||||
int mlen = strlen(mqtt_data);
|
||||
int len = vsnprintf_P(mqtt_data + mlen, sizeof(mqtt_data) - mlen, format, args);
|
||||
int mlen = strlen(TasmotaGlobal.mqtt_data);
|
||||
int len = vsnprintf_P(TasmotaGlobal.mqtt_data + mlen, sizeof(TasmotaGlobal.mqtt_data) - mlen, format, args);
|
||||
va_end(args);
|
||||
return len + mlen;
|
||||
}
|
||||
|
@ -1110,8 +1114,8 @@ int ResponseAppend_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 mlen = strlen(mqtt_data);
|
||||
int len = vsnprintf_P(mqtt_data + mlen, sizeof(mqtt_data) - mlen, format, args);
|
||||
int mlen = strlen(TasmotaGlobal.mqtt_data);
|
||||
int len = vsnprintf_P(TasmotaGlobal.mqtt_data + mlen, sizeof(TasmotaGlobal.mqtt_data) - mlen, format, args);
|
||||
va_end(args);
|
||||
return len + mlen;
|
||||
}
|
||||
|
@ -1233,7 +1237,7 @@ void DumpConvertTable(void) {
|
|||
lines++;
|
||||
}
|
||||
}
|
||||
mqtt_data[0] = '\0';
|
||||
ResponseClear();
|
||||
}
|
||||
*/
|
||||
#endif // ESP8266
|
||||
|
@ -1430,7 +1434,7 @@ void ModuleDefault(uint32_t module)
|
|||
|
||||
void SetModuleType(void)
|
||||
{
|
||||
my_module_type = (USER_MODULE == Settings.module) ? Settings.user_template_base : Settings.module;
|
||||
TasmotaGlobal.module_type = (USER_MODULE == Settings.module) ? Settings.user_template_base : Settings.module;
|
||||
}
|
||||
|
||||
bool FlashPin(uint32_t pin)
|
||||
|
@ -1444,7 +1448,7 @@ uint32_t ValidPin(uint32_t pin, uint32_t gpio)
|
|||
return GPIO_NONE; // Disable flash pins GPIO6, GPIO7, GPIO8 and GPIO11
|
||||
}
|
||||
|
||||
// if (!is_8285 && !Settings.flag3.user_esp8285_enable) { // SetOption51 - Enable ESP8285 user GPIO's
|
||||
// if (!TasmotaGlobal.is_8285 && !Settings.flag3.user_esp8285_enable) { // SetOption51 - Enable ESP8285 user GPIO's
|
||||
if ((WEMOS == Settings.module) && !Settings.flag3.user_esp8285_enable) { // SetOption51 - Enable ESP8285 user GPIO's
|
||||
if ((9 == pin) || (10 == pin)) {
|
||||
return GPIO_NONE; // Disable possible flash GPIO9 and GPIO10
|
||||
|
@ -1927,14 +1931,14 @@ bool I2cSetDevice(uint32_t addr)
|
|||
void SetSeriallog(uint32_t loglevel)
|
||||
{
|
||||
Settings.seriallog_level = loglevel;
|
||||
seriallog_level = loglevel;
|
||||
TasmotaGlobal.seriallog_level = loglevel;
|
||||
TasmotaGlobal.seriallog_timer = 0;
|
||||
}
|
||||
|
||||
void SetSyslog(uint32_t loglevel)
|
||||
{
|
||||
Settings.syslog_level = loglevel;
|
||||
syslog_level = loglevel;
|
||||
TasmotaGlobal.syslog_level = loglevel;
|
||||
TasmotaGlobal.syslog_timer = 0;
|
||||
}
|
||||
|
||||
|
@ -1945,7 +1949,7 @@ void GetLog(uint32_t idx, char** entry_pp, size_t* len_p)
|
|||
size_t len = 0;
|
||||
|
||||
if (idx) {
|
||||
char* it = web_log;
|
||||
char* it = TasmotaGlobal.web_log;
|
||||
do {
|
||||
uint32_t cur_idx = *it;
|
||||
it++;
|
||||
|
@ -1957,7 +1961,7 @@ void GetLog(uint32_t idx, char** entry_pp, size_t* len_p)
|
|||
break;
|
||||
}
|
||||
it += tmp;
|
||||
} while (it < web_log + WEB_LOG_SIZE && *it != '\0');
|
||||
} while (it < TasmotaGlobal.web_log + WEB_LOG_SIZE && *it != '\0');
|
||||
}
|
||||
*entry_pp = entry_p;
|
||||
*len_p = len;
|
||||
|
@ -1966,7 +1970,7 @@ void GetLog(uint32_t idx, char** entry_pp, size_t* len_p)
|
|||
|
||||
void Syslog(void)
|
||||
{
|
||||
// Destroys log_data
|
||||
// Destroys TasmotaGlobal.log_data
|
||||
|
||||
uint32_t current_hash = GetHash(SettingsText(SET_SYSLOG_HOST), strlen(SettingsText(SET_SYSLOG_HOST)));
|
||||
if (syslog_host_hash != current_hash) {
|
||||
|
@ -1976,14 +1980,14 @@ void Syslog(void)
|
|||
if (PortUdp.beginPacket(syslog_host_addr, Settings.syslog_port)) {
|
||||
char syslog_preamble[64]; // Hostname + Id
|
||||
snprintf_P(syslog_preamble, sizeof(syslog_preamble), PSTR("%s ESP-"), NetworkHostname());
|
||||
memmove(log_data + strlen(syslog_preamble), log_data, sizeof(log_data) - strlen(syslog_preamble));
|
||||
log_data[sizeof(log_data) -1] = '\0';
|
||||
memcpy(log_data, syslog_preamble, strlen(syslog_preamble));
|
||||
PortUdp_write(log_data, strlen(log_data));
|
||||
memmove(TasmotaGlobal.log_data + strlen(syslog_preamble), TasmotaGlobal.log_data, sizeof(TasmotaGlobal.log_data) - strlen(syslog_preamble));
|
||||
TasmotaGlobal.log_data[sizeof(TasmotaGlobal.log_data) -1] = '\0';
|
||||
memcpy(TasmotaGlobal.log_data, syslog_preamble, strlen(syslog_preamble));
|
||||
PortUdp_write(TasmotaGlobal.log_data, strlen(TasmotaGlobal.log_data));
|
||||
PortUdp.endPacket();
|
||||
delay(1); // Add time for UDP handling (#5512)
|
||||
} else {
|
||||
syslog_level = 0;
|
||||
TasmotaGlobal.syslog_level = 0;
|
||||
TasmotaGlobal.syslog_timer = SYSLOG_TIMER;
|
||||
AddLog_P2(LOG_LEVEL_INFO, PSTR(D_LOG_APPLICATION D_SYSLOG_HOST_NOT_FOUND ". " D_RETRY_IN " %d " D_UNIT_SECOND), SYSLOG_TIMER);
|
||||
}
|
||||
|
@ -1994,30 +1998,30 @@ void AddLog(uint32_t loglevel)
|
|||
char mxtime[10]; // "13:45:21 "
|
||||
snprintf_P(mxtime, sizeof(mxtime), PSTR("%02d" D_HOUR_MINUTE_SEPARATOR "%02d" D_MINUTE_SECOND_SEPARATOR "%02d "), RtcTime.hour, RtcTime.minute, RtcTime.second);
|
||||
|
||||
if ((loglevel <= seriallog_level) &&
|
||||
(masterlog_level <= seriallog_level)) {
|
||||
Serial.printf("%s%s\r\n", mxtime, log_data);
|
||||
if ((loglevel <= TasmotaGlobal.seriallog_level) &&
|
||||
(TasmotaGlobal.masterlog_level <= TasmotaGlobal.seriallog_level)) {
|
||||
Serial.printf("%s%s\r\n", mxtime, TasmotaGlobal.log_data);
|
||||
}
|
||||
#ifdef USE_WEBSERVER
|
||||
if (Settings.webserver &&
|
||||
(loglevel <= Settings.weblog_level) &&
|
||||
(masterlog_level <= Settings.weblog_level)) {
|
||||
(TasmotaGlobal.masterlog_level <= Settings.weblog_level)) {
|
||||
// Delimited, zero-terminated buffer of log lines.
|
||||
// Each entry has this format: [index][log data]['\1']
|
||||
TasmotaGlobal.web_log_index &= 0xFF;
|
||||
if (!TasmotaGlobal.web_log_index) {
|
||||
TasmotaGlobal.web_log_index++; // Index 0 is not allowed as it is the end of char string
|
||||
}
|
||||
while (TasmotaGlobal.web_log_index == web_log[0] || // If log already holds the next index, remove it
|
||||
strlen(web_log) + strlen(log_data) + 13 > WEB_LOG_SIZE) // 13 = web_log_index + mxtime + '\1' + '\0'
|
||||
while (TasmotaGlobal.web_log_index == TasmotaGlobal.web_log[0] || // If log already holds the next index, remove it
|
||||
strlen(TasmotaGlobal.web_log) + strlen(TasmotaGlobal.log_data) + 13 > WEB_LOG_SIZE) // 13 = web_log_index + mxtime + '\1' + '\0'
|
||||
{
|
||||
char* it = web_log;
|
||||
char* it = TasmotaGlobal.web_log;
|
||||
it++; // Skip web_log_index
|
||||
it += strchrspn(it, '\1'); // Skip log line
|
||||
it++; // Skip delimiting "\1"
|
||||
memmove(web_log, it, WEB_LOG_SIZE -(it-web_log)); // Move buffer forward to remove oldest log line
|
||||
memmove(TasmotaGlobal.web_log, it, WEB_LOG_SIZE -(it-TasmotaGlobal.web_log)); // Move buffer forward to remove oldest log line
|
||||
}
|
||||
snprintf_P(web_log, sizeof(web_log), PSTR("%s%c%s%s\1"), web_log, TasmotaGlobal.web_log_index++, mxtime, log_data);
|
||||
snprintf_P(TasmotaGlobal.web_log, sizeof(TasmotaGlobal.web_log), PSTR("%s%c%s%s\1"), TasmotaGlobal.web_log, TasmotaGlobal.web_log_index++, mxtime, TasmotaGlobal.log_data);
|
||||
TasmotaGlobal.web_log_index &= 0xFF;
|
||||
if (!TasmotaGlobal.web_log_index) {
|
||||
TasmotaGlobal.web_log_index++; // Index 0 is not allowed as it is the end of char string
|
||||
|
@ -2025,30 +2029,30 @@ void AddLog(uint32_t loglevel)
|
|||
}
|
||||
#endif // USE_WEBSERVER
|
||||
if (Settings.flag.mqtt_enabled && // SetOption3 - Enable MQTT
|
||||
!global_state.mqtt_down &&
|
||||
!TasmotaGlobal.global_state.mqtt_down &&
|
||||
(loglevel <= Settings.mqttlog_level) &&
|
||||
(masterlog_level <= Settings.mqttlog_level)) { MqttPublishLogging(mxtime); }
|
||||
(TasmotaGlobal.masterlog_level <= Settings.mqttlog_level)) { MqttPublishLogging(mxtime); }
|
||||
|
||||
if (!global_state.network_down &&
|
||||
(loglevel <= syslog_level) &&
|
||||
(masterlog_level <= syslog_level)) { Syslog(); }
|
||||
if (!TasmotaGlobal.global_state.network_down &&
|
||||
(loglevel <= TasmotaGlobal.syslog_level) &&
|
||||
(TasmotaGlobal.masterlog_level <= TasmotaGlobal.syslog_level)) { Syslog(); }
|
||||
|
||||
prepped_loglevel = 0;
|
||||
TasmotaGlobal.prepped_loglevel = 0;
|
||||
}
|
||||
|
||||
void AddLog_P(uint32_t loglevel, const char *formatP)
|
||||
{
|
||||
snprintf_P(log_data, sizeof(log_data), formatP);
|
||||
snprintf_P(TasmotaGlobal.log_data, sizeof(TasmotaGlobal.log_data), formatP);
|
||||
AddLog(loglevel);
|
||||
}
|
||||
|
||||
void AddLog_P(uint32_t loglevel, const char *formatP, const char *formatP2)
|
||||
{
|
||||
char message[sizeof(log_data)];
|
||||
char message[sizeof(TasmotaGlobal.log_data)];
|
||||
|
||||
snprintf_P(log_data, sizeof(log_data), formatP);
|
||||
snprintf_P(TasmotaGlobal.log_data, sizeof(TasmotaGlobal.log_data), formatP);
|
||||
snprintf_P(message, sizeof(message), formatP2);
|
||||
strncat(log_data, message, sizeof(log_data) - strlen(log_data) -1);
|
||||
strncat(TasmotaGlobal.log_data, message, sizeof(TasmotaGlobal.log_data) - strlen(TasmotaGlobal.log_data) -1);
|
||||
AddLog(loglevel);
|
||||
}
|
||||
|
||||
|
@ -2056,17 +2060,17 @@ void PrepLog_P2(uint32_t loglevel, PGM_P formatP, ...)
|
|||
{
|
||||
va_list arg;
|
||||
va_start(arg, formatP);
|
||||
vsnprintf_P(log_data, sizeof(log_data), formatP, arg);
|
||||
vsnprintf_P(TasmotaGlobal.log_data, sizeof(TasmotaGlobal.log_data), formatP, arg);
|
||||
va_end(arg);
|
||||
|
||||
prepped_loglevel = loglevel;
|
||||
TasmotaGlobal.prepped_loglevel = loglevel;
|
||||
}
|
||||
|
||||
void AddLog_P2(uint32_t loglevel, PGM_P formatP, ...)
|
||||
{
|
||||
va_list arg;
|
||||
va_start(arg, formatP);
|
||||
vsnprintf_P(log_data, sizeof(log_data), formatP, arg);
|
||||
vsnprintf_P(TasmotaGlobal.log_data, sizeof(TasmotaGlobal.log_data), formatP, arg);
|
||||
va_end(arg);
|
||||
|
||||
AddLog(loglevel);
|
||||
|
@ -2076,7 +2080,7 @@ void AddLog_Debug(PGM_P formatP, ...)
|
|||
{
|
||||
va_list arg;
|
||||
va_start(arg, formatP);
|
||||
vsnprintf_P(log_data, sizeof(log_data), formatP, arg);
|
||||
vsnprintf_P(TasmotaGlobal.log_data, sizeof(TasmotaGlobal.log_data), formatP, arg);
|
||||
va_end(arg);
|
||||
|
||||
AddLog(LOG_LEVEL_DEBUG);
|
||||
|
@ -2085,15 +2089,15 @@ void AddLog_Debug(PGM_P formatP, ...)
|
|||
void AddLogBuffer(uint32_t loglevel, uint8_t *buffer, uint32_t count)
|
||||
{
|
||||
/*
|
||||
snprintf_P(log_data, sizeof(log_data), PSTR("DMP:"));
|
||||
snprintf_P(TasmotaGlobal.log_data, sizeof(TasmotaGlobal.log_data), PSTR("DMP:"));
|
||||
for (uint32_t i = 0; i < count; i++) {
|
||||
snprintf_P(log_data, sizeof(log_data), PSTR("%s %02X"), log_data, *(buffer++));
|
||||
snprintf_P(TasmotaGlobal.log_data, sizeof(TasmotaGlobal.log_data), PSTR("%s %02X"), TasmotaGlobal.log_data, *(buffer++));
|
||||
}
|
||||
AddLog(loglevel);
|
||||
*/
|
||||
/*
|
||||
strcpy_P(log_data, PSTR("DMP: "));
|
||||
ToHex_P(buffer, count, log_data + strlen(log_data), sizeof(log_data) - strlen(log_data), ' ');
|
||||
strcpy_P(TasmotaGlobal.log_data, PSTR("DMP: "));
|
||||
ToHex_P(buffer, count, TasmotaGlobal.log_data + strlen(TasmotaGlobal.log_data), sizeof(TasmotaGlobal.log_data) - strlen(TasmotaGlobal.log_data), ' ');
|
||||
AddLog(loglevel);
|
||||
*/
|
||||
char hex_char[(count * 3) + 2];
|
||||
|
@ -2102,7 +2106,7 @@ void AddLogBuffer(uint32_t loglevel, uint8_t *buffer, uint32_t count)
|
|||
|
||||
void AddLogSerial(uint32_t loglevel)
|
||||
{
|
||||
AddLogBuffer(loglevel, (uint8_t*)serial_in_buffer, TasmotaGlobal.serial_in_byte_counter);
|
||||
AddLogBuffer(loglevel, (uint8_t*)TasmotaGlobal.serial_in_buffer, TasmotaGlobal.serial_in_byte_counter);
|
||||
}
|
||||
|
||||
void AddLogMissed(const char *sensor, uint32_t misses)
|
||||
|
@ -2111,12 +2115,12 @@ void AddLogMissed(const char *sensor, uint32_t misses)
|
|||
}
|
||||
|
||||
void AddLogBufferSize(uint32_t loglevel, uint8_t *buffer, uint32_t count, uint32_t size) {
|
||||
snprintf_P(log_data, sizeof(log_data), PSTR("DMP:"));
|
||||
snprintf_P(TasmotaGlobal.log_data, sizeof(TasmotaGlobal.log_data), PSTR("DMP:"));
|
||||
for (uint32_t i = 0; i < count; i++) {
|
||||
if (1 == size) { // uint8_t
|
||||
snprintf_P(log_data, sizeof(log_data), PSTR("%s %02X"), log_data, *(buffer));
|
||||
snprintf_P(TasmotaGlobal.log_data, sizeof(TasmotaGlobal.log_data), PSTR("%s %02X"), TasmotaGlobal.log_data, *(buffer));
|
||||
} else { // uint16_t
|
||||
snprintf_P(log_data, sizeof(log_data), PSTR("%s %02X%02X"), log_data, *(buffer +1), *(buffer));
|
||||
snprintf_P(TasmotaGlobal.log_data, sizeof(TasmotaGlobal.log_data), PSTR("%s %02X%02X"), TasmotaGlobal.log_data, *(buffer +1), *(buffer));
|
||||
}
|
||||
buffer += size;
|
||||
}
|
||||
|
|
|
@ -80,7 +80,7 @@ void ButtonInit(void)
|
|||
{
|
||||
Button.present = 0;
|
||||
#ifdef ESP8266
|
||||
if ((SONOFF_DUAL == my_module_type) || (CH4 == my_module_type)) {
|
||||
if ((SONOFF_DUAL == TasmotaGlobal.module_type) || (CH4 == TasmotaGlobal.module_type)) {
|
||||
Button.present++;
|
||||
}
|
||||
#endif // ESP8266
|
||||
|
@ -146,7 +146,7 @@ void ButtonHandler(void)
|
|||
uint8_t button_present = 0;
|
||||
|
||||
#ifdef ESP8266
|
||||
if (!button_index && ((SONOFF_DUAL == my_module_type) || (CH4 == my_module_type))) {
|
||||
if (!button_index && ((SONOFF_DUAL == TasmotaGlobal.module_type) || (CH4 == TasmotaGlobal.module_type))) {
|
||||
button_present = 1;
|
||||
if (Button.dual_code) {
|
||||
AddLog_P2(LOG_LEVEL_DEBUG, PSTR(D_LOG_APPLICATION D_BUTTON " " D_CODE " %04X"), Button.dual_code);
|
||||
|
@ -204,7 +204,7 @@ void ButtonHandler(void)
|
|||
// Serviced
|
||||
}
|
||||
#ifdef ESP8266
|
||||
else if (SONOFF_4CHPRO == my_module_type) {
|
||||
else if (SONOFF_4CHPRO == TasmotaGlobal.module_type) {
|
||||
if (Button.hold_timer[button_index]) { Button.hold_timer[button_index]--; }
|
||||
|
||||
bool button_pressed = false;
|
||||
|
@ -286,13 +286,13 @@ void ButtonHandler(void)
|
|||
bool single_press = false;
|
||||
if (Button.press_counter[button_index] < 3) { // Single or Double press
|
||||
#ifdef ESP8266
|
||||
if ((SONOFF_DUAL_R2 == my_module_type) || (SONOFF_DUAL == my_module_type) || (CH4 == my_module_type)) {
|
||||
if ((SONOFF_DUAL_R2 == TasmotaGlobal.module_type) || (SONOFF_DUAL == TasmotaGlobal.module_type) || (CH4 == TasmotaGlobal.module_type)) {
|
||||
single_press = true;
|
||||
} else
|
||||
#endif // ESP8266
|
||||
{
|
||||
single_press = (Settings.flag.button_swap +1 == Button.press_counter[button_index]); // SetOption11 (0)
|
||||
if ((1 == Button.present) && (2 == devices_present)) { // Single Button with two devices only
|
||||
if ((1 == Button.present) && (2 == TasmotaGlobal.devices_present)) { // Single Button with two devices only
|
||||
if (Settings.flag.button_swap) { // SetOption11 (0)
|
||||
Button.press_counter[button_index] = (single_press) ? 1 : 2;
|
||||
}
|
||||
|
@ -317,8 +317,8 @@ void ButtonHandler(void)
|
|||
if (0 == button_index) { // BUTTON1 can toggle up to 5 relays if present. If a relay is not present will send out the key value (2,11,12,13 and 14) for rules
|
||||
bool valid_relay = PinUsed(GPIO_REL1, Button.press_counter[button_index]-1);
|
||||
#ifdef ESP8266
|
||||
if ((SONOFF_DUAL == my_module_type) || (CH4 == my_module_type)) {
|
||||
valid_relay = (Button.press_counter[button_index] <= devices_present);
|
||||
if ((SONOFF_DUAL == TasmotaGlobal.module_type) || (CH4 == TasmotaGlobal.module_type)) {
|
||||
valid_relay = (Button.press_counter[button_index] <= TasmotaGlobal.devices_present);
|
||||
}
|
||||
#endif // ESP8266
|
||||
if ((Button.press_counter[button_index] > 1) && valid_relay && (Button.press_counter[button_index] <= MAX_RELAY_BUTTON1)) {
|
||||
|
@ -366,7 +366,7 @@ void MqttButtonTopic(uint8_t button_id, uint8_t action, uint8_t hold)
|
|||
if (!Settings.flag.hass_discovery) {
|
||||
GetTextIndexed(mqttstate, sizeof(mqttstate), action, kMultiPress);
|
||||
snprintf_P(scommand, sizeof(scommand), PSTR("BUTTON%d"), button_id);
|
||||
GetTopic_P(stopic, STAT, mqtt_topic, scommand);
|
||||
GetTopic_P(stopic, STAT, TasmotaGlobal.mqtt_topic, scommand);
|
||||
Response_P(S_JSON_COMMAND_SVALUE, "ACTION", (hold) ? SettingsText(SET_STATE_TXT4) : mqttstate);
|
||||
MqttPublish(stopic);
|
||||
}
|
||||
|
|
|
@ -121,7 +121,7 @@ void ResponseCmndIdxChar(const char* value)
|
|||
void ResponseCmndAll(uint32_t text_index, uint32_t count)
|
||||
{
|
||||
uint32_t real_index = text_index;
|
||||
mqtt_data[0] = '\0';
|
||||
ResponseClear();
|
||||
for (uint32_t i = 0; i < count; i++) {
|
||||
if ((SET_MQTT_GRP_TOPIC == text_index) && (1 == i)) { real_index = SET_MQTT_GRP_TOPIC2 -1; }
|
||||
ResponseAppend_P(PSTR("%c\"%s%d\":\"%s\""), (i) ? ',' : '{', XdrvMailbox.command, i +1, EscapeJSONString(SettingsText(real_index +i)).c_str());
|
||||
|
@ -200,7 +200,7 @@ void CommandHandler(char* topicBuf, char* dataBuf, uint32_t data_len)
|
|||
|
||||
char stemp1[TOPSZ];
|
||||
GetFallbackTopic_P(stemp1, ""); // Full Fallback topic = cmnd/DVES_xxxxxxxx_fb/
|
||||
fallback_topic_flag = (!strncmp(topicBuf, stemp1, strlen(stemp1)));
|
||||
TasmotaGlobal.fallback_topic_flag = (!strncmp(topicBuf, stemp1, strlen(stemp1)));
|
||||
|
||||
char *type = strrchr(topicBuf, '/'); // Last part of received topic is always the command (type)
|
||||
|
||||
|
@ -287,22 +287,22 @@ void CommandHandler(char* topicBuf, char* dataBuf, uint32_t data_len)
|
|||
type = (char*)stemp1;
|
||||
}
|
||||
|
||||
if (mqtt_data[0] != '\0') {
|
||||
if (TasmotaGlobal.mqtt_data[0] != '\0') {
|
||||
/*
|
||||
// Add "Command":"POWERONSTATE", like:
|
||||
// 12:15:37 MQT: stat/wemos4/RESULT = {"Command":"POWERONSTATE","PowerOnState":3}
|
||||
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(mqtt_data) +1;
|
||||
if (mq_len < sizeof(mqtt_data) - jc_len) {
|
||||
memmove(mqtt_data +jc_len -1, mqtt_data, mq_len);
|
||||
memmove(mqtt_data, json_command, jc_len);
|
||||
uint32_t mq_len = strlen(TasmotaGlobal.mqtt_data) +1;
|
||||
if (mq_len < sizeof(TasmotaGlobal.mqtt_data) - jc_len) {
|
||||
memmove(TasmotaGlobal.mqtt_data +jc_len -1, TasmotaGlobal.mqtt_data, mq_len);
|
||||
memmove(TasmotaGlobal.mqtt_data, json_command, jc_len);
|
||||
}
|
||||
*/
|
||||
MqttPublishPrefixTopicRulesProcess_P(RESULT_OR_STAT, type);
|
||||
}
|
||||
fallback_topic_flag = false;
|
||||
TasmotaGlobal.fallback_topic_flag = false;
|
||||
}
|
||||
|
||||
/********************************************************************************************/
|
||||
|
@ -315,10 +315,10 @@ void CmndBacklog(void)
|
|||
char *blcommand = strtok(XdrvMailbox.data, ";");
|
||||
while ((blcommand != nullptr) && (backlog.size() < MAX_BACKLOG))
|
||||
#else
|
||||
uint32_t bl_pointer = (!backlog_pointer) ? MAX_BACKLOG -1 : backlog_pointer;
|
||||
uint32_t bl_pointer = (!TasmotaGlobal.backlog_pointer) ? MAX_BACKLOG -1 : TasmotaGlobal.backlog_pointer;
|
||||
bl_pointer--;
|
||||
char *blcommand = strtok(XdrvMailbox.data, ";");
|
||||
while ((blcommand != nullptr) && (backlog_index != bl_pointer))
|
||||
while ((blcommand != nullptr) && (TasmotaGlobal.backlog_index != bl_pointer))
|
||||
#endif
|
||||
{
|
||||
while(true) {
|
||||
|
@ -335,22 +335,22 @@ void CmndBacklog(void)
|
|||
backlog.add(blcommand);
|
||||
}
|
||||
#else
|
||||
backlog[backlog_index] = blcommand;
|
||||
backlog_index++;
|
||||
if (backlog_index >= MAX_BACKLOG) backlog_index = 0;
|
||||
TasmotaGlobal.backlog[TasmotaGlobal.backlog_index] = blcommand;
|
||||
TasmotaGlobal.backlog_index++;
|
||||
if (TasmotaGlobal.backlog_index >= MAX_BACKLOG) TasmotaGlobal.backlog_index = 0;
|
||||
#endif
|
||||
}
|
||||
blcommand = strtok(nullptr, ";");
|
||||
}
|
||||
// ResponseCmndChar(D_JSON_APPENDED);
|
||||
mqtt_data[0] = '\0';
|
||||
ResponseClear();
|
||||
TasmotaGlobal.backlog_delay = 0;
|
||||
} else {
|
||||
bool blflag = BACKLOG_EMPTY;
|
||||
#ifdef SUPPORT_IF_STATEMENT
|
||||
backlog.clear();
|
||||
#else
|
||||
backlog_pointer = backlog_index;
|
||||
TasmotaGlobal.backlog_pointer = TasmotaGlobal.backlog_index;
|
||||
#endif
|
||||
ResponseCmndChar(blflag ? D_JSON_EMPTY : D_JSON_ABORTED);
|
||||
}
|
||||
|
@ -369,13 +369,13 @@ void CmndDelay(void)
|
|||
|
||||
void CmndPower(void)
|
||||
{
|
||||
if ((XdrvMailbox.index > 0) && (XdrvMailbox.index <= devices_present)) {
|
||||
if ((XdrvMailbox.index > 0) && (XdrvMailbox.index <= TasmotaGlobal.devices_present)) {
|
||||
if ((XdrvMailbox.payload < POWER_OFF) || (XdrvMailbox.payload > POWER_BLINK_STOP)) {
|
||||
XdrvMailbox.payload = POWER_SHOW_STATE;
|
||||
}
|
||||
// Settings.flag.device_index_enable = XdrvMailbox.usridx; // SetOption26 - Switch between POWER or POWER1
|
||||
ExecuteCommandPower(XdrvMailbox.index, XdrvMailbox.payload, SRC_IGNORE);
|
||||
mqtt_data[0] = '\0';
|
||||
ResponseClear();
|
||||
}
|
||||
else if (0 == XdrvMailbox.index) {
|
||||
if ((XdrvMailbox.payload < POWER_OFF) || (XdrvMailbox.payload > POWER_TOGGLE)) {
|
||||
|
@ -385,7 +385,7 @@ void CmndPower(void)
|
|||
if (Settings.flag3.hass_tele_on_power) { // SetOption59 - Send tele/%topic%/STATE in addition to stat/%topic%/RESULT
|
||||
MqttPublishTeleState();
|
||||
}
|
||||
mqtt_data[0] = '\0';
|
||||
ResponseClear();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -395,7 +395,7 @@ void CmndStatus(void)
|
|||
|
||||
if (payload > MAX_STATUS) { return; } // {"Command":"Error"}
|
||||
if (!Settings.flag.mqtt_enabled && (6 == payload)) { return; } // SetOption3 - Enable MQTT
|
||||
if (!energy_flg && (9 == payload)) { return; }
|
||||
if (!TasmotaGlobal.energy_driver && (9 == payload)) { return; }
|
||||
if (!CrashFlag() && (12 == payload)) { return; }
|
||||
if (!Settings.flag3.shutter_mode && (13 == payload)) { return; }
|
||||
|
||||
|
@ -403,7 +403,7 @@ void CmndStatus(void)
|
|||
char stemp2[TOPSZ];
|
||||
|
||||
if (0 == payload) {
|
||||
uint32_t maxfn = (devices_present > MAX_FRIENDLYNAMES) ? MAX_FRIENDLYNAMES : (!devices_present) ? 1 : devices_present;
|
||||
uint32_t maxfn = (TasmotaGlobal.devices_present > MAX_FRIENDLYNAMES) ? MAX_FRIENDLYNAMES : (!TasmotaGlobal.devices_present) ? 1 : TasmotaGlobal.devices_present;
|
||||
#ifdef USE_SONOFF_IFAN
|
||||
if (IsModuleIfan()) { maxfn = 1; }
|
||||
#endif // USE_SONOFF_IFAN
|
||||
|
@ -419,7 +419,7 @@ void CmndStatus(void)
|
|||
D_CMND_BUTTONTOPIC "\":\"%s\",\"" D_CMND_POWER "\":%d,\"" D_CMND_POWERONSTATE "\":%d,\"" D_CMND_LEDSTATE "\":%d,\""
|
||||
D_CMND_LEDMASK "\":\"%04X\",\"" D_CMND_SAVEDATA "\":%d,\"" D_JSON_SAVESTATE "\":%d,\"" D_CMND_SWITCHTOPIC "\":\"%s\",\""
|
||||
D_CMND_SWITCHMODE "\":[%s],\"" D_CMND_BUTTONRETAIN "\":%d,\"" D_CMND_SWITCHRETAIN "\":%d,\"" D_CMND_SENSORRETAIN "\":%d,\"" D_CMND_POWERRETAIN "\":%d}}"),
|
||||
ModuleNr(), EscapeJSONString(SettingsText(SET_DEVICENAME)).c_str(), stemp, mqtt_topic,
|
||||
ModuleNr(), EscapeJSONString(SettingsText(SET_DEVICENAME)).c_str(), stemp, TasmotaGlobal.mqtt_topic,
|
||||
SettingsText(SET_MQTT_BUTTON_TOPIC), TasmotaGlobal.power, Settings.poweronstate, Settings.ledstate,
|
||||
Settings.ledmask, Settings.save_data,
|
||||
Settings.flag.save_state, // SetOption0 - Save power state and use after restart
|
||||
|
@ -458,7 +458,7 @@ void CmndStatus(void)
|
|||
",\"" D_JSON_COREVERSION "\":\"" ARDUINO_CORE_RELEASE "\",\"" D_JSON_SDKVERSION "\":\"%s\","
|
||||
"\"CpuFrequency\":%d,\"Hardware\":\"%s\""
|
||||
"%s}}"),
|
||||
my_version, my_image, GetBuildDateAndTime().c_str()
|
||||
TasmotaGlobal.version, TasmotaGlobal.image_name, GetBuildDateAndTime().c_str()
|
||||
#ifdef ESP8266
|
||||
, ESP.getBootVersion()
|
||||
#endif
|
||||
|
@ -520,7 +520,7 @@ void CmndStatus(void)
|
|||
Response_P(PSTR("{\"" D_CMND_STATUS D_STATUS6_MQTT "\":{\"" D_CMND_MQTTHOST "\":\"%s\",\"" D_CMND_MQTTPORT "\":%d,\"" D_CMND_MQTTCLIENT D_JSON_MASK "\":\"%s\",\""
|
||||
D_CMND_MQTTCLIENT "\":\"%s\",\"" D_CMND_MQTTUSER "\":\"%s\",\"" D_JSON_MQTT_COUNT "\":%d,\"MAX_PACKET_SIZE\":%d,\"KEEPALIVE\":%d}}"),
|
||||
SettingsText(SET_MQTT_HOST), Settings.mqtt_port, EscapeJSONString(SettingsText(SET_MQTT_CLIENT)).c_str(),
|
||||
mqtt_client, EscapeJSONString(SettingsText(SET_MQTT_USER)).c_str(), MqttConnectCount(), MQTT_MAX_PACKET_SIZE, MQTT_KEEPALIVE);
|
||||
TasmotaGlobal.mqtt_client, EscapeJSONString(SettingsText(SET_MQTT_USER)).c_str(), MqttConnectCount(), MQTT_MAX_PACKET_SIZE, MQTT_KEEPALIVE);
|
||||
MqttPublishPrefixTopic_P(STAT, PSTR(D_CMND_STATUS "6"));
|
||||
}
|
||||
|
||||
|
@ -545,7 +545,7 @@ void CmndStatus(void)
|
|||
}
|
||||
|
||||
#if defined(USE_ENERGY_SENSOR) && defined(USE_ENERGY_MARGIN_DETECTION)
|
||||
if (energy_flg) {
|
||||
if (TasmotaGlobal.energy_driver) {
|
||||
if ((0 == payload) || (9 == payload)) {
|
||||
Response_P(PSTR("{\"" D_CMND_STATUS D_STATUS9_MARGIN "\":{\"" D_CMND_POWERDELTA "\":[%d,%d,%d],\"" D_CMND_POWERLOW "\":%d,\"" D_CMND_POWERHIGH "\":%d,\""
|
||||
D_CMND_VOLTAGELOW "\":%d,\"" D_CMND_VOLTAGEHIGH "\":%d,\"" D_CMND_CURRENTLOW "\":%d,\"" D_CMND_CURRENTHIGH "\":%d}}"),
|
||||
|
@ -606,19 +606,19 @@ void CmndStatus(void)
|
|||
#endif
|
||||
|
||||
#ifdef USE_SCRIPT_STATUS
|
||||
if (bitRead(Settings.rule_enabled, 0)) Run_Scripter(">U",2,mqtt_data);
|
||||
if (bitRead(Settings.rule_enabled, 0)) { Run_Scripter(">U", 2, TasmotaGlobal.mqtt_data); }
|
||||
#endif
|
||||
|
||||
if (payload) {
|
||||
XdrvRulesProcess(); // Allow rule processing on single Status command only
|
||||
}
|
||||
|
||||
mqtt_data[0] = '\0';
|
||||
ResponseClear();
|
||||
}
|
||||
|
||||
void CmndState(void)
|
||||
{
|
||||
mqtt_data[0] = '\0';
|
||||
ResponseClear();
|
||||
MqttShowState();
|
||||
if (Settings.flag3.hass_tele_on_power) { // SetOption59 - Send tele/%topic%/STATE in addition to stat/%topic%/RESULT
|
||||
MqttPublishPrefixTopic_P(TELE, PSTR(D_RSLT_STATE), MQTT_TELE_RETAIN);
|
||||
|
@ -699,9 +699,9 @@ void CmndUpgrade(void)
|
|||
if (((1 == XdrvMailbox.data_len) && (1 == XdrvMailbox.payload)) || ((XdrvMailbox.data_len >= 3) && NewerVersion(XdrvMailbox.data))) {
|
||||
TasmotaGlobal.ota_state_flag = 3;
|
||||
char stemp1[TOPSZ];
|
||||
Response_P(PSTR("{\"%s\":\"" D_JSON_VERSION " %s " D_JSON_FROM " %s\"}"), XdrvMailbox.command, my_version, GetOtaUrl(stemp1, sizeof(stemp1)));
|
||||
Response_P(PSTR("{\"%s\":\"" D_JSON_VERSION " %s " D_JSON_FROM " %s\"}"), XdrvMailbox.command, TasmotaGlobal.version, GetOtaUrl(stemp1, sizeof(stemp1)));
|
||||
} else {
|
||||
Response_P(PSTR("{\"%s\":\"" D_JSON_ONE_OR_GT "\"}"), XdrvMailbox.command, my_version);
|
||||
Response_P(PSTR("{\"%s\":\"" D_JSON_ONE_OR_GT "\"}"), XdrvMailbox.command, TasmotaGlobal.version);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -719,7 +719,7 @@ void CmndSeriallog(void)
|
|||
Settings.flag.mqtt_serial = 0; // CMND_SERIALSEND and CMND_SERIALLOG
|
||||
SetSeriallog(XdrvMailbox.payload);
|
||||
}
|
||||
Response_P(S_JSON_COMMAND_NVALUE_ACTIVE_NVALUE, XdrvMailbox.command, Settings.seriallog_level, seriallog_level);
|
||||
Response_P(S_JSON_COMMAND_NVALUE_ACTIVE_NVALUE, XdrvMailbox.command, Settings.seriallog_level, TasmotaGlobal.seriallog_level);
|
||||
}
|
||||
|
||||
void CmndRestart(void)
|
||||
|
@ -731,7 +731,7 @@ void CmndRestart(void)
|
|||
break;
|
||||
case 2:
|
||||
TasmotaGlobal.restart_flag = 2;
|
||||
restart_halt = true;
|
||||
TasmotaGlobal.restart_halt = true;
|
||||
ResponseCmndChar(D_JSON_HALTING);
|
||||
break;
|
||||
case -1:
|
||||
|
@ -755,7 +755,7 @@ void CmndRestart(void)
|
|||
void CmndPowerOnState(void)
|
||||
{
|
||||
#ifdef ESP8266
|
||||
if (my_module_type != MOTOR)
|
||||
if (TasmotaGlobal.module_type != MOTOR)
|
||||
#endif // ESP8266
|
||||
{
|
||||
/* 0 = Keep relays off after power on
|
||||
|
@ -768,7 +768,7 @@ void CmndPowerOnState(void)
|
|||
if ((XdrvMailbox.payload >= POWER_ALL_OFF) && (XdrvMailbox.payload <= POWER_ALL_OFF_PULSETIME_ON)) {
|
||||
Settings.poweronstate = XdrvMailbox.payload;
|
||||
if (POWER_ALL_ALWAYS_ON == Settings.poweronstate) {
|
||||
for (uint32_t i = 1; i <= devices_present; i++) {
|
||||
for (uint32_t i = 1; i <= TasmotaGlobal.devices_present; i++) {
|
||||
ExecuteCommandPower(i, POWER_ON, SRC_IGNORE);
|
||||
}
|
||||
}
|
||||
|
@ -789,7 +789,7 @@ void CmndPulsetime(void)
|
|||
SetPulseTimer(XdrvMailbox.index -1, XdrvMailbox.payload);
|
||||
}
|
||||
}
|
||||
mqtt_data[0] = '\0';
|
||||
ResponseClear();
|
||||
for (uint32_t i = 0; i < items; i++) {
|
||||
uint32_t index = (1 == items) ? XdrvMailbox.index : i +1;
|
||||
ResponseAppend_P(PSTR("%c\"%s%d\":{\"" D_JSON_SET "\":%d,\"" D_JSON_REMAINING "\":%d}"),
|
||||
|
@ -912,7 +912,7 @@ void CmndSetoption(void)
|
|||
bitWrite(Settings.flag.data, pindex, XdrvMailbox.payload);
|
||||
}
|
||||
if (12 == pindex) { // stop_flash_rotate
|
||||
stop_flash_rotate = XdrvMailbox.payload;
|
||||
TasmotaGlobal.stop_flash_rotate = XdrvMailbox.payload;
|
||||
SettingsSave(2);
|
||||
}
|
||||
#ifdef USE_HOME_ASSISTANT
|
||||
|
@ -1120,7 +1120,7 @@ void CmndModules(void)
|
|||
lines++;
|
||||
}
|
||||
}
|
||||
mqtt_data[0] = '\0';
|
||||
ResponseClear();
|
||||
}
|
||||
|
||||
void CmndGpio(void)
|
||||
|
@ -1227,7 +1227,7 @@ void CmndGpios(void)
|
|||
ShowGpios(kAdcNiceList, ARRAY_SIZE(kAdcNiceList), 1, lines);
|
||||
#endif // USE_ADC_VCC
|
||||
#endif // ESP8266
|
||||
mqtt_data[0] = '\0';
|
||||
ResponseClear();
|
||||
}
|
||||
|
||||
void CmndTemplate(void)
|
||||
|
@ -1258,8 +1258,8 @@ void CmndTemplate(void)
|
|||
for (uint32_t i = 0; i < ARRAY_SIZE(Settings.user_template.gp.io); i++) {
|
||||
if (6 == i) { j = 9; }
|
||||
if (8 == i) { j = 12; }
|
||||
if (my_module.io[j] > GPIO_NONE) {
|
||||
Settings.user_template.gp.io[i] = my_module.io[j];
|
||||
if (TasmotaGlobal.my_module.io[j] > GPIO_NONE) {
|
||||
Settings.user_template.gp.io[i] = TasmotaGlobal.my_module.io[j];
|
||||
}
|
||||
j++;
|
||||
}
|
||||
|
@ -1278,10 +1278,10 @@ void CmndTemplate(void)
|
|||
|
||||
void CmndPwm(void)
|
||||
{
|
||||
if (pwm_present && (XdrvMailbox.index > 0) && (XdrvMailbox.index <= MAX_PWMS)) {
|
||||
if (TasmotaGlobal.pwm_present && (XdrvMailbox.index > 0) && (XdrvMailbox.index <= MAX_PWMS)) {
|
||||
if ((XdrvMailbox.payload >= 0) && (XdrvMailbox.payload <= Settings.pwm_range) && PinUsed(GPIO_PWM1, XdrvMailbox.index -1)) {
|
||||
Settings.pwm_value[XdrvMailbox.index -1] = XdrvMailbox.payload;
|
||||
analogWrite(Pin(GPIO_PWM1, XdrvMailbox.index -1), bitRead(pwm_inverted, XdrvMailbox.index -1) ? Settings.pwm_range - XdrvMailbox.payload : XdrvMailbox.payload);
|
||||
analogWrite(Pin(GPIO_PWM1, XdrvMailbox.index -1), bitRead(TasmotaGlobal.pwm_inverted, XdrvMailbox.index -1) ? Settings.pwm_range - XdrvMailbox.payload : XdrvMailbox.payload);
|
||||
}
|
||||
Response_P(PSTR("{"));
|
||||
MqttShowPWMState(); // Render the PWM status to MQTT
|
||||
|
@ -1439,7 +1439,7 @@ void CmndSyslog(void)
|
|||
if ((XdrvMailbox.payload >= LOG_LEVEL_NONE) && (XdrvMailbox.payload <= LOG_LEVEL_DEBUG_MORE)) {
|
||||
SetSyslog(XdrvMailbox.payload);
|
||||
}
|
||||
Response_P(S_JSON_COMMAND_NVALUE_ACTIVE_NVALUE, XdrvMailbox.command, Settings.syslog_level, syslog_level);
|
||||
Response_P(S_JSON_COMMAND_NVALUE_ACTIVE_NVALUE, XdrvMailbox.command, Settings.syslog_level, TasmotaGlobal.syslog_level);
|
||||
}
|
||||
|
||||
void CmndLoghost(void)
|
||||
|
@ -1484,7 +1484,7 @@ void CmndNtpServer(void)
|
|||
(SC_CLEAR == Shortcut()) ? "" : (SC_DEFAULT == Shortcut()) ? (1 == XdrvMailbox.index) ? PSTR(NTP_SERVER1) : (2 == XdrvMailbox.index) ? PSTR(NTP_SERVER2) : PSTR(NTP_SERVER3) : XdrvMailbox.data);
|
||||
SettingsUpdateText(ntp_server, ReplaceCommaWithDot(SettingsText(ntp_server)));
|
||||
// TasmotaGlobal.restart_flag = 2; // Issue #3890
|
||||
ntp_force_sync = true;
|
||||
TasmotaGlobal.ntp_force_sync = true;
|
||||
}
|
||||
ResponseCmndIdxChar(SettingsText(ntp_server));
|
||||
}
|
||||
|
@ -1618,8 +1618,8 @@ void CmndSwitchMode(void)
|
|||
void CmndInterlock(void)
|
||||
{
|
||||
// Interlock 0 - Off, Interlock 1 - On, Interlock 1,2 3,4 5,6,7
|
||||
uint32_t max_relays = devices_present;
|
||||
if (light_type) { max_relays--; }
|
||||
uint32_t max_relays = TasmotaGlobal.devices_present;
|
||||
if (TasmotaGlobal.light_type) { max_relays--; }
|
||||
if (max_relays > sizeof(Settings.interlock[0]) * 8) { max_relays = sizeof(Settings.interlock[0]) * 8; }
|
||||
if (max_relays > 1) { // Only interlock with more than 1 relay
|
||||
if (XdrvMailbox.data_len > 0) {
|
||||
|
@ -1744,7 +1744,7 @@ void CmndTime(void)
|
|||
RtcSetTime(XdrvMailbox.payload);
|
||||
}
|
||||
}
|
||||
mqtt_data[0] = '\0';
|
||||
ResponseClear();
|
||||
ResponseAppendTimeFormat(format);
|
||||
ResponseJsonEnd();
|
||||
}
|
||||
|
@ -1766,7 +1766,7 @@ void CmndTimezone(void)
|
|||
} else {
|
||||
Settings.timezone = 99;
|
||||
}
|
||||
ntp_force_sync = true;
|
||||
TasmotaGlobal.ntp_force_sync = true;
|
||||
}
|
||||
if (99 == Settings.timezone) {
|
||||
ResponseCmndNumber(Settings.timezone);
|
||||
|
@ -1802,7 +1802,7 @@ void CmndTimeStdDst(uint32_t ts)
|
|||
value = strtol(p, &p, 10);
|
||||
tpos++; // Next parameter
|
||||
}
|
||||
ntp_force_sync = true;
|
||||
TasmotaGlobal.ntp_force_sync = true;
|
||||
} else {
|
||||
if (0 == XdrvMailbox.payload) {
|
||||
if (0 == ts) {
|
||||
|
@ -1811,7 +1811,7 @@ void CmndTimeStdDst(uint32_t ts)
|
|||
SettingsResetDst();
|
||||
}
|
||||
}
|
||||
ntp_force_sync = true;
|
||||
TasmotaGlobal.ntp_force_sync = true;
|
||||
}
|
||||
}
|
||||
Response_P(PSTR("{\"%s\":{\"Hemisphere\":%d,\"Week\":%d,\"Month\":%d,\"Day\":%d,\"Hour\":%d,\"Offset\":%d}}"),
|
||||
|
@ -1837,7 +1837,7 @@ void CmndAltitude(void)
|
|||
}
|
||||
|
||||
void CmndLedPower(void) {
|
||||
// If GPIO_LEDLINK (used for network status) then allow up to 4 GPIO_LEDx control using led_power
|
||||
// If GPIO_LEDLINK (used for network status) then allow up to 4 GPIO_LEDx control using TasmotaGlobal.led_power
|
||||
// If no GPIO_LEDLINK then allow legacy single led GPIO_LED1 control using Settings.ledstate
|
||||
if ((XdrvMailbox.index > 0) && (XdrvMailbox.index <= MAX_LEDS)) {
|
||||
if (!PinUsed(GPIO_LEDLNK)) { XdrvMailbox.index = 1; }
|
||||
|
@ -1846,15 +1846,15 @@ void CmndLedPower(void) {
|
|||
uint32_t mask = 1 << (XdrvMailbox.index -1); // Led to control
|
||||
switch (XdrvMailbox.payload) {
|
||||
case 0: // Off
|
||||
led_power &= (0xFF ^ mask);
|
||||
TasmotaGlobal.led_power &= (0xFF ^ mask);
|
||||
Settings.ledstate = 0;
|
||||
break;
|
||||
case 1: // On
|
||||
led_power |= mask;
|
||||
TasmotaGlobal.led_power |= mask;
|
||||
Settings.ledstate = 8;
|
||||
break;
|
||||
case 2: // Toggle
|
||||
led_power ^= mask;
|
||||
TasmotaGlobal.led_power ^= mask;
|
||||
Settings.ledstate ^= 8;
|
||||
break;
|
||||
}
|
||||
|
@ -1862,10 +1862,10 @@ void CmndLedPower(void) {
|
|||
if (!PinUsed(GPIO_LEDLNK)) {
|
||||
SetLedPower(Settings.ledstate &8);
|
||||
} else {
|
||||
SetLedPowerIdx(XdrvMailbox.index -1, (led_power & mask));
|
||||
SetLedPowerIdx(XdrvMailbox.index -1, (TasmotaGlobal.led_power & mask));
|
||||
}
|
||||
}
|
||||
bool state = bitRead(led_power, XdrvMailbox.index -1);
|
||||
bool state = bitRead(TasmotaGlobal.led_power, XdrvMailbox.index -1);
|
||||
if (!PinUsed(GPIO_LEDLNK)) {
|
||||
state = bitRead(Settings.ledstate, 3);
|
||||
}
|
||||
|
@ -1967,8 +1967,8 @@ void CmndWifiPower(void)
|
|||
#ifdef USE_I2C
|
||||
void CmndI2cScan(void)
|
||||
{
|
||||
if (i2c_flg) {
|
||||
I2cScan(mqtt_data, sizeof(mqtt_data));
|
||||
if (TasmotaGlobal.i2c_enabled) {
|
||||
I2cScan(TasmotaGlobal.mqtt_data, sizeof(TasmotaGlobal.mqtt_data));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -295,7 +295,7 @@ void SendReceiveDeviceGroupMessage(struct device_group * device_group, struct de
|
|||
XdrvMailbox.index = flags | message_sequence << 16;
|
||||
if (device_group_index == 0 && first_device_group_is_local) XdrvMailbox.index |= DGR_FLAG_LOCAL;
|
||||
XdrvMailbox.topic = (char *)&device_group_index;
|
||||
if (flags & (DGR_FLAG_MORE_TO_COME | DGR_FLAG_DIRECT)) skip_light_fade = true;
|
||||
if (flags & (DGR_FLAG_MORE_TO_COME | DGR_FLAG_DIRECT)) TasmotaGlobal.skip_light_fade = true;
|
||||
|
||||
// Set the flag to ignore device group send message request so callbacks from the drivers do not
|
||||
// send updates.
|
||||
|
@ -386,14 +386,14 @@ void SendReceiveDeviceGroupMessage(struct device_group * device_group, struct de
|
|||
switch (item) {
|
||||
case DGR_ITEM_POWER:
|
||||
if (Settings.flag4.multiple_device_groups) { // SetOption88 - Enable relays in separate device groups
|
||||
if (device_group_index < devices_present) {
|
||||
if (device_group_index < TasmotaGlobal.devices_present) {
|
||||
bool on = (value & 1);
|
||||
if (on != (TasmotaGlobal.power & (1 << device_group_index))) ExecuteCommandPower(device_group_index + 1, (on ? POWER_ON : POWER_OFF), SRC_REMOTE);
|
||||
}
|
||||
}
|
||||
else if (XdrvMailbox.index & DGR_FLAG_LOCAL) {
|
||||
uint8_t mask_devices = value >> 24;
|
||||
if (mask_devices > devices_present) mask_devices = devices_present;
|
||||
if (mask_devices > TasmotaGlobal.devices_present) mask_devices = TasmotaGlobal.devices_present;
|
||||
for (uint32_t i = 0; i < mask_devices; i++) {
|
||||
uint32_t mask = 1 << i;
|
||||
bool on = (value & mask);
|
||||
|
@ -455,7 +455,7 @@ badmsg:
|
|||
|
||||
cleanup:
|
||||
if (received) {
|
||||
skip_light_fade = false;
|
||||
TasmotaGlobal.skip_light_fade = false;
|
||||
ignore_dgr_sends = false;
|
||||
}
|
||||
}
|
||||
|
@ -679,7 +679,7 @@ bool _SendDeviceGroupMessage(uint8_t device_group_index, DevGroupMessageType mes
|
|||
*message_ptr++ = value & 0xff;
|
||||
value >>= 8;
|
||||
// For the power item, the device count is overlayed onto the highest 8 bits.
|
||||
if (item == DGR_ITEM_POWER && !value) value = (device_group_index == 0 && first_device_group_is_local ? devices_present : 1);
|
||||
if (item == DGR_ITEM_POWER && !value) value = (device_group_index == 0 && first_device_group_is_local ? TasmotaGlobal.devices_present : 1);
|
||||
*message_ptr++ = value;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -39,7 +39,7 @@ void eeprom_readBytes(uint32_t addr, uint32_t len, uint8_t *buff) {
|
|||
}
|
||||
|
||||
uint32_t eeprom_init(uint32_t size) {
|
||||
if (i2c_flg) {
|
||||
if (TasmotaGlobal.i2c_enabled) {
|
||||
if (I2cActive(EEPROM_ADDRESS) || I2cSetDevice(EEPROM_ADDRESS)) {
|
||||
// eeprom is present
|
||||
I2cSetActiveFound(EEPROM_ADDRESS, "24C256");
|
||||
|
|
|
@ -168,13 +168,13 @@ void SntpInit() {
|
|||
|
||||
uint32_t SntpGetCurrentTimestamp(void) {
|
||||
time_t now = 0;
|
||||
if (bNetIsTimeSync || ntp_force_sync)
|
||||
if (bNetIsTimeSync || TasmotaGlobal.ntp_force_sync)
|
||||
{
|
||||
//Serial_DebugX(("timesync configTime %d\n", ntp_force_sync, bNetIsTimeSync));
|
||||
//Serial_DebugX(("timesync configTime %d\n", TasmotaGlobal.ntp_force_sync, bNetIsTimeSync));
|
||||
// init to UTC Time
|
||||
configTime(0, 0, SettingsText(SET_NTPSERVER1), SettingsText(SET_NTPSERVER2), SettingsText(SET_NTPSERVER3));
|
||||
bNetIsTimeSync = false;
|
||||
ntp_force_sync = false;
|
||||
TasmotaGlobal.ntp_force_sync = false;
|
||||
}
|
||||
time(&now);
|
||||
return now;
|
||||
|
|
|
@ -27,6 +27,8 @@ struct {
|
|||
|
||||
#ifdef USE_DISCOVERY
|
||||
void StartMdns(void) {
|
||||
// static uint8_t mdns_delayed_start = Settings.param[P_MDNS_DELAYED_START];
|
||||
|
||||
if (Settings.flag3.mdns_enabled) { // SetOption55 - Control mDNS service
|
||||
if (!Mdns.begun) {
|
||||
// if (mdns_delayed_start) {
|
||||
|
@ -34,7 +36,7 @@ void StartMdns(void) {
|
|||
// mdns_delayed_start--;
|
||||
// } else {
|
||||
// mdns_delayed_start = Settings.param[P_MDNS_DELAYED_START];
|
||||
Mdns.begun = (uint8_t)MDNS.begin(my_hostname);
|
||||
Mdns.begun = (uint8_t)MDNS.begin(TasmotaGlobal.hostname);
|
||||
AddLog_P2(LOG_LEVEL_INFO, PSTR(D_LOG_MDNS "%s"), (Mdns.begun) ? D_INITIALIZED : D_FAILED);
|
||||
// }
|
||||
}
|
||||
|
@ -92,18 +94,18 @@ void MdnsUpdate(void) {
|
|||
char* NetworkHostname(void) {
|
||||
#ifdef ESP32
|
||||
#ifdef USE_ETHERNET
|
||||
if (!global_state.eth_down) {
|
||||
if (!TasmotaGlobal.global_state.eth_down) {
|
||||
return EthernetHostname();
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
return my_hostname;
|
||||
return TasmotaGlobal.hostname;
|
||||
}
|
||||
|
||||
IPAddress NetworkAddress(void) {
|
||||
#ifdef ESP32
|
||||
#ifdef USE_ETHERNET
|
||||
if (!global_state.eth_down) {
|
||||
if (!TasmotaGlobal.global_state.eth_down) {
|
||||
return EthernetLocalIP();
|
||||
}
|
||||
#endif
|
||||
|
@ -114,7 +116,7 @@ IPAddress NetworkAddress(void) {
|
|||
String NetworkMacAddress(void) {
|
||||
#ifdef ESP32
|
||||
#ifdef USE_ETHERNET
|
||||
if (!global_state.eth_down) {
|
||||
if (!TasmotaGlobal.global_state.eth_down) {
|
||||
return EthernetMacAddress();
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -126,7 +126,7 @@ void RotaryInit(void) {
|
|||
Rotary.present = false;
|
||||
Rotary.model = 1;
|
||||
#ifdef ESP8266
|
||||
if (MI_DESK_LAMP == my_module_type) {
|
||||
if (MI_DESK_LAMP == TasmotaGlobal.module_type) {
|
||||
Rotary.model = 0;
|
||||
}
|
||||
#endif // ESP8266
|
||||
|
|
|
@ -379,7 +379,7 @@ void RtcSecond(void)
|
|||
Rtc.millis = millis();
|
||||
|
||||
if (!Rtc.user_time_entry) {
|
||||
if (!global_state.network_down) {
|
||||
if (!TasmotaGlobal.global_state.network_down) {
|
||||
uint8_t uptime_minute = (TasmotaGlobal.uptime / 60) % 60; // 0 .. 59
|
||||
if ((Rtc.ntp_sync_minute > 59) && (uptime_minute > 2)) {
|
||||
Rtc.ntp_sync_minute = 1; // If sync prepare for a new cycle
|
||||
|
@ -387,10 +387,10 @@ void RtcSecond(void)
|
|||
uint8_t offset = (TasmotaGlobal.uptime < 30) ? RtcTime.second : (((ESP_getChipId() & 0xF) * 3) + 3) ; // First try ASAP to sync. If fails try once every 60 seconds based on chip id
|
||||
if ( (((offset == RtcTime.second) && ( (RtcTime.year < 2016) || // Never synced
|
||||
(Rtc.ntp_sync_minute == uptime_minute))) || // Re-sync every hour
|
||||
ntp_force_sync ) ) { // Forced sync
|
||||
TasmotaGlobal.ntp_force_sync ) ) { // Forced sync
|
||||
Rtc.ntp_time = sntp_get_current_timestamp();
|
||||
if (Rtc.ntp_time > START_VALID_TIME) { // Fix NTP bug in core 2.4.1/SDK 2.2.1 (returns Thu Jan 01 08:00:10 1970 after power on)
|
||||
ntp_force_sync = false;
|
||||
TasmotaGlobal.ntp_force_sync = false;
|
||||
Rtc.utc_time = Rtc.ntp_time;
|
||||
Rtc.last_sync = Rtc.ntp_time;
|
||||
Rtc.ntp_sync_minute = 60; // Sync so block further requests
|
||||
|
@ -476,7 +476,7 @@ void RtcSetTime(uint32_t epoch)
|
|||
{
|
||||
if (epoch < START_VALID_TIME) { // 2016-01-01
|
||||
Rtc.user_time_entry = false;
|
||||
ntp_force_sync = true;
|
||||
TasmotaGlobal.ntp_force_sync = true;
|
||||
sntp_init();
|
||||
} else {
|
||||
sntp_stop();
|
||||
|
|
|
@ -401,7 +401,7 @@ void SwitchHandler(uint8_t mode)
|
|||
}
|
||||
if (switchflag <= POWER_TOGGLE) {
|
||||
if (!SendKey(KEY_SWITCH, i +1, switchflag)) { // Execute command via MQTT
|
||||
ExecuteCommandPower(i +1, switchflag, SRC_SWITCH); // Execute command internally (if i < devices_present)
|
||||
ExecuteCommandPower(i +1, switchflag, SRC_SWITCH); // Execute command internally (if i < TasmotaGlobal.devices_present)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -92,14 +92,14 @@ char* GetTopic_P(char *stopic, uint32_t prefix, char *topic, const char* subtopi
|
|||
String fulltopic;
|
||||
|
||||
snprintf_P(romram, sizeof(romram), subtopic);
|
||||
if (fallback_topic_flag || (prefix > 3)) {
|
||||
if (TasmotaGlobal.fallback_topic_flag || (prefix > 3)) {
|
||||
bool fallback = (prefix < 8);
|
||||
prefix &= 3;
|
||||
char stemp[11];
|
||||
fulltopic = GetTextIndexed(stemp, sizeof(stemp), prefix, kPrefixes);
|
||||
fulltopic += F("/");
|
||||
if (fallback) {
|
||||
fulltopic += mqtt_client;
|
||||
fulltopic += TasmotaGlobal.mqtt_client;
|
||||
fulltopic += F("_fb"); // cmnd/<mqttclient>_fb
|
||||
} else {
|
||||
fulltopic += topic; // cmnd/<grouptopic>
|
||||
|
@ -119,7 +119,7 @@ char* GetTopic_P(char *stopic, uint32_t prefix, char *topic, const char* subtopi
|
|||
fulltopic.replace(FPSTR(MQTT_TOKEN_PREFIX), SettingsText(SET_MQTTPREFIX1 + prefix));
|
||||
|
||||
fulltopic.replace(FPSTR(MQTT_TOKEN_TOPIC), topic);
|
||||
fulltopic.replace(F("%hostname%"), my_hostname);
|
||||
fulltopic.replace(F("%hostname%"), TasmotaGlobal.hostname);
|
||||
String token_id = WiFi.macAddress();
|
||||
token_id.replace(":", "");
|
||||
fulltopic.replace(F("%id%"), token_id);
|
||||
|
@ -168,7 +168,7 @@ void SetLatchingRelay(power_t lpower, uint32_t state)
|
|||
TasmotaGlobal.latching_relay_pulse = 2; // max 200mS (initiated by stateloop())
|
||||
}
|
||||
|
||||
for (uint32_t i = 0; i < devices_present; i++) {
|
||||
for (uint32_t i = 0; i < TasmotaGlobal.devices_present; i++) {
|
||||
uint32_t port = (i << 1) + ((latching_power >> i) &1);
|
||||
DigitalWrite(GPIO_REL1, port, bitRead(TasmotaGlobal.rel_inverted, port) ? !state : state);
|
||||
}
|
||||
|
@ -177,10 +177,10 @@ void SetLatchingRelay(power_t lpower, uint32_t state)
|
|||
void SetDevicePower(power_t rpower, uint32_t source)
|
||||
{
|
||||
ShowSource(source);
|
||||
last_source = source;
|
||||
TasmotaGlobal.last_source = source;
|
||||
|
||||
if (POWER_ALL_ALWAYS_ON == Settings.poweronstate) { // All on and stay on
|
||||
TasmotaGlobal.power = (1 << devices_present) -1;
|
||||
TasmotaGlobal.power = (1 << TasmotaGlobal.devices_present) -1;
|
||||
rpower = TasmotaGlobal.power;
|
||||
}
|
||||
|
||||
|
@ -188,7 +188,7 @@ void SetDevicePower(power_t rpower, uint32_t source)
|
|||
for (uint32_t i = 0; i < MAX_INTERLOCKS; i++) {
|
||||
power_t mask = 1;
|
||||
uint32_t count = 0;
|
||||
for (uint32_t j = 0; j < devices_present; j++) {
|
||||
for (uint32_t j = 0; j < TasmotaGlobal.devices_present; j++) {
|
||||
if ((Settings.interlock[i] & mask) && (rpower & mask)) {
|
||||
count++;
|
||||
}
|
||||
|
@ -216,7 +216,7 @@ void SetDevicePower(power_t rpower, uint32_t source)
|
|||
// Serviced
|
||||
}
|
||||
#ifdef ESP8266
|
||||
else if ((SONOFF_DUAL == my_module_type) || (CH4 == my_module_type)) {
|
||||
else if ((SONOFF_DUAL == TasmotaGlobal.module_type) || (CH4 == TasmotaGlobal.module_type)) {
|
||||
Serial.write(0xA0);
|
||||
Serial.write(0x04);
|
||||
Serial.write(rpower &0xFF);
|
||||
|
@ -224,13 +224,13 @@ void SetDevicePower(power_t rpower, uint32_t source)
|
|||
Serial.write('\n');
|
||||
Serial.flush();
|
||||
}
|
||||
else if (EXS_RELAY == my_module_type) {
|
||||
else if (EXS_RELAY == TasmotaGlobal.module_type) {
|
||||
SetLatchingRelay(rpower, 1);
|
||||
}
|
||||
#endif // ESP8266
|
||||
else
|
||||
{
|
||||
for (uint32_t i = 0; i < devices_present; i++) {
|
||||
for (uint32_t i = 0; i < TasmotaGlobal.devices_present; i++) {
|
||||
power_t state = rpower &1;
|
||||
if (i < MAX_RELAYS) {
|
||||
DigitalWrite(GPIO_REL1, i, bitRead(TasmotaGlobal.rel_inverted, i) ? !state : state);
|
||||
|
@ -267,7 +267,7 @@ void SetAllPower(uint32_t state, uint32_t source)
|
|||
publish_power = false;
|
||||
}
|
||||
if ((state >= POWER_OFF) && (state <= POWER_TOGGLE)) {
|
||||
power_t all_on = (1 << devices_present) -1;
|
||||
power_t all_on = (1 << TasmotaGlobal.devices_present) -1;
|
||||
switch (state) {
|
||||
case POWER_OFF:
|
||||
TasmotaGlobal.power = 0;
|
||||
|
@ -288,7 +288,7 @@ void SetAllPower(uint32_t state, uint32_t source)
|
|||
void SetPowerOnState(void)
|
||||
{
|
||||
#ifdef ESP8266
|
||||
if (MOTOR == my_module_type) {
|
||||
if (MOTOR == TasmotaGlobal.module_type) {
|
||||
Settings.poweronstate = POWER_ALL_ON; // Needs always on else in limbo!
|
||||
}
|
||||
#endif // ESP8266
|
||||
|
@ -303,24 +303,24 @@ void SetPowerOnState(void)
|
|||
SetDevicePower(TasmotaGlobal.power, SRC_RESTART);
|
||||
break;
|
||||
case POWER_ALL_ON: // All on
|
||||
TasmotaGlobal.power = (1 << devices_present) -1;
|
||||
TasmotaGlobal.power = (1 << TasmotaGlobal.devices_present) -1;
|
||||
SetDevicePower(TasmotaGlobal.power, SRC_RESTART);
|
||||
break;
|
||||
case POWER_ALL_SAVED_TOGGLE:
|
||||
TasmotaGlobal.power = (Settings.power & ((1 << devices_present) -1)) ^ POWER_MASK;
|
||||
TasmotaGlobal.power = (Settings.power & ((1 << TasmotaGlobal.devices_present) -1)) ^ POWER_MASK;
|
||||
if (Settings.flag.save_state) { // SetOption0 - Save power state and use after restart
|
||||
SetDevicePower(TasmotaGlobal.power, SRC_RESTART);
|
||||
}
|
||||
break;
|
||||
case POWER_ALL_SAVED:
|
||||
TasmotaGlobal.power = Settings.power & ((1 << devices_present) -1);
|
||||
TasmotaGlobal.power = Settings.power & ((1 << TasmotaGlobal.devices_present) -1);
|
||||
if (Settings.flag.save_state) { // SetOption0 - Save power state and use after restart
|
||||
SetDevicePower(TasmotaGlobal.power, SRC_RESTART);
|
||||
}
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
TasmotaGlobal.power = Settings.power & ((1 << devices_present) -1);
|
||||
TasmotaGlobal.power = Settings.power & ((1 << TasmotaGlobal.devices_present) -1);
|
||||
if (Settings.flag.save_state) { // SetOption0 - Save power state and use after restart
|
||||
SetDevicePower(TasmotaGlobal.power, SRC_RESTART);
|
||||
}
|
||||
|
@ -328,7 +328,7 @@ void SetPowerOnState(void)
|
|||
}
|
||||
|
||||
// Issue #526 and #909
|
||||
for (uint32_t i = 0; i < devices_present; i++) {
|
||||
for (uint32_t i = 0; i < TasmotaGlobal.devices_present; i++) {
|
||||
if (!Settings.flag3.no_power_feedback) { // SetOption63 - Don't scan relay power state at restart - #5594 and #5663
|
||||
if ((i < MAX_RELAYS) && PinUsed(GPIO_REL1, i)) {
|
||||
bitWrite(TasmotaGlobal.power, i, digitalRead(Pin(GPIO_REL1, i)) ^ bitRead(TasmotaGlobal.rel_inverted, i));
|
||||
|
@ -343,8 +343,8 @@ void SetPowerOnState(void)
|
|||
|
||||
void UpdateLedPowerAll()
|
||||
{
|
||||
for (uint32_t i = 0; i < leds_present; i++) {
|
||||
SetLedPowerIdx(i, bitRead(led_power, i));
|
||||
for (uint32_t i = 0; i < TasmotaGlobal.leds_present; i++) {
|
||||
SetLedPowerIdx(i, bitRead(TasmotaGlobal.led_power, i));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -359,9 +359,9 @@ void SetLedPowerIdx(uint32_t led, uint32_t state)
|
|||
uint32_t mask = 1 << led;
|
||||
if (state) {
|
||||
state = 1;
|
||||
led_power |= mask;
|
||||
TasmotaGlobal.led_power |= mask;
|
||||
} else {
|
||||
led_power &= (0xFF ^ mask);
|
||||
TasmotaGlobal.led_power &= (0xFF ^ mask);
|
||||
}
|
||||
uint16_t pwm = 0;
|
||||
if (bitRead(Settings.ledpwm_mask, led)) {
|
||||
|
@ -370,9 +370,9 @@ void SetLedPowerIdx(uint32_t led, uint32_t state)
|
|||
#else //USE_LIGHT
|
||||
pwm = changeUIntScale((uint16_t)(state ? Settings.ledpwm_on : Settings.ledpwm_off), 0, 255, 0, Settings.pwm_range); // linear
|
||||
#endif //USE_LIGHT
|
||||
analogWrite(Pin(GPIO_LED1, led), bitRead(led_inverted, led) ? Settings.pwm_range - pwm : pwm);
|
||||
analogWrite(Pin(GPIO_LED1, led), bitRead(TasmotaGlobal.led_inverted, led) ? Settings.pwm_range - pwm : pwm);
|
||||
} else {
|
||||
DigitalWrite(GPIO_LED1, led, bitRead(led_inverted, led) ? !state : state);
|
||||
DigitalWrite(GPIO_LED1, led, bitRead(TasmotaGlobal.led_inverted, led) ? !state : state);
|
||||
}
|
||||
}
|
||||
#ifdef USE_BUZZER
|
||||
|
@ -388,7 +388,7 @@ void SetLedPower(uint32_t state)
|
|||
SetLedPowerIdx(0, state);
|
||||
} else {
|
||||
power_t mask = 1;
|
||||
for (uint32_t i = 0; i < leds_present; i++) { // Map leds to power
|
||||
for (uint32_t i = 0; i < TasmotaGlobal.leds_present; i++) { // Map leds to power
|
||||
bool tstate = (TasmotaGlobal.power & mask);
|
||||
SetLedPowerIdx(i, tstate);
|
||||
mask <<= 1;
|
||||
|
@ -398,7 +398,7 @@ void SetLedPower(uint32_t state)
|
|||
|
||||
void SetLedPowerAll(uint32_t state)
|
||||
{
|
||||
for (uint32_t i = 0; i < leds_present; i++) {
|
||||
for (uint32_t i = 0; i < TasmotaGlobal.leds_present; i++) {
|
||||
SetLedPowerIdx(i, state);
|
||||
}
|
||||
}
|
||||
|
@ -406,7 +406,7 @@ void SetLedPowerAll(uint32_t state)
|
|||
void SetLedLink(uint32_t state)
|
||||
{
|
||||
uint32_t led_pin = Pin(GPIO_LEDLNK);
|
||||
uint32_t led_inv = ledlnk_inverted;
|
||||
uint32_t led_inv = TasmotaGlobal.ledlnk_inverted;
|
||||
if (99 == led_pin) { // Legacy - LED1 is status
|
||||
SetLedPowerIdx(0, state);
|
||||
}
|
||||
|
@ -459,24 +459,24 @@ bool SendKey(uint32_t key, uint32_t device, uint32_t state)
|
|||
char *tmp = (key) ? SettingsText(SET_MQTT_SWITCH_TOPIC) : SettingsText(SET_MQTT_BUTTON_TOPIC);
|
||||
Format(key_topic, tmp, sizeof(key_topic));
|
||||
if (Settings.flag.mqtt_enabled && MqttIsConnected() && (strlen(key_topic) != 0) && strcmp(key_topic, "0")) { // SetOption3 - Enable MQTT
|
||||
if (!key && (device > devices_present)) {
|
||||
if (!key && (device > TasmotaGlobal.devices_present)) {
|
||||
device = 1; // Only allow number of buttons up to number of devices
|
||||
}
|
||||
GetTopic_P(stopic, CMND, key_topic,
|
||||
GetPowerDevice(scommand, device, sizeof(scommand), (key + Settings.flag.device_index_enable))); // cmnd/switchtopic/POWERx - SetOption26 - Switch between POWER or POWER1
|
||||
if (CLEAR_RETAIN == state) {
|
||||
mqtt_data[0] = '\0';
|
||||
ResponseClear();
|
||||
} else {
|
||||
if ((Settings.flag3.button_switch_force_local || // SetOption61 - Force local operation when button/switch topic is set
|
||||
!strcmp(mqtt_topic, key_topic) ||
|
||||
!strcmp(TasmotaGlobal.mqtt_topic, key_topic) ||
|
||||
!strcmp(SettingsText(SET_MQTT_GRP_TOPIC), key_topic)) &&
|
||||
(POWER_TOGGLE == state)) {
|
||||
state = ~(TasmotaGlobal.power >> (device -1)) &1; // POWER_OFF or POWER_ON
|
||||
}
|
||||
snprintf_P(mqtt_data, sizeof(mqtt_data), GetStateText(state));
|
||||
snprintf_P(TasmotaGlobal.mqtt_data, sizeof(TasmotaGlobal.mqtt_data), GetStateText(state));
|
||||
}
|
||||
#ifdef USE_DOMOTICZ
|
||||
if (!(DomoticzSendKey(key, device, state, strlen(mqtt_data)))) {
|
||||
if (!(DomoticzSendKey(key, device, state, strlen(TasmotaGlobal.mqtt_data)))) {
|
||||
#endif // USE_DOMOTICZ
|
||||
MqttPublish(stopic, ((key) ? Settings.flag.mqtt_switch_retain // CMND_SWITCHRETAIN
|
||||
: Settings.flag.mqtt_button_retain) && // CMND_BUTTONRETAIN
|
||||
|
@ -490,7 +490,7 @@ bool SendKey(uint32_t key, uint32_t device, uint32_t state)
|
|||
result = XdrvRulesProcess();
|
||||
}
|
||||
#ifdef USE_PWM_DIMMER
|
||||
if (PWM_DIMMER == my_module_type && !result) {
|
||||
if (PWM_DIMMER == TasmotaGlobal.module_type && !result) {
|
||||
#endif // USE_PWM_DIMMER
|
||||
int32_t payload_save = XdrvMailbox.payload;
|
||||
XdrvMailbox.payload = device_save << 24 | key << 16 | state << 8 | device;
|
||||
|
@ -534,7 +534,7 @@ void ExecuteCommandPower(uint32_t device, uint32_t state, uint32_t source)
|
|||
publish_power = false;
|
||||
}
|
||||
|
||||
if ((device < 1) || (device > devices_present)) {
|
||||
if ((device < 1) || (device > TasmotaGlobal.devices_present)) {
|
||||
device = 1;
|
||||
}
|
||||
TasmotaGlobal.active_device = device;
|
||||
|
@ -556,7 +556,7 @@ void ExecuteCommandPower(uint32_t device, uint32_t state, uint32_t source)
|
|||
interlock_mutex = true; // Clear all but masked relay in interlock group if new set requested
|
||||
for (uint32_t i = 0; i < MAX_INTERLOCKS; i++) {
|
||||
if (Settings.interlock[i] & mask) { // Find interlock group
|
||||
for (uint32_t j = 0; j < devices_present; j++) {
|
||||
for (uint32_t j = 0; j < TasmotaGlobal.devices_present; j++) {
|
||||
power_t imask = 1 << j;
|
||||
if ((Settings.interlock[i] & imask) && (TasmotaGlobal.power & imask) && (mask != imask)) {
|
||||
ExecuteCommandPower(j +1, POWER_OFF, SRC_IGNORE);
|
||||
|
@ -630,7 +630,7 @@ void StopAllPowerBlink(void)
|
|||
{
|
||||
power_t mask;
|
||||
|
||||
for (uint32_t i = 1; i <= devices_present; i++) {
|
||||
for (uint32_t i = 1; i <= TasmotaGlobal.devices_present; i++) {
|
||||
mask = 1 << (i -1);
|
||||
if (TasmotaGlobal.blink_mask & mask) {
|
||||
TasmotaGlobal.blink_mask &= (POWER_MASK ^ mask); // Clear device mask
|
||||
|
@ -671,7 +671,7 @@ void MqttShowState(void)
|
|||
ESP_getFreeHeap()/1024, GetTextIndexed(stemp1, sizeof(stemp1), Settings.flag3.sleep_normal, kSleepMode), // SetOption60 - Enable normal sleep instead of dynamic sleep
|
||||
TasmotaGlobal.sleep, TasmotaGlobal.loop_load_avg, MqttConnectCount());
|
||||
|
||||
for (uint32_t i = 1; i <= devices_present; i++) {
|
||||
for (uint32_t i = 1; i <= TasmotaGlobal.devices_present; i++) {
|
||||
#ifdef USE_LIGHT
|
||||
if ((LightDevice()) && (i >= LightDevice())) {
|
||||
if (i == LightDevice()) { ResponseLightState(1); } // call it only once
|
||||
|
@ -690,12 +690,12 @@ void MqttShowState(void)
|
|||
#endif
|
||||
}
|
||||
|
||||
if (pwm_present) {
|
||||
if (TasmotaGlobal.pwm_present) {
|
||||
ResponseAppend_P(PSTR(","));
|
||||
MqttShowPWMState();
|
||||
}
|
||||
|
||||
if (!global_state.wifi_down) {
|
||||
if (!TasmotaGlobal.global_state.wifi_down) {
|
||||
int32_t rssi = WiFi.RSSI();
|
||||
ResponseAppend_P(PSTR(",\"" D_JSON_WIFI "\":{\"" D_JSON_AP "\":%d,\"" D_JSON_SSID "\":\"%s\",\"" D_JSON_BSSID "\":\"%s\",\"" D_JSON_CHANNEL "\":%d,\"" D_JSON_RSSI "\":%d,\"" D_JSON_SIGNAL "\":%d,\"" D_JSON_LINK_COUNT "\":%d,\"" D_JSON_DOWNTIME "\":\"%s\"}"),
|
||||
Settings.sta_active +1, EscapeJSONString(SettingsText(SET_STASSID1 + Settings.sta_active)).c_str(), WiFi.BSSIDstr().c_str(), WiFi.channel(),
|
||||
|
@ -707,7 +707,7 @@ void MqttShowState(void)
|
|||
|
||||
void MqttPublishTeleState(void)
|
||||
{
|
||||
mqtt_data[0] = '\0';
|
||||
ResponseClear();
|
||||
MqttShowState();
|
||||
MqttPublishPrefixTopic_P(TELE, PSTR(D_RSLT_STATE), MQTT_TELE_RETAIN);
|
||||
#if defined(USE_RULES) || defined(USE_SCRIPT)
|
||||
|
@ -743,7 +743,7 @@ bool MqttShowSensor(void)
|
|||
{
|
||||
ResponseAppendTime();
|
||||
|
||||
int json_data_start = strlen(mqtt_data);
|
||||
int json_data_start = strlen(TasmotaGlobal.mqtt_data);
|
||||
for (uint32_t i = 0; i < MAX_SWITCHES; i++) {
|
||||
#ifdef USE_TM1638
|
||||
if (PinUsed(GPIO_SWT1, i) || (PinUsed(GPIO_TM16CLK) && PinUsed(GPIO_TM16DIO) && PinUsed(GPIO_TM16STB))) {
|
||||
|
@ -756,14 +756,14 @@ bool MqttShowSensor(void)
|
|||
XsnsCall(FUNC_JSON_APPEND);
|
||||
XdrvCall(FUNC_JSON_APPEND);
|
||||
|
||||
bool json_data_available = (strlen(mqtt_data) - json_data_start);
|
||||
if (strstr_P(mqtt_data, PSTR(D_JSON_PRESSURE)) != nullptr) {
|
||||
bool json_data_available = (strlen(TasmotaGlobal.mqtt_data) - json_data_start);
|
||||
if (strstr_P(TasmotaGlobal.mqtt_data, PSTR(D_JSON_PRESSURE)) != nullptr) {
|
||||
ResponseAppend_P(PSTR(",\"" D_JSON_PRESSURE_UNIT "\":\"%s\""), PressureUnit().c_str());
|
||||
}
|
||||
if (strstr_P(mqtt_data, PSTR(D_JSON_TEMPERATURE)) != nullptr) {
|
||||
if (strstr_P(TasmotaGlobal.mqtt_data, PSTR(D_JSON_TEMPERATURE)) != nullptr) {
|
||||
ResponseAppend_P(PSTR(",\"" D_JSON_TEMPERATURE_UNIT "\":\"%c\""), TempUnit());
|
||||
}
|
||||
if ((strstr_P(mqtt_data, PSTR(D_JSON_SPEED)) != nullptr) && Settings.flag2.speed_conversion) {
|
||||
if ((strstr_P(TasmotaGlobal.mqtt_data, PSTR(D_JSON_SPEED)) != nullptr) && Settings.flag2.speed_conversion) {
|
||||
ResponseAppend_P(PSTR(",\"" D_JSON_SPEED_UNIT "\":\"%s\""), SpeedUnit().c_str());
|
||||
}
|
||||
ResponseJsonEnd();
|
||||
|
@ -774,7 +774,7 @@ bool MqttShowSensor(void)
|
|||
|
||||
void MqttPublishSensor(void)
|
||||
{
|
||||
mqtt_data[0] = '\0';
|
||||
ResponseClear();
|
||||
if (MqttShowSensor()) {
|
||||
MqttPublishTeleSensor();
|
||||
}
|
||||
|
@ -818,17 +818,17 @@ void PerformEverySecond(void)
|
|||
if (TasmotaGlobal.seriallog_timer) {
|
||||
TasmotaGlobal.seriallog_timer--;
|
||||
if (!TasmotaGlobal.seriallog_timer) {
|
||||
if (seriallog_level) {
|
||||
if (TasmotaGlobal.seriallog_level) {
|
||||
AddLog_P(LOG_LEVEL_INFO, PSTR(D_LOG_APPLICATION D_SERIAL_LOGGING_DISABLED));
|
||||
}
|
||||
seriallog_level = 0;
|
||||
TasmotaGlobal.seriallog_level = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (TasmotaGlobal.syslog_timer) { // Restore syslog level
|
||||
TasmotaGlobal.syslog_timer--;
|
||||
if (!TasmotaGlobal.syslog_timer) {
|
||||
syslog_level = Settings.syslog_level;
|
||||
TasmotaGlobal.syslog_level = Settings.syslog_level;
|
||||
if (Settings.syslog_level) {
|
||||
AddLog_P(LOG_LEVEL_INFO, PSTR(D_LOG_APPLICATION D_SYSLOG_LOGGING_REENABLED)); // Might trigger disable again (on purpose)
|
||||
}
|
||||
|
@ -839,7 +839,7 @@ void PerformEverySecond(void)
|
|||
|
||||
if (Settings.tele_period) {
|
||||
if (TasmotaGlobal.tele_period >= 9999) {
|
||||
if (!global_state.network_down) {
|
||||
if (!TasmotaGlobal.global_state.network_down) {
|
||||
TasmotaGlobal.tele_period = 0; // Allow teleperiod once wifi is connected
|
||||
}
|
||||
} else {
|
||||
|
@ -849,7 +849,7 @@ void PerformEverySecond(void)
|
|||
|
||||
MqttPublishTeleState();
|
||||
|
||||
mqtt_data[0] = '\0';
|
||||
ResponseClear();
|
||||
if (MqttShowSensor()) {
|
||||
MqttPublishPrefixTopic_P(TELE, PSTR(D_RSLT_SENSOR), Settings.flag.mqtt_sensor_retain); // CMND_SENSORRETAIN
|
||||
#if defined(USE_RULES) || defined(USE_SCRIPT)
|
||||
|
@ -882,8 +882,8 @@ void Every100mSeconds(void)
|
|||
// As the max amount of sleep = 250 mSec this loop will shift in time...
|
||||
power_t power_now;
|
||||
|
||||
if (prepped_loglevel) {
|
||||
AddLog(prepped_loglevel);
|
||||
if (TasmotaGlobal.prepped_loglevel) {
|
||||
AddLog(TasmotaGlobal.prepped_loglevel);
|
||||
}
|
||||
|
||||
if (TasmotaGlobal.latching_relay_pulse) {
|
||||
|
@ -895,7 +895,7 @@ void Every100mSeconds(void)
|
|||
if (TasmotaGlobal.pulse_timer[i] != 0L) { // Timer active?
|
||||
if (TimeReached(TasmotaGlobal.pulse_timer[i])) { // Timer finished?
|
||||
TasmotaGlobal.pulse_timer[i] = 0L; // Turn off this timer
|
||||
for (uint32_t j = 0; j < devices_present; j = j +MAX_PULSETIMERS) {
|
||||
for (uint32_t j = 0; j < TasmotaGlobal.devices_present; j = j +MAX_PULSETIMERS) {
|
||||
ExecuteCommandPower(i + j +1, (POWER_ALL_OFF_PULSETIME_ON == Settings.poweronstate) ? POWER_ON : POWER_OFF, SRC_PULSETIMER);
|
||||
}
|
||||
}
|
||||
|
@ -931,29 +931,29 @@ void Every250mSeconds(void)
|
|||
TasmotaGlobal.state_250mS++;
|
||||
TasmotaGlobal.state_250mS &= 0x3;
|
||||
|
||||
global_state.network_down = (global_state.wifi_down && global_state.eth_down) ? 1 : 0;
|
||||
TasmotaGlobal.global_state.network_down = (TasmotaGlobal.global_state.wifi_down && TasmotaGlobal.global_state.eth_down) ? 1 : 0;
|
||||
|
||||
if (!Settings.flag.global_state) { // SetOption31 - Control link led blinking
|
||||
if (global_state.data &0x03) { // Network or MQTT problem
|
||||
if (global_state.mqtt_down) { blinkinterval = 7; } // MQTT problem so blink every 2 seconds (slowest)
|
||||
if (global_state.network_down) { blinkinterval = 3; } // Network problem so blink every second (slow)
|
||||
if (TasmotaGlobal.global_state.data &0x03) { // Network or MQTT problem
|
||||
if (TasmotaGlobal.global_state.mqtt_down) { blinkinterval = 7; } // MQTT problem so blink every 2 seconds (slowest)
|
||||
if (TasmotaGlobal.global_state.network_down) { blinkinterval = 3; } // Network problem so blink every second (slow)
|
||||
TasmotaGlobal.blinks = 201; // Allow only a single blink in case the problem is solved
|
||||
}
|
||||
}
|
||||
if (TasmotaGlobal.blinks || TasmotaGlobal.restart_flag || TasmotaGlobal.ota_state_flag) {
|
||||
if (TasmotaGlobal.restart_flag || TasmotaGlobal.ota_state_flag) { // Overrule blinks and keep led lit
|
||||
blinkstate = true; // Stay lit
|
||||
TasmotaGlobal.blinkstate = true; // Stay lit
|
||||
} else {
|
||||
blinkspeed--;
|
||||
if (!blinkspeed) {
|
||||
blinkspeed = blinkinterval; // Set interval to 0.2 (default), 1 or 2 seconds
|
||||
blinkstate ^= 1; // Blink
|
||||
TasmotaGlobal.blinkstate ^= 1; // Blink
|
||||
}
|
||||
}
|
||||
if ((!(Settings.ledstate &0x08)) && ((Settings.ledstate &0x06) || (TasmotaGlobal.blinks > 200) || (blinkstate))) {
|
||||
SetLedLink(blinkstate); // Set led on or off
|
||||
if ((!(Settings.ledstate &0x08)) && ((Settings.ledstate &0x06) || (TasmotaGlobal.blinks > 200) || (TasmotaGlobal.blinkstate))) {
|
||||
SetLedLink(TasmotaGlobal.blinkstate); // Set led on or off
|
||||
}
|
||||
if (!blinkstate) {
|
||||
if (!TasmotaGlobal.blinkstate) {
|
||||
TasmotaGlobal.blinks--;
|
||||
if (200 == TasmotaGlobal.blinks) { TasmotaGlobal.blinks = 0; } // Disable blink
|
||||
}
|
||||
|
@ -961,7 +961,7 @@ void Every250mSeconds(void)
|
|||
if (Settings.ledstate &1 && (PinUsed(GPIO_LEDLNK) || !(TasmotaGlobal.blinks || TasmotaGlobal.restart_flag || TasmotaGlobal.ota_state_flag)) ) {
|
||||
bool tstate = TasmotaGlobal.power & Settings.ledmask;
|
||||
#ifdef ESP8266
|
||||
if ((SONOFF_TOUCH == my_module_type) || (SONOFF_T11 == my_module_type) || (SONOFF_T12 == my_module_type) || (SONOFF_T13 == my_module_type)) {
|
||||
if ((SONOFF_TOUCH == TasmotaGlobal.module_type) || (SONOFF_T11 == TasmotaGlobal.module_type) || (SONOFF_T12 == TasmotaGlobal.module_type) || (SONOFF_T13 == TasmotaGlobal.module_type)) {
|
||||
tstate = (!TasmotaGlobal.power) ? 1 : 0; // As requested invert signal for Touch devices to find them in the dark
|
||||
}
|
||||
#endif // ESP8266
|
||||
|
@ -999,7 +999,7 @@ void Every250mSeconds(void)
|
|||
ota_result = 0;
|
||||
ota_retry_counter--;
|
||||
if (ota_retry_counter) {
|
||||
strlcpy(mqtt_data, GetOtaUrl(log_data, sizeof(log_data)), sizeof(mqtt_data));
|
||||
strlcpy(TasmotaGlobal.mqtt_data, GetOtaUrl(TasmotaGlobal.log_data, sizeof(TasmotaGlobal.log_data)), sizeof(TasmotaGlobal.mqtt_data));
|
||||
#ifndef FIRMWARE_MINIMAL
|
||||
if (RtcSettings.ota_loader) {
|
||||
// OTA File too large so try OTA minimal version
|
||||
|
@ -1018,10 +1018,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(mqtt_data, '/'); // Only consider filename after last backslash prevent change of urls having "-" in it
|
||||
if (bch == nullptr) { bch = mqtt_data; } // No path found so use filename only
|
||||
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 *ech = strchr(bch, '.'); // Find file type in filename (none, .ino.bin, .ino.bin.gz, .bin, .bin.gz or .gz)
|
||||
if (ech == nullptr) { ech = mqtt_data + strlen(mqtt_data); } // Point to '/0' at end of mqtt_data becoming an empty string
|
||||
if (ech == nullptr) { ech = TasmotaGlobal.mqtt_data + strlen(TasmotaGlobal.mqtt_data); } // Point to '/0' at end of mqtt_data becoming an empty string
|
||||
|
||||
//AddLog_P2(LOG_LEVEL_DEBUG, PSTR("OTA: File type [%s]"), ech);
|
||||
|
||||
|
@ -1031,12 +1031,12 @@ 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(mqtt_data, sizeof(mqtt_data), PSTR("%s-" D_JSON_MINIMAL "%s"), mqtt_data, ota_url_type); // Minimal filename must be filename-minimal
|
||||
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
|
||||
}
|
||||
#endif // FIRMWARE_MINIMAL
|
||||
AddLog_P2(LOG_LEVEL_DEBUG, PSTR(D_LOG_UPLOAD "%s"), mqtt_data);
|
||||
AddLog_P2(LOG_LEVEL_DEBUG, PSTR(D_LOG_UPLOAD "%s"), TasmotaGlobal.mqtt_data);
|
||||
WiFiClient OTAclient;
|
||||
ota_result = (HTTP_UPDATE_FAILED != ESPhttpUpdate.update(OTAclient, mqtt_data));
|
||||
ota_result = (HTTP_UPDATE_FAILED != ESPhttpUpdate.update(OTAclient, TasmotaGlobal.mqtt_data));
|
||||
if (!ota_result) {
|
||||
#ifndef FIRMWARE_MINIMAL
|
||||
int ota_error = ESPhttpUpdate.getLastError();
|
||||
|
@ -1081,7 +1081,7 @@ void Every250mSeconds(void)
|
|||
if (TasmotaGlobal.save_data_counter <= 0) {
|
||||
if (Settings.flag.save_state) { // SetOption0 - Save power state and use after restart
|
||||
power_t mask = POWER_MASK;
|
||||
for (uint32_t i = 0; i < devices_present; i++) {
|
||||
for (uint32_t i = 0; i < TasmotaGlobal.devices_present; i++) {
|
||||
if ((Settings.pulse_timer[i % MAX_PULSETIMERS] > 0) && (Settings.pulse_timer[i % MAX_PULSETIMERS] < 30)) { // 3 seconds
|
||||
mask &= ~(1 << i);
|
||||
}
|
||||
|
@ -1157,7 +1157,7 @@ void Every250mSeconds(void)
|
|||
}
|
||||
TasmotaGlobal.restart_flag--;
|
||||
if (TasmotaGlobal.restart_flag <= 0) {
|
||||
AddLog_P2(LOG_LEVEL_INFO, PSTR(D_LOG_APPLICATION "%s"), (restart_halt) ? "Halted" : D_RESTARTING);
|
||||
AddLog_P2(LOG_LEVEL_INFO, PSTR(D_LOG_APPLICATION "%s"), (TasmotaGlobal.restart_halt) ? "Halted" : D_RESTARTING);
|
||||
EspRestart();
|
||||
}
|
||||
}
|
||||
|
@ -1169,7 +1169,7 @@ void Every250mSeconds(void)
|
|||
}
|
||||
break;
|
||||
case 3: // Every x.75 second
|
||||
if (!global_state.network_down) {
|
||||
if (!TasmotaGlobal.global_state.network_down) {
|
||||
#ifdef FIRMWARE_MINIMAL
|
||||
if (1 == RtcSettings.ota_loader) {
|
||||
RtcSettings.ota_loader = 0;
|
||||
|
@ -1275,7 +1275,7 @@ void ArduinoOTAInit(void)
|
|||
|
||||
ArduinoOTA.onProgress([](unsigned int progress, unsigned int total)
|
||||
{
|
||||
if ((LOG_LEVEL_DEBUG <= seriallog_level)) {
|
||||
if ((LOG_LEVEL_DEBUG <= TasmotaGlobal.seriallog_level)) {
|
||||
arduino_ota_progress_dot_count++;
|
||||
Serial.printf(".");
|
||||
if (!(arduino_ota_progress_dot_count % 80)) { Serial.println(); }
|
||||
|
@ -1290,7 +1290,7 @@ void ArduinoOTAInit(void)
|
|||
*/
|
||||
char error_str[100];
|
||||
|
||||
if ((LOG_LEVEL_DEBUG <= seriallog_level) && arduino_ota_progress_dot_count) { Serial.println(); }
|
||||
if ((LOG_LEVEL_DEBUG <= TasmotaGlobal.seriallog_level) && arduino_ota_progress_dot_count) { Serial.println(); }
|
||||
switch (error) {
|
||||
case OTA_BEGIN_ERROR: strncpy_P(error_str, PSTR(D_UPLOAD_ERR_2), sizeof(error_str)); break;
|
||||
case OTA_RECEIVE_ERROR: strncpy_P(error_str, PSTR(D_UPLOAD_ERR_5), sizeof(error_str)); break;
|
||||
|
@ -1304,7 +1304,7 @@ void ArduinoOTAInit(void)
|
|||
|
||||
ArduinoOTA.onEnd([]()
|
||||
{
|
||||
if ((LOG_LEVEL_DEBUG <= seriallog_level)) { Serial.println(); }
|
||||
if ((LOG_LEVEL_DEBUG <= TasmotaGlobal.seriallog_level)) { Serial.println(); }
|
||||
AddLog_P2(LOG_LEVEL_INFO, PSTR(D_LOG_UPLOAD "Arduino OTA " D_SUCCESSFUL ". " D_RESTARTING));
|
||||
EspRestart();
|
||||
});
|
||||
|
@ -1332,7 +1332,7 @@ void SerialInput(void)
|
|||
while (Serial.available()) {
|
||||
// yield();
|
||||
delay(0);
|
||||
serial_in_byte = Serial.read();
|
||||
TasmotaGlobal.serial_in_byte = Serial.read();
|
||||
|
||||
if (0 == TasmotaGlobal.serial_in_byte_counter) {
|
||||
serial_buffer_overrun = false;
|
||||
|
@ -1349,8 +1349,8 @@ void SerialInput(void)
|
|||
/*-------------------------------------------------------------------------------------------*\
|
||||
* Sonoff dual and ch4 19200 baud serial interface
|
||||
\*-------------------------------------------------------------------------------------------*/
|
||||
if ((SONOFF_DUAL == my_module_type) || (CH4 == my_module_type)) {
|
||||
serial_in_byte = ButtonSerial(serial_in_byte);
|
||||
if ((SONOFF_DUAL == TasmotaGlobal.module_type) || (CH4 == TasmotaGlobal.module_type)) {
|
||||
TasmotaGlobal.serial_in_byte = ButtonSerial(TasmotaGlobal.serial_in_byte);
|
||||
}
|
||||
#endif // ESP8266
|
||||
/*-------------------------------------------------------------------------------------------*/
|
||||
|
@ -1363,29 +1363,29 @@ void SerialInput(void)
|
|||
|
||||
/*-------------------------------------------------------------------------------------------*/
|
||||
|
||||
if (serial_in_byte > 127 && !Settings.flag.mqtt_serial_raw) { // Discard binary data above 127 if no raw reception allowed - CMND_SERIALSEND3
|
||||
if (TasmotaGlobal.serial_in_byte > 127 && !Settings.flag.mqtt_serial_raw) { // Discard binary data above 127 if no raw reception allowed - CMND_SERIALSEND3
|
||||
TasmotaGlobal.serial_in_byte_counter = 0;
|
||||
Serial.flush();
|
||||
return;
|
||||
}
|
||||
if (!Settings.flag.mqtt_serial) { // SerialSend active - CMND_SERIALSEND and CMND_SERIALLOG
|
||||
if (isprint(serial_in_byte)) { // Any char between 32 and 127
|
||||
if (isprint(TasmotaGlobal.serial_in_byte)) { // Any char between 32 and 127
|
||||
if (TasmotaGlobal.serial_in_byte_counter < INPUT_BUFFER_SIZE -1) { // Add char to string if it still fits
|
||||
serial_in_buffer[TasmotaGlobal.serial_in_byte_counter++] = serial_in_byte;
|
||||
TasmotaGlobal.serial_in_buffer[TasmotaGlobal.serial_in_byte_counter++] = TasmotaGlobal.serial_in_byte;
|
||||
} else {
|
||||
serial_buffer_overrun = true; // Signal overrun but continue reading input to flush until '\n' (EOL)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (serial_in_byte || Settings.flag.mqtt_serial_raw) { // Any char between 1 and 127 or any char (0 - 255) - CMND_SERIALSEND3
|
||||
if (TasmotaGlobal.serial_in_byte || Settings.flag.mqtt_serial_raw) { // Any char between 1 and 127 or any char (0 - 255) - CMND_SERIALSEND3
|
||||
bool in_byte_is_delimiter = // Char is delimiter when...
|
||||
(((Settings.serial_delimiter < 128) && (serial_in_byte == Settings.serial_delimiter)) || // Any char between 1 and 127 and being delimiter
|
||||
((Settings.serial_delimiter == 128) && !isprint(serial_in_byte))) && // Any char not between 32 and 127
|
||||
(((Settings.serial_delimiter < 128) && (TasmotaGlobal.serial_in_byte == Settings.serial_delimiter)) || // Any char between 1 and 127 and being delimiter
|
||||
((Settings.serial_delimiter == 128) && !isprint(TasmotaGlobal.serial_in_byte))) && // Any char not between 32 and 127
|
||||
!Settings.flag.mqtt_serial_raw; // In raw mode (CMND_SERIALSEND3) there is never a delimiter
|
||||
|
||||
if ((TasmotaGlobal.serial_in_byte_counter < INPUT_BUFFER_SIZE -1) && // Add char to string if it still fits and ...
|
||||
!in_byte_is_delimiter) { // Char is not a delimiter
|
||||
serial_in_buffer[TasmotaGlobal.serial_in_byte_counter++] = serial_in_byte;
|
||||
TasmotaGlobal.serial_in_buffer[TasmotaGlobal.serial_in_byte_counter++] = TasmotaGlobal.serial_in_byte;
|
||||
}
|
||||
|
||||
if ((TasmotaGlobal.serial_in_byte_counter >= INPUT_BUFFER_SIZE -1) || // Send message when buffer is full or ...
|
||||
|
@ -1402,10 +1402,10 @@ void SerialInput(void)
|
|||
/*-------------------------------------------------------------------------------------------*\
|
||||
* Sonoff SC 19200 baud serial interface
|
||||
\*-------------------------------------------------------------------------------------------*/
|
||||
if (SONOFF_SC == my_module_type) {
|
||||
if (serial_in_byte == '\x1B') { // Sonoff SC status from ATMEGA328P
|
||||
serial_in_buffer[TasmotaGlobal.serial_in_byte_counter] = 0; // Serial data completed
|
||||
SonoffScSerialInput(serial_in_buffer);
|
||||
if (SONOFF_SC == TasmotaGlobal.module_type) {
|
||||
if (TasmotaGlobal.serial_in_byte == '\x1B') { // Sonoff SC status from ATMEGA328P
|
||||
TasmotaGlobal.serial_in_buffer[TasmotaGlobal.serial_in_byte_counter] = 0; // Serial data completed
|
||||
SonoffScSerialInput(TasmotaGlobal.serial_in_buffer);
|
||||
TasmotaGlobal.serial_in_byte_counter = 0;
|
||||
Serial.flush();
|
||||
return;
|
||||
|
@ -1414,14 +1414,14 @@ void SerialInput(void)
|
|||
#endif // USE_SONOFF_SC
|
||||
/*-------------------------------------------------------------------------------------------*/
|
||||
|
||||
if (!Settings.flag.mqtt_serial && (serial_in_byte == '\n')) { // CMND_SERIALSEND and CMND_SERIALLOG
|
||||
serial_in_buffer[TasmotaGlobal.serial_in_byte_counter] = 0; // Serial data completed
|
||||
seriallog_level = (Settings.seriallog_level < LOG_LEVEL_INFO) ? (uint8_t)LOG_LEVEL_INFO : Settings.seriallog_level;
|
||||
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;
|
||||
if (serial_buffer_overrun) {
|
||||
AddLog_P2(LOG_LEVEL_INFO, PSTR(D_LOG_COMMAND "Serial buffer overrun"));
|
||||
} else {
|
||||
AddLog_P2(LOG_LEVEL_INFO, PSTR(D_LOG_COMMAND "%s"), serial_in_buffer);
|
||||
ExecuteCommand(serial_in_buffer, SRC_SERIAL);
|
||||
AddLog_P2(LOG_LEVEL_INFO, PSTR(D_LOG_COMMAND "%s"), TasmotaGlobal.serial_in_buffer);
|
||||
ExecuteCommand(TasmotaGlobal.serial_in_buffer, SRC_SERIAL);
|
||||
}
|
||||
TasmotaGlobal.serial_in_byte_counter = 0;
|
||||
serial_polling_window = 0;
|
||||
|
@ -1431,19 +1431,19 @@ void SerialInput(void)
|
|||
}
|
||||
|
||||
if (Settings.flag.mqtt_serial && TasmotaGlobal.serial_in_byte_counter && (millis() > (serial_polling_window + SERIAL_POLLING))) { // CMND_SERIALSEND and CMND_SERIALLOG
|
||||
serial_in_buffer[TasmotaGlobal.serial_in_byte_counter] = 0; // Serial data completed
|
||||
bool assume_json = (!Settings.flag.mqtt_serial_raw && (serial_in_buffer[0] == '{'));
|
||||
TasmotaGlobal.serial_in_buffer[TasmotaGlobal.serial_in_byte_counter] = 0; // Serial data completed
|
||||
bool assume_json = (!Settings.flag.mqtt_serial_raw && (TasmotaGlobal.serial_in_buffer[0] == '{'));
|
||||
|
||||
Response_P(PSTR("{\"" D_JSON_SERIALRECEIVED "\":"));
|
||||
if (assume_json) {
|
||||
ResponseAppend_P(serial_in_buffer);
|
||||
ResponseAppend_P(TasmotaGlobal.serial_in_buffer);
|
||||
} else {
|
||||
ResponseAppend_P(PSTR("\""));
|
||||
if (Settings.flag.mqtt_serial_raw) {
|
||||
char hex_char[(TasmotaGlobal.serial_in_byte_counter * 2) + 2];
|
||||
ResponseAppend_P(ToHex_P((unsigned char*)serial_in_buffer, TasmotaGlobal.serial_in_byte_counter, hex_char, sizeof(hex_char)));
|
||||
ResponseAppend_P(ToHex_P((unsigned char*)TasmotaGlobal.serial_in_buffer, TasmotaGlobal.serial_in_byte_counter, hex_char, sizeof(hex_char)));
|
||||
} else {
|
||||
ResponseAppend_P(EscapeJSONString(serial_in_buffer).c_str());
|
||||
ResponseAppend_P(EscapeJSONString(TasmotaGlobal.serial_in_buffer).c_str());
|
||||
}
|
||||
ResponseAppend_P(PSTR("\""));
|
||||
}
|
||||
|
@ -1460,8 +1460,8 @@ void ResetPwm(void)
|
|||
{
|
||||
for (uint32_t i = 0; i < MAX_PWMS; i++) { // Basic PWM control only
|
||||
if (PinUsed(GPIO_PWM1, i)) {
|
||||
analogWrite(Pin(GPIO_PWM1, i), bitRead(pwm_inverted, i) ? Settings.pwm_range : 0);
|
||||
// analogWrite(Pin(GPIO_PWM1, i), bitRead(pwm_inverted, i) ? Settings.pwm_range - Settings.pwm_value[i] : Settings.pwm_value[i]);
|
||||
analogWrite(Pin(GPIO_PWM1, i), bitRead(TasmotaGlobal.pwm_inverted, i) ? Settings.pwm_range : 0);
|
||||
// analogWrite(Pin(GPIO_PWM1, i), bitRead(TasmotaGlobal.pwm_inverted, i) ? Settings.pwm_range - Settings.pwm_value[i] : Settings.pwm_value[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1511,15 +1511,15 @@ void GpioInit(void)
|
|||
Settings.my_gp.io[i] = GPIO_NONE; // Fix not supported sensor ids in module
|
||||
}
|
||||
else if (Settings.my_gp.io[i] > GPIO_NONE) {
|
||||
my_module.io[i] = Settings.my_gp.io[i]; // Set User selected Module sensors
|
||||
TasmotaGlobal.my_module.io[i] = Settings.my_gp.io[i]; // Set User selected Module sensors
|
||||
}
|
||||
if ((def_gp.io[i] > GPIO_NONE) && (def_gp.io[i] < AGPIO(GPIO_USER))) {
|
||||
my_module.io[i] = def_gp.io[i]; // Force Template override
|
||||
TasmotaGlobal.my_module.io[i] = def_gp.io[i]; // Force Template override
|
||||
}
|
||||
}
|
||||
|
||||
for (uint32_t i = 0; i < ARRAY_SIZE(my_module.io); i++) {
|
||||
uint32_t mpin = ValidPin(i, my_module.io[i]);
|
||||
for (uint32_t i = 0; i < ARRAY_SIZE(TasmotaGlobal.my_module.io); i++) {
|
||||
uint32_t mpin = ValidPin(i, TasmotaGlobal.my_module.io[i]);
|
||||
|
||||
DEBUG_CORE_LOG(PSTR("INI: gpio pin %d, mpin %d"), i, mpin);
|
||||
|
||||
|
@ -1555,15 +1555,15 @@ void GpioInit(void)
|
|||
mpin -= (AGPIO(GPIO_REL1_INV) - AGPIO(GPIO_REL1));
|
||||
}
|
||||
else if ((mpin >= AGPIO(GPIO_LED1_INV)) && (mpin < (AGPIO(GPIO_LED1_INV) + MAX_LEDS))) {
|
||||
bitSet(led_inverted, mpin - AGPIO(GPIO_LED1_INV));
|
||||
bitSet(TasmotaGlobal.led_inverted, mpin - AGPIO(GPIO_LED1_INV));
|
||||
mpin -= (AGPIO(GPIO_LED1_INV) - AGPIO(GPIO_LED1));
|
||||
}
|
||||
else if (mpin == AGPIO(GPIO_LEDLNK_INV)) {
|
||||
ledlnk_inverted = 1;
|
||||
TasmotaGlobal.ledlnk_inverted = 1;
|
||||
mpin -= (AGPIO(GPIO_LEDLNK_INV) - AGPIO(GPIO_LEDLNK));
|
||||
}
|
||||
else if ((mpin >= AGPIO(GPIO_PWM1_INV)) && (mpin < (AGPIO(GPIO_PWM1_INV) + MAX_PWMS))) {
|
||||
bitSet(pwm_inverted, mpin - AGPIO(GPIO_PWM1_INV));
|
||||
bitSet(TasmotaGlobal.pwm_inverted, mpin - AGPIO(GPIO_PWM1_INV));
|
||||
mpin -= (AGPIO(GPIO_PWM1_INV) - AGPIO(GPIO_PWM1));
|
||||
}
|
||||
else if (XdrvCall(FUNC_PIN_STATE)) {
|
||||
|
@ -1582,16 +1582,16 @@ void GpioInit(void)
|
|||
analogWriteFreq(Settings.pwm_frequency); // Default is 1000 (core_esp8266_wiring_pwm.c)
|
||||
|
||||
#ifdef ESP8266
|
||||
if ((2 == Pin(GPIO_TXD)) || (H801 == my_module_type)) { Serial.set_tx(2); }
|
||||
if ((2 == Pin(GPIO_TXD)) || (H801 == TasmotaGlobal.module_type)) { Serial.set_tx(2); }
|
||||
|
||||
#ifdef USE_SPI
|
||||
spi_flg = (((PinUsed(GPIO_SPI_CS) && (Pin(GPIO_SPI_CS) > 14)) || (Pin(GPIO_SPI_CS) < 12)) || ((PinUsed(GPIO_SPI_DC) && (Pin(GPIO_SPI_DC) > 14)) || (Pin(GPIO_SPI_DC) < 12)));
|
||||
if (spi_flg) {
|
||||
my_module.io[12] = GPIO_SPI_MISO;
|
||||
TasmotaGlobal.spi_enabled = (((PinUsed(GPIO_SPI_CS) && (Pin(GPIO_SPI_CS) > 14)) || (Pin(GPIO_SPI_CS) < 12)) || ((PinUsed(GPIO_SPI_DC) && (Pin(GPIO_SPI_DC) > 14)) || (Pin(GPIO_SPI_DC) < 12)));
|
||||
if (TasmotaGlobal.spi_enabled) {
|
||||
TasmotaGlobal.my_module.io[12] = GPIO_SPI_MISO;
|
||||
SetPin(12, GPIO_SPI_MISO);
|
||||
my_module.io[13] = GPIO_SPI_MOSI;
|
||||
TasmotaGlobal.my_module.io[13] = GPIO_SPI_MOSI;
|
||||
SetPin(13, GPIO_SPI_MOSI);
|
||||
my_module.io[14] = GPIO_SPI_CLK;
|
||||
TasmotaGlobal.my_module.io[14] = GPIO_SPI_CLK;
|
||||
SetPin(14, GPIO_SPI_CLK);
|
||||
AddLog_P2(LOG_LEVEL_DEBUG, PSTR("SPI: Using GPIO12(MISO), GPIO13(MOSI) and GPIO14(CLK)"));
|
||||
}
|
||||
|
@ -1600,39 +1600,39 @@ void GpioInit(void)
|
|||
#ifdef USE_SPI
|
||||
if (PinUsed(GPIO_SPI_CS) || PinUsed(GPIO_SPI_DC)) {
|
||||
if ((15 == Pin(GPIO_SPI_CS)) && (!GetPin(12) && !GetPin(13) && !GetPin(14))) { // HSPI
|
||||
my_module.io[12] = AGPIO(GPIO_SPI_MISO);
|
||||
TasmotaGlobal.my_module.io[12] = AGPIO(GPIO_SPI_MISO);
|
||||
SetPin(12, AGPIO(GPIO_SPI_MISO));
|
||||
my_module.io[13] = AGPIO(GPIO_SPI_MOSI);
|
||||
TasmotaGlobal.my_module.io[13] = AGPIO(GPIO_SPI_MOSI);
|
||||
SetPin(13, AGPIO(GPIO_SPI_MOSI));
|
||||
my_module.io[14] = AGPIO(GPIO_SPI_CLK);
|
||||
TasmotaGlobal.my_module.io[14] = AGPIO(GPIO_SPI_CLK);
|
||||
SetPin(14, AGPIO(GPIO_SPI_CLK));
|
||||
}
|
||||
else if ((5 == Pin(GPIO_SPI_CS)) && (!GetPin(19) && !GetPin(23) && !GetPin(18))) { // VSPI
|
||||
my_module.io[19] = AGPIO(GPIO_SPI_MISO);
|
||||
TasmotaGlobal.my_module.io[19] = AGPIO(GPIO_SPI_MISO);
|
||||
SetPin(19, AGPIO(GPIO_SPI_MISO));
|
||||
my_module.io[23] = AGPIO(GPIO_SPI_MOSI);
|
||||
TasmotaGlobal.my_module.io[23] = AGPIO(GPIO_SPI_MOSI);
|
||||
SetPin(23, AGPIO(GPIO_SPI_MOSI));
|
||||
my_module.io[18] = AGPIO(GPIO_SPI_CLK);
|
||||
TasmotaGlobal.my_module.io[18] = AGPIO(GPIO_SPI_CLK);
|
||||
SetPin(18, AGPIO(GPIO_SPI_CLK));
|
||||
}
|
||||
else if ((12 == Pin(GPIO_SPI_MISO)) || (13 == Pin(GPIO_SPI_MOSI)) || (14 == Pin(GPIO_SPI_CLK))) { // HSPI
|
||||
my_module.io[12] = AGPIO(GPIO_SPI_MISO);
|
||||
TasmotaGlobal.my_module.io[12] = AGPIO(GPIO_SPI_MISO);
|
||||
SetPin(12, AGPIO(GPIO_SPI_MISO));
|
||||
my_module.io[13] = AGPIO(GPIO_SPI_MOSI);
|
||||
TasmotaGlobal.my_module.io[13] = AGPIO(GPIO_SPI_MOSI);
|
||||
SetPin(13, AGPIO(GPIO_SPI_MOSI));
|
||||
my_module.io[14] = AGPIO(GPIO_SPI_CLK);
|
||||
TasmotaGlobal.my_module.io[14] = AGPIO(GPIO_SPI_CLK);
|
||||
SetPin(14, AGPIO(GPIO_SPI_CLK));
|
||||
}
|
||||
else if ((19 == Pin(GPIO_SPI_MISO)) || (23 == Pin(GPIO_SPI_MOSI)) || (18 == Pin(GPIO_SPI_CLK))) { // VSPI
|
||||
my_module.io[19] = AGPIO(GPIO_SPI_MISO);
|
||||
TasmotaGlobal.my_module.io[19] = AGPIO(GPIO_SPI_MISO);
|
||||
SetPin(19, AGPIO(GPIO_SPI_MISO));
|
||||
my_module.io[23] = AGPIO(GPIO_SPI_MOSI);
|
||||
TasmotaGlobal.my_module.io[23] = AGPIO(GPIO_SPI_MOSI);
|
||||
SetPin(23, AGPIO(GPIO_SPI_MOSI));
|
||||
my_module.io[18] = AGPIO(GPIO_SPI_CLK);
|
||||
TasmotaGlobal.my_module.io[18] = AGPIO(GPIO_SPI_CLK);
|
||||
SetPin(18, AGPIO(GPIO_SPI_CLK));
|
||||
}
|
||||
spi_flg = (PinUsed(GPIO_SPI_CLK) && (PinUsed(GPIO_SPI_MOSI) || PinUsed(GPIO_SPI_MISO)));
|
||||
if (spi_flg) {
|
||||
TasmotaGlobal.spi_enabled = (PinUsed(GPIO_SPI_CLK) && (PinUsed(GPIO_SPI_MOSI) || PinUsed(GPIO_SPI_MISO)));
|
||||
if (TasmotaGlobal.spi_enabled) {
|
||||
if (PinUsed(GPIO_SPI_MOSI) && PinUsed(GPIO_SPI_MISO)) {
|
||||
AddLog_P2(LOG_LEVEL_DEBUG, PSTR("SPI: Using GPIO%02d(MISO), GPIO%02d(MOSI) and GPIO%02d(CLK)"),
|
||||
Pin(GPIO_SPI_MISO), Pin(GPIO_SPI_MOSI), Pin(GPIO_SPI_CLK));
|
||||
|
@ -1649,10 +1649,10 @@ void GpioInit(void)
|
|||
}
|
||||
#endif // USE_SPI
|
||||
#endif // ESP8266 - ESP32
|
||||
soft_spi_flg = (PinUsed(GPIO_SSPI_SCLK) && (PinUsed(GPIO_SSPI_MOSI) || PinUsed(GPIO_SSPI_MISO)));
|
||||
TasmotaGlobal.soft_spi_enabled = (PinUsed(GPIO_SSPI_SCLK) && (PinUsed(GPIO_SSPI_MOSI) || PinUsed(GPIO_SSPI_MISO)));
|
||||
|
||||
for (uint32_t i = 0; i < ARRAY_SIZE(my_module.io); i++) {
|
||||
uint32_t mpin = ValidPin(i, my_module.io[i]);
|
||||
for (uint32_t i = 0; i < ARRAY_SIZE(TasmotaGlobal.my_module.io); i++) {
|
||||
uint32_t mpin = ValidPin(i, TasmotaGlobal.my_module.io[i]);
|
||||
// AddLog_P2(LOG_LEVEL_DEBUG, PSTR("INI: gpio pin %d, mpin %d"), i, mpin);
|
||||
if (AGPIO(GPIO_OUTPUT_HI) == mpin) {
|
||||
pinMode(i, OUTPUT);
|
||||
|
@ -1672,14 +1672,14 @@ void GpioInit(void)
|
|||
}
|
||||
|
||||
#ifdef USE_I2C
|
||||
i2c_flg = (PinUsed(GPIO_I2C_SCL) && PinUsed(GPIO_I2C_SDA));
|
||||
if (i2c_flg) {
|
||||
TasmotaGlobal.i2c_enabled = (PinUsed(GPIO_I2C_SCL) && PinUsed(GPIO_I2C_SDA));
|
||||
if (TasmotaGlobal.i2c_enabled) {
|
||||
Wire.begin(Pin(GPIO_I2C_SDA), Pin(GPIO_I2C_SCL));
|
||||
}
|
||||
#endif // USE_I2C
|
||||
|
||||
devices_present = 0;
|
||||
light_type = LT_BASIC; // Use basic PWM control if SetOption15 = 0
|
||||
TasmotaGlobal.devices_present = 0;
|
||||
TasmotaGlobal.light_type = LT_BASIC; // Use basic PWM control if SetOption15 = 0
|
||||
|
||||
XsnsCall(FUNC_MODULE_INIT);
|
||||
|
||||
|
@ -1687,20 +1687,20 @@ void GpioInit(void)
|
|||
// Serviced
|
||||
}
|
||||
#ifdef ESP8266
|
||||
else if (YTF_IR_BRIDGE == my_module_type) {
|
||||
else if (YTF_IR_BRIDGE == TasmotaGlobal.module_type) {
|
||||
ClaimSerial(); // Stop serial loopback mode
|
||||
// devices_present = 1;
|
||||
// TasmotaGlobal.devices_present = 1;
|
||||
}
|
||||
else if (SONOFF_DUAL == my_module_type) {
|
||||
devices_present = 2;
|
||||
else if (SONOFF_DUAL == TasmotaGlobal.module_type) {
|
||||
TasmotaGlobal.devices_present = 2;
|
||||
SetSerial(19200, TS_SERIAL_8N1);
|
||||
}
|
||||
else if (CH4 == my_module_type) {
|
||||
devices_present = 4;
|
||||
else if (CH4 == TasmotaGlobal.module_type) {
|
||||
TasmotaGlobal.devices_present = 4;
|
||||
SetSerial(19200, TS_SERIAL_8N1);
|
||||
}
|
||||
#ifdef USE_SONOFF_SC
|
||||
else if (SONOFF_SC == my_module_type) {
|
||||
else if (SONOFF_SC == TasmotaGlobal.module_type) {
|
||||
SetSerial(19200, TS_SERIAL_8N1);
|
||||
}
|
||||
#endif // USE_SONOFF_SC
|
||||
|
@ -1713,12 +1713,12 @@ void GpioInit(void)
|
|||
#else // ESP32
|
||||
analogAttach(Pin(GPIO_PWM1, i), i);
|
||||
#endif
|
||||
if (light_type) {
|
||||
if (TasmotaGlobal.light_type) {
|
||||
// force PWM GPIOs to low or high mode, see #7165
|
||||
analogWrite(Pin(GPIO_PWM1, i), bitRead(pwm_inverted, i) ? Settings.pwm_range : 0);
|
||||
analogWrite(Pin(GPIO_PWM1, i), bitRead(TasmotaGlobal.pwm_inverted, i) ? Settings.pwm_range : 0);
|
||||
} else {
|
||||
pwm_present = true;
|
||||
analogWrite(Pin(GPIO_PWM1, i), bitRead(pwm_inverted, i) ? Settings.pwm_range - Settings.pwm_value[i] : Settings.pwm_value[i]);
|
||||
TasmotaGlobal.pwm_present = true;
|
||||
analogWrite(Pin(GPIO_PWM1, i), bitRead(TasmotaGlobal.pwm_inverted, i) ? Settings.pwm_range - Settings.pwm_value[i] : Settings.pwm_value[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1726,11 +1726,11 @@ void GpioInit(void)
|
|||
for (uint32_t i = 0; i < MAX_RELAYS; i++) {
|
||||
if (PinUsed(GPIO_REL1, i)) {
|
||||
pinMode(Pin(GPIO_REL1, i), OUTPUT);
|
||||
devices_present++;
|
||||
TasmotaGlobal.devices_present++;
|
||||
#ifdef ESP8266
|
||||
if (EXS_RELAY == my_module_type) {
|
||||
if (EXS_RELAY == TasmotaGlobal.module_type) {
|
||||
digitalWrite(Pin(GPIO_REL1, i), bitRead(TasmotaGlobal.rel_inverted, i) ? 1 : 0);
|
||||
if (i &1) { devices_present--; }
|
||||
if (i &1) { TasmotaGlobal.devices_present--; }
|
||||
}
|
||||
#endif // ESP8266
|
||||
}
|
||||
|
@ -1739,13 +1739,13 @@ void GpioInit(void)
|
|||
for (uint32_t i = 0; i < MAX_LEDS; i++) {
|
||||
if (PinUsed(GPIO_LED1, i)) {
|
||||
#ifdef USE_ARILUX_RF
|
||||
if ((3 == i) && (leds_present < 2) && !PinUsed(GPIO_ARIRFSEL)) {
|
||||
if ((3 == i) && (TasmotaGlobal.leds_present < 2) && !PinUsed(GPIO_ARIRFSEL)) {
|
||||
SetPin(Pin(GPIO_LED1, i), AGPIO(GPIO_ARIRFSEL)); // Legacy support where LED4 was Arilux RF enable
|
||||
} else {
|
||||
#endif
|
||||
pinMode(Pin(GPIO_LED1, i), OUTPUT);
|
||||
leds_present++;
|
||||
digitalWrite(Pin(GPIO_LED1, i), bitRead(led_inverted, i));
|
||||
TasmotaGlobal.leds_present++;
|
||||
digitalWrite(Pin(GPIO_LED1, i), bitRead(TasmotaGlobal.led_inverted, i));
|
||||
#ifdef USE_ARILUX_RF
|
||||
}
|
||||
#endif
|
||||
|
@ -1753,11 +1753,11 @@ void GpioInit(void)
|
|||
}
|
||||
if (PinUsed(GPIO_LEDLNK)) {
|
||||
pinMode(Pin(GPIO_LEDLNK), OUTPUT);
|
||||
digitalWrite(Pin(GPIO_LEDLNK), ledlnk_inverted);
|
||||
digitalWrite(Pin(GPIO_LEDLNK), TasmotaGlobal.ledlnk_inverted);
|
||||
}
|
||||
|
||||
#ifdef USE_PWM_DIMMER
|
||||
if (PWM_DIMMER == my_module_type && PinUsed(GPIO_REL1)) { devices_present--; }
|
||||
if (PWM_DIMMER == TasmotaGlobal.module_type && PinUsed(GPIO_REL1)) { TasmotaGlobal.devices_present--; }
|
||||
#endif // USE_PWM_DIMMER
|
||||
|
||||
ButtonInit();
|
||||
|
|
|
@ -133,7 +133,7 @@ void PollUdp(void)
|
|||
#if defined(USE_SCRIPT_HUE) || defined(USE_ZIGBEE)
|
||||
if (!udp_response_mutex && (strstr_P(packet_buffer, PSTR("M-SEARCH")) != nullptr)) {
|
||||
#else
|
||||
if (devices_present && !udp_response_mutex && (strstr_P(packet_buffer, PSTR("M-SEARCH")) != nullptr)) {
|
||||
if (TasmotaGlobal.devices_present && !udp_response_mutex && (strstr_P(packet_buffer, PSTR("M-SEARCH")) != nullptr)) {
|
||||
#endif
|
||||
udp_response_mutex = true;
|
||||
|
||||
|
|
|
@ -193,7 +193,7 @@ void WifiBegin(uint8_t flag, uint8_t channel)
|
|||
if (Settings.ip_address[0]) {
|
||||
WiFi.config(Settings.ip_address[0], Settings.ip_address[1], Settings.ip_address[2], Settings.ip_address[3]); // Set static IP
|
||||
}
|
||||
WiFi.hostname(my_hostname);
|
||||
WiFi.hostname(TasmotaGlobal.hostname);
|
||||
|
||||
char stemp[40] = { 0 };
|
||||
if (channel) {
|
||||
|
@ -205,7 +205,7 @@ void WifiBegin(uint8_t flag, uint8_t channel)
|
|||
WiFi.begin(SettingsText(SET_STASSID1 + Settings.sta_active), SettingsText(SET_STAPWD1 + Settings.sta_active));
|
||||
}
|
||||
AddLog_P2(LOG_LEVEL_INFO, PSTR(D_LOG_WIFI D_CONNECTING_TO_AP "%d %s%s " D_IN_MODE " 11%c " D_AS " %s..."),
|
||||
Settings.sta_active +1, SettingsText(SET_STASSID1 + Settings.sta_active), stemp, kWifiPhyMode[WiFi.getPhyMode() & 0x3], my_hostname);
|
||||
Settings.sta_active +1, SettingsText(SET_STASSID1 + Settings.sta_active), stemp, kWifiPhyMode[WiFi.getPhyMode() & 0x3], TasmotaGlobal.hostname);
|
||||
|
||||
#if LWIP_IPV6
|
||||
for (bool configured = false; !configured;) {
|
||||
|
@ -331,7 +331,7 @@ String WifiDowntime(void)
|
|||
|
||||
void WifiSetState(uint8_t state)
|
||||
{
|
||||
if (state == global_state.wifi_down) {
|
||||
if (state == TasmotaGlobal.global_state.wifi_down) {
|
||||
if (state) {
|
||||
TasmotaGlobal.rules_flag.wifi_connected = 1;
|
||||
Wifi.link_count++;
|
||||
|
@ -341,9 +341,9 @@ void WifiSetState(uint8_t state)
|
|||
Wifi.last_event = UpTime();
|
||||
}
|
||||
}
|
||||
global_state.wifi_down = state ^1;
|
||||
if (!global_state.wifi_down) {
|
||||
global_state.network_down = 0;
|
||||
TasmotaGlobal.global_state.wifi_down = state ^1;
|
||||
if (!TasmotaGlobal.global_state.wifi_down) {
|
||||
TasmotaGlobal.global_state.network_down = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -536,7 +536,7 @@ int WifiState(void)
|
|||
{
|
||||
int state = -1;
|
||||
|
||||
if (!global_state.wifi_down) { state = WIFI_RESTART; }
|
||||
if (!TasmotaGlobal.global_state.wifi_down) { state = WIFI_RESTART; }
|
||||
if (Wifi.config_type) { state = Wifi.config_type; }
|
||||
return state;
|
||||
}
|
||||
|
@ -641,7 +641,7 @@ void EspRestart(void)
|
|||
WifiShutdown(true);
|
||||
CrashDumpClear(); // Clear the stack dump in RTC
|
||||
|
||||
if (restart_halt) {
|
||||
if (TasmotaGlobal.restart_halt) {
|
||||
while (1) {
|
||||
OsWatchLoop(); // Feed OsWatch timer to prevent restart
|
||||
SetLedLink(1); // Wifi led on
|
||||
|
|
|
@ -101,14 +101,29 @@ struct {
|
|||
float pressure_hpa; // Provide a global pressure to be used by some sensors
|
||||
|
||||
uint16_t gpio_pin[MAX_GPIO_PIN]; // GPIO functions indexed by pin number
|
||||
myio my_module; // Active copy of Module GPIOs (17 x 16 bits)
|
||||
uint16_t blink_counter; // Number of blink cycles
|
||||
uint16_t seriallog_timer; // Timer to disable Seriallog
|
||||
uint16_t syslog_timer; // Timer to re-enable syslog_level
|
||||
uint16_t tele_period; // Tele period timer
|
||||
int16_t save_data_counter; // Counter and flag for config save to Flash
|
||||
|
||||
RulesBitfield rules_flag; // Rule state flags (16 bits)
|
||||
|
||||
bool serial_local; // Handle serial locally
|
||||
bool fallback_topic_flag; // Use Topic or FallbackTopic
|
||||
bool backlog_mutex; // Command backlog pending
|
||||
bool stop_flash_rotate; // Allow flash configuration rotation
|
||||
bool blinkstate; // LED state
|
||||
bool pwm_present; // Any PWM channel configured with SetOption15 0
|
||||
bool i2c_enabled; // I2C configured
|
||||
bool spi_enabled; // SPI configured
|
||||
bool soft_spi_enabled; // Software SPI configured
|
||||
bool ntp_force_sync; // Force NTP sync
|
||||
bool is_8285; // Hardware device ESP8266EX (0) or ESP8285 (1)
|
||||
bool skip_light_fade; // Temporarily skip light fading
|
||||
bool restart_halt; // Do not restart but stay in wait loop
|
||||
|
||||
StateBitfield global_state; // Global states (currently Wifi and Mqtt) (8 bits)
|
||||
uint8_t blinks; // Number of LED blinks
|
||||
uint8_t restart_flag; // Tasmota restart flag
|
||||
uint8_t ota_state_flag; // OTA state flag
|
||||
|
@ -119,61 +134,47 @@ struct {
|
|||
uint8_t latching_relay_pulse; // Latching relay pulse timer
|
||||
uint8_t active_device; // Active device in ExecuteCommandPower
|
||||
uint8_t sleep; // Current copy of Settings.sleep
|
||||
uint8_t leds_present; // Max number of LED supported
|
||||
uint8_t led_inverted; // LED inverted flag (1 = (0 = On, 1 = Off))
|
||||
uint8_t led_power; // LED power state
|
||||
uint8_t ledlnk_inverted; // Link LED inverted flag (1 = (0 = On, 1 = Off))
|
||||
uint8_t pwm_inverted; // PWM inverted flag (1 = inverted)
|
||||
uint8_t energy_driver; // Energy monitor configured
|
||||
uint8_t light_driver; // Light module configured
|
||||
uint8_t light_type; // Light types
|
||||
uint8_t serial_in_byte; // Received byte
|
||||
uint8_t devices_present; // Max number of devices supported
|
||||
uint8_t masterlog_level; // Master log level used to override set log level
|
||||
uint8_t seriallog_level; // Current copy of Settings.seriallog_level
|
||||
uint8_t syslog_level; // Current copy of Settings.syslog_level
|
||||
uint8_t module_type; // Current copy of Settings.module or user template type
|
||||
uint8_t last_source; // Last command source
|
||||
uint8_t shutters_present; // Number of actual define shutters
|
||||
uint8_t prepped_loglevel; // Delayed log level message
|
||||
|
||||
#ifndef SUPPORT_IF_STATEMENT
|
||||
uint8_t backlog_index; // Command backlog index
|
||||
uint8_t backlog_pointer; // Command backlog pointer
|
||||
String backlog[MAX_BACKLOG]; // Command backlog buffer
|
||||
#endif
|
||||
|
||||
char version[16]; // Composed version string like 255.255.255.255
|
||||
char image_name[33]; // Code image and/or commit
|
||||
char hostname[33]; // Composed Wifi hostname
|
||||
char serial_in_buffer[INPUT_BUFFER_SIZE]; // Receive buffer
|
||||
char mqtt_client[99]; // Composed MQTT Clientname
|
||||
char mqtt_topic[TOPSZ]; // Composed MQTT topic
|
||||
char mqtt_data[MESSZ]; // MQTT publish buffer and web page ajax buffer
|
||||
char log_data[LOGSZ]; // Logging
|
||||
char web_log[WEB_LOG_SIZE]; // Web log buffer
|
||||
} TasmotaGlobal;
|
||||
|
||||
uint8_t leds_present = 0; // Max number of LED supported
|
||||
uint8_t led_inverted = 0; // LED inverted flag (1 = (0 = On, 1 = Off))
|
||||
uint8_t led_power = 0; // LED power state
|
||||
uint8_t ledlnk_inverted = 0; // Link LED inverted flag (1 = (0 = On, 1 = Off))
|
||||
uint8_t pwm_inverted = 0; // PWM inverted flag (1 = inverted)
|
||||
uint8_t energy_flg = 0; // Energy monitor configured
|
||||
uint8_t light_flg = 0; // Light module configured
|
||||
uint8_t light_type = 0; // Light types
|
||||
uint8_t serial_in_byte; // Received byte
|
||||
uint8_t devices_present = 0; // Max number of devices supported
|
||||
uint8_t masterlog_level = 0; // Master log level used to override set log level
|
||||
uint8_t seriallog_level; // Current copy of Settings.seriallog_level
|
||||
uint8_t syslog_level; // Current copy of Settings.syslog_level
|
||||
uint8_t my_module_type; // Current copy of Settings.module or user template type
|
||||
uint8_t last_source = 0; // Last command source
|
||||
uint8_t shutters_present = 0; // Number of actual define shutters
|
||||
uint8_t prepped_loglevel = 0; // Delayed log level message
|
||||
//uint8_t mdns_delayed_start = 0; // mDNS delayed start
|
||||
bool serial_local = false; // Handle serial locally
|
||||
bool fallback_topic_flag = false; // Use Topic or FallbackTopic
|
||||
bool backlog_mutex = false; // Command backlog pending
|
||||
bool stop_flash_rotate = false; // Allow flash configuration rotation
|
||||
bool blinkstate = false; // LED state
|
||||
//bool latest_uptime_flag = true; // Signal latest uptime
|
||||
bool pwm_present = false; // Any PWM channel configured with SetOption15 0
|
||||
bool i2c_flg = false; // I2C configured
|
||||
bool spi_flg = false; // SPI configured
|
||||
bool soft_spi_flg = false; // Software SPI configured
|
||||
bool ntp_force_sync = false; // Force NTP sync
|
||||
bool is_8285 = false; // Hardware device ESP8266EX (0) or ESP8285 (1)
|
||||
bool skip_light_fade; // Temporarily skip light fading
|
||||
bool restart_halt = false; // Do not restart but stay in wait loop
|
||||
myio my_module; // Active copy of Module GPIOs (17 x 8 bits)
|
||||
StateBitfield global_state; // Global states (currently Wifi and Mqtt) (8 bits)
|
||||
char my_version[33]; // Composed version string
|
||||
char my_image[33]; // Code image and/or commit
|
||||
char my_hostname[33]; // Composed Wifi hostname
|
||||
char mqtt_client[TOPSZ]; // Composed MQTT Clientname
|
||||
char mqtt_topic[TOPSZ]; // Composed MQTT topic
|
||||
char serial_in_buffer[INPUT_BUFFER_SIZE]; // Receive buffer
|
||||
char mqtt_data[MESSZ]; // MQTT publish buffer and web page ajax buffer
|
||||
char log_data[LOGSZ]; // Logging
|
||||
char web_log[WEB_LOG_SIZE] = {'\0'}; // Web log buffer
|
||||
#ifdef SUPPORT_IF_STATEMENT
|
||||
#include <LinkedList.h>
|
||||
LinkedList<String> backlog; // Command backlog implemented with LinkedList
|
||||
#define BACKLOG_EMPTY (backlog.size() == 0)
|
||||
#else
|
||||
uint8_t backlog_index = 0; // Command backlog index
|
||||
uint8_t backlog_pointer = 0; // Command backlog pointer
|
||||
String backlog[MAX_BACKLOG]; // Command backlog buffer
|
||||
#define BACKLOG_EMPTY (backlog_pointer == backlog_index)
|
||||
#define BACKLOG_EMPTY (TasmotaGlobal.backlog_pointer == TasmotaGlobal.backlog_index)
|
||||
#endif
|
||||
|
||||
/*********************************************************************************************\
|
||||
|
@ -194,8 +195,7 @@ void setup(void) {
|
|||
TasmotaGlobal.wifi_state_flag = WIFI_RESTART;
|
||||
TasmotaGlobal.tele_period = 9999;
|
||||
TasmotaGlobal.active_device = 1;
|
||||
|
||||
global_state.data = 0xF; // Init global state (wifi_down, mqtt_down) to solve possible network issues
|
||||
TasmotaGlobal.global_state.data = 0xF; // Init global state (wifi_down, mqtt_down) to solve possible network issues
|
||||
|
||||
RtcRebootLoad();
|
||||
if (!RtcRebootValid()) {
|
||||
|
@ -210,14 +210,14 @@ void setup(void) {
|
|||
|
||||
Serial.begin(TasmotaGlobal.baudrate);
|
||||
// Serial.setRxBufferSize(INPUT_BUFFER_SIZE); // Default is 256 chars
|
||||
seriallog_level = LOG_LEVEL_INFO; // Allow specific serial messages until config loaded
|
||||
TasmotaGlobal.seriallog_level = LOG_LEVEL_INFO; // Allow specific serial messages until config loaded
|
||||
|
||||
snprintf_P(my_version, sizeof(my_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
|
||||
snprintf_P(my_version, sizeof(my_version), PSTR("%s.%d"), my_version, VERSION & 0xff);
|
||||
snprintf_P(TasmotaGlobal.version, sizeof(TasmotaGlobal.version), PSTR("%s.%d"), TasmotaGlobal.version, VERSION & 0xff);
|
||||
}
|
||||
// Thehackbox inserts "release" or "commit number" before compiling using sed -i -e 's/PSTR("(%s)")/PSTR("(85cff52-%s)")/g' tasmota.ino
|
||||
snprintf_P(my_image, sizeof(my_image), PSTR("(%s)"), CODE_IMAGE_STR); // Results in (85cff52-tasmota) or (release-tasmota)
|
||||
snprintf_P(TasmotaGlobal.image_name, sizeof(TasmotaGlobal.image_name), PSTR("(%s)"), CODE_IMAGE_STR); // Results in (85cff52-tasmota) or (release-tasmota)
|
||||
|
||||
SettingsLoad();
|
||||
SettingsDelta();
|
||||
|
@ -229,11 +229,10 @@ void setup(void) {
|
|||
XdrvCall(FUNC_SETTINGS_OVERRIDE);
|
||||
}
|
||||
|
||||
// mdns_delayed_start = Settings.param[P_MDNS_DELAYED_START];
|
||||
seriallog_level = Settings.seriallog_level;
|
||||
TasmotaGlobal.seriallog_level = Settings.seriallog_level;
|
||||
TasmotaGlobal.seriallog_timer = SERIALLOG_TIMER;
|
||||
syslog_level = Settings.syslog_level;
|
||||
stop_flash_rotate = Settings.flag.stop_flash_rotate; // SetOption12 - Switch between dynamic or fixed slot flash save location
|
||||
TasmotaGlobal.syslog_level = Settings.syslog_level;
|
||||
TasmotaGlobal.stop_flash_rotate = Settings.flag.stop_flash_rotate; // SetOption12 - Switch between dynamic or fixed slot flash save location
|
||||
TasmotaGlobal.save_data_counter = Settings.save_data;
|
||||
TasmotaGlobal.sleep = Settings.sleep;
|
||||
#ifndef USE_EMULATION
|
||||
|
@ -276,13 +275,13 @@ void setup(void) {
|
|||
}
|
||||
}
|
||||
|
||||
Format(mqtt_client, SettingsText(SET_MQTT_CLIENT), sizeof(mqtt_client));
|
||||
Format(mqtt_topic, SettingsText(SET_MQTT_TOPIC), sizeof(mqtt_topic));
|
||||
Format(TasmotaGlobal.mqtt_client, SettingsText(SET_MQTT_CLIENT), sizeof(TasmotaGlobal.mqtt_client));
|
||||
Format(TasmotaGlobal.mqtt_topic, SettingsText(SET_MQTT_TOPIC), sizeof(TasmotaGlobal.mqtt_topic));
|
||||
if (strstr(SettingsText(SET_HOSTNAME), "%") != nullptr) {
|
||||
SettingsUpdateText(SET_HOSTNAME, WIFI_HOSTNAME);
|
||||
snprintf_P(my_hostname, sizeof(my_hostname)-1, SettingsText(SET_HOSTNAME), mqtt_topic, ESP_getChipId() & 0x1FFF);
|
||||
snprintf_P(TasmotaGlobal.hostname, sizeof(TasmotaGlobal.hostname)-1, SettingsText(SET_HOSTNAME), TasmotaGlobal.mqtt_topic, ESP_getChipId() & 0x1FFF);
|
||||
} else {
|
||||
snprintf_P(my_hostname, sizeof(my_hostname)-1, SettingsText(SET_HOSTNAME));
|
||||
snprintf_P(TasmotaGlobal.hostname, sizeof(TasmotaGlobal.hostname)-1, SettingsText(SET_HOSTNAME));
|
||||
}
|
||||
|
||||
GetEspHardwareType();
|
||||
|
@ -294,12 +293,12 @@ void setup(void) {
|
|||
|
||||
SetPowerOnState();
|
||||
|
||||
AddLog_P2(LOG_LEVEL_INFO, PSTR(D_PROJECT " %s %s " D_VERSION " %s%s-" ARDUINO_CORE_RELEASE), PROJECT, SettingsText(SET_DEVICENAME), my_version, my_image);
|
||||
AddLog_P2(LOG_LEVEL_INFO, PSTR(D_PROJECT " %s %s " D_VERSION " %s%s-" ARDUINO_CORE_RELEASE), PROJECT, SettingsText(SET_DEVICENAME), TasmotaGlobal.version, TasmotaGlobal.image_name);
|
||||
#ifdef FIRMWARE_MINIMAL
|
||||
AddLog_P2(LOG_LEVEL_INFO, PSTR(D_WARNING_MINIMAL_VERSION));
|
||||
#endif // FIRMWARE_MINIMAL
|
||||
|
||||
memcpy_P(log_data, VERSION_MARKER, 1); // Dummy for compiler saving VERSION_MARKER
|
||||
memcpy_P(TasmotaGlobal.log_data, VERSION_MARKER, 1); // Dummy for compiler saving VERSION_MARKER
|
||||
|
||||
RtcInit();
|
||||
|
||||
|
@ -318,8 +317,8 @@ void setup(void) {
|
|||
|
||||
void BacklogLoop(void) {
|
||||
if (TimeReached(TasmotaGlobal.backlog_delay)) {
|
||||
if (!BACKLOG_EMPTY && !backlog_mutex) {
|
||||
backlog_mutex = true;
|
||||
if (!BACKLOG_EMPTY && !TasmotaGlobal.backlog_mutex) {
|
||||
TasmotaGlobal.backlog_mutex = true;
|
||||
bool nodelay = false;
|
||||
bool nodelay_detected = false;
|
||||
String cmd;
|
||||
|
@ -327,10 +326,10 @@ void BacklogLoop(void) {
|
|||
#ifdef SUPPORT_IF_STATEMENT
|
||||
cmd = backlog.shift();
|
||||
#else
|
||||
cmd = backlog[backlog_pointer];
|
||||
backlog[backlog_pointer] = (const char*) nullptr; // Force deallocation of the String internal memory
|
||||
backlog_pointer++;
|
||||
if (backlog_pointer >= MAX_BACKLOG) { backlog_pointer = 0; }
|
||||
cmd = TasmotaGlobal.backlog[TasmotaGlobal.backlog_pointer];
|
||||
TasmotaGlobal.backlog[TasmotaGlobal.backlog_pointer] = (const char*) nullptr; // Force deallocation of the String internal memory
|
||||
TasmotaGlobal.backlog_pointer++;
|
||||
if (TasmotaGlobal.backlog_pointer >= MAX_BACKLOG) { TasmotaGlobal.backlog_pointer = 0; }
|
||||
#endif
|
||||
nodelay_detected = !strncasecmp_P(cmd.c_str(), PSTR(D_CMND_NODELAY), strlen(D_CMND_NODELAY));
|
||||
if (nodelay_detected) { nodelay = true; }
|
||||
|
@ -341,7 +340,7 @@ void BacklogLoop(void) {
|
|||
if (nodelay) {
|
||||
TasmotaGlobal.backlog_delay = 0; // Reset backlog_delay which has been set by ExecuteCommand (CommandHandler)
|
||||
}
|
||||
backlog_mutex = false;
|
||||
TasmotaGlobal.backlog_mutex = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -406,7 +405,7 @@ void loop(void) {
|
|||
XsnsCall(FUNC_EVERY_SECOND);
|
||||
}
|
||||
|
||||
if (!serial_local) { SerialInput(); }
|
||||
if (!TasmotaGlobal.serial_local) { SerialInput(); }
|
||||
|
||||
#ifdef USE_ARDUINO_OTA
|
||||
ArduinoOtaLoop();
|
||||
|
@ -421,7 +420,7 @@ void loop(void) {
|
|||
if (my_activity < (uint32_t)TasmotaGlobal.sleep) {
|
||||
SleepDelay((uint32_t)TasmotaGlobal.sleep - my_activity); // Provide time for background tasks like wifi
|
||||
} else {
|
||||
if (global_state.network_down) {
|
||||
if (TasmotaGlobal.global_state.network_down) {
|
||||
SleepDelay(my_activity /2); // If wifi down and my_activity > setoption36 then force loop delay to 1/3 of my_activity period
|
||||
}
|
||||
}
|
||||
|
|
|
@ -840,7 +840,7 @@ void ShowWebSource(uint32_t source)
|
|||
void ExecuteWebCommand(char* svalue, uint32_t source)
|
||||
{
|
||||
ShowWebSource(source);
|
||||
last_source = source;
|
||||
TasmotaGlobal.last_source = source;
|
||||
ExecuteCommand(svalue, SRC_IGNORE);
|
||||
}
|
||||
|
||||
|
@ -938,7 +938,7 @@ void StopWebserver(void)
|
|||
void WifiManagerBegin(bool reset_only)
|
||||
{
|
||||
// setup AP
|
||||
if (!global_state.wifi_down) {
|
||||
if (!TasmotaGlobal.global_state.wifi_down) {
|
||||
// WiFi.mode(WIFI_AP_STA);
|
||||
WifiSetMode(WIFI_AP_STA);
|
||||
AddLog_P(LOG_LEVEL_DEBUG, PSTR(D_LOG_WIFI D_WIFIMANAGER_SET_ACCESSPOINT_AND_STATION));
|
||||
|
@ -956,7 +956,7 @@ void WifiManagerBegin(bool reset_only)
|
|||
if ((channel < 1) || (channel > 13)) { channel = 1; }
|
||||
|
||||
// bool softAP(const char* ssid, const char* passphrase = NULL, int channel = 1, int ssid_hidden = 0, int max_connection = 4);
|
||||
WiFi.softAP(my_hostname, WIFI_AP_PASSPHRASE, channel, 0, 1);
|
||||
WiFi.softAP(TasmotaGlobal.hostname, WIFI_AP_PASSPHRASE, channel, 0, 1);
|
||||
delay(500); // Without delay I've seen the IP address blank
|
||||
/* Setup the DNS server redirecting all the domains to the apIP */
|
||||
DnsServer->setErrorReplyCode(DNSReplyCode::NoError);
|
||||
|
@ -1041,7 +1041,7 @@ void _WSContentSend(const String& content) // Low level sendContent for a
|
|||
#ifdef USE_DEBUG_DRIVER
|
||||
ShowFreeMem(PSTR("WSContentSend"));
|
||||
#endif
|
||||
DEBUG_CORE_LOG(PSTR("WEB: Chunk size %d/%d"), len, sizeof(mqtt_data));
|
||||
DEBUG_CORE_LOG(PSTR("WEB: Chunk size %d/%d"), len, sizeof(TasmotaGlobal.mqtt_data));
|
||||
}
|
||||
|
||||
void WSContentFlush(void)
|
||||
|
@ -1054,24 +1054,24 @@ void WSContentFlush(void)
|
|||
|
||||
void _WSContentSendBuffer(void)
|
||||
{
|
||||
int len = strlen(mqtt_data);
|
||||
int len = strlen(TasmotaGlobal.mqtt_data);
|
||||
|
||||
if (0 == len) { // No content
|
||||
return;
|
||||
}
|
||||
else if (len == sizeof(mqtt_data)) {
|
||||
else if (len == sizeof(TasmotaGlobal.mqtt_data)) {
|
||||
AddLog_P(LOG_LEVEL_INFO, PSTR("HTP: Content too large"));
|
||||
}
|
||||
else if (len < CHUNKED_BUFFER_SIZE) { // Append chunk buffer with small content
|
||||
Web.chunk_buffer += mqtt_data;
|
||||
Web.chunk_buffer += TasmotaGlobal.mqtt_data;
|
||||
len = Web.chunk_buffer.length();
|
||||
}
|
||||
|
||||
if (len >= CHUNKED_BUFFER_SIZE) { // Either content or chunk buffer is oversize
|
||||
WSContentFlush(); // Send chunk buffer before possible content oversize
|
||||
}
|
||||
if (strlen(mqtt_data) >= CHUNKED_BUFFER_SIZE) { // Content is oversize
|
||||
_WSContentSend(mqtt_data); // Send content
|
||||
if (strlen(TasmotaGlobal.mqtt_data) >= CHUNKED_BUFFER_SIZE) { // Content is oversize
|
||||
_WSContentSend(TasmotaGlobal.mqtt_data); // Send content
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1080,13 +1080,13 @@ void WSContentSend_P(const char* formatP, ...) // Content send snprintf_P ch
|
|||
// This uses char strings. Be aware of sending %% if % is needed
|
||||
va_list arg;
|
||||
va_start(arg, formatP);
|
||||
int len = vsnprintf_P(mqtt_data, sizeof(mqtt_data), formatP, arg);
|
||||
int len = vsnprintf_P(TasmotaGlobal.mqtt_data, sizeof(TasmotaGlobal.mqtt_data), formatP, arg);
|
||||
va_end(arg);
|
||||
|
||||
#ifdef DEBUG_TASMOTA_CORE
|
||||
if (len > (sizeof(mqtt_data) -1)) {
|
||||
mqtt_data[33] = '\0';
|
||||
DEBUG_CORE_LOG(PSTR("ERROR: WSContentSend_P size %d > mqtt_data size %d. Start of data [%s...]"), len, sizeof(mqtt_data), mqtt_data);
|
||||
if (len > (sizeof(TasmotaGlobal.mqtt_data) -1)) {
|
||||
TasmotaGlobal.mqtt_data[33] = '\0';
|
||||
DEBUG_CORE_LOG(PSTR("ERROR: WSContentSend_P size %d > mqtt_data size %d. Start of data [%s...]"), len, sizeof(TasmotaGlobal.mqtt_data), TasmotaGlobal.mqtt_data);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -1098,20 +1098,20 @@ void WSContentSend_PD(const char* formatP, ...) // Content send snprintf_P ch
|
|||
// This uses char strings. Be aware of sending %% if % is needed
|
||||
va_list arg;
|
||||
va_start(arg, formatP);
|
||||
int len = vsnprintf_P(mqtt_data, sizeof(mqtt_data), formatP, arg);
|
||||
int len = vsnprintf_P(TasmotaGlobal.mqtt_data, sizeof(TasmotaGlobal.mqtt_data), formatP, arg);
|
||||
va_end(arg);
|
||||
|
||||
#ifdef DEBUG_TASMOTA_CORE
|
||||
if (len > (sizeof(mqtt_data) -1)) {
|
||||
mqtt_data[33] = '\0';
|
||||
DEBUG_CORE_LOG(PSTR("ERROR: WSContentSend_PD size %d > mqtt_data size %d. Start of data [%s...]"), len, sizeof(mqtt_data), mqtt_data);
|
||||
if (len > (sizeof(TasmotaGlobal.mqtt_data) -1)) {
|
||||
TasmotaGlobal.mqtt_data[33] = '\0';
|
||||
DEBUG_CORE_LOG(PSTR("ERROR: WSContentSend_PD size %d > mqtt_data size %d. Start of data [%s...]"), len, sizeof(TasmotaGlobal.mqtt_data), TasmotaGlobal.mqtt_data);
|
||||
}
|
||||
#endif
|
||||
|
||||
if (D_DECIMAL_SEPARATOR[0] != '.') {
|
||||
for (uint32_t i = 0; i < len; i++) {
|
||||
if ('.' == mqtt_data[i]) {
|
||||
mqtt_data[i] = D_DECIMAL_SEPARATOR[0];
|
||||
if ('.' == TasmotaGlobal.mqtt_data[i]) {
|
||||
TasmotaGlobal.mqtt_data[i] = D_DECIMAL_SEPARATOR[0];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1162,13 +1162,13 @@ void WSContentSendStyle_P(const char* formatP, ...)
|
|||
// This uses char strings. Be aware of sending %% if % is needed
|
||||
va_list arg;
|
||||
va_start(arg, formatP);
|
||||
int len = vsnprintf_P(mqtt_data, sizeof(mqtt_data), formatP, arg);
|
||||
int len = vsnprintf_P(TasmotaGlobal.mqtt_data, sizeof(TasmotaGlobal.mqtt_data), formatP, arg);
|
||||
va_end(arg);
|
||||
|
||||
#ifdef DEBUG_TASMOTA_CORE
|
||||
if (len > (sizeof(mqtt_data) -1)) {
|
||||
mqtt_data[33] = '\0';
|
||||
DEBUG_CORE_LOG(PSTR("ERROR: WSContentSendStyle_P size %d > mqtt_data size %d. Start of data [%s...]"), len, sizeof(mqtt_data), mqtt_data);
|
||||
if (len > (sizeof(TasmotaGlobal.mqtt_data) -1)) {
|
||||
TasmotaGlobal.mqtt_data[33] = '\0';
|
||||
DEBUG_CORE_LOG(PSTR("ERROR: WSContentSendStyle_P size %d > mqtt_data size %d. Start of data [%s...]"), len, sizeof(TasmotaGlobal.mqtt_data), TasmotaGlobal.mqtt_data);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -1248,7 +1248,7 @@ void WSContentStop(void)
|
|||
WSContentSend_P(HTTP_COUNTER);
|
||||
}
|
||||
}
|
||||
WSContentSend_P(HTTP_END, my_version);
|
||||
WSContentSend_P(HTTP_END, TasmotaGlobal.version);
|
||||
WSContentEnd();
|
||||
}
|
||||
|
||||
|
@ -1360,12 +1360,12 @@ void HandleRoot(void)
|
|||
WSContentSendStyle();
|
||||
|
||||
WSContentSend_P(PSTR("<div id='l1' name='l1'></div>"));
|
||||
if (devices_present) {
|
||||
if (TasmotaGlobal.devices_present) {
|
||||
#ifdef USE_LIGHT
|
||||
if (light_type) {
|
||||
uint8_t light_subtype = light_type &7;
|
||||
if (TasmotaGlobal.light_type) {
|
||||
uint8_t light_subtype = TasmotaGlobal.light_type &7;
|
||||
if (!Settings.flag3.pwm_multi_channels) { // SetOption68 0 - Enable multi-channels PWM instead of Color PWM
|
||||
bool split_white = ((LST_RGBW <= light_subtype) && (devices_present > 1)); // Only on RGBW or RGBCW and SetOption37 128
|
||||
bool split_white = ((LST_RGBW <= light_subtype) && (TasmotaGlobal.devices_present > 1)); // Only on RGBW or RGBCW and SetOption37 128
|
||||
|
||||
if ((LST_COLDWARM == light_subtype) || ((LST_RGBCW == light_subtype) && !split_white)) {
|
||||
WebSliderColdWarm();
|
||||
|
@ -1439,7 +1439,7 @@ void HandleRoot(void)
|
|||
#endif // USE_LIGHT
|
||||
#ifdef USE_SHUTTER
|
||||
if (Settings.flag3.shutter_mode) { // SetOption80 - Enable shutter support
|
||||
for (uint32_t i = 0; i < shutters_present; i++) {
|
||||
for (uint32_t i = 0; i < TasmotaGlobal.shutters_present; i++) {
|
||||
WSContentSend_P(HTTP_MSG_SLIDER_SHUTTER, Settings.shutter_position[i], i+1);
|
||||
}
|
||||
}
|
||||
|
@ -1459,21 +1459,21 @@ void HandleRoot(void)
|
|||
}
|
||||
} else {
|
||||
#endif // USE_SONOFF_IFAN
|
||||
for (uint32_t idx = 1; idx <= devices_present; idx++) {
|
||||
for (uint32_t idx = 1; idx <= TasmotaGlobal.devices_present; idx++) {
|
||||
bool set_button = ((idx <= MAX_BUTTON_TEXT) && strlen(SettingsText(SET_BUTTON1 + idx -1)));
|
||||
#ifdef USE_SHUTTER
|
||||
int32_t ShutterWebButton;
|
||||
if (ShutterWebButton = IsShutterWebButton(idx)) {
|
||||
WSContentSend_P(HTTP_DEVICE_CONTROL, 100 / devices_present, idx,
|
||||
WSContentSend_P(HTTP_DEVICE_CONTROL, 100 / TasmotaGlobal.devices_present, idx,
|
||||
(set_button) ? SettingsText(SET_BUTTON1 + idx -1) : ((Settings.shutter_options[abs(ShutterWebButton)-1] & 2) /* is locked */ ? "-" : ((Settings.shutter_options[abs(ShutterWebButton)-1] & 8) /* invert web buttons */ ? ((ShutterWebButton>0) ? "▼" : "▲") : ((ShutterWebButton>0) ? "▲" : "▼"))),
|
||||
"");
|
||||
continue;
|
||||
}
|
||||
#endif // USE_SHUTTER
|
||||
snprintf_P(stemp, sizeof(stemp), PSTR(" %d"), idx);
|
||||
WSContentSend_P(HTTP_DEVICE_CONTROL, 100 / devices_present, idx,
|
||||
(set_button) ? SettingsText(SET_BUTTON1 + idx -1) : (devices_present < 5) ? D_BUTTON_TOGGLE : "",
|
||||
(set_button) ? "" : (devices_present > 1) ? stemp : "");
|
||||
WSContentSend_P(HTTP_DEVICE_CONTROL, 100 / TasmotaGlobal.devices_present, idx,
|
||||
(set_button) ? SettingsText(SET_BUTTON1 + idx -1) : (TasmotaGlobal.devices_present < 5) ? D_BUTTON_TOGGLE : "",
|
||||
(set_button) ? "" : (TasmotaGlobal.devices_present > 1) ? stemp : "");
|
||||
}
|
||||
#ifdef USE_SONOFF_IFAN
|
||||
}
|
||||
|
@ -1487,13 +1487,13 @@ void HandleRoot(void)
|
|||
WSContentSend_P(HTTP_TABLE100);
|
||||
WSContentSend_P(PSTR("<tr><div></div>"));
|
||||
snprintf_P(stemp, sizeof(stemp), PSTR("" D_JSON_IRHVAC_MODE ""));
|
||||
WSContentSend_P(HTTP_DEVICE_CONTROL, 26, devices_present + 1,
|
||||
(strlen(SettingsText(SET_BUTTON1 + devices_present))) ? SettingsText(SET_BUTTON1 + devices_present) : stemp, "");
|
||||
WSContentSend_P(HTTP_DEVICE_CONTROL, 26, TasmotaGlobal.devices_present + 1,
|
||||
(strlen(SettingsText(SET_BUTTON1 + TasmotaGlobal.devices_present))) ? SettingsText(SET_BUTTON1 + TasmotaGlobal.devices_present) : stemp, "");
|
||||
WSContentSend_P(PSTR("</tr></table>"));
|
||||
modeset = 1;
|
||||
}
|
||||
if (IsTuyaFanCtrl()) {
|
||||
uint8_t device = devices_present + modeset;
|
||||
uint8_t device = TasmotaGlobal.devices_present + modeset;
|
||||
WSContentSend_P(HTTP_TABLE100);
|
||||
WSContentSend_P(PSTR("<tr><div></div>"));
|
||||
for (uint32_t i = device + 1; i <= (TuyaFanSpeeds() + device) + 1; i++) {
|
||||
|
@ -1506,7 +1506,7 @@ void HandleRoot(void)
|
|||
}
|
||||
#endif // USE_TUYA_MCU
|
||||
#ifdef USE_SONOFF_RF
|
||||
if (SONOFF_BRIDGE == my_module_type) {
|
||||
if (SONOFF_BRIDGE == TasmotaGlobal.module_type) {
|
||||
WSContentSend_P(HTTP_TABLE100);
|
||||
WSContentSend_P(PSTR("<tr>"));
|
||||
uint32_t idx = 0;
|
||||
|
@ -1578,10 +1578,10 @@ bool HandleRootStatusRefresh(void)
|
|||
#ifdef USE_TUYA_MCU
|
||||
if (IsModuleTuya()) {
|
||||
uint8_t FuncIdx = 0;
|
||||
if (device <= devices_present) {
|
||||
if (device <= TasmotaGlobal.devices_present) {
|
||||
ExecuteCommandPower(device, POWER_TOGGLE, SRC_IGNORE);
|
||||
} else {
|
||||
if (AsModuleTuyaMS() && device == devices_present + 1) {
|
||||
if (AsModuleTuyaMS() && device == TasmotaGlobal.devices_present + 1) {
|
||||
uint8_t dpId = TuyaGetDpId(TUYA_MCU_FUNC_MODESET);
|
||||
snprintf_P(svalue, sizeof(svalue), PSTR("Tuyasend4 %d,%d"), dpId, !TuyaModeSet());
|
||||
ExecuteCommand(svalue, SRC_WEBGUI);
|
||||
|
@ -1593,9 +1593,9 @@ bool HandleRootStatusRefresh(void)
|
|||
dpId = TuyaGetDpId(TUYA_MCU_FUNC_FAN3 + i);
|
||||
}
|
||||
}
|
||||
if ((AsModuleTuyaMS() && device != devices_present + 1) || !AsModuleTuyaMS()) {
|
||||
if ((AsModuleTuyaMS() && device != TasmotaGlobal.devices_present + 1) || !AsModuleTuyaMS()) {
|
||||
if (AsModuleTuyaMS()) {FuncIdx = 1;}
|
||||
snprintf_P(svalue, sizeof(svalue), PSTR("Tuyasend2 %d,%d"), dpId, (device - (devices_present + FuncIdx) - 1));
|
||||
snprintf_P(svalue, sizeof(svalue), PSTR("Tuyasend2 %d,%d"), dpId, (device - (TasmotaGlobal.devices_present + FuncIdx) - 1));
|
||||
ExecuteCommand(svalue, SRC_WEBGUI);
|
||||
}
|
||||
}
|
||||
|
@ -1632,7 +1632,7 @@ bool HandleRootStatusRefresh(void)
|
|||
ExecuteWebCommand(svalue, SRC_WEBGUI);
|
||||
}
|
||||
uint32_t light_device = LightDevice(); // Channel number offset
|
||||
uint32_t pwm_channels = (light_type & 7) > LST_MAX ? LST_MAX : (light_type & 7);
|
||||
uint32_t pwm_channels = (TasmotaGlobal.light_type & 7) > LST_MAX ? LST_MAX : (TasmotaGlobal.light_type & 7);
|
||||
for (uint32_t j = 0; j < pwm_channels; j++) {
|
||||
snprintf_P(webindex, sizeof(webindex), PSTR("e%d"), j +1);
|
||||
WebGetArg(webindex, tmp, sizeof(tmp)); // 0 - 100 percent
|
||||
|
@ -1658,7 +1658,7 @@ bool HandleRootStatusRefresh(void)
|
|||
}
|
||||
#endif // USE_LIGHT
|
||||
#ifdef USE_SHUTTER
|
||||
for (uint32_t j = 1; j <= shutters_present; j++) {
|
||||
for (uint32_t j = 1; j <= TasmotaGlobal.shutters_present; j++) {
|
||||
snprintf_P(webindex, sizeof(webindex), PSTR("u%d"), j);
|
||||
WebGetArg(webindex, tmp, sizeof(tmp)); // 0 - 100 percent
|
||||
if (strlen(tmp)) {
|
||||
|
@ -1681,9 +1681,9 @@ bool HandleRootStatusRefresh(void)
|
|||
|
||||
WSContentSend_P(PSTR("</table>"));
|
||||
|
||||
if (devices_present) {
|
||||
if (TasmotaGlobal.devices_present) {
|
||||
WSContentSend_P(PSTR("{t}<tr>"));
|
||||
uint32_t fsize = (devices_present < 5) ? 70 - (devices_present * 8) : 32;
|
||||
uint32_t fsize = (TasmotaGlobal.devices_present < 5) ? 70 - (TasmotaGlobal.devices_present * 8) : 32;
|
||||
#ifdef USE_SONOFF_IFAN
|
||||
if (IsModuleIfan()) {
|
||||
WSContentSend_P(HTTP_DEVICE_STATE, 36, (bitRead(TasmotaGlobal.power, 0)) ? "bold" : "normal", 54, GetStateText(bitRead(TasmotaGlobal.power, 0)));
|
||||
|
@ -1692,9 +1692,9 @@ bool HandleRootStatusRefresh(void)
|
|||
WSContentSend_P(HTTP_DEVICE_STATE, 64, (fanspeed) ? "bold" : "normal", 54, (fanspeed) ? svalue : GetStateText(0));
|
||||
} else {
|
||||
#endif // USE_SONOFF_IFAN
|
||||
for (uint32_t idx = 1; idx <= devices_present; idx++) {
|
||||
for (uint32_t idx = 1; idx <= TasmotaGlobal.devices_present; idx++) {
|
||||
snprintf_P(svalue, sizeof(svalue), PSTR("%d"), bitRead(TasmotaGlobal.power, idx -1));
|
||||
WSContentSend_P(HTTP_DEVICE_STATE, 100 / devices_present, (bitRead(TasmotaGlobal.power, idx -1)) ? "bold" : "normal", fsize, (devices_present < 5) ? GetStateText(bitRead(TasmotaGlobal.power, idx -1)) : svalue);
|
||||
WSContentSend_P(HTTP_DEVICE_STATE, 100 / TasmotaGlobal.devices_present, (bitRead(TasmotaGlobal.power, idx -1)) ? "bold" : "normal", fsize, (TasmotaGlobal.devices_present < 5) ? GetStateText(bitRead(TasmotaGlobal.power, idx -1)) : svalue);
|
||||
}
|
||||
#ifdef USE_SONOFF_IFAN
|
||||
}
|
||||
|
@ -1997,7 +1997,7 @@ void HandleModuleConfiguration(void)
|
|||
|
||||
for (uint32_t i = 0; i < ARRAY_SIZE(cmodule.io); i++) {
|
||||
if (ValidGPIO(i, cmodule.io[i])) {
|
||||
WSContentSend_P(PSTR("sk(%d,%d);"), my_module.io[i], i); // g0 - g17
|
||||
WSContentSend_P(PSTR("sk(%d,%d);"), TasmotaGlobal.my_module.io[i], i); // g0 - g17
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2016,7 +2016,7 @@ void HandleModuleConfiguration(void)
|
|||
if (ValidGPIO(i, cmodule.io[i])) {
|
||||
snprintf_P(stemp, 3, PINS_WEMOS +i*2);
|
||||
WSContentSend_P(PSTR("<tr><td style='width:116px'>%s <b>" D_GPIO "%d</b></td><td style='width:150px'><select id='g%d' onchange='ot(%d,this.value)'></select></td>"),
|
||||
(WEMOS==my_module_type)?stemp:"", i, i, i);
|
||||
(WEMOS==TasmotaGlobal.module_type)?stemp:"", i, i, i);
|
||||
WSContentSend_P(PSTR("<td style='width:50px'><select id='h%d'></select></td></tr>"), i);
|
||||
}
|
||||
}
|
||||
|
@ -2281,13 +2281,13 @@ void HandleOtherConfiguration(void)
|
|||
WSContentSendStyle();
|
||||
|
||||
TemplateJson();
|
||||
char stemp[strlen(mqtt_data) +1];
|
||||
strlcpy(stemp, mqtt_data, sizeof(stemp)); // Get JSON template
|
||||
char stemp[strlen(TasmotaGlobal.mqtt_data) +1];
|
||||
strlcpy(stemp, TasmotaGlobal.mqtt_data, sizeof(stemp)); // Get JSON template
|
||||
WSContentSend_P(HTTP_FORM_OTHER, stemp, (USER_MODULE == Settings.module) ? " checked disabled" : "",
|
||||
(Settings.flag.mqtt_enabled) ? " checked" : "", // SetOption3 - Enable MQTT
|
||||
SettingsText(SET_FRIENDLYNAME1), SettingsText(SET_DEVICENAME));
|
||||
|
||||
uint32_t maxfn = (devices_present > MAX_FRIENDLYNAMES) ? MAX_FRIENDLYNAMES : (!devices_present) ? 1 : devices_present;
|
||||
uint32_t maxfn = (TasmotaGlobal.devices_present > MAX_FRIENDLYNAMES) ? MAX_FRIENDLYNAMES : (!TasmotaGlobal.devices_present) ? 1 : TasmotaGlobal.devices_present;
|
||||
#ifdef USE_SONOFF_IFAN
|
||||
if (IsModuleIfan()) { maxfn = 1; }
|
||||
#endif // USE_SONOFF_IFAN
|
||||
|
@ -2382,10 +2382,10 @@ void HandleBackupConfiguration(void)
|
|||
char attachment[TOPSZ];
|
||||
|
||||
// char friendlyname[TOPSZ];
|
||||
// snprintf_P(attachment, sizeof(attachment), PSTR("attachment; filename=Config_%s_%s.dmp"), NoAlNumToUnderscore(friendlyname, SettingsText(SET_FRIENDLYNAME1)), my_version);
|
||||
// snprintf_P(attachment, sizeof(attachment), PSTR("attachment; filename=Config_%s_%s.dmp"), NoAlNumToUnderscore(friendlyname, SettingsText(SET_FRIENDLYNAME1)), TasmotaGlobal.version);
|
||||
|
||||
char hostname[sizeof(my_hostname)];
|
||||
snprintf_P(attachment, sizeof(attachment), PSTR("attachment; filename=Config_%s_%s.dmp"), NoAlNumToUnderscore(hostname, my_hostname), my_version);
|
||||
char hostname[sizeof(TasmotaGlobal.hostname)];
|
||||
snprintf_P(attachment, sizeof(attachment), PSTR("attachment; filename=Config_%s_%s.dmp"), NoAlNumToUnderscore(hostname, TasmotaGlobal.hostname), TasmotaGlobal.version);
|
||||
|
||||
Webserver->sendHeader(F("Content-Disposition"), attachment);
|
||||
|
||||
|
@ -2467,7 +2467,7 @@ void HandleInformation(void)
|
|||
// }2 = </th><td>
|
||||
WSContentSend_P(HTTP_SCRIPT_INFO_BEGIN);
|
||||
WSContentSend_P(PSTR("<table style='width:100%%'><tr><th>"));
|
||||
WSContentSend_P(PSTR(D_PROGRAM_VERSION "}2%s%s"), my_version, my_image);
|
||||
WSContentSend_P(PSTR(D_PROGRAM_VERSION "}2%s%s"), TasmotaGlobal.version, TasmotaGlobal.image_name);
|
||||
WSContentSend_P(PSTR("}1" D_BUILD_DATE_AND_TIME "}2%s"), GetBuildDateAndTime().c_str());
|
||||
WSContentSend_P(PSTR("}1" D_CORE_AND_SDK_VERSION "}2" ARDUINO_CORE_RELEASE "/%s"), ESP.getSdkVersion());
|
||||
WSContentSend_P(PSTR("}1" D_UPTIME "}2%s"), GetUptime().c_str());
|
||||
|
@ -2478,7 +2478,7 @@ void HandleInformation(void)
|
|||
#endif
|
||||
WSContentSend_P(PSTR("}1" D_BOOT_COUNT "}2%d"), Settings.bootcount);
|
||||
WSContentSend_P(PSTR("}1" D_RESTART_REASON "}2%s"), GetResetReason().c_str());
|
||||
uint32_t maxfn = (devices_present > MAX_FRIENDLYNAMES) ? MAX_FRIENDLYNAMES : devices_present;
|
||||
uint32_t maxfn = (TasmotaGlobal.devices_present > MAX_FRIENDLYNAMES) ? MAX_FRIENDLYNAMES : TasmotaGlobal.devices_present;
|
||||
#ifdef USE_SONOFF_IFAN
|
||||
if (IsModuleIfan()) { maxfn = 1; }
|
||||
#endif // USE_SONOFF_IFAN
|
||||
|
@ -2499,7 +2499,7 @@ void HandleInformation(void)
|
|||
if (Settings.flag4.network_wifi) {
|
||||
int32_t rssi = WiFi.RSSI();
|
||||
WSContentSend_P(PSTR("}1" D_AP "%d " D_SSID " (" D_RSSI ")}2%s (%d%%, %d dBm)"), Settings.sta_active +1, HtmlEscape(SettingsText(SET_STASSID1 + Settings.sta_active)).c_str(), WifiGetRssiAsQuality(rssi), rssi);
|
||||
WSContentSend_P(PSTR("}1" D_HOSTNAME "}2%s%s"), my_hostname, (Mdns.begun) ? ".local" : "");
|
||||
WSContentSend_P(PSTR("}1" D_HOSTNAME "}2%s%s"), TasmotaGlobal.hostname, (Mdns.begun) ? ".local" : "");
|
||||
#if LWIP_IPV6
|
||||
String ipv6_addr = WifiGetIPv6();
|
||||
if (ipv6_addr != "") {
|
||||
|
@ -2512,7 +2512,7 @@ void HandleInformation(void)
|
|||
WSContentSend_P(PSTR("}1<hr/>}2<hr/>"));
|
||||
}
|
||||
}
|
||||
if (!global_state.network_down) {
|
||||
if (!TasmotaGlobal.global_state.network_down) {
|
||||
WSContentSend_P(PSTR("}1" D_GATEWAY "}2%s"), IPAddress(Settings.ip_address[1]).toString().c_str());
|
||||
WSContentSend_P(PSTR("}1" D_SUBNET_MASK "}2%s"), IPAddress(Settings.ip_address[2]).toString().c_str());
|
||||
WSContentSend_P(PSTR("}1" D_DNS_SERVER "}2%s"), IPAddress(Settings.ip_address[3]).toString().c_str());
|
||||
|
@ -2531,7 +2531,7 @@ void HandleInformation(void)
|
|||
WSContentSend_P(PSTR("}1" D_MQTT_TLS_ENABLE "}2%s"), Settings.flag4.mqtt_tls ? PSTR(D_ENABLED) : PSTR(D_DISABLED));
|
||||
#endif // USE_MQTT_TLS
|
||||
WSContentSend_P(PSTR("}1" D_MQTT_USER "}2%s"), SettingsText(SET_MQTT_USER));
|
||||
WSContentSend_P(PSTR("}1" D_MQTT_CLIENT "}2%s"), mqtt_client);
|
||||
WSContentSend_P(PSTR("}1" D_MQTT_CLIENT "}2%s"), TasmotaGlobal.mqtt_client);
|
||||
WSContentSend_P(PSTR("}1" D_MQTT_TOPIC "}2%s"), SettingsText(SET_MQTT_TOPIC));
|
||||
uint32_t real_index = SET_MQTT_GRP_TOPIC;
|
||||
for (uint32_t i = 0; i < MAX_GROUP_TOPICS; i++) {
|
||||
|
@ -2540,7 +2540,7 @@ void HandleInformation(void)
|
|||
WSContentSend_P(PSTR("}1" D_MQTT_GROUP_TOPIC " %d}2%s"), 1 +i, GetGroupTopic_P(stopic, "", real_index +i));
|
||||
}
|
||||
}
|
||||
WSContentSend_P(PSTR("}1" D_MQTT_FULL_TOPIC "}2%s"), GetTopic_P(stopic, CMND, mqtt_topic, ""));
|
||||
WSContentSend_P(PSTR("}1" D_MQTT_FULL_TOPIC "}2%s"), GetTopic_P(stopic, CMND, TasmotaGlobal.mqtt_topic, ""));
|
||||
WSContentSend_P(PSTR("}1" D_MQTT " " D_FALLBACK_TOPIC "}2%s"), GetFallbackTopic_P(stopic, ""));
|
||||
WSContentSend_P(PSTR("}1" D_MQTT_NO_RETAIN "}2%s"), Settings.flag4.mqtt_no_retain ? PSTR(D_ENABLED) : PSTR(D_DISABLED));
|
||||
} else {
|
||||
|
@ -2694,7 +2694,7 @@ void HandleUploadDone(void)
|
|||
}
|
||||
WSContentSend_P(error);
|
||||
DEBUG_CORE_LOG(PSTR("UPL: %s"), error);
|
||||
stop_flash_rotate = Settings.flag.stop_flash_rotate; // SetOption12 - Switch between dynamic or fixed slot flash save location
|
||||
TasmotaGlobal.stop_flash_rotate = Settings.flag.stop_flash_rotate; // SetOption12 - Switch between dynamic or fixed slot flash save location
|
||||
} else {
|
||||
WSContentSend_P(PSTR("%06x'>" D_SUCCESSFUL "</font></b><br>"), WebColor(COL_TEXT_SUCCESS));
|
||||
TasmotaGlobal.restart_flag = 2; // Always restart to re-enable disabled features during update
|
||||
|
@ -2724,7 +2724,7 @@ void HandleUploadDone(void)
|
|||
void HandleUploadLoop(void)
|
||||
{
|
||||
// Based on ESP8266HTTPUpdateServer.cpp uses ESP8266WebServer Parsing.cpp and Cores Updater.cpp (Update)
|
||||
bool _serialoutput = (LOG_LEVEL_DEBUG <= seriallog_level);
|
||||
bool _serialoutput = (LOG_LEVEL_DEBUG <= TasmotaGlobal.seriallog_level);
|
||||
|
||||
if (HTTP_USER == Web.state) { return; }
|
||||
if (Web.upload_error) {
|
||||
|
@ -2786,7 +2786,7 @@ void HandleUploadLoop(void)
|
|||
else {
|
||||
#if defined(USE_ZIGBEE) && defined(USE_ZIGBEE_EZSP)
|
||||
#ifdef ESP8266
|
||||
if ((SONOFF_ZB_BRIDGE == my_module_type) && (upload.buf[0] == 0xEB)) { // Check if this is a Zigbee bridge FW file
|
||||
if ((SONOFF_ZB_BRIDGE == TasmotaGlobal.module_type) && (upload.buf[0] == 0xEB)) { // Check if this is a Zigbee bridge FW file
|
||||
#else // ESP32
|
||||
if (PinUsed(GPIO_ZIGBEE_RX) && PinUsed(GPIO_ZIGBEE_TX) && (upload.buf[0] == 0xEB)) { // Check if this is a Zigbee bridge FW file
|
||||
#endif // ESP8266 or ESP32
|
||||
|
@ -2798,7 +2798,7 @@ void HandleUploadLoop(void)
|
|||
} else
|
||||
#endif // USE_ZIGBEE and USE_ZIGBEE_EZSP
|
||||
#ifdef USE_RF_FLASH
|
||||
if ((SONOFF_BRIDGE == my_module_type) && (upload.buf[0] == ':')) { // Check if this is a RF bridge FW file
|
||||
if ((SONOFF_BRIDGE == TasmotaGlobal.module_type) && (upload.buf[0] == ':')) { // Check if this is a RF bridge FW file
|
||||
Update.end(); // End esp8266 update session
|
||||
Web.upload_file_type = UPL_EFM8BB1;
|
||||
|
||||
|
@ -3046,7 +3046,7 @@ void HandleHttpCommand(void)
|
|||
char* JSON = (char*)memchr(tmp, '{', len);
|
||||
if (JSON) { // Is it a JSON message (and not only [15:26:08 MQT: stat/wemos5/POWER = O])
|
||||
size_t JSONlen = len - (JSON - tmp);
|
||||
if (JSONlen > sizeof(mqtt_data)) { JSONlen = sizeof(mqtt_data); }
|
||||
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);
|
||||
|
@ -3119,7 +3119,7 @@ void HandleConsoleRefresh(void)
|
|||
size_t len;
|
||||
GetLog(counter, &tmp, &len);
|
||||
if (len) {
|
||||
if (len > sizeof(mqtt_data) -2) { len = sizeof(mqtt_data); }
|
||||
if (len > sizeof(TasmotaGlobal.mqtt_data) -2) { len = sizeof(TasmotaGlobal.mqtt_data); }
|
||||
char stemp[len +1];
|
||||
strlcpy(stemp, tmp, len);
|
||||
WSContentSend_P(PSTR("%s%s"), (cflg) ? "\n" : "", stemp);
|
||||
|
@ -3264,11 +3264,11 @@ int WebSend(char *buffer)
|
|||
while (text != '\0') {
|
||||
text = *read++;
|
||||
if (text > 31) { // Remove control characters like linefeed
|
||||
mqtt_data[j++] = text;
|
||||
if (j == sizeof(mqtt_data) -2) { break; }
|
||||
TasmotaGlobal.mqtt_data[j++] = text;
|
||||
if (j == sizeof(TasmotaGlobal.mqtt_data) -2) { break; }
|
||||
}
|
||||
}
|
||||
mqtt_data[j] = '\0';
|
||||
TasmotaGlobal.mqtt_data[j] = '\0';
|
||||
MqttPublishPrefixTopic_P(RESULT_OR_STAT, PSTR(D_CMND_WEBSEND));
|
||||
#ifdef USE_SCRIPT
|
||||
extern uint8_t tasm_cmd_activ;
|
||||
|
|
|
@ -215,7 +215,7 @@ bool MqttPublishLib(const char* topic, bool retained)
|
|||
}
|
||||
}
|
||||
|
||||
bool result = MqttClient.publish(topic, mqtt_data, retained);
|
||||
bool result = MqttClient.publish(topic, TasmotaGlobal.mqtt_data, retained);
|
||||
yield(); // #3313
|
||||
return result;
|
||||
}
|
||||
|
@ -252,7 +252,7 @@ void MqttDataHandler(char* mqtt_topic, uint8_t* mqtt_data, unsigned int data_len
|
|||
memcpy(data, mqtt_data, sizeof(data));
|
||||
|
||||
// AddLog_P2(LOG_LEVEL_DEBUG_MORE, PSTR(D_LOG_MQTT D_DATA_SIZE " %d, \"%s %s\""), data_len, topic, data);
|
||||
// if (LOG_LEVEL_DEBUG_MORE <= seriallog_level) { Serial.println(data); }
|
||||
// if (LOG_LEVEL_DEBUG_MORE <= TasmotaGlobal.seriallog_level) { Serial.println(data); }
|
||||
MqttDumpData(topic, data, data_len); // Use a function to save stack space used by dump_data
|
||||
|
||||
// MQTT pre-processing
|
||||
|
@ -288,16 +288,16 @@ void MqttUnsubscribe(const char *topic)
|
|||
|
||||
void MqttPublishLogging(const char *mxtime)
|
||||
{
|
||||
char saved_mqtt_data[strlen(mqtt_data) +1];
|
||||
memcpy(saved_mqtt_data, mqtt_data, sizeof(saved_mqtt_data));
|
||||
char saved_mqtt_data[strlen(TasmotaGlobal.mqtt_data) +1];
|
||||
memcpy(saved_mqtt_data, TasmotaGlobal.mqtt_data, sizeof(saved_mqtt_data));
|
||||
|
||||
// ResponseTime_P(PSTR(",\"Log\":{\"%s\"}}"), log_data); // Will fail as some messages contain JSON
|
||||
Response_P(PSTR("%s%s"), mxtime, log_data); // No JSON and ugly!!
|
||||
// ResponseTime_P(PSTR(",\"Log\":{\"%s\"}}"), TasmotaGlobal.log_data); // Will fail as some messages contain JSON
|
||||
Response_P(PSTR("%s%s"), mxtime, TasmotaGlobal.log_data); // No JSON and ugly!!
|
||||
char stopic[TOPSZ];
|
||||
GetTopic_P(stopic, STAT, mqtt_topic, PSTR("LOGGING"));
|
||||
GetTopic_P(stopic, STAT, TasmotaGlobal.mqtt_topic, PSTR("LOGGING"));
|
||||
MqttPublishLib(stopic, false);
|
||||
|
||||
memcpy(mqtt_data, saved_mqtt_data, sizeof(saved_mqtt_data));
|
||||
memcpy(TasmotaGlobal.mqtt_data, saved_mqtt_data, sizeof(saved_mqtt_data));
|
||||
}
|
||||
|
||||
void MqttPublish(const char* topic, bool retained)
|
||||
|
@ -324,12 +324,12 @@ void MqttPublish(const char* topic, bool retained)
|
|||
}
|
||||
}
|
||||
|
||||
snprintf_P(log_data, sizeof(log_data), PSTR("%s%s = %s"), slog_type, (Settings.flag.mqtt_enabled) ? topic : strrchr(topic,'/')+1, mqtt_data); // SetOption3 - Enable MQTT
|
||||
if (strlen(log_data) >= (sizeof(log_data) - strlen(sretained) -1)) {
|
||||
log_data[sizeof(log_data) - strlen(sretained) -5] = '\0';
|
||||
snprintf_P(log_data, sizeof(log_data), PSTR("%s ..."), log_data);
|
||||
snprintf_P(TasmotaGlobal.log_data, sizeof(TasmotaGlobal.log_data), PSTR("%s%s = %s"), slog_type, (Settings.flag.mqtt_enabled) ? topic : strrchr(topic,'/')+1, TasmotaGlobal.mqtt_data); // SetOption3 - Enable MQTT
|
||||
if (strlen(TasmotaGlobal.log_data) >= (sizeof(TasmotaGlobal.log_data) - strlen(sretained) -1)) {
|
||||
TasmotaGlobal.log_data[sizeof(TasmotaGlobal.log_data) - strlen(sretained) -5] = '\0';
|
||||
snprintf_P(TasmotaGlobal.log_data, sizeof(TasmotaGlobal.log_data), PSTR("%s ..."), TasmotaGlobal.log_data);
|
||||
}
|
||||
snprintf_P(log_data, sizeof(log_data), PSTR("%s%s"), log_data, sretained);
|
||||
snprintf_P(TasmotaGlobal.log_data, sizeof(TasmotaGlobal.log_data), PSTR("%s%s"), TasmotaGlobal.log_data, sretained);
|
||||
AddLog(LOG_LEVEL_INFO);
|
||||
|
||||
if (Settings.ledstate &0x04) {
|
||||
|
@ -359,7 +359,7 @@ void MqttPublishPrefixTopic_P(uint32_t prefix, const char* subtopic, bool retain
|
|||
romram[i] = toupper(romram[i]);
|
||||
}
|
||||
prefix &= 3;
|
||||
GetTopic_P(stopic, prefix, mqtt_topic, romram);
|
||||
GetTopic_P(stopic, prefix, TasmotaGlobal.mqtt_topic, romram);
|
||||
MqttPublish(stopic, retained);
|
||||
|
||||
#if defined(USE_MQTT_AWS_IOT) || defined(USE_MQTT_AWS_IOT_LIGHT)
|
||||
|
@ -380,13 +380,13 @@ void MqttPublishPrefixTopic_P(uint32_t prefix, const char* subtopic, bool retain
|
|||
snprintf_P(romram, sizeof(romram), PSTR("$aws/things/%s/shadow/update"), topic2);
|
||||
|
||||
// copy buffer
|
||||
char *mqtt_save = (char*) malloc(strlen(mqtt_data)+1);
|
||||
char *mqtt_save = (char*) malloc(strlen(TasmotaGlobal.mqtt_data)+1);
|
||||
if (!mqtt_save) { return; } // abort
|
||||
strcpy(mqtt_save, mqtt_data);
|
||||
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"state\":{\"reported\":%s}}"), mqtt_save);
|
||||
strcpy(mqtt_save, TasmotaGlobal.mqtt_data);
|
||||
snprintf_P(TasmotaGlobal.mqtt_data, sizeof(TasmotaGlobal.mqtt_data), PSTR("{\"state\":{\"reported\":%s}}"), mqtt_save);
|
||||
free(mqtt_save);
|
||||
|
||||
bool result = MqttClient.publish(romram, mqtt_data, false);
|
||||
bool result = MqttClient.publish(romram, TasmotaGlobal.mqtt_data, false);
|
||||
AddLog_P2(LOG_LEVEL_DEBUG, PSTR(D_LOG_MQTT "Updated shadow: %s"), romram);
|
||||
yield(); // #3313
|
||||
}
|
||||
|
@ -419,7 +419,7 @@ void MqttPublishPowerState(uint32_t device)
|
|||
char stopic[TOPSZ];
|
||||
char scommand[33];
|
||||
|
||||
if ((device < 1) || (device > devices_present)) { device = 1; }
|
||||
if ((device < 1) || (device > TasmotaGlobal.devices_present)) { device = 1; }
|
||||
|
||||
#ifdef USE_SONOFF_IFAN
|
||||
if (IsModuleIfan() && (device > 1)) {
|
||||
|
@ -428,19 +428,19 @@ void MqttPublishPowerState(uint32_t device)
|
|||
DomoticzUpdateFanState(); // RC Button feedback
|
||||
#endif // USE_DOMOTICZ
|
||||
snprintf_P(scommand, sizeof(scommand), PSTR(D_CMND_FANSPEED));
|
||||
GetTopic_P(stopic, STAT, mqtt_topic, (Settings.flag.mqtt_response) ? scommand : S_RSLT_RESULT); // SetOption4 - Switch between MQTT RESULT or COMMAND
|
||||
GetTopic_P(stopic, STAT, TasmotaGlobal.mqtt_topic, (Settings.flag.mqtt_response) ? scommand : S_RSLT_RESULT); // SetOption4 - Switch between MQTT RESULT or COMMAND
|
||||
Response_P(S_JSON_COMMAND_NVALUE, scommand, GetFanspeed());
|
||||
MqttPublish(stopic);
|
||||
}
|
||||
} else {
|
||||
#endif // USE_SONOFF_IFAN
|
||||
GetPowerDevice(scommand, device, sizeof(scommand), Settings.flag.device_index_enable); // SetOption26 - Switch between POWER or POWER1
|
||||
GetTopic_P(stopic, STAT, mqtt_topic, (Settings.flag.mqtt_response) ? scommand : S_RSLT_RESULT); // SetOption4 - Switch between MQTT RESULT or COMMAND
|
||||
GetTopic_P(stopic, STAT, TasmotaGlobal.mqtt_topic, (Settings.flag.mqtt_response) ? scommand : S_RSLT_RESULT); // SetOption4 - Switch between MQTT RESULT or COMMAND
|
||||
Response_P(S_JSON_COMMAND_SVALUE, scommand, GetStateText(bitRead(TasmotaGlobal.power, device -1)));
|
||||
MqttPublish(stopic);
|
||||
|
||||
if (!Settings.flag4.only_json_message) { // SetOption90 - Disable non-json MQTT response
|
||||
GetTopic_P(stopic, STAT, mqtt_topic, scommand);
|
||||
GetTopic_P(stopic, STAT, TasmotaGlobal.mqtt_topic, scommand);
|
||||
Response_P(GetStateText(bitRead(TasmotaGlobal.power, device -1)));
|
||||
MqttPublish(stopic, Settings.flag.mqtt_power_retain); // CMND_POWERRETAIN
|
||||
}
|
||||
|
@ -451,7 +451,7 @@ void MqttPublishPowerState(uint32_t device)
|
|||
|
||||
void MqttPublishAllPowerState(void)
|
||||
{
|
||||
for (uint32_t i = 1; i <= devices_present; i++) {
|
||||
for (uint32_t i = 1; i <= TasmotaGlobal.devices_present; i++) {
|
||||
MqttPublishPowerState(i);
|
||||
#ifdef USE_SONOFF_IFAN
|
||||
if (IsModuleIfan()) { break; } // Report status of light relay only
|
||||
|
@ -463,7 +463,7 @@ void MqttPublishPowerBlinkState(uint32_t device)
|
|||
{
|
||||
char scommand[33];
|
||||
|
||||
if ((device < 1) || (device > devices_present)) {
|
||||
if ((device < 1) || (device > TasmotaGlobal.devices_present)) {
|
||||
device = 1;
|
||||
}
|
||||
Response_P(PSTR("{\"%s\":\"" D_JSON_BLINK " %s\"}"),
|
||||
|
@ -500,17 +500,17 @@ void MqttConnected(void)
|
|||
Mqtt.retry_counter = 0;
|
||||
Mqtt.connect_count++;
|
||||
|
||||
GetTopic_P(stopic, TELE, mqtt_topic, S_LWT);
|
||||
GetTopic_P(stopic, TELE, TasmotaGlobal.mqtt_topic, S_LWT);
|
||||
Response_P(PSTR(MQTT_LWT_ONLINE));
|
||||
MqttPublish(stopic, true);
|
||||
|
||||
if (!Settings.flag4.only_json_message) { // SetOption90 - Disable non-json MQTT response
|
||||
// Satisfy iobroker (#299)
|
||||
mqtt_data[0] = '\0';
|
||||
ResponseClear();
|
||||
MqttPublishPrefixTopic_P(CMND, S_RSLT_POWER);
|
||||
}
|
||||
|
||||
GetTopic_P(stopic, CMND, mqtt_topic, PSTR("#"));
|
||||
GetTopic_P(stopic, CMND, TasmotaGlobal.mqtt_topic, PSTR("#"));
|
||||
MqttSubscribe(stopic);
|
||||
if (strstr_P(SettingsText(SET_MQTT_FULLTOPIC), MQTT_TOKEN_TOPIC) != nullptr) {
|
||||
uint32_t real_index = SET_MQTT_GRP_TOPIC;
|
||||
|
@ -532,7 +532,7 @@ void MqttConnected(void)
|
|||
if (ResetReason() != REASON_DEEP_SLEEP_AWAKE) {
|
||||
char stopic2[TOPSZ];
|
||||
Response_P(PSTR("{\"" D_CMND_MODULE "\":\"%s\",\"" D_JSON_VERSION "\":\"%s%s\",\"" D_JSON_FALLBACKTOPIC "\":\"%s\",\"" D_CMND_GROUPTOPIC "\":\"%s\"}"),
|
||||
ModuleName().c_str(), my_version, my_image, GetFallbackTopic_P(stopic, ""), GetGroupTopic_P(stopic2, "", SET_MQTT_GRP_TOPIC));
|
||||
ModuleName().c_str(), TasmotaGlobal.version, TasmotaGlobal.image_name, GetFallbackTopic_P(stopic, ""), GetGroupTopic_P(stopic2, "", SET_MQTT_GRP_TOPIC));
|
||||
MqttPublishPrefixTopic_P(TELE, PSTR(D_RSLT_INFO "1"));
|
||||
#ifdef USE_WEBSERVER
|
||||
if (Settings.webserver) {
|
||||
|
@ -565,7 +565,7 @@ void MqttConnected(void)
|
|||
}
|
||||
Mqtt.initial_connection_state = 0;
|
||||
|
||||
global_state.mqtt_down = 0;
|
||||
TasmotaGlobal.global_state.mqtt_down = 0;
|
||||
if (Settings.flag.mqtt_enabled) { // SetOption3 - Enable MQTT
|
||||
TasmotaGlobal.rules_flag.mqtt_connected = 1;
|
||||
}
|
||||
|
@ -607,7 +607,7 @@ void MqttReconnect(void)
|
|||
|
||||
Mqtt.connected = false;
|
||||
Mqtt.retry_counter = Settings.mqtt_retry;
|
||||
global_state.mqtt_down = 1;
|
||||
TasmotaGlobal.global_state.mqtt_down = 1;
|
||||
|
||||
char *mqtt_user = nullptr;
|
||||
char *mqtt_pwd = nullptr;
|
||||
|
@ -618,7 +618,7 @@ void MqttReconnect(void)
|
|||
mqtt_pwd = SettingsText(SET_MQTT_PWD);
|
||||
}
|
||||
|
||||
GetTopic_P(stopic, TELE, mqtt_topic, S_LWT);
|
||||
GetTopic_P(stopic, TELE, TasmotaGlobal.mqtt_topic, S_LWT);
|
||||
Response_P(S_LWT_OFFLINE);
|
||||
|
||||
if (MqttClient.connected()) { MqttClient.disconnect(); }
|
||||
|
@ -678,7 +678,7 @@ void MqttReconnect(void)
|
|||
}
|
||||
#endif
|
||||
|
||||
if (MqttClient.connect(mqtt_client, mqtt_user, mqtt_pwd, stopic, 1, lwt_retain, mqtt_data, MQTT_CLEAN_SESSION)) {
|
||||
if (MqttClient.connect(TasmotaGlobal.mqtt_client, mqtt_user, mqtt_pwd, stopic, 1, lwt_retain, TasmotaGlobal.mqtt_data, MQTT_CLEAN_SESSION)) {
|
||||
#ifdef USE_MQTT_TLS
|
||||
if (Mqtt.mqtt_tls) {
|
||||
AddLog_P2(LOG_LEVEL_INFO, PSTR(D_LOG_MQTT "TLS connected in %d ms, max ThunkStack used %d"),
|
||||
|
@ -764,17 +764,17 @@ void MqttCheck(void)
|
|||
{
|
||||
if (Settings.flag.mqtt_enabled) { // SetOption3 - Enable MQTT
|
||||
if (!MqttIsConnected()) {
|
||||
global_state.mqtt_down = 1;
|
||||
TasmotaGlobal.global_state.mqtt_down = 1;
|
||||
if (!Mqtt.retry_counter) {
|
||||
MqttReconnect();
|
||||
} else {
|
||||
Mqtt.retry_counter--;
|
||||
}
|
||||
} else {
|
||||
global_state.mqtt_down = 0;
|
||||
TasmotaGlobal.global_state.mqtt_down = 0;
|
||||
}
|
||||
} else {
|
||||
global_state.mqtt_down = 0;
|
||||
TasmotaGlobal.global_state.mqtt_down = 0;
|
||||
if (Mqtt.initial_connection_state) {
|
||||
MqttReconnect();
|
||||
}
|
||||
|
@ -902,7 +902,7 @@ void CmndFullTopic(void)
|
|||
{
|
||||
if (XdrvMailbox.data_len > 0) {
|
||||
MakeValidMqtt(1, XdrvMailbox.data);
|
||||
if (!strcmp(XdrvMailbox.data, mqtt_client)) { SetShortcutDefault(); }
|
||||
if (!strcmp(XdrvMailbox.data, TasmotaGlobal.mqtt_client)) { SetShortcutDefault(); }
|
||||
char stemp1[TOPSZ];
|
||||
strlcpy(stemp1, (SC_DEFAULT == Shortcut()) ? MQTT_FULLTOPIC : XdrvMailbox.data, sizeof(stemp1));
|
||||
if (strcmp(stemp1, SettingsText(SET_MQTT_FULLTOPIC))) {
|
||||
|
@ -941,13 +941,13 @@ void CmndPublish(void)
|
|||
char stemp1[TOPSZ];
|
||||
strlcpy(stemp1, mqtt_part, sizeof(stemp1));
|
||||
if ((payload_part != nullptr) && strlen(payload_part)) {
|
||||
strlcpy(mqtt_data, payload_part, sizeof(mqtt_data));
|
||||
strlcpy(TasmotaGlobal.mqtt_data, payload_part, sizeof(TasmotaGlobal.mqtt_data));
|
||||
} else {
|
||||
mqtt_data[0] = '\0';
|
||||
ResponseClear();
|
||||
}
|
||||
MqttPublish(stemp1, (XdrvMailbox.index == 2));
|
||||
// ResponseCmndDone();
|
||||
mqtt_data[0] = '\0';
|
||||
ResponseClear();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -958,7 +958,7 @@ void CmndGroupTopic(void)
|
|||
if (XdrvMailbox.data_len > 0) {
|
||||
uint32_t settings_text_index = (1 == XdrvMailbox.index) ? SET_MQTT_GRP_TOPIC : SET_MQTT_GRP_TOPIC2 + XdrvMailbox.index - 2;
|
||||
MakeValidMqtt(0, XdrvMailbox.data);
|
||||
if (!strcmp(XdrvMailbox.data, mqtt_client)) { SetShortcutDefault(); }
|
||||
if (!strcmp(XdrvMailbox.data, TasmotaGlobal.mqtt_client)) { SetShortcutDefault(); }
|
||||
SettingsUpdateText(settings_text_index, (SC_CLEAR == Shortcut()) ? "" : (SC_DEFAULT == Shortcut()) ? MQTT_GRPTOPIC : XdrvMailbox.data);
|
||||
|
||||
// Eliminate duplicates, have at least one and fill from index 1
|
||||
|
@ -1006,7 +1006,7 @@ void CmndTopic(void)
|
|||
{
|
||||
if (!XdrvMailbox.grpflg && (XdrvMailbox.data_len > 0)) {
|
||||
MakeValidMqtt(0, XdrvMailbox.data);
|
||||
if (!strcmp(XdrvMailbox.data, mqtt_client)) { SetShortcutDefault(); }
|
||||
if (!strcmp(XdrvMailbox.data, TasmotaGlobal.mqtt_client)) { SetShortcutDefault(); }
|
||||
char stemp1[TOPSZ];
|
||||
strlcpy(stemp1, (SC_DEFAULT == Shortcut()) ? MQTT_TOPIC : XdrvMailbox.data, sizeof(stemp1));
|
||||
if (strcmp(stemp1, SettingsText(SET_MQTT_TOPIC))) {
|
||||
|
@ -1023,10 +1023,10 @@ void CmndButtonTopic(void)
|
|||
{
|
||||
if (!XdrvMailbox.grpflg && (XdrvMailbox.data_len > 0)) {
|
||||
MakeValidMqtt(0, XdrvMailbox.data);
|
||||
if (!strcmp(XdrvMailbox.data, mqtt_client)) { SetShortcutDefault(); }
|
||||
if (!strcmp(XdrvMailbox.data, TasmotaGlobal.mqtt_client)) { SetShortcutDefault(); }
|
||||
switch (Shortcut()) {
|
||||
case SC_CLEAR: SettingsUpdateText(SET_MQTT_BUTTON_TOPIC, ""); break;
|
||||
case SC_DEFAULT: SettingsUpdateText(SET_MQTT_BUTTON_TOPIC, mqtt_topic); break;
|
||||
case SC_DEFAULT: SettingsUpdateText(SET_MQTT_BUTTON_TOPIC, TasmotaGlobal.mqtt_topic); break;
|
||||
case SC_USER: SettingsUpdateText(SET_MQTT_BUTTON_TOPIC, MQTT_BUTTON_TOPIC); break;
|
||||
default: SettingsUpdateText(SET_MQTT_BUTTON_TOPIC, XdrvMailbox.data);
|
||||
}
|
||||
|
@ -1038,10 +1038,10 @@ void CmndSwitchTopic(void)
|
|||
{
|
||||
if (!XdrvMailbox.grpflg && (XdrvMailbox.data_len > 0)) {
|
||||
MakeValidMqtt(0, XdrvMailbox.data);
|
||||
if (!strcmp(XdrvMailbox.data, mqtt_client)) { SetShortcutDefault(); }
|
||||
if (!strcmp(XdrvMailbox.data, TasmotaGlobal.mqtt_client)) { SetShortcutDefault(); }
|
||||
switch (Shortcut()) {
|
||||
case SC_CLEAR: SettingsUpdateText(SET_MQTT_SWITCH_TOPIC, ""); break;
|
||||
case SC_DEFAULT: SettingsUpdateText(SET_MQTT_SWITCH_TOPIC, mqtt_topic); break;
|
||||
case SC_DEFAULT: SettingsUpdateText(SET_MQTT_SWITCH_TOPIC, TasmotaGlobal.mqtt_topic); break;
|
||||
case SC_USER: SettingsUpdateText(SET_MQTT_SWITCH_TOPIC, MQTT_SWITCH_TOPIC); break;
|
||||
default: SettingsUpdateText(SET_MQTT_SWITCH_TOPIC, XdrvMailbox.data);
|
||||
}
|
||||
|
@ -1081,9 +1081,9 @@ void CmndPowerRetain(void)
|
|||
if (!XdrvMailbox.payload) {
|
||||
char stemp1[TOPSZ];
|
||||
char scommand[CMDSZ];
|
||||
for (uint32_t i = 1; i <= devices_present; i++) { // Clear MQTT retain in broker
|
||||
GetTopic_P(stemp1, STAT, mqtt_topic, GetPowerDevice(scommand, i, sizeof(scommand), Settings.flag.device_index_enable)); // SetOption26 - Switch between POWER or POWER1
|
||||
mqtt_data[0] = '\0';
|
||||
for (uint32_t i = 1; i <= TasmotaGlobal.devices_present; i++) { // Clear MQTT retain in broker
|
||||
GetTopic_P(stemp1, STAT, TasmotaGlobal.mqtt_topic, GetPowerDevice(scommand, i, sizeof(scommand), Settings.flag.device_index_enable)); // SetOption26 - Switch between POWER or POWER1
|
||||
ResponseClear();
|
||||
MqttPublish(stemp1, Settings.flag.mqtt_power_retain); // CMND_POWERRETAIN
|
||||
}
|
||||
}
|
||||
|
@ -1099,7 +1099,7 @@ void CmndSensorRetain(void)
|
|||
{
|
||||
if ((XdrvMailbox.payload >= 0) && (XdrvMailbox.payload <= 1)) {
|
||||
if (!XdrvMailbox.payload) {
|
||||
mqtt_data[0] = '\0';
|
||||
ResponseClear();
|
||||
MqttPublishPrefixTopic_P(TELE, PSTR(D_RSLT_SENSOR), Settings.flag.mqtt_sensor_retain); // CMND_SENSORRETAIN
|
||||
MqttPublishPrefixTopic_P(TELE, PSTR(D_RSLT_ENERGY), Settings.flag.mqtt_sensor_retain); // CMND_SENSORRETAIN
|
||||
}
|
||||
|
|
|
@ -492,7 +492,7 @@ void EnergyMqttShow(void)
|
|||
// {"Time":"2017-12-16T11:48:55","ENERGY":{"Total":0.212,"Yesterday":0.000,"Today":0.014,"Period":2.0,"Power":22.0,"Factor":1.00,"Voltage":213.6,"Current":0.100}}
|
||||
int tele_period_save = TasmotaGlobal.tele_period;
|
||||
TasmotaGlobal.tele_period = 2;
|
||||
mqtt_data[0] = '\0';
|
||||
ResponseClear();
|
||||
ResponseAppendTime();
|
||||
EnergyShow(true);
|
||||
TasmotaGlobal.tele_period = tele_period_save;
|
||||
|
@ -898,7 +898,7 @@ void EnergySnsInit(void)
|
|||
{
|
||||
XnrgCall(FUNC_INIT);
|
||||
|
||||
if (energy_flg) {
|
||||
if (TasmotaGlobal.energy_driver) {
|
||||
Energy.kWhtoday_offset = 0;
|
||||
// Do not use at Power On as Rtc was invalid (but has been restored from Settings already)
|
||||
if ((ResetReason() != REASON_DEFAULT_RST) && RtcSettingsValid()) {
|
||||
|
@ -1180,10 +1180,10 @@ bool Xdrv03(uint8_t function)
|
|||
bool result = false;
|
||||
|
||||
if (FUNC_PRE_INIT == function) {
|
||||
energy_flg = ENERGY_NONE;
|
||||
TasmotaGlobal.energy_driver = ENERGY_NONE;
|
||||
XnrgCall(FUNC_PRE_INIT); // Find first energy driver
|
||||
}
|
||||
else if (energy_flg) {
|
||||
else if (TasmotaGlobal.energy_driver) {
|
||||
switch (function) {
|
||||
case FUNC_LOOP:
|
||||
XnrgCall(FUNC_LOOP);
|
||||
|
@ -1214,7 +1214,7 @@ bool Xsns03(uint8_t function)
|
|||
{
|
||||
bool result = false;
|
||||
|
||||
if (energy_flg) {
|
||||
if (TasmotaGlobal.energy_driver) {
|
||||
switch (function) {
|
||||
case FUNC_EVERY_SECOND:
|
||||
EnergyEverySecond();
|
||||
|
|
|
@ -572,7 +572,7 @@ class LightStateClass {
|
|||
_briRGB = bri_rgb;
|
||||
if (bri_rgb > 0) { addRGBMode(); }
|
||||
#ifdef USE_PWM_DIMMER
|
||||
if (PWM_DIMMER == my_module_type) PWMDimmerSetBrightnessLeds(-1);
|
||||
if (PWM_DIMMER == TasmotaGlobal.module_type) PWMDimmerSetBrightnessLeds(-1);
|
||||
#endif // USE_PWM_DIMMER
|
||||
return prev_bri;
|
||||
}
|
||||
|
@ -583,7 +583,7 @@ class LightStateClass {
|
|||
_briCT = bri_ct;
|
||||
if (bri_ct > 0) { addCTMode(); }
|
||||
#ifdef USE_PWM_DIMMER
|
||||
if (PWM_DIMMER == my_module_type) PWMDimmerSetBrightnessLeds(-1);
|
||||
if (PWM_DIMMER == TasmotaGlobal.module_type) PWMDimmerSetBrightnessLeds(-1);
|
||||
#endif // USE_PWM_DIMMER
|
||||
return prev_bri;
|
||||
}
|
||||
|
@ -973,7 +973,7 @@ public:
|
|||
Settings.light_color[0], Settings.light_color[1], Settings.light_color[2],
|
||||
Settings.light_color[3], Settings.light_color[4], Settings.light_dimmer);
|
||||
AddLog_P2(LOG_LEVEL_DEBUG_MORE, "LightControllerClass::loadSettings light_type/sub (%d %d)",
|
||||
light_type, Light.subtype);
|
||||
TasmotaGlobal.light_type, Light.subtype);
|
||||
#endif
|
||||
if (_pwm_multi_channels) {
|
||||
_state->setChannelsRaw(Settings.light_color);
|
||||
|
@ -1246,64 +1246,64 @@ void LightPwmOffset(uint32_t offset)
|
|||
|
||||
bool LightModuleInit(void)
|
||||
{
|
||||
light_type = LT_BASIC; // Use basic PWM control if SetOption15 = 0
|
||||
TasmotaGlobal.light_type = LT_BASIC; // Use basic PWM control if SetOption15 = 0
|
||||
|
||||
if (Settings.flag.pwm_control) { // SetOption15 - Switch between commands PWM or COLOR/DIMMER/CT/CHANNEL
|
||||
for (uint32_t i = 0; i < MAX_PWMS; i++) {
|
||||
if (PinUsed(GPIO_PWM1, i)) { light_type++; } // Use Dimmer/Color control for all PWM as SetOption15 = 1
|
||||
if (PinUsed(GPIO_PWM1, i)) { TasmotaGlobal.light_type++; } // Use Dimmer/Color control for all PWM as SetOption15 = 1
|
||||
}
|
||||
}
|
||||
|
||||
light_flg = 0;
|
||||
TasmotaGlobal.light_driver = 0;
|
||||
if (XlgtCall(FUNC_MODULE_INIT)) {
|
||||
// serviced
|
||||
}
|
||||
#ifdef ESP8266
|
||||
else if (SONOFF_BN == my_module_type) { // PWM Single color led (White)
|
||||
light_type = LT_PWM1;
|
||||
else if (SONOFF_BN == TasmotaGlobal.module_type) { // PWM Single color led (White)
|
||||
TasmotaGlobal.light_type = LT_PWM1;
|
||||
}
|
||||
else if (SONOFF_LED == my_module_type) { // PWM Dual color led (White warm and cold)
|
||||
if (!my_module.io[4]) { // Fix Sonoff Led instabilities
|
||||
else if (SONOFF_LED == TasmotaGlobal.module_type) { // PWM Dual color led (White warm and cold)
|
||||
if (!TasmotaGlobal.my_module.io[4]) { // Fix Sonoff Led instabilities
|
||||
pinMode(4, OUTPUT); // Stop floating outputs
|
||||
digitalWrite(4, LOW);
|
||||
}
|
||||
if (!my_module.io[5]) {
|
||||
if (!TasmotaGlobal.my_module.io[5]) {
|
||||
pinMode(5, OUTPUT); // Stop floating outputs
|
||||
digitalWrite(5, LOW);
|
||||
}
|
||||
if (!my_module.io[14]) {
|
||||
if (!TasmotaGlobal.my_module.io[14]) {
|
||||
pinMode(14, OUTPUT); // Stop floating outputs
|
||||
digitalWrite(14, LOW);
|
||||
}
|
||||
light_type = LT_PWM2;
|
||||
TasmotaGlobal.light_type = LT_PWM2;
|
||||
}
|
||||
#endif // ESP8266
|
||||
#ifdef USE_PWM_DIMMER
|
||||
#ifdef USE_DEVICE_GROUPS
|
||||
else if (PWM_DIMMER == my_module_type) {
|
||||
light_type = Settings.pwm_dimmer_cfg.pwm_count + 1;
|
||||
else if (PWM_DIMMER == TasmotaGlobal.module_type) {
|
||||
TasmotaGlobal.light_type = Settings.pwm_dimmer_cfg.pwm_count + 1;
|
||||
}
|
||||
#endif // USE_DEVICE_GROUPS
|
||||
#endif // USE_PWM_DIMMER
|
||||
|
||||
if (light_type > LT_BASIC) {
|
||||
devices_present++;
|
||||
if (TasmotaGlobal.light_type > LT_BASIC) {
|
||||
TasmotaGlobal.devices_present++;
|
||||
}
|
||||
|
||||
// post-process for lights
|
||||
uint32_t pwm_channels = (light_type & 7) > LST_MAX ? LST_MAX : (light_type & 7);
|
||||
uint32_t pwm_channels = (TasmotaGlobal.light_type & 7) > LST_MAX ? LST_MAX : (TasmotaGlobal.light_type & 7);
|
||||
if (Settings.flag3.pwm_multi_channels) { // SetOption68 - Enable multi-channels PWM instead of Color PWM
|
||||
if (0 == pwm_channels) { pwm_channels = 1; }
|
||||
devices_present += pwm_channels - 1; // add the pwm channels controls at the end
|
||||
TasmotaGlobal.devices_present += pwm_channels - 1; // add the pwm channels controls at the end
|
||||
} else if ((Settings.param[P_RGB_REMAP] & 128) && (LST_RGBW <= pwm_channels)) {
|
||||
// if RGBW or RGBCW, and SetOption37 >= 128, we manage RGB and W separately, hence adding a device
|
||||
devices_present++;
|
||||
TasmotaGlobal.devices_present++;
|
||||
} else if ((Settings.flag4.virtual_ct) && (LST_RGBW == pwm_channels)) {
|
||||
Light.virtual_ct = true; // enabled
|
||||
light_type++; // create an additional virtual 5th channel
|
||||
TasmotaGlobal.light_type++; // create an additional virtual 5th channel
|
||||
}
|
||||
|
||||
return (light_type > LT_BASIC);
|
||||
return (TasmotaGlobal.light_type > LT_BASIC);
|
||||
}
|
||||
|
||||
// compute actual PWM min/max values from DimmerRange
|
||||
|
@ -1333,8 +1333,8 @@ void LightInit(void)
|
|||
Settings.rgbwwTable[4] = 255; // set RGBWWTable value to its default
|
||||
}
|
||||
|
||||
Light.device = devices_present;
|
||||
Light.subtype = (light_type & 7) > LST_MAX ? LST_MAX : (light_type & 7); // Always 0 - LST_MAX (5)
|
||||
Light.device = TasmotaGlobal.devices_present;
|
||||
Light.subtype = (TasmotaGlobal.light_type & 7) > LST_MAX ? LST_MAX : (TasmotaGlobal.light_type & 7); // Always 0 - LST_MAX (5)
|
||||
Light.pwm_multi_channels = Settings.flag3.pwm_multi_channels; // SetOption68 - Enable multi-channels PWM instead of Color PWM
|
||||
|
||||
if (LST_RGBW <= Light.subtype) {
|
||||
|
@ -1347,15 +1347,15 @@ void LightInit(void)
|
|||
if ((LST_SINGLE <= Light.subtype) && Light.pwm_multi_channels) {
|
||||
// we treat each PWM channel as an independant one, hence we switch to
|
||||
light_controller.setPWMMultiChannel(true);
|
||||
Light.device = devices_present - Light.subtype + 1; // adjust if we also have relays
|
||||
Light.device = TasmotaGlobal.devices_present - Light.subtype + 1; // adjust if we also have relays
|
||||
} else if (!light_controller.isCTRGBLinked()) {
|
||||
// if RGBW or RGBCW, and SetOption37 >= 128, we manage RGB and W separately
|
||||
Light.device--; // we take the last two devices as lights
|
||||
}
|
||||
LightCalcPWMRange();
|
||||
#ifdef DEBUG_LIGHT
|
||||
AddLog_P2(LOG_LEVEL_DEBUG_MORE, "LightInit Light.pwm_multi_channels=%d Light.subtype=%d Light.device=%d devices_present=%d",
|
||||
Light.pwm_multi_channels, Light.subtype, Light.device, devices_present);
|
||||
AddLog_P2(LOG_LEVEL_DEBUG_MORE, "LightInit Light.pwm_multi_channels=%d Light.subtype=%d Light.device=%d TasmotaGlobal.devices_present=%d",
|
||||
Light.pwm_multi_channels, Light.subtype, Light.device, TasmotaGlobal.devices_present);
|
||||
#endif
|
||||
|
||||
light_controller.setSubType(Light.subtype);
|
||||
|
@ -1366,8 +1366,8 @@ void LightInit(void)
|
|||
if (LST_SINGLE == Light.subtype) {
|
||||
Settings.light_color[0] = 255; // One channel only supports Dimmer but needs max color
|
||||
}
|
||||
if (light_type < LT_PWM6) { // PWM
|
||||
for (uint32_t i = 0; i < light_type; i++) {
|
||||
if (TasmotaGlobal.light_type < LT_PWM6) { // PWM
|
||||
for (uint32_t i = 0; i < TasmotaGlobal.light_type; i++) {
|
||||
Settings.pwm_value[i] = 0; // Disable direct PWM control
|
||||
if (PinUsed(GPIO_PWM1, i)) {
|
||||
#ifdef ESP8266
|
||||
|
@ -1457,7 +1457,7 @@ void LightHsToRgb(uint16_t hue, uint8_t sat, uint8_t *r_r, uint8_t *r_g, uint8_t
|
|||
uint8_t LightGetBri(uint8_t device) {
|
||||
uint8_t bri = 254; // default value if relay
|
||||
if (Light.pwm_multi_channels) {
|
||||
if ((device >= Light.device) && (device < Light.device + LST_MAX) && (device <= devices_present)) {
|
||||
if ((device >= Light.device) && (device < Light.device + LST_MAX) && (device <= TasmotaGlobal.devices_present)) {
|
||||
bri = Light.current_color[device - Light.device];
|
||||
}
|
||||
} else if (light_controller.isCTRGBLinked()) { // standard behavior
|
||||
|
@ -1477,7 +1477,7 @@ uint8_t LightGetBri(uint8_t device) {
|
|||
// If SetOption68 is set, set the brightness for a specific device
|
||||
void LightSetBri(uint8_t device, uint8_t bri) {
|
||||
if (Light.pwm_multi_channels) {
|
||||
if ((device >= Light.device) && (device < Light.device + LST_MAX) && (device <= devices_present)) {
|
||||
if ((device >= Light.device) && (device < Light.device + LST_MAX) && (device <= TasmotaGlobal.devices_present)) {
|
||||
Light.current_color[device - Light.device] = bri;
|
||||
light_controller.changeChannels(Light.current_color);
|
||||
}
|
||||
|
@ -1825,10 +1825,10 @@ void LightSetPower(void)
|
|||
}
|
||||
uint32_t shift = Light.device - 1;
|
||||
// If PWM multi_channels
|
||||
// Ex: 3 Relays and 4 PWM - devices_present = 7, Light.device = 4, Light.subtype = 4
|
||||
// Ex: 3 Relays and 4 PWM - TasmotaGlobal.devices_present = 7, Light.device = 4, Light.subtype = 4
|
||||
// Result: mask = 0b00001111 = 0x0F, shift = 3.
|
||||
// Power bits we consider are: 0b01111000 = 0x78
|
||||
// If regular situation: devices_present == Light.subtype
|
||||
// If regular situation: TasmotaGlobal.devices_present == Light.subtype
|
||||
Light.power = (XdrvMailbox.index & (mask << shift)) >> shift;
|
||||
if (Light.wakeup_active) {
|
||||
Light.wakeup_active--;
|
||||
|
@ -2035,7 +2035,7 @@ void LightAnimate(void)
|
|||
cur_col_10[i] = orig_col_10bits[Light.color_remap[i]];
|
||||
}
|
||||
|
||||
if (!Settings.light_fade || skip_light_fade || power_off || (!Light.fade_initialized)) { // no fade
|
||||
if (!Settings.light_fade || TasmotaGlobal.skip_light_fade || power_off || (!Light.fade_initialized)) { // no fade
|
||||
// record the current value for a future Fade
|
||||
memcpy(Light.fade_start_10, cur_col_10, sizeof(Light.fade_start_10));
|
||||
// push the final values at 8 and 10 bits resolution to the PWMs
|
||||
|
@ -2063,7 +2063,7 @@ void LightAnimate(void)
|
|||
}
|
||||
#ifdef USE_PWM_DIMMER
|
||||
// If the power is off and the fade is done, turn the relay off.
|
||||
if (PWM_DIMMER == my_module_type && !Light.power && !Light.fade_running) PWMDimmerSetPower();
|
||||
if (PWM_DIMMER == TasmotaGlobal.module_type && !Light.power && !Light.fade_running) PWMDimmerSetPower();
|
||||
#endif // USE_PWM_DIMMER
|
||||
}
|
||||
}
|
||||
|
@ -2072,7 +2072,7 @@ bool isChannelGammaCorrected(uint32_t channel) {
|
|||
if (!Settings.light_correction) { return false; } // Gamma correction not activated
|
||||
if (channel >= Light.subtype) { return false; } // Out of range
|
||||
#ifdef ESP8266
|
||||
if ((PHILIPS == my_module_type) || (Settings.flag4.pwm_ct_mode)) {
|
||||
if ((PHILIPS == TasmotaGlobal.module_type) || (Settings.flag4.pwm_ct_mode)) {
|
||||
if ((LST_COLDWARM == Light.subtype) && (1 == channel)) { return false; } // PMW reserved for CT
|
||||
if ((LST_RGBCW == Light.subtype) && (4 == channel)) { return false; } // PMW reserved for CT
|
||||
}
|
||||
|
@ -2083,7 +2083,7 @@ bool isChannelGammaCorrected(uint32_t channel) {
|
|||
// is the channel a regular PWM or ColorTemp control
|
||||
bool isChannelCT(uint32_t channel) {
|
||||
#ifdef ESP8266
|
||||
if ((PHILIPS == my_module_type) || (Settings.flag4.pwm_ct_mode)) {
|
||||
if ((PHILIPS == TasmotaGlobal.module_type) || (Settings.flag4.pwm_ct_mode)) {
|
||||
if ((LST_COLDWARM == Light.subtype) && (1 == channel)) { return true; } // PMW reserved for CT
|
||||
if ((LST_RGBCW == Light.subtype) && (4 == channel)) { return true; } // PMW reserved for CT
|
||||
}
|
||||
|
@ -2207,7 +2207,7 @@ void LightApplyPower(uint8_t new_color[LST_MAX], power_t power) {
|
|||
|
||||
void LightSetOutputs(const uint16_t *cur_col_10) {
|
||||
// now apply the actual PWM values, adjusted and remapped 10-bits range
|
||||
if (light_type < LT_PWM6) { // only for direct PWM lights, not for Tuya, Armtronix...
|
||||
if (TasmotaGlobal.light_type < LT_PWM6) { // only for direct PWM lights, not for Tuya, Armtronix...
|
||||
for (uint32_t i = 0; i < (Light.subtype - Light.pwm_offset); i++) {
|
||||
if (PinUsed(GPIO_PWM1, i)) {
|
||||
//AddLog_P2(LOG_LEVEL_DEBUG, PSTR(D_LOG_APPLICATION "Cur_Col%d 10 bits %d"), i, cur_col_10[i]);
|
||||
|
@ -2216,7 +2216,7 @@ void LightSetOutputs(const uint16_t *cur_col_10) {
|
|||
cur_col = cur_col > 0 ? changeUIntScale(cur_col, 0, Settings.pwm_range, Light.pwm_min, Light.pwm_max) : 0; // shrink to the range of pwm_min..pwm_max
|
||||
}
|
||||
if (!Settings.flag4.zerocross_dimmer) {
|
||||
analogWrite(Pin(GPIO_PWM1, i), bitRead(pwm_inverted, i) ? Settings.pwm_range - cur_col : cur_col);
|
||||
analogWrite(Pin(GPIO_PWM1, i), bitRead(TasmotaGlobal.pwm_inverted, i) ? Settings.pwm_range - cur_col : cur_col);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2269,7 +2269,7 @@ void calcGammaBulbs(uint16_t cur_col_10[5]) {
|
|||
uint16_t white_bri10_1023 = (white_bri10 > 1023) ? 1023 : white_bri10; // max 1023
|
||||
|
||||
#ifdef ESP8266
|
||||
if ((PHILIPS == my_module_type) || (Settings.flag4.pwm_ct_mode)) { // channel 1 is the color tone, mapped to cold channel (0..255)
|
||||
if ((PHILIPS == TasmotaGlobal.module_type) || (Settings.flag4.pwm_ct_mode)) { // channel 1 is the color tone, mapped to cold channel (0..255)
|
||||
// Xiaomi Philips bulbs follow a different scheme:
|
||||
cur_col_10[cw1] = light_state.getCT10bits();
|
||||
// channel 0=intensity, channel1=temperature
|
||||
|
@ -2833,7 +2833,7 @@ void CmndDimmer(void)
|
|||
// Dimmer<x> - - Decrement Dimmer in steps of 10
|
||||
uint32_t dimmer;
|
||||
if (XdrvMailbox.index == 3) {
|
||||
skip_light_fade = true;
|
||||
TasmotaGlobal.skip_light_fade = true;
|
||||
XdrvMailbox.index = 0;
|
||||
}
|
||||
else if (XdrvMailbox.index > 2) {
|
||||
|
@ -2878,11 +2878,11 @@ void CmndDimmer(void)
|
|||
}
|
||||
#endif // USE_PWM_DIMMER && USE_DEVICE_GROUPS
|
||||
Light.update = true;
|
||||
if (skip_light_fade) LightAnimate();
|
||||
if (TasmotaGlobal.skip_light_fade) LightAnimate();
|
||||
} else {
|
||||
ResponseCmndNumber(dimmer);
|
||||
}
|
||||
skip_light_fade = false;
|
||||
TasmotaGlobal.skip_light_fade = false;
|
||||
}
|
||||
|
||||
void CmndDimmerRange(void)
|
||||
|
@ -3093,7 +3093,7 @@ void CmndUndocA(void)
|
|||
scolor[6] = '\0'; // RGB only
|
||||
Response_P(PSTR("%s,%d,%d,%d,%d,%d"), scolor, Settings.light_fade, Settings.light_correction, Settings.light_scheme, Settings.light_speed, Settings.light_width);
|
||||
MqttPublishPrefixTopic_P(STAT, XdrvMailbox.topic);
|
||||
mqtt_data[0] = '\0';
|
||||
ResponseClear();
|
||||
}
|
||||
|
||||
/*********************************************************************************************\
|
||||
|
@ -3107,7 +3107,7 @@ bool Xdrv04(uint8_t function)
|
|||
if (FUNC_MODULE_INIT == function) {
|
||||
return LightModuleInit();
|
||||
}
|
||||
else if (light_type) {
|
||||
else if (TasmotaGlobal.light_type) {
|
||||
switch (function) {
|
||||
case FUNC_SERIAL:
|
||||
result = XlgtCall(FUNC_SERIAL);
|
||||
|
|
|
@ -232,7 +232,7 @@ void IrReceiveCheck(void)
|
|||
prev_number = true;
|
||||
}
|
||||
ir_high = !ir_high;
|
||||
if (strlen(mqtt_data) > sizeof(mqtt_data) - 40) { break; } // Quit if char string becomes too long
|
||||
if (strlen(TasmotaGlobal.mqtt_data) > sizeof(TasmotaGlobal.mqtt_data) - 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);
|
||||
|
|
|
@ -320,7 +320,7 @@ void IrReceiveCheck(void)
|
|||
prev_number = true;
|
||||
}
|
||||
ir_high = !ir_high;
|
||||
if (strlen(mqtt_data) > sizeof(mqtt_data) - 40) { break; } // Quit if char string becomes too long
|
||||
if (strlen(TasmotaGlobal.mqtt_data) > sizeof(TasmotaGlobal.mqtt_data) - 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);
|
||||
|
|
|
@ -213,12 +213,12 @@ void SonoffBridgeReceivedRaw(void)
|
|||
// Decoding according to https://github.com/Portisch/RF-Bridge-EFM8BB1
|
||||
uint8_t buckets = 0;
|
||||
|
||||
if (0xB1 == serial_in_buffer[1]) { buckets = serial_in_buffer[2] << 1; } // Bucket sniffing
|
||||
if (0xB1 == TasmotaGlobal.serial_in_buffer[1]) { buckets = TasmotaGlobal.serial_in_buffer[2] << 1; } // Bucket sniffing
|
||||
|
||||
ResponseTime_P(PSTR(",\"" D_CMND_RFRAW "\":{\"" D_JSON_DATA "\":\""));
|
||||
for (uint32_t i = 0; i < TasmotaGlobal.serial_in_byte_counter; i++) {
|
||||
ResponseAppend_P(PSTR("%02X"), serial_in_buffer[i]);
|
||||
if (0xB1 == serial_in_buffer[1]) {
|
||||
ResponseAppend_P(PSTR("%02X"), TasmotaGlobal.serial_in_buffer[i]);
|
||||
if (0xB1 == TasmotaGlobal.serial_in_buffer[1]) {
|
||||
if ((i > 3) && buckets) { buckets--; }
|
||||
if ((i < 3) || (buckets % 2) || (i == TasmotaGlobal.serial_in_byte_counter -2)) {
|
||||
ResponseAppend_P(PSTR(" "));
|
||||
|
@ -249,16 +249,16 @@ void SonoffBridgeReceived(void)
|
|||
|
||||
AddLogSerial(LOG_LEVEL_DEBUG);
|
||||
|
||||
if (0xA2 == serial_in_buffer[0]) { // Learn timeout
|
||||
if (0xA2 == TasmotaGlobal.serial_in_buffer[0]) { // Learn timeout
|
||||
SonoffBridgeLearnFailed();
|
||||
}
|
||||
else if (0xA3 == serial_in_buffer[0]) { // Learned A3 20 F8 01 18 03 3E 2E 1A 22 55
|
||||
else if (0xA3 == TasmotaGlobal.serial_in_buffer[0]) { // Learned A3 20 F8 01 18 03 3E 2E 1A 22 55
|
||||
SnfBridge.learn_active = 0;
|
||||
low_time = serial_in_buffer[3] << 8 | serial_in_buffer[4]; // Low time in uSec
|
||||
high_time = serial_in_buffer[5] << 8 | serial_in_buffer[6]; // High time in uSec
|
||||
low_time = TasmotaGlobal.serial_in_buffer[3] << 8 | TasmotaGlobal.serial_in_buffer[4]; // Low time in uSec
|
||||
high_time = TasmotaGlobal.serial_in_buffer[5] << 8 | TasmotaGlobal.serial_in_buffer[6]; // High time in uSec
|
||||
if (low_time && high_time) {
|
||||
for (uint32_t i = 0; i < 9; i++) {
|
||||
Settings.rf_code[SnfBridge.learn_key][i] = serial_in_buffer[i +1];
|
||||
Settings.rf_code[SnfBridge.learn_key][i] = TasmotaGlobal.serial_in_buffer[i +1];
|
||||
}
|
||||
Response_P(S_JSON_COMMAND_INDEX_SVALUE, D_CMND_RFKEY, SnfBridge.learn_key, D_JSON_LEARNED);
|
||||
MqttPublishPrefixTopic_P(RESULT_OR_STAT, PSTR(D_CMND_RFKEY));
|
||||
|
@ -266,14 +266,14 @@ void SonoffBridgeReceived(void)
|
|||
SonoffBridgeLearnFailed();
|
||||
}
|
||||
}
|
||||
else if (0xA4 == serial_in_buffer[0]) { // Received RF data A4 20 EE 01 18 03 3E 2E 1A 22 55
|
||||
else if (0xA4 == TasmotaGlobal.serial_in_buffer[0]) { // Received RF data A4 20 EE 01 18 03 3E 2E 1A 22 55
|
||||
if (SnfBridge.learn_active) {
|
||||
SonoffBridgeLearnFailed();
|
||||
} else {
|
||||
sync_time = serial_in_buffer[1] << 8 | serial_in_buffer[2]; // Sync time in uSec
|
||||
low_time = serial_in_buffer[3] << 8 | serial_in_buffer[4]; // Low time in uSec
|
||||
high_time = serial_in_buffer[5] << 8 | serial_in_buffer[6]; // High time in uSec
|
||||
received_id = serial_in_buffer[7] << 16 | serial_in_buffer[8] << 8 | serial_in_buffer[9];
|
||||
sync_time = TasmotaGlobal.serial_in_buffer[1] << 8 | TasmotaGlobal.serial_in_buffer[2]; // Sync time in uSec
|
||||
low_time = TasmotaGlobal.serial_in_buffer[3] << 8 | TasmotaGlobal.serial_in_buffer[4]; // Low time in uSec
|
||||
high_time = TasmotaGlobal.serial_in_buffer[5] << 8 | TasmotaGlobal.serial_in_buffer[6]; // High time in uSec
|
||||
received_id = TasmotaGlobal.serial_in_buffer[7] << 16 | TasmotaGlobal.serial_in_buffer[8] << 8 | TasmotaGlobal.serial_in_buffer[9];
|
||||
|
||||
unsigned long now = millis();
|
||||
if (!((received_id == SnfBridge.last_received_id) && (now - SnfBridge.last_time < SFB_TIME_AVOID_DUPLICATE))) {
|
||||
|
@ -313,44 +313,44 @@ bool SonoffBridgeSerialInput(void)
|
|||
if (SnfBridge.receive_flag) {
|
||||
if (SnfBridge.receive_raw_flag) {
|
||||
if (!TasmotaGlobal.serial_in_byte_counter) {
|
||||
serial_in_buffer[TasmotaGlobal.serial_in_byte_counter++] = 0xAA;
|
||||
TasmotaGlobal.serial_in_buffer[TasmotaGlobal.serial_in_byte_counter++] = 0xAA;
|
||||
}
|
||||
serial_in_buffer[TasmotaGlobal.serial_in_byte_counter++] = serial_in_byte;
|
||||
TasmotaGlobal.serial_in_buffer[TasmotaGlobal.serial_in_byte_counter++] = TasmotaGlobal.serial_in_byte;
|
||||
if (TasmotaGlobal.serial_in_byte_counter == 3) {
|
||||
if ((0xA6 == serial_in_buffer[1]) || (0xAB == serial_in_buffer[1])) { // AA A6 06 023908010155 55 - 06 is receive_len
|
||||
receive_len = serial_in_buffer[2] + 4; // Get at least receive_len bytes
|
||||
if ((0xA6 == TasmotaGlobal.serial_in_buffer[1]) || (0xAB == TasmotaGlobal.serial_in_buffer[1])) { // AA A6 06 023908010155 55 - 06 is receive_len
|
||||
receive_len = TasmotaGlobal.serial_in_buffer[2] + 4; // Get at least receive_len bytes
|
||||
}
|
||||
}
|
||||
if ((!receive_len && (0x55 == serial_in_byte)) || (receive_len && (TasmotaGlobal.serial_in_byte_counter == receive_len))) { // 0x55 - End of text
|
||||
if ((!receive_len && (0x55 == TasmotaGlobal.serial_in_byte)) || (receive_len && (TasmotaGlobal.serial_in_byte_counter == receive_len))) { // 0x55 - End of text
|
||||
SonoffBridgeReceivedRaw();
|
||||
SnfBridge.receive_flag = 0;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
else if (!((0 == TasmotaGlobal.serial_in_byte_counter) && (0 == serial_in_byte))) { // Skip leading 0
|
||||
else if (!((0 == TasmotaGlobal.serial_in_byte_counter) && (0 == TasmotaGlobal.serial_in_byte))) { // Skip leading 0
|
||||
if (0 == TasmotaGlobal.serial_in_byte_counter) {
|
||||
SnfBridge.expected_bytes = 2; // 0xA0, 0xA1, 0xA2
|
||||
if (serial_in_byte >= 0xA3) {
|
||||
if (TasmotaGlobal.serial_in_byte >= 0xA3) {
|
||||
SnfBridge.expected_bytes = 11; // 0xA3, 0xA4, 0xA5
|
||||
}
|
||||
if (serial_in_byte == 0xA6) {
|
||||
if (TasmotaGlobal.serial_in_byte == 0xA6) {
|
||||
SnfBridge.expected_bytes = 0; // 0xA6 and up supported by Portisch firmware only
|
||||
serial_in_buffer[TasmotaGlobal.serial_in_byte_counter++] = 0xAA;
|
||||
TasmotaGlobal.serial_in_buffer[TasmotaGlobal.serial_in_byte_counter++] = 0xAA;
|
||||
SnfBridge.receive_raw_flag = 1;
|
||||
}
|
||||
}
|
||||
serial_in_buffer[TasmotaGlobal.serial_in_byte_counter++] = serial_in_byte;
|
||||
if ((SnfBridge.expected_bytes == TasmotaGlobal.serial_in_byte_counter) && (0x55 == serial_in_byte)) { // 0x55 - End of text
|
||||
TasmotaGlobal.serial_in_buffer[TasmotaGlobal.serial_in_byte_counter++] = TasmotaGlobal.serial_in_byte;
|
||||
if ((SnfBridge.expected_bytes == TasmotaGlobal.serial_in_byte_counter) && (0x55 == TasmotaGlobal.serial_in_byte)) { // 0x55 - End of text
|
||||
SonoffBridgeReceived();
|
||||
SnfBridge.receive_flag = 0;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
serial_in_byte = 0;
|
||||
TasmotaGlobal.serial_in_byte = 0;
|
||||
}
|
||||
if (0xAA == serial_in_byte) { // 0xAA - Start of text
|
||||
if (0xAA == TasmotaGlobal.serial_in_byte) { // 0xAA - Start of text
|
||||
TasmotaGlobal.serial_in_byte_counter = 0;
|
||||
serial_in_byte = 0;
|
||||
TasmotaGlobal.serial_in_byte = 0;
|
||||
SnfBridge.receive_flag = 1;
|
||||
receive_len = 0;
|
||||
}
|
||||
|
@ -563,7 +563,7 @@ bool Xdrv06(uint8_t function)
|
|||
bool result = false;
|
||||
|
||||
#ifdef ESP8266
|
||||
if (SONOFF_BRIDGE == my_module_type) {
|
||||
if (SONOFF_BRIDGE == TasmotaGlobal.module_type) {
|
||||
switch (function) {
|
||||
case FUNC_SERIAL:
|
||||
result = SonoffBridgeSerialInput();
|
||||
|
|
|
@ -112,7 +112,7 @@ void DomoticzUpdateFanState(void) {
|
|||
void MqttPublishDomoticzPowerState(uint8_t device) {
|
||||
if (Settings.flag.mqtt_enabled) { // SetOption3 - Enable MQTT
|
||||
if (device < 1) { device = 1; }
|
||||
if ((device > devices_present) || (device > MAX_DOMOTICZ_IDX)) { return; }
|
||||
if ((device > TasmotaGlobal.devices_present) || (device > MAX_DOMOTICZ_IDX)) { return; }
|
||||
if (Settings.domoticz_relay_idx[device -1]) {
|
||||
#ifdef USE_SHUTTER
|
||||
if (domoticz_is_shutter) {
|
||||
|
@ -127,7 +127,7 @@ void MqttPublishDomoticzPowerState(uint8_t device) {
|
|||
char svalue[8]; // Dimmer value
|
||||
|
||||
snprintf_P(svalue, sizeof(svalue), PSTR("%d"), Settings.light_dimmer);
|
||||
Response_P(DOMOTICZ_MESSAGE, (int)Settings.domoticz_relay_idx[device -1], (TasmotaGlobal.power & (1 << (device -1))) ? 1 : 0, (light_type) ? svalue : "", DomoticzBatteryQuality(), DomoticzRssiQuality());
|
||||
Response_P(DOMOTICZ_MESSAGE, (int)Settings.domoticz_relay_idx[device -1], (TasmotaGlobal.power & (1 << (device -1))) ? 1 : 0, (TasmotaGlobal.light_type) ? svalue : "", DomoticzBatteryQuality(), DomoticzRssiQuality());
|
||||
MqttPublish(domoticz_in_topic);
|
||||
#ifdef USE_SONOFF_IFAN
|
||||
}
|
||||
|
@ -151,7 +151,7 @@ void DomoticzMqttUpdate(void) {
|
|||
domoticz_update_timer--;
|
||||
if (domoticz_update_timer <= 0) {
|
||||
domoticz_update_timer = Settings.domoticz_update_timer;
|
||||
for (uint32_t i = 1; i <= devices_present; i++) {
|
||||
for (uint32_t i = 1; i <= TasmotaGlobal.devices_present; i++) {
|
||||
#ifdef USE_SHUTTER
|
||||
if (domoticz_is_shutter)
|
||||
{
|
||||
|
@ -175,7 +175,7 @@ void DomoticzMqttUpdate(void) {
|
|||
}
|
||||
|
||||
void DomoticzMqttSubscribe(void) {
|
||||
uint8_t maxdev = (devices_present > MAX_DOMOTICZ_IDX) ? MAX_DOMOTICZ_IDX : devices_present;
|
||||
uint8_t maxdev = (TasmotaGlobal.devices_present > MAX_DOMOTICZ_IDX) ? MAX_DOMOTICZ_IDX : TasmotaGlobal.devices_present;
|
||||
for (uint32_t i = 0; i < maxdev; i++) {
|
||||
if (Settings.domoticz_relay_idx[i]) {
|
||||
domoticz_subscribe = true;
|
||||
|
@ -223,7 +223,7 @@ bool DomoticzMqttData(void) {
|
|||
|
||||
bool found = false;
|
||||
if ((idx > 0) && (nvalue >= 0) && (nvalue <= 15)) {
|
||||
uint8_t maxdev = (devices_present > MAX_DOMOTICZ_IDX) ? MAX_DOMOTICZ_IDX : devices_present;
|
||||
uint8_t maxdev = (TasmotaGlobal.devices_present > MAX_DOMOTICZ_IDX) ? MAX_DOMOTICZ_IDX : TasmotaGlobal.devices_present;
|
||||
for (uint32_t i = 0; i < maxdev; i++) {
|
||||
if (idx == Settings.domoticz_relay_idx[i]) {
|
||||
bool iscolordimmer = strcmp_P(domoticz.getStr(PSTR("dtype")), PSTR("Color Switch")) == 0;
|
||||
|
@ -293,7 +293,7 @@ bool DomoticzMqttData(void) {
|
|||
} else {
|
||||
return true; // Invalid data
|
||||
}
|
||||
if (light_type && (Settings.light_dimmer == nvalue) && ((TasmotaGlobal.power >> i) &1)) {
|
||||
if (TasmotaGlobal.light_type && (Settings.light_dimmer == nvalue) && ((TasmotaGlobal.power >> i) &1)) {
|
||||
return true; // State already set
|
||||
}
|
||||
snprintf_P(XdrvMailbox.topic, XdrvMailbox.index, PSTR("/" D_CMND_DIMMER));
|
||||
|
@ -305,7 +305,7 @@ bool DomoticzMqttData(void) {
|
|||
if (((TasmotaGlobal.power >> i) &1) == (power_t)nvalue) {
|
||||
return true; // Stop loop
|
||||
}
|
||||
snprintf_P(XdrvMailbox.topic, XdrvMailbox.index, PSTR("/" D_CMND_POWER "%s"), (devices_present > 1) ? stemp1 : "");
|
||||
snprintf_P(XdrvMailbox.topic, XdrvMailbox.index, PSTR("/" D_CMND_POWER "%s"), (TasmotaGlobal.devices_present > 1) ? stemp1 : "");
|
||||
snprintf_P(XdrvMailbox.data, XdrvMailbox.data_len, PSTR("%d"), nvalue);
|
||||
found = true;
|
||||
}
|
||||
|
@ -381,9 +381,9 @@ void DomoticzSensor(uint8_t idx, char *data) {
|
|||
if (Settings.domoticz_sensor_idx[idx]) {
|
||||
char dmess[128]; // {"idx":26700,"nvalue":0,"svalue":"22330.1;10234.4;22000.5;10243.4;1006;3000","Battery":100,"RSSI":10}
|
||||
|
||||
memcpy(dmess, mqtt_data, sizeof(dmess));
|
||||
memcpy(dmess, TasmotaGlobal.mqtt_data, sizeof(dmess));
|
||||
DomoticzSendData(idx, Settings.domoticz_sensor_idx[idx], data);
|
||||
memcpy(mqtt_data, dmess, sizeof(dmess));
|
||||
memcpy(TasmotaGlobal.mqtt_data, dmess, sizeof(dmess));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -560,7 +560,7 @@ void HandleDomoticzConfiguration(void) {
|
|||
WSContentSendStyle();
|
||||
WSContentSend_P(HTTP_FORM_DOMOTICZ);
|
||||
for (uint32_t i = 0; i < MAX_DOMOTICZ_IDX; i++) {
|
||||
if (i < devices_present) {
|
||||
if (i < TasmotaGlobal.devices_present) {
|
||||
WSContentSend_P(HTTP_FORM_DOMOTICZ_RELAY,
|
||||
i +1, i, Settings.domoticz_relay_idx[i],
|
||||
i +1, i, Settings.domoticz_key_idx[i]);
|
||||
|
|
|
@ -109,7 +109,7 @@ void SerialBridgeInit(void)
|
|||
if (SerialBridgeSerial->begin(Settings.sbaudrate * 300)) { // Baud rate is stored div 300 so it fits into 16 bits
|
||||
if (SerialBridgeSerial->hardwareSerial()) {
|
||||
ClaimSerial();
|
||||
serial_bridge_buffer = serial_in_buffer; // Use idle serial buffer to save RAM
|
||||
serial_bridge_buffer = TasmotaGlobal.serial_in_buffer; // Use idle serial buffer to save RAM
|
||||
} else {
|
||||
serial_bridge_buffer = (char*)(malloc(SERIAL_BRIDGE_BUFFER_SIZE));
|
||||
}
|
||||
|
|
|
@ -290,7 +290,7 @@ void TimerEverySecond(void)
|
|||
XdrvRulesProcess();
|
||||
} else
|
||||
#endif // USE_RULES
|
||||
if (devices_present) { ExecuteCommandPower(xtimer.device +1, xtimer.power, SRC_TIMER); }
|
||||
if (TasmotaGlobal.devices_present) { ExecuteCommandPower(xtimer.device +1, xtimer.power, SRC_TIMER); }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -311,7 +311,7 @@ void PrepShowTimer(uint32_t index)
|
|||
|
||||
char soutput[80];
|
||||
soutput[0] = '\0';
|
||||
if (devices_present) {
|
||||
if (TasmotaGlobal.devices_present) {
|
||||
snprintf_P(soutput, sizeof(soutput), PSTR(",\"" D_JSON_TIMER_OUTPUT "\":%d"), xtimer.device +1);
|
||||
}
|
||||
#ifdef USE_SUNRISE
|
||||
|
@ -350,7 +350,7 @@ void CmndTimer(void)
|
|||
} else {
|
||||
//#ifndef USE_RULES
|
||||
#if defined(USE_RULES)==0 && defined(USE_SCRIPT)==0
|
||||
if (devices_present) {
|
||||
if (TasmotaGlobal.devices_present) {
|
||||
#endif
|
||||
JsonParser parser(XdrvMailbox.data);
|
||||
JsonParserObject root = parser.getRootObject();
|
||||
|
@ -425,12 +425,12 @@ void CmndTimer(void)
|
|||
val = root[PSTR(D_JSON_TIMER_OUTPUT)];
|
||||
if (val) {
|
||||
uint8_t device = (val.getUInt() -1) & 0x0F;
|
||||
Settings.timer[index].device = (device < devices_present) ? device : 0;
|
||||
Settings.timer[index].device = (device < TasmotaGlobal.devices_present) ? device : 0;
|
||||
}
|
||||
val = root[PSTR(D_JSON_TIMER_ACTION)];
|
||||
if (val) {
|
||||
uint8_t action = val.getUInt() & 0x03;
|
||||
Settings.timer[index].power = (devices_present) ? action : 3; // If no devices than only allow rules
|
||||
Settings.timer[index].power = (TasmotaGlobal.devices_present) ? action : 3; // If no devices than only allow rules
|
||||
}
|
||||
|
||||
index++;
|
||||
|
@ -482,7 +482,7 @@ void CmndTimers(void)
|
|||
jsflg = 0;
|
||||
}
|
||||
}
|
||||
mqtt_data[0] = '\0';
|
||||
ResponseClear();
|
||||
}
|
||||
|
||||
#ifdef USE_SUNRISE
|
||||
|
@ -856,10 +856,10 @@ void HandleTimerConfiguration(void)
|
|||
#ifdef USE_SUNRISE
|
||||
WSContentSend_P(HTTP_TIMER_SCRIPT2);
|
||||
#endif // USE_SUNRISE
|
||||
WSContentSend_P(HTTP_TIMER_SCRIPT3, devices_present);
|
||||
WSContentSend_P(HTTP_TIMER_SCRIPT4, WebColor(COL_TIMER_TAB_BACKGROUND), WebColor(COL_TIMER_TAB_TEXT), WebColor(COL_FORM), WebColor(COL_TEXT), devices_present);
|
||||
WSContentSend_P(HTTP_TIMER_SCRIPT5, MAX_TIMERS, devices_present);
|
||||
WSContentSend_P(HTTP_TIMER_SCRIPT6, devices_present);
|
||||
WSContentSend_P(HTTP_TIMER_SCRIPT3, TasmotaGlobal.devices_present);
|
||||
WSContentSend_P(HTTP_TIMER_SCRIPT4, WebColor(COL_TIMER_TAB_BACKGROUND), WebColor(COL_TIMER_TAB_TEXT), WebColor(COL_FORM), WebColor(COL_TEXT), TasmotaGlobal.devices_present);
|
||||
WSContentSend_P(HTTP_TIMER_SCRIPT5, MAX_TIMERS, TasmotaGlobal.devices_present);
|
||||
WSContentSend_P(HTTP_TIMER_SCRIPT6, TasmotaGlobal.devices_present);
|
||||
WSContentSendStyle_P(HTTP_TIMER_STYLE, WebColor(COL_FORM));
|
||||
WSContentSend_P(HTTP_FORM_TIMER1, (Settings.flag3.timers_enable) ? " checked" : ""); // CMND_TIMERS
|
||||
for (uint32_t i = 0; i < MAX_TIMERS; i++) {
|
||||
|
@ -924,7 +924,7 @@ bool Xdrv09(uint8_t function)
|
|||
#if defined(USE_RULES) || defined(USE_SCRIPT)
|
||||
WSContentSend_P(HTTP_BTN_MENU_TIMER);
|
||||
#else
|
||||
if (devices_present) { WSContentSend_P(HTTP_BTN_MENU_TIMER); }
|
||||
if (TasmotaGlobal.devices_present) { WSContentSend_P(HTTP_BTN_MENU_TIMER); }
|
||||
#endif // USE_RULES
|
||||
break;
|
||||
case FUNC_WEB_ADD_HANDLER:
|
||||
|
|
|
@ -725,7 +725,7 @@ bool RuleSetProcess(uint8_t rule_set, String &event_saved)
|
|||
RulesVarReplace(commands, F("%UTCTIME%"), String(UtcTime()));
|
||||
RulesVarReplace(commands, F("%UPTIME%"), String(MinutesUptime()));
|
||||
RulesVarReplace(commands, F("%TIMESTAMP%"), GetDateAndTime(DT_LOCAL));
|
||||
RulesVarReplace(commands, F("%TOPIC%"), mqtt_topic);
|
||||
RulesVarReplace(commands, F("%TOPIC%"), TasmotaGlobal.mqtt_topic);
|
||||
snprintf_P(stemp, sizeof(stemp), PSTR("%06X"), ESP_getChipId());
|
||||
RulesVarReplace(commands, F("%DEVICEID%"), stemp);
|
||||
String mac_address = WiFi.macAddress();
|
||||
|
@ -805,7 +805,7 @@ bool RulesProcessEvent(char *json_event)
|
|||
|
||||
bool RulesProcess(void)
|
||||
{
|
||||
return RulesProcessEvent(mqtt_data);
|
||||
return RulesProcessEvent(TasmotaGlobal.mqtt_data);
|
||||
}
|
||||
|
||||
void RulesInit(void)
|
||||
|
@ -833,7 +833,7 @@ void RulesEvery50ms(void)
|
|||
if (-1 == Rules.new_power) { Rules.new_power = TasmotaGlobal.power; }
|
||||
if (Rules.new_power != Rules.old_power) {
|
||||
if (Rules.old_power != -1) {
|
||||
for (uint32_t i = 0; i < devices_present; i++) {
|
||||
for (uint32_t i = 0; i < TasmotaGlobal.devices_present; i++) {
|
||||
uint8_t new_state = (Rules.new_power >> i) &1;
|
||||
if (new_state != ((Rules.old_power >> i) &1)) {
|
||||
snprintf_P(json_event, sizeof(json_event), PSTR("{\"Power%d\":{\"State\":%d}}"), i +1, new_state);
|
||||
|
@ -842,7 +842,7 @@ void RulesEvery50ms(void)
|
|||
}
|
||||
} else {
|
||||
// Boot time POWER OUTPUTS (Relays) Status
|
||||
for (uint32_t i = 0; i < devices_present; i++) {
|
||||
for (uint32_t i = 0; i < TasmotaGlobal.devices_present; i++) {
|
||||
uint8_t new_state = (Rules.new_power >> i) &1;
|
||||
snprintf_P(json_event, sizeof(json_event), PSTR("{\"Power%d\":{\"Boot\":%d}}"), i +1, new_state);
|
||||
RulesProcessEvent(json_event);
|
||||
|
@ -948,15 +948,15 @@ uint8_t rules_xsns_index = 0;
|
|||
void RulesEvery100ms(void)
|
||||
{
|
||||
if (Settings.rule_enabled && !Rules.busy && (TasmotaGlobal.uptime > 4)) { // Any rule enabled and allow 4 seconds start-up time for sensors (#3811)
|
||||
mqtt_data[0] = '\0';
|
||||
ResponseClear();
|
||||
int tele_period_save = TasmotaGlobal.tele_period;
|
||||
TasmotaGlobal.tele_period = 2; // Do not allow HA updates during next function call
|
||||
XsnsNextCall(FUNC_JSON_APPEND, rules_xsns_index); // ,"INA219":{"Voltage":4.494,"Current":0.020,"Power":0.089}
|
||||
TasmotaGlobal.tele_period = tele_period_save;
|
||||
if (strlen(mqtt_data)) {
|
||||
mqtt_data[0] = '{'; // {"INA219":{"Voltage":4.494,"Current":0.020,"Power":0.089}
|
||||
if (strlen(TasmotaGlobal.mqtt_data)) {
|
||||
TasmotaGlobal.mqtt_data[0] = '{'; // {"INA219":{"Voltage":4.494,"Current":0.020,"Power":0.089}
|
||||
ResponseJsonEnd();
|
||||
RulesProcessEvent(mqtt_data);
|
||||
RulesProcessEvent(TasmotaGlobal.mqtt_data);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1882,12 +1882,12 @@ void ExecuteCommandBlock(const char * commands, int len)
|
|||
String sCurrentCommand = oneCommand;
|
||||
sCurrentCommand.trim();
|
||||
if (sCurrentCommand.length() > 0
|
||||
&& backlog.size() < MAX_BACKLOG && !backlog_mutex)
|
||||
&& backlog.size() < MAX_BACKLOG && !TasmotaGlobal.backlog_mutex)
|
||||
{
|
||||
//Insert into backlog
|
||||
backlog_mutex = true;
|
||||
TasmotaGlobal.backlog_mutex = true;
|
||||
backlog.add(insertPosition, sCurrentCommand);
|
||||
backlog_mutex = false;
|
||||
TasmotaGlobal.backlog_mutex = false;
|
||||
insertPosition++;
|
||||
}
|
||||
}
|
||||
|
@ -2030,7 +2030,7 @@ void CmndRule(void)
|
|||
CmndRule();
|
||||
MqttPublishPrefixTopic_P(RESULT_OR_STAT, XdrvMailbox.command);
|
||||
}
|
||||
mqtt_data[0] = '\0'; // Disable further processing
|
||||
ResponseClear(); // Disable further processing
|
||||
return;
|
||||
}
|
||||
uint8_t index = XdrvMailbox.index;
|
||||
|
@ -2099,10 +2099,10 @@ void CmndRule(void)
|
|||
rule = rule.substring(0, MAX_RULE_SIZE);
|
||||
rule += F("...");
|
||||
}
|
||||
// snprintf_P (mqtt_data, sizeof(mqtt_data), PSTR("{\"%s%d\":\"%s\",\"Once\":\"%s\",\"StopOnError\":\"%s\",\"Free\":%d,\"Rules\":\"%s\"}"),
|
||||
// snprintf_P (TasmotaGlobal.mqtt_data, sizeof(TasmotaGlobal.mqtt_data), PSTR("{\"%s%d\":\"%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 (mqtt_data, sizeof(mqtt_data), PSTR("{\"%s%d\":\"%s\",\"Once\":\"%s\",\"StopOnError\":\"%s\",\"Length\":%d,\"Free\":%d,\"Rules\":\"%s\"}"),
|
||||
snprintf_P (TasmotaGlobal.mqtt_data, sizeof(TasmotaGlobal.mqtt_data), PSTR("{\"%s%d\":\"%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),
|
||||
|
@ -2121,7 +2121,7 @@ void CmndRuleTimer(void)
|
|||
Rules.timer[XdrvMailbox.index -1] = (XdrvMailbox.payload > 0) ? millis() + (1000 * XdrvMailbox.payload) : 0;
|
||||
#endif // USE_EXPRESSION
|
||||
}
|
||||
mqtt_data[0] = '\0';
|
||||
ResponseClear();
|
||||
for (uint32_t i = 0; i < MAX_RULE_TIMERS; i++) {
|
||||
ResponseAppend_P(PSTR("%c\"T%d\":%d"), (i) ? ',' : '{', i +1, (Rules.timer[i]) ? (Rules.timer[i] - millis()) / 1000 : 0);
|
||||
}
|
||||
|
@ -2144,7 +2144,7 @@ void CmndVariable(void)
|
|||
{
|
||||
if ((XdrvMailbox.index > 0) && (XdrvMailbox.index <= MAX_RULE_VARS)) {
|
||||
if (!XdrvMailbox.usridx) {
|
||||
mqtt_data[0] = '\0';
|
||||
ResponseClear();
|
||||
for (uint32_t i = 0; i < MAX_RULE_VARS; i++) {
|
||||
ResponseAppend_P(PSTR("%c\"Var%d\":\"%s\""), (i) ? ',' : '{', i +1, rules_vars[i]);
|
||||
}
|
||||
|
|
|
@ -512,7 +512,7 @@ void ScriptEverySecond(void) {
|
|||
}
|
||||
|
||||
void RulesTeleperiod(void) {
|
||||
if (bitRead(Settings.rule_enabled, 0) && mqtt_data[0]) Run_Scripter(">T", 2, mqtt_data);
|
||||
if (bitRead(Settings.rule_enabled, 0) && TasmotaGlobal.mqtt_data[0]) Run_Scripter(">T", 2, TasmotaGlobal.mqtt_data);
|
||||
}
|
||||
|
||||
// EEPROM MACROS
|
||||
|
@ -1019,7 +1019,7 @@ void Script_Stop_UDP(void) {
|
|||
}
|
||||
|
||||
void Script_Init_UDP() {
|
||||
if (global_state.network_down) return;
|
||||
if (TasmotaGlobal.global_state.network_down) return;
|
||||
if (!glob_script_mem.udp_flags.udp_used) return;
|
||||
if (glob_script_mem.udp_flags.udp_connected) return;
|
||||
|
||||
|
@ -1033,7 +1033,7 @@ void Script_Init_UDP() {
|
|||
}
|
||||
|
||||
void Script_PollUdp(void) {
|
||||
if (global_state.network_down) return;
|
||||
if (TasmotaGlobal.global_state.network_down) return;
|
||||
if (!glob_script_mem.udp_flags.udp_used) return;
|
||||
if (glob_script_mem.udp_flags.udp_connected ) {
|
||||
while (Script_PortUdp.parsePacket()) {
|
||||
|
@ -2548,7 +2548,7 @@ chknext:
|
|||
goto exit;
|
||||
}
|
||||
if (!strncmp(vname, "mqtts", 5)) {
|
||||
fvar = !global_state.mqtt_down;
|
||||
fvar = !TasmotaGlobal.global_state.mqtt_down;
|
||||
goto exit;
|
||||
}
|
||||
if (!strncmp(vname, "mp(", 3)) {
|
||||
|
@ -2680,7 +2680,7 @@ chknext:
|
|||
if (!strncmp(vname, "pwr[", 4)) {
|
||||
GetNumericArgument(vname + 4, OPER_EQU, &fvar, 0);
|
||||
uint8_t index = fvar;
|
||||
if (index<=devices_present) {
|
||||
if (index<=TasmotaGlobal.devices_present) {
|
||||
fvar = bitRead(TasmotaGlobal.power, index - 1);
|
||||
} else {
|
||||
fvar = -1;
|
||||
|
@ -2854,7 +2854,7 @@ chknext:
|
|||
if (!strncmp(vname, "sht[", 4)) {
|
||||
GetNumericArgument(vname + 4, OPER_EQU, &fvar, 0);
|
||||
uint8_t index = fvar;
|
||||
if (index<=shutters_present) {
|
||||
if (index<=TasmotaGlobal.shutters_present) {
|
||||
fvar = Settings.shutter_position[index - 1];
|
||||
} else {
|
||||
fvar = -1;
|
||||
|
@ -3139,7 +3139,7 @@ chknext:
|
|||
goto exit;
|
||||
}
|
||||
if (!strncmp(vname, "wifis", 5)) {
|
||||
fvar = !global_state.wifi_down;
|
||||
fvar = !TasmotaGlobal.global_state.wifi_down;
|
||||
goto exit;
|
||||
}
|
||||
break;
|
||||
|
@ -3555,7 +3555,7 @@ void toLogN(const char *cp, uint8_t len) {
|
|||
void toLogEOL(const char *s1,const char *str) {
|
||||
if (!str) return;
|
||||
uint8_t index = 0;
|
||||
char *cp = log_data;
|
||||
char *cp = TasmotaGlobal.log_data;
|
||||
strcpy(cp, s1);
|
||||
cp += strlen(s1);
|
||||
while (*str) {
|
||||
|
@ -4496,15 +4496,15 @@ uint8_t script_xsns_index = 0;
|
|||
void ScripterEvery100ms(void) {
|
||||
|
||||
if (Settings.rule_enabled && (TasmotaGlobal.uptime > 4)) {
|
||||
mqtt_data[0] = '\0';
|
||||
ResponseClear();
|
||||
uint16_t script_tele_period_save = TasmotaGlobal.tele_period;
|
||||
TasmotaGlobal.tele_period = 2;
|
||||
XsnsNextCall(FUNC_JSON_APPEND, script_xsns_index);
|
||||
TasmotaGlobal.tele_period = script_tele_period_save;
|
||||
if (strlen(mqtt_data)) {
|
||||
mqtt_data[0] = '{';
|
||||
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s}"), mqtt_data);
|
||||
Run_Scripter(">T", 2, mqtt_data);
|
||||
if (strlen(TasmotaGlobal.mqtt_data)) {
|
||||
TasmotaGlobal.mqtt_data[0] = '{';
|
||||
snprintf_P(TasmotaGlobal.mqtt_data, sizeof(TasmotaGlobal.mqtt_data), PSTR("%s}"), TasmotaGlobal.mqtt_data);
|
||||
Run_Scripter(">T", 2, TasmotaGlobal.mqtt_data);
|
||||
}
|
||||
}
|
||||
if (Settings.rule_enabled) {
|
||||
|
@ -5517,14 +5517,14 @@ void Script_Check_Hue(String *response) {
|
|||
}
|
||||
// append response
|
||||
if (response) {
|
||||
if (devices_present) {
|
||||
if (TasmotaGlobal.devices_present) {
|
||||
*response += ",\"";
|
||||
}
|
||||
else {
|
||||
if (hue_devs>0) *response += ",\"";
|
||||
else *response += "\"";
|
||||
}
|
||||
*response += String(EncodeLightId(hue_devs + devices_present + 1))+"\":";
|
||||
*response += String(EncodeLightId(hue_devs + TasmotaGlobal.devices_present + 1))+"\":";
|
||||
Script_HueStatus(response, hue_devs);
|
||||
//AddLog_P2(LOG_LEVEL_INFO, PSTR("Hue: %s - %d "),response->c_str(), hue_devs);
|
||||
}
|
||||
|
@ -5571,7 +5571,7 @@ void Script_Handle_Hue(String *path) {
|
|||
bool resp = false;
|
||||
|
||||
uint8_t device = DecodeLightId(atoi(path->c_str()));
|
||||
uint8_t index = device - devices_present - 1;
|
||||
uint8_t index = device - TasmotaGlobal.devices_present - 1;
|
||||
|
||||
if (Webserver->args()) {
|
||||
response = "[";
|
||||
|
@ -5784,7 +5784,7 @@ bool ScriptCommand(void) {
|
|||
} else {
|
||||
if ('>' == XdrvMailbox.data[0]) {
|
||||
// execute script
|
||||
snprintf_P (mqtt_data, sizeof(mqtt_data), PSTR("{\"%s\":\"%s\"}"), command,XdrvMailbox.data);
|
||||
snprintf_P (TasmotaGlobal.mqtt_data, sizeof(TasmotaGlobal.mqtt_data), PSTR("{\"%s\":\"%s\"}"), command,XdrvMailbox.data);
|
||||
if (bitRead(Settings.rule_enabled, 0)) {
|
||||
for (uint8_t count = 0; count<XdrvMailbox.data_len; count++) {
|
||||
if (XdrvMailbox.data[count]==';') XdrvMailbox.data[count] = '\n';
|
||||
|
@ -5803,15 +5803,15 @@ bool ScriptCommand(void) {
|
|||
if (glob_script_mem.glob_error==1) {
|
||||
// was string, not number
|
||||
GetStringArgument(lp, OPER_EQU, str, 0);
|
||||
snprintf_P (mqtt_data, sizeof(mqtt_data), PSTR("{\"script\":{\"%s\":\"%s\"}}"), lp, str);
|
||||
snprintf_P (TasmotaGlobal.mqtt_data, sizeof(TasmotaGlobal.mqtt_data), PSTR("{\"script\":{\"%s\":\"%s\"}}"), lp, str);
|
||||
} else {
|
||||
dtostrfd(fvar, 6, str);
|
||||
snprintf_P (mqtt_data, sizeof(mqtt_data), PSTR("{\"script\":{\"%s\":%s}}"), lp, str);
|
||||
snprintf_P (TasmotaGlobal.mqtt_data, sizeof(TasmotaGlobal.mqtt_data), PSTR("{\"script\":{\"%s\":%s}}"), lp, str);
|
||||
}
|
||||
}
|
||||
return serviced;
|
||||
}
|
||||
snprintf_P (mqtt_data, sizeof(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));
|
||||
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));
|
||||
#ifdef SUPPORT_MQTT_EVENT
|
||||
} else if (CMND_SUBSCRIBE == command_code) { //MQTT Subscribe command. Subscribe <Event>, <Topic> [, <Key>]
|
||||
String result = ScriptSubscribe(XdrvMailbox.data, XdrvMailbox.data_len);
|
||||
|
@ -7231,7 +7231,7 @@ uint32_t scripter_create_task(uint32_t num, uint32_t time, uint32_t core, uint32
|
|||
|
||||
// get tesla powerwall info page json string
|
||||
uint32_t call2https(const char *host, const char *path) {
|
||||
if (global_state.wifi_down) return 1;
|
||||
if (TasmotaGlobal.global_state.wifi_down) return 1;
|
||||
uint32_t status = 0;
|
||||
#ifdef ESP32
|
||||
WiFiClientSecure *httpsClient;
|
||||
|
@ -7481,7 +7481,7 @@ bool Xdrv10(uint8_t function)
|
|||
break;
|
||||
case FUNC_RULES_PROCESS:
|
||||
if (bitRead(Settings.rule_enabled, 0)) {
|
||||
Run_Scripter(">E", 2, mqtt_data);
|
||||
Run_Scripter(">E", 2, TasmotaGlobal.mqtt_data);
|
||||
result = event_handeled;
|
||||
}
|
||||
break;
|
||||
|
|
|
@ -468,45 +468,45 @@ void KNX_INIT(void)
|
|||
// and activate options according to the hardware
|
||||
/*for (uint32_t i = GPIO_REL1; i < GPIO_REL8 + 1; ++i)
|
||||
{
|
||||
if (GetUsedInModule(i, my_module.io)) { device_param[i - GPIO_REL1].show = true; }
|
||||
if (GetUsedInModule(i, TasmotaGlobal.my_module.io)) { device_param[i - GPIO_REL1].show = true; }
|
||||
}
|
||||
for (uint32_t i = GPIO_REL1_INV; i < GPIO_REL8_INV + 1; ++i)
|
||||
{
|
||||
if (GetUsedInModule(i, my_module.io)) { device_param[i - GPIO_REL1_INV].show = true; }
|
||||
if (GetUsedInModule(i, TasmotaGlobal.my_module.io)) { device_param[i - GPIO_REL1_INV].show = true; }
|
||||
}*/
|
||||
for (uint32_t i = 0; i < devices_present; ++i)
|
||||
for (uint32_t i = 0; i < TasmotaGlobal.devices_present; ++i)
|
||||
{
|
||||
device_param[i].show = true;
|
||||
}
|
||||
for (uint32_t i = GPIO_SWT1; i < GPIO_SWT1 + 4; ++i)
|
||||
{
|
||||
if (GetUsedInModule(i, my_module.io)) { device_param[i - GPIO_SWT1 + 8].show = true; }
|
||||
if (GetUsedInModule(i, TasmotaGlobal.my_module.io)) { device_param[i - GPIO_SWT1 + 8].show = true; }
|
||||
}
|
||||
for (uint32_t i = GPIO_KEY1; i < GPIO_KEY1 + 4; ++i)
|
||||
{
|
||||
if (GetUsedInModule(i, my_module.io)) { device_param[i - GPIO_KEY1 + 8].show = true; }
|
||||
if (GetUsedInModule(i, TasmotaGlobal.my_module.io)) { device_param[i - GPIO_KEY1 + 8].show = true; }
|
||||
}
|
||||
for (uint32_t i = GPIO_SWT1_NP; i < GPIO_SWT1_NP + 4; ++i)
|
||||
{
|
||||
if (GetUsedInModule(i, my_module.io)) { device_param[i - GPIO_SWT1_NP + 8].show = true; }
|
||||
if (GetUsedInModule(i, TasmotaGlobal.my_module.io)) { device_param[i - GPIO_SWT1_NP + 8].show = true; }
|
||||
}
|
||||
for (uint32_t i = GPIO_KEY1_NP; i < GPIO_KEY1_NP + 4; ++i)
|
||||
{
|
||||
if (GetUsedInModule(i, my_module.io)) { device_param[i - GPIO_KEY1_NP + 8].show = true; }
|
||||
if (GetUsedInModule(i, TasmotaGlobal.my_module.io)) { device_param[i - GPIO_KEY1_NP + 8].show = true; }
|
||||
}
|
||||
if (GetUsedInModule(GPIO_DHT11, my_module.io)) { device_param[KNX_TEMPERATURE-1].show = true; }
|
||||
if (GetUsedInModule(GPIO_DHT22, my_module.io)) { device_param[KNX_TEMPERATURE-1].show = true; }
|
||||
if (GetUsedInModule(GPIO_SI7021, my_module.io)) { device_param[KNX_TEMPERATURE-1].show = true; }
|
||||
if (GetUsedInModule(GPIO_DHT11, TasmotaGlobal.my_module.io)) { device_param[KNX_TEMPERATURE-1].show = true; }
|
||||
if (GetUsedInModule(GPIO_DHT22, TasmotaGlobal.my_module.io)) { device_param[KNX_TEMPERATURE-1].show = true; }
|
||||
if (GetUsedInModule(GPIO_SI7021, TasmotaGlobal.my_module.io)) { device_param[KNX_TEMPERATURE-1].show = true; }
|
||||
#ifdef USE_DS18x20
|
||||
if (GetUsedInModule(GPIO_DSB, my_module.io)) { device_param[KNX_TEMPERATURE-1].show = true; }
|
||||
if (GetUsedInModule(GPIO_DSB, TasmotaGlobal.my_module.io)) { device_param[KNX_TEMPERATURE-1].show = true; }
|
||||
#endif
|
||||
if (GetUsedInModule(GPIO_DHT11, my_module.io)) { device_param[KNX_HUMIDITY-1].show = true; }
|
||||
if (GetUsedInModule(GPIO_DHT22, my_module.io)) { device_param[KNX_HUMIDITY-1].show = true; }
|
||||
if (GetUsedInModule(GPIO_SI7021, my_module.io)) { device_param[KNX_HUMIDITY-1].show = true; }
|
||||
if (GetUsedInModule(GPIO_DHT11, TasmotaGlobal.my_module.io)) { device_param[KNX_HUMIDITY-1].show = true; }
|
||||
if (GetUsedInModule(GPIO_DHT22, TasmotaGlobal.my_module.io)) { device_param[KNX_HUMIDITY-1].show = true; }
|
||||
if (GetUsedInModule(GPIO_SI7021, TasmotaGlobal.my_module.io)) { device_param[KNX_HUMIDITY-1].show = true; }
|
||||
|
||||
#if defined(USE_ENERGY_SENSOR)
|
||||
// Any device with a Power Monitoring
|
||||
if ( energy_flg != ENERGY_NONE ) {
|
||||
if ( TasmotaGlobal.energy_driver != ENERGY_NONE ) {
|
||||
device_param[KNX_ENERGY_POWER-1].show = true;
|
||||
device_param[KNX_ENERGY_DAILY-1].show = true;
|
||||
device_param[KNX_ENERGY_START-1].show = true;
|
||||
|
@ -1255,7 +1255,7 @@ bool Xdrv11(uint8_t function)
|
|||
bool result = false;
|
||||
switch (function) {
|
||||
case FUNC_LOOP:
|
||||
if (!global_state.network_down) { knx.loop(); } // Process knx events
|
||||
if (!TasmotaGlobal.global_state.network_down) { knx.loop(); } // Process knx events
|
||||
break;
|
||||
case FUNC_EVERY_50_MSECOND:
|
||||
if (toggle_inhibit) {
|
||||
|
|
|
@ -213,27 +213,27 @@ void HassDiscoveryRelays(struct HASS &Hass)
|
|||
uint8_t lightidx = MAX_RELAYS + 1; // Will store the starting position of the lights
|
||||
bool iFan = false;
|
||||
|
||||
Hass.RelPst = devices_present > 0;
|
||||
Hass.RelPst = TasmotaGlobal.devices_present > 0;
|
||||
|
||||
#ifdef ESP8266
|
||||
if (SONOFF_IFAN02 == my_module_type || SONOFF_IFAN03 == my_module_type) { iFan = true;}
|
||||
if (SONOFF_IFAN02 == TasmotaGlobal.module_type || SONOFF_IFAN03 == TasmotaGlobal.module_type) { iFan = true;}
|
||||
#endif // ESP8266
|
||||
|
||||
if (Light.subtype > LST_NONE) {
|
||||
if (!light_controller.isCTRGBLinked()) { // One or two lights present
|
||||
lightidx = devices_present - 2;
|
||||
lightidx = TasmotaGlobal.devices_present - 2;
|
||||
} else {
|
||||
lightidx = devices_present - 1;
|
||||
lightidx = TasmotaGlobal.devices_present - 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (Light.device > 0 && Settings.flag3.pwm_multi_channels) { // How many relays are light devices?
|
||||
lightidx = devices_present - Light.subtype;
|
||||
lightidx = TasmotaGlobal.devices_present - Light.subtype;
|
||||
}
|
||||
|
||||
for (uint32_t i = 0; i < MAX_RELAYS; i++) {
|
||||
|
||||
if (i < devices_present) {
|
||||
if (i < TasmotaGlobal.devices_present) {
|
||||
|
||||
#ifdef USE_SHUTTER
|
||||
if (Settings.flag3.shutter_mode) {
|
||||
|
@ -255,7 +255,7 @@ void HassDiscoveryRelays(struct HASS &Hass)
|
|||
if (i >= lightidx || (iFan && i == 0)) { // First relay on Ifan controls the light
|
||||
Hass.Relay[i] = 2; // Relay is a light
|
||||
} else {
|
||||
if (!iFan) { // Relays 2-4 for ifan are controlled by FANSPEED and don't need to be present if my_module_type = SONOFF_IFAN02 or SONOFF_IFAN03
|
||||
if (!iFan) { // Relays 2-4 for ifan are controlled by FANSPEED and don't need to be present if TasmotaGlobal.module_type = SONOFF_IFAN02 or SONOFF_IFAN03
|
||||
Hass.Relay[i] = 1; // Simple Relay
|
||||
}
|
||||
}
|
||||
|
@ -282,7 +282,7 @@ void NewHAssDiscovery(void)
|
|||
struct HASS Hass;
|
||||
HassDiscoveryRelays(Hass);
|
||||
|
||||
uint32_t maxfn = (devices_present > MAX_FRIENDLYNAMES) ? MAX_FRIENDLYNAMES : (!devices_present) ? 1 : devices_present;
|
||||
uint32_t maxfn = (TasmotaGlobal.devices_present > MAX_FRIENDLYNAMES) ? MAX_FRIENDLYNAMES : (!TasmotaGlobal.devices_present) ? 1 : TasmotaGlobal.devices_present;
|
||||
for (uint32_t i = 0; i < MAX_FRIENDLYNAMES; i++) {
|
||||
char fname[TOPSZ];
|
||||
snprintf_P(fname, sizeof(fname), PSTR("\"%s\""), EscapeJSONString(SettingsText(SET_FRIENDLYNAME1 +i)).c_str());
|
||||
|
@ -291,7 +291,7 @@ void NewHAssDiscovery(void)
|
|||
|
||||
stemp3[0] = '\0';
|
||||
// Enable Discovery for Switches only if SwitchTopic is set to a custom name or if there is not a Power device
|
||||
auto discover_switches = ((KeyTopicActive(1) && (strcmp(SettingsText(SET_MQTT_SWITCH_TOPIC), mqtt_topic))) || !Hass.RelPst);
|
||||
auto discover_switches = ((KeyTopicActive(1) && (strcmp(SettingsText(SET_MQTT_SWITCH_TOPIC), TasmotaGlobal.mqtt_topic))) || !Hass.RelPst);
|
||||
for (uint32_t i = 0; i < MAX_SWITCHES; i++) {
|
||||
snprintf_P(stemp3, sizeof(stemp3), PSTR("%s%s%d"), stemp3, (i > 0 ? "," : ""), (PinUsed(GPIO_SWT1, i) & discover_switches) ? Settings.switchmode[i] : -1);
|
||||
}
|
||||
|
@ -301,15 +301,15 @@ void NewHAssDiscovery(void)
|
|||
for (uint32_t i = 0; i < MAX_KEYS; i++) {
|
||||
|
||||
#ifdef ESP8266
|
||||
if (i == 0 && (SONOFF_DUAL == my_module_type )) { SerialButton = true; }
|
||||
if (TUYA_DIMMER == my_module_type || SK03_TUYA == my_module_type) { TuyaMod = true; }
|
||||
if (i == 0 && (SONOFF_DUAL == TasmotaGlobal.module_type )) { SerialButton = true; }
|
||||
if (TUYA_DIMMER == TasmotaGlobal.module_type || SK03_TUYA == TasmotaGlobal.module_type) { TuyaMod = true; }
|
||||
#endif // ESP8266
|
||||
|
||||
snprintf_P(stemp4, sizeof(stemp4), PSTR("%s%s%d"), stemp4, (i > 0 ? "," : ""), (SerialButton ? 1 : (PinUsed(GPIO_KEY1, i)) & Settings.flag3.mqtt_buttons));
|
||||
SerialButton = false;
|
||||
}
|
||||
|
||||
mqtt_data[0] = '\0'; // Clear retained message
|
||||
ResponseClear(); // Clear retained message
|
||||
|
||||
// Full 12 chars MAC address as ID
|
||||
String mac_address = WiFi.macAddress();
|
||||
|
@ -318,11 +318,11 @@ void NewHAssDiscovery(void)
|
|||
snprintf_P(stopic, sizeof(stopic), PSTR("tasmota/discovery/%s/config"), unique_id);
|
||||
|
||||
// Send empty message if new discovery is disabled
|
||||
masterlog_level = 4; // Hide topic on clean and remove use weblog 4 to see it
|
||||
TasmotaGlobal.masterlog_level = 4; // Hide topic on clean and remove use weblog 4 to see it
|
||||
if (!Settings.flag.hass_discovery) { // HassDiscoveryRelays(relays)
|
||||
Response_P(HASS_DISCOVER_DEVICE, WiFi.localIP().toString().c_str(), SettingsText(SET_DEVICENAME),
|
||||
stemp2, my_hostname, unique_id, ModuleName().c_str(), TuyaMod, GetStateText(0), GetStateText(1), GetStateText(2), GetStateText(3),
|
||||
my_version, mqtt_topic, SettingsText(SET_MQTT_FULLTOPIC), SUB_PREFIX, PUB_PREFIX, PUB_PREFIX2, Hass.RelLst, stemp3, stemp4, Settings.flag.button_swap,
|
||||
stemp2, TasmotaGlobal.hostname, unique_id, ModuleName().c_str(), TuyaMod, GetStateText(0), GetStateText(1), GetStateText(2), GetStateText(3),
|
||||
TasmotaGlobal.version, TasmotaGlobal.mqtt_topic, SettingsText(SET_MQTT_FULLTOPIC), SUB_PREFIX, PUB_PREFIX, PUB_PREFIX2, Hass.RelLst, stemp3, stemp4, Settings.flag.button_swap,
|
||||
Settings.flag.button_single, Settings.flag.decimal_text, Settings.flag.not_power_linked, Settings.flag.hass_light, Settings.flag3.pwm_multi_channels,
|
||||
Settings.flag3.mqtt_buttons, Settings.flag3.shutter_mode, Settings.flag4.alexa_ct_range, light_controller.isCTRGBLinked(), Light.subtype);
|
||||
}
|
||||
|
@ -335,7 +335,7 @@ void NewHAssDiscovery(void)
|
|||
ResponseAppend_P(PSTR(",\"ver\":1}"));
|
||||
MqttPublish(stopic, true);
|
||||
}
|
||||
masterlog_level = 0; // Restore WebLog state
|
||||
TasmotaGlobal.masterlog_level = 0; // Restore WebLog state
|
||||
}
|
||||
|
||||
// NEW DISCOVERY
|
||||
|
@ -347,19 +347,19 @@ void TryResponseAppend_P(const char *format, ...)
|
|||
char dummy[2];
|
||||
int dlen = vsnprintf_P(dummy, 1, format, args);
|
||||
|
||||
int mlen = strlen(mqtt_data);
|
||||
int slen = sizeof(mqtt_data) - 1 - mlen;
|
||||
int mlen = strlen(TasmotaGlobal.mqtt_data);
|
||||
int slen = sizeof(TasmotaGlobal.mqtt_data) - 1 - mlen;
|
||||
if (dlen >= slen)
|
||||
{
|
||||
AddLog_P2(LOG_LEVEL_ERROR, PSTR("%s (%u/%u):"), kHAssError1, dlen, slen);
|
||||
va_start(args, format);
|
||||
vsnprintf_P(log_data, sizeof(log_data), format, args);
|
||||
vsnprintf_P(TasmotaGlobal.log_data, sizeof(TasmotaGlobal.log_data), format, args);
|
||||
AddLog(LOG_LEVEL_ERROR);
|
||||
}
|
||||
else
|
||||
{
|
||||
va_start(args, format);
|
||||
vsnprintf_P(mqtt_data + mlen, slen, format, args);
|
||||
vsnprintf_P(TasmotaGlobal.mqtt_data + mlen, slen, format, args);
|
||||
}
|
||||
va_end(args);
|
||||
}
|
||||
|
@ -393,10 +393,10 @@ void HAssAnnounceRelayLight(void)
|
|||
uint8_t shutter_mask = 0;
|
||||
|
||||
#ifdef ESP8266
|
||||
if (PWM_DIMMER == my_module_type ) { PwmMod = true; } //
|
||||
if (SONOFF_IFAN02 == my_module_type || SONOFF_IFAN03 == my_module_type) { FanMod = true; }
|
||||
if (SONOFF_DUAL == my_module_type) { valid_relay = 2; }
|
||||
if (TUYA_DIMMER == my_module_type || SK03_TUYA == my_module_type) { TuyaMod = true; }
|
||||
if (PWM_DIMMER == TasmotaGlobal.module_type ) { PwmMod = true; } //
|
||||
if (SONOFF_IFAN02 == TasmotaGlobal.module_type || SONOFF_IFAN03 == TasmotaGlobal.module_type) { FanMod = true; }
|
||||
if (SONOFF_DUAL == TasmotaGlobal.module_type) { valid_relay = 2; }
|
||||
if (TUYA_DIMMER == TasmotaGlobal.module_type || SK03_TUYA == TasmotaGlobal.module_type) { TuyaMod = true; }
|
||||
#endif //ESP8266
|
||||
|
||||
// If there is a special Light to be enabled and managed with SetOption68 or SetOption37 >= 128, Discovery calculates the maximum number of entities to be generated in advance
|
||||
|
@ -428,11 +428,11 @@ void HAssAnnounceRelayLight(void)
|
|||
TuyaDim = TuyaGetDpId((TUYA_MCU_FUNC_DIMMER) + TasmotaGlobal.active_device - 1);
|
||||
#endif //USE_TUYA_MCU
|
||||
|
||||
masterlog_level = ShowTopic = 4; // Hide topic on clean and remove use weblog 4 to see it
|
||||
TasmotaGlobal.masterlog_level = ShowTopic = 4; // Hide topic on clean and remove use weblog 4 to see it
|
||||
|
||||
bool RelayX = PinUsed(GPIO_REL1, i-1) || (valid_relay >= i) || (TuyaRel > 0 && TuyaMod) || (TuyaRelInv > 0 && TuyaMod); // Check if the gpio is configured as Relay or force it for Sonoff DUAL R1 with MCU and Tuya MCU
|
||||
is_topic_light = Settings.flag.hass_light && RelayX || light_type && !RelayX || PwmMod || (TuyaDim > 0 && TuyaMod); // SetOption30 - Enforce HAss autodiscovery as light
|
||||
mqtt_data[0] = '\0'; // Clear retained message
|
||||
is_topic_light = Settings.flag.hass_light && RelayX || TasmotaGlobal.light_type && !RelayX || PwmMod || (TuyaDim > 0 && TuyaMod); // SetOption30 - Enforce HAss autodiscovery as light
|
||||
ResponseClear(); // Clear retained message
|
||||
|
||||
// Clear "other" topic first in case the device has been reconfigured from light to switch or vice versa
|
||||
snprintf_P(unique_id, sizeof(unique_id), PSTR("%06X_%s_%d"), ESP_getChipId(), (is_topic_light) ? "RL" : "LI", i);
|
||||
|
@ -468,9 +468,9 @@ void HAssAnnounceRelayLight(void)
|
|||
}
|
||||
|
||||
GetPowerDevice(value_template, i, sizeof(value_template), Settings.flag.device_index_enable); // SetOption26 - Switch between POWER or POWER1
|
||||
GetTopic_P(command_topic, CMND, mqtt_topic, value_template);
|
||||
GetTopic_P(state_topic, TELE, mqtt_topic, D_RSLT_STATE);
|
||||
GetTopic_P(availability_topic, TELE, mqtt_topic, S_LWT);
|
||||
GetTopic_P(command_topic, CMND, TasmotaGlobal.mqtt_topic, value_template);
|
||||
GetTopic_P(state_topic, TELE, TasmotaGlobal.mqtt_topic, D_RSLT_STATE);
|
||||
GetTopic_P(availability_topic, TELE, TasmotaGlobal.mqtt_topic, S_LWT);
|
||||
Response_P(HASS_DISCOVER_BASE, name, state_topic);
|
||||
TryResponseAppend_P(HASS_DISCOVER_SENSOR_LWT, availability_topic);
|
||||
TryResponseAppend_P(HASS_DISCOVER_RELAY, command_topic, value_template, SettingsText(SET_STATE_TXT1), SettingsText(SET_STATE_TXT2));
|
||||
|
@ -492,7 +492,7 @@ void HAssAnnounceRelayLight(void)
|
|||
snprintf_P(channel_num, sizeof(channel_num), PSTR("" D_CMND_DIMMER ""));
|
||||
}
|
||||
}
|
||||
GetTopic_P(brightness_command_topic, CMND, mqtt_topic, channel_num);
|
||||
GetTopic_P(brightness_command_topic, CMND, TasmotaGlobal.mqtt_topic, channel_num);
|
||||
TryResponseAppend_P(HASS_DISCOVER_BASE_LIGHT, brightness_command_topic, state_topic, stemp3, channel_num);
|
||||
}
|
||||
if ((ind_light && !PwmMulti) || LightControl) {
|
||||
|
@ -500,11 +500,11 @@ void HAssAnnounceRelayLight(void)
|
|||
if (Light.subtype >= LST_RGB) {
|
||||
char *rgb_command_topic = stemp1;
|
||||
|
||||
GetTopic_P(rgb_command_topic, CMND, mqtt_topic, D_CMND_COLOR);
|
||||
GetTopic_P(rgb_command_topic, CMND, TasmotaGlobal.mqtt_topic, D_CMND_COLOR);
|
||||
TryResponseAppend_P(HASS_DISCOVER_LIGHT_COLOR, rgb_command_topic, state_topic);
|
||||
|
||||
char *effect_command_topic = stemp1;
|
||||
GetTopic_P(effect_command_topic, CMND, mqtt_topic, D_CMND_SCHEME);
|
||||
GetTopic_P(effect_command_topic, CMND, TasmotaGlobal.mqtt_topic, D_CMND_SCHEME);
|
||||
TryResponseAppend_P(HASS_DISCOVER_LIGHT_SCHEME, effect_command_topic, state_topic);
|
||||
}
|
||||
if (LST_RGBW <= Light.subtype) { wt_light = true; }
|
||||
|
@ -515,7 +515,7 @@ void HAssAnnounceRelayLight(void)
|
|||
!PwmMulti && LightControl)) {
|
||||
char *color_temp_command_topic = stemp1;
|
||||
|
||||
GetTopic_P(color_temp_command_topic, CMND, mqtt_topic, D_CMND_COLORTEMPERATURE);
|
||||
GetTopic_P(color_temp_command_topic, CMND, TasmotaGlobal.mqtt_topic, D_CMND_COLORTEMPERATURE);
|
||||
TryResponseAppend_P(HASS_DISCOVER_LIGHT_CT, color_temp_command_topic, state_topic);
|
||||
ct_light = false;
|
||||
}
|
||||
|
@ -523,7 +523,7 @@ void HAssAnnounceRelayLight(void)
|
|||
!PwmMulti && LightControl)) {
|
||||
char *white_temp_command_topic = stemp1;
|
||||
|
||||
GetTopic_P(white_temp_command_topic, CMND, mqtt_topic, D_CMND_WHITE);
|
||||
GetTopic_P(white_temp_command_topic, CMND, TasmotaGlobal.mqtt_topic, D_CMND_WHITE);
|
||||
TryResponseAppend_P(HASS_DISCOVER_LIGHT_WHITE, white_temp_command_topic, state_topic);
|
||||
wt_light = false;
|
||||
}
|
||||
|
@ -534,7 +534,7 @@ void HAssAnnounceRelayLight(void)
|
|||
TryResponseAppend_P(PSTR("}"));
|
||||
}
|
||||
}
|
||||
masterlog_level = ShowTopic;
|
||||
TasmotaGlobal.masterlog_level = ShowTopic;
|
||||
MqttPublish(stopic, true);
|
||||
}
|
||||
}
|
||||
|
@ -549,14 +549,14 @@ void HAssAnnouncerTriggers(uint8_t device, uint8_t present, uint8_t key, uint8_t
|
|||
char unique_id[30];
|
||||
char trigger2[8];
|
||||
uint8_t ShowTopic; // Used to hide/unhide a topic during Discovery to spare some cpu load
|
||||
mqtt_data[0] = '\0'; // Clear retained message
|
||||
ResponseClear(); // Clear retained message
|
||||
|
||||
for (uint8_t i = trg_start; i <= trg_end; i++) {
|
||||
GetTextIndexed(trigger2, sizeof(trigger2), i, kHAssTriggerStringButtons);
|
||||
snprintf_P(unique_id, sizeof(unique_id), PSTR("%06X_%s_%d_%s"), ESP_getChipId(), key ? "SW" : "BTN", device + 1, key ? GetStateText(i) : trigger2);
|
||||
snprintf_P(stopic, sizeof(stopic), PSTR(HOME_ASSISTANT_DISCOVERY_PREFIX "/device_automation/%s/config"), unique_id);
|
||||
|
||||
masterlog_level = ShowTopic = 4; // Hide topic on clean and remove use weblog 4 to see it
|
||||
TasmotaGlobal.masterlog_level = ShowTopic = 4; // Hide topic on clean and remove use weblog 4 to see it
|
||||
|
||||
if (Settings.flag.hass_discovery && present) { // SetOption19 - Control Home Assistantautomatic discovery (See SetOption59)
|
||||
char name[TOPSZ]; // friendlyname(33) + " " + "BTN" + " " + index
|
||||
|
@ -569,8 +569,8 @@ void HAssAnnouncerTriggers(uint8_t device, uint8_t present, uint8_t key, uint8_t
|
|||
|
||||
GetPowerDevice(value_template, device + 1, sizeof(value_template), key + Settings.flag.device_index_enable); // Force index for Switch 1, Index on Button1 is controlled by SetOption26 - Switch between POWER or POWER1
|
||||
snprintf_P(jsoname, sizeof(jsoname), PSTR("%s%d"), key ? "SWITCH" : "BUTTON", device + 1);
|
||||
GetTopic_P(state_topic, STAT, mqtt_topic, jsoname);
|
||||
GetTopic_P(availability_topic, TELE, mqtt_topic, S_LWT);
|
||||
GetTopic_P(state_topic, STAT, TasmotaGlobal.mqtt_topic, jsoname);
|
||||
GetTopic_P(availability_topic, TELE, TasmotaGlobal.mqtt_topic, S_LWT);
|
||||
|
||||
char param[21];
|
||||
char subtype[9];
|
||||
|
@ -581,19 +581,19 @@ void HAssAnnouncerTriggers(uint8_t device, uint8_t present, uint8_t key, uint8_t
|
|||
GetTextIndexed(param, sizeof(param), pload, kHAssTriggerType);
|
||||
snprintf_P(subtype, sizeof(subtype), PSTR("switch_%d"), device + 1);
|
||||
Response_P(HASS_TRIGGER_TYPE, state_topic, GetStateText(i), param, subtype, ESP_getChipId());
|
||||
} else { mqtt_data[0] = '\0'; } // Need to be cleaned again to avoid duplicate
|
||||
} else { ResponseClear(); } // Need to be cleaned again to avoid duplicate
|
||||
} else {
|
||||
char trigger1[24];
|
||||
GetTextIndexed(trigger1, sizeof(trigger1), i, kHAssTriggerTypeButtons);
|
||||
snprintf_P(subtype, sizeof(subtype), PSTR("button_%d"), device + 1);
|
||||
if (i > 1 && single) {
|
||||
mqtt_data[0] = '\0'; // Need to be cleaned again to avoid duplicate
|
||||
ResponseClear(); // Need to be cleaned again to avoid duplicate
|
||||
} else {
|
||||
Response_P(HASS_TRIGGER_TYPE, state_topic, trigger2, trigger1, subtype, ESP_getChipId());
|
||||
}
|
||||
}
|
||||
}
|
||||
masterlog_level = ShowTopic;
|
||||
TasmotaGlobal.masterlog_level = ShowTopic;
|
||||
MqttPublish(stopic, true);
|
||||
}
|
||||
}
|
||||
|
@ -606,14 +606,14 @@ void HAssAnnouncerBinSensors(uint8_t device, uint8_t present, uint8_t dual, uint
|
|||
char unique_id[30];
|
||||
uint8_t ShowTopic; // Used to hide/unhide a topic during Discovery to spare some cpu load
|
||||
|
||||
mqtt_data[0] = '\0'; // Clear retained message
|
||||
masterlog_level = 4; // Hide topic on clean and remove use weblog 4 to see it
|
||||
ResponseClear(); // Clear retained message
|
||||
TasmotaGlobal.masterlog_level = 4; // Hide topic on clean and remove use weblog 4 to see it
|
||||
|
||||
|
||||
snprintf_P(unique_id, sizeof(unique_id), PSTR("%06X_SW_%d"), ESP_getChipId(), device + 1);
|
||||
snprintf_P(stopic, sizeof(stopic), PSTR(HOME_ASSISTANT_DISCOVERY_PREFIX "/binary_sensor/%s/config"), unique_id);
|
||||
|
||||
masterlog_level = ShowTopic = 4; // Hide topic on clean and remove use weblog 4 to see it
|
||||
TasmotaGlobal.masterlog_level = ShowTopic = 4; // Hide topic on clean and remove use weblog 4 to see it
|
||||
|
||||
if (Settings.flag.hass_discovery && present ) { // SetOption19 - Control Home Assistantautomatic discovery (See SetOption59)
|
||||
if (!toggle || dual) {
|
||||
|
@ -628,8 +628,8 @@ void HAssAnnouncerBinSensors(uint8_t device, uint8_t present, uint8_t dual, uint
|
|||
|
||||
GetPowerDevice(value_template, device + 1, sizeof(value_template), 1 + Settings.flag.device_index_enable); // Force index for Switch 1, Index on Button1 is controlled by SetOption26 - Switch between POWER or POWER1
|
||||
snprintf_P(jsoname, sizeof(jsoname), PSTR("SWITCH%d"), device + 1);
|
||||
GetTopic_P(state_topic, STAT, mqtt_topic, jsoname);
|
||||
GetTopic_P(availability_topic, TELE, mqtt_topic, S_LWT);
|
||||
GetTopic_P(state_topic, STAT, TasmotaGlobal.mqtt_topic, jsoname);
|
||||
GetTopic_P(availability_topic, TELE, TasmotaGlobal.mqtt_topic, S_LWT);
|
||||
|
||||
snprintf_P(name, sizeof(name), PSTR("%s Switch%d"), SettingsText(SET_DEVICENAME), device + 1);
|
||||
Response_P(HASS_DISCOVER_BASE, name, state_topic, availability_topic);
|
||||
|
@ -650,7 +650,7 @@ void HAssAnnouncerBinSensors(uint8_t device, uint8_t present, uint8_t dual, uint
|
|||
TryResponseAppend_P(PSTR("}"));
|
||||
}
|
||||
}
|
||||
masterlog_level = ShowTopic;
|
||||
TasmotaGlobal.masterlog_level = ShowTopic;
|
||||
MqttPublish(stopic, true);
|
||||
|
||||
}
|
||||
|
@ -667,7 +667,7 @@ void HAssAnnounceSwitches(void)
|
|||
|
||||
if (PinUsed(GPIO_SWT1, switch_index)) { switch_present = 1; }
|
||||
|
||||
if (KeyTopicActive(1) && strcmp(SettingsText(SET_MQTT_SWITCH_TOPIC), mqtt_topic)) // Enable Discovery for Switches only if SwitchTopic is set to a custom name
|
||||
if (KeyTopicActive(1) && strcmp(SettingsText(SET_MQTT_SWITCH_TOPIC), TasmotaGlobal.mqtt_topic)) // Enable Discovery for Switches only if SwitchTopic is set to a custom name
|
||||
{
|
||||
|
||||
// switch matrix for triggers and binary sensor generation when switchtopic is set as custom (default index is 0,0 - TOGGLE, TOGGLE):
|
||||
|
@ -739,7 +739,7 @@ void HAssAnnounceButtons(void)
|
|||
uint8_t single = 0;
|
||||
|
||||
#ifdef ESP8266
|
||||
if (!button_index && ((SONOFF_DUAL == my_module_type) || (CH4 == my_module_type)))
|
||||
if (!button_index && ((SONOFF_DUAL == TasmotaGlobal.module_type) || (CH4 == TasmotaGlobal.module_type)))
|
||||
{
|
||||
button_present = 1;
|
||||
} else
|
||||
|
@ -782,7 +782,7 @@ void HAssAnnounceSensor(const char *sensorname, const char *subsensortype, const
|
|||
char unique_id[30];
|
||||
char subname[20];
|
||||
|
||||
mqtt_data[0] = '\0'; // Clear retained message
|
||||
ResponseClear(); // Clear retained message
|
||||
|
||||
// Clear or Set topic
|
||||
NoAlNumToUnderscore(subname, MultiSubName); //Replace all non alphaumeric characters to '_' to avoid topic name issues
|
||||
|
@ -794,11 +794,11 @@ void HAssAnnounceSensor(const char *sensorname, const char *subsensortype, const
|
|||
char prefix[TOPSZ];
|
||||
char *state_topic = stemp1;
|
||||
char *availability_topic = stemp2;
|
||||
masterlog_level = 0; // Show the new generated topic
|
||||
TasmotaGlobal.masterlog_level = 0; // Show the new generated topic
|
||||
|
||||
GetTopic_P(state_topic, TELE, mqtt_topic, PSTR(D_RSLT_SENSOR));
|
||||
GetTopic_P(state_topic, TELE, TasmotaGlobal.mqtt_topic, PSTR(D_RSLT_SENSOR));
|
||||
snprintf_P(name, sizeof(name), PSTR("%s %s %s"), SettingsText(SET_DEVICENAME), sensorname, MultiSubName);
|
||||
GetTopic_P(availability_topic, TELE, mqtt_topic, S_LWT);
|
||||
GetTopic_P(availability_topic, TELE, TasmotaGlobal.mqtt_topic, S_LWT);
|
||||
|
||||
Response_P(HASS_DISCOVER_BASE, name, state_topic);
|
||||
#ifdef DEEPSLEEP_LWT_HA_DISCOVERY
|
||||
|
@ -850,14 +850,14 @@ void HAssAnnounceSensors(void)
|
|||
uint8_t hass_xsns_index = 0;
|
||||
do
|
||||
{
|
||||
mqtt_data[0] = '\0';
|
||||
ResponseClear();
|
||||
int tele_period_save = TasmotaGlobal.tele_period;
|
||||
TasmotaGlobal.tele_period = 2; // Do not allow HA updates during next function call
|
||||
XsnsNextCall(FUNC_JSON_APPEND, hass_xsns_index); // ,"INA219":{"Voltage":4.494,"Current":0.020,"Power":0.089}
|
||||
TasmotaGlobal.tele_period = tele_period_save;
|
||||
size_t sensordata_len = strlen(mqtt_data);
|
||||
size_t sensordata_len = strlen(TasmotaGlobal.mqtt_data);
|
||||
char sensordata[sensordata_len+2]; // dynamically adjust the size
|
||||
strcpy(sensordata, mqtt_data); // we can use strcpy since the buffer has the right size
|
||||
strcpy(sensordata, TasmotaGlobal.mqtt_data); // we can use strcpy since the buffer has the right size
|
||||
|
||||
// ******************* JSON TEST *******************
|
||||
// char sensordata[512];
|
||||
|
@ -932,8 +932,8 @@ void HAssAnnounceShutters(void)
|
|||
uint8_t ShowTopic; // Used to hide/unhide a topic during Discovery to spare some cpu load
|
||||
|
||||
for (uint32_t i = 0; i < MAX_SHUTTERS; i++) {
|
||||
mqtt_data[0] = '\0'; // Clear retained message
|
||||
masterlog_level = ShowTopic = 4; // Hide topic on clean and remove use weblog 4 to see it
|
||||
ResponseClear(); // Clear retained message
|
||||
TasmotaGlobal.masterlog_level = ShowTopic = 4; // Hide topic on clean and remove use weblog 4 to see it
|
||||
|
||||
|
||||
snprintf_P(unique_id, sizeof(unique_id), PSTR("%06X_SHT_%d"), ESP_getChipId(), i + 1);
|
||||
|
@ -946,24 +946,24 @@ void HAssAnnounceShutters(void)
|
|||
} else {
|
||||
snprintf_P(stemp1, sizeof(stemp1), PSTR("%s"), SettingsText(SET_FRIENDLYNAME1 + i));
|
||||
}
|
||||
GetTopic_P(stemp2, TELE, mqtt_topic, D_RSLT_STATE);
|
||||
GetTopic_P(stemp2, TELE, TasmotaGlobal.mqtt_topic, D_RSLT_STATE);
|
||||
Response_P(HASS_DISCOVER_BASE, stemp1, stemp2);
|
||||
|
||||
GetTopic_P(stemp1, TELE, mqtt_topic, S_LWT);
|
||||
GetTopic_P(stemp1, TELE, TasmotaGlobal.mqtt_topic, S_LWT);
|
||||
TryResponseAppend_P(HASS_DISCOVER_SENSOR_LWT, stemp1);
|
||||
|
||||
GetTopic_P(stemp1, CMND, mqtt_topic, PSTR("Backlog"));
|
||||
GetTopic_P(stemp1, CMND, TasmotaGlobal.mqtt_topic, PSTR("Backlog"));
|
||||
TryResponseAppend_P(HASS_DISCOVER_SHUTTER_BASE, stemp1, i + 1, i + 1, i + 1);
|
||||
|
||||
GetTopic_P(stemp1, STAT, mqtt_topic, PSTR("SHUTTER"));
|
||||
GetTopic_P(stemp2, CMND, mqtt_topic, PSTR("ShutterPosition"));
|
||||
GetTopic_P(stemp1, STAT, TasmotaGlobal.mqtt_topic, PSTR("SHUTTER"));
|
||||
GetTopic_P(stemp2, CMND, TasmotaGlobal.mqtt_topic, PSTR("ShutterPosition"));
|
||||
TryResponseAppend_P(HASS_DISCOVER_SHUTTER_POS, stemp1, i + 1, stemp2, i + 1);
|
||||
|
||||
TryResponseAppend_P(HASS_DISCOVER_DEVICE_INFO_SHORT, unique_id, ESP_getChipId());
|
||||
TryResponseAppend_P(PSTR("}"));
|
||||
}
|
||||
|
||||
masterlog_level = ShowTopic;
|
||||
TasmotaGlobal.masterlog_level = ShowTopic;
|
||||
MqttPublish(stopic, true);
|
||||
}
|
||||
#endif
|
||||
|
@ -978,8 +978,8 @@ void HAssAnnounceDeviceInfoAndStatusSensor(void)
|
|||
uint8_t ShowTopic; // Used to hide/unhide a topic during Discovery to spare some cpu load
|
||||
|
||||
// Announce sensor
|
||||
mqtt_data[0] = '\0'; // Clear retained message
|
||||
masterlog_level = ShowTopic = 4; // Hide topic on clean and remove use weblog 4 to see it
|
||||
ResponseClear(); // Clear retained message
|
||||
TasmotaGlobal.masterlog_level = ShowTopic = 4; // Hide topic on clean and remove use weblog 4 to see it
|
||||
// Clear or Set topic
|
||||
snprintf_P(unique_id, sizeof(unique_id), PSTR("%06X_status"), ESP_getChipId());
|
||||
snprintf_P(stopic, sizeof(stopic), PSTR(HOME_ASSISTANT_DISCOVERY_PREFIX "/sensor/%s/config"), unique_id);
|
||||
|
@ -992,21 +992,21 @@ void HAssAnnounceDeviceInfoAndStatusSensor(void)
|
|||
char *availability_topic = stemp2;
|
||||
ShowTopic = 0; // Show the new generated topic
|
||||
snprintf_P(name, sizeof(name), PSTR("%s status"), SettingsText(SET_DEVICENAME));
|
||||
GetTopic_P(state_topic, TELE, mqtt_topic, PSTR(D_RSLT_HASS_STATE));
|
||||
GetTopic_P(availability_topic, TELE, mqtt_topic, S_LWT);
|
||||
GetTopic_P(state_topic, TELE, TasmotaGlobal.mqtt_topic, PSTR(D_RSLT_HASS_STATE));
|
||||
GetTopic_P(availability_topic, TELE, TasmotaGlobal.mqtt_topic, S_LWT);
|
||||
|
||||
Response_P(HASS_DISCOVER_BASE, name, state_topic);
|
||||
TryResponseAppend_P(HASS_DISCOVER_SENSOR_LWT, availability_topic);
|
||||
TryResponseAppend_P(HASS_DISCOVER_SENSOR_HASS_STATUS, state_topic);
|
||||
TryResponseAppend_P(HASS_DISCOVER_DEVICE_INFO, unique_id, ESP_getChipId(), SettingsText(SET_DEVICENAME),
|
||||
ModuleName().c_str(), my_version, my_image);
|
||||
ModuleName().c_str(), TasmotaGlobal.version, TasmotaGlobal.image_name);
|
||||
TryResponseAppend_P(PSTR("}"));
|
||||
}
|
||||
masterlog_level = ShowTopic;
|
||||
TasmotaGlobal.masterlog_level = ShowTopic;
|
||||
MqttPublish(stopic, true);
|
||||
|
||||
if (!Settings.flag.hass_discovery) {
|
||||
masterlog_level = 0;
|
||||
TasmotaGlobal.masterlog_level = 0;
|
||||
AddLog_P2(LOG_LEVEL_INFO, PSTR(D_LOG_LOG "Home Assistant MQTT Discovery disabled."));
|
||||
}
|
||||
}
|
||||
|
@ -1017,8 +1017,8 @@ void HAssPublishStatus(void)
|
|||
"\"" D_JSON_RESTARTREASON "\":\"%s\",\"" D_JSON_UPTIME "\":\"%s\",\"" D_CMND_HOSTNAME "\":\"%s\","
|
||||
"\"" D_CMND_IPADDRESS "\":\"%s\",\"" D_JSON_RSSI "\":\"%d\",\"" D_JSON_SIGNAL " (dBm)""\":\"%d\","
|
||||
"\"WiFi " D_JSON_LINK_COUNT "\":%d,\"WiFi " D_JSON_DOWNTIME "\":\"%s\",\"" D_JSON_MQTT_COUNT "\":%d,\"LoadAvg\":%lu}"),
|
||||
my_version, my_image, GetBuildDateAndTime().c_str(), ModuleName().c_str(), GetResetReason().c_str(),
|
||||
GetUptime().c_str(), my_hostname, WiFi.localIP().toString().c_str(), WifiGetRssiAsQuality(WiFi.RSSI()),
|
||||
TasmotaGlobal.version, TasmotaGlobal.image_name, GetBuildDateAndTime().c_str(), ModuleName().c_str(), GetResetReason().c_str(),
|
||||
GetUptime().c_str(), TasmotaGlobal.hostname, WiFi.localIP().toString().c_str(), WifiGetRssiAsQuality(WiFi.RSSI()),
|
||||
WiFi.RSSI(), WifiLinkCount(), WifiDowntime().c_str(), MqttConnectCount(), TasmotaGlobal.loop_load_avg);
|
||||
MqttPublishPrefixTopic_P(TELE, PSTR(D_RSLT_HASS_STATE));
|
||||
}
|
||||
|
@ -1056,7 +1056,7 @@ void HAssDiscovery(void)
|
|||
|
||||
// Send info about status sensor
|
||||
HAssAnnounceDeviceInfoAndStatusSensor();
|
||||
masterlog_level = 0; // Restores weblog level
|
||||
TasmotaGlobal.masterlog_level = 0; // Restores weblog level
|
||||
hass_mode = 3; // Needed for generating bluetooth entities for MI_ESP32
|
||||
}
|
||||
}
|
||||
|
@ -1102,7 +1102,7 @@ void HAssAnyKey(void)
|
|||
}
|
||||
}
|
||||
|
||||
GetTopic_P(stopic, STAT, mqtt_topic, scommand);
|
||||
GetTopic_P(stopic, STAT, TasmotaGlobal.mqtt_topic, scommand);
|
||||
Response_P(S_JSON_COMMAND_SVALUE, (evkey) ? "TRIG" : PSTR(D_RSLT_STATE), (key) ? GetStateText(state) : trg_state);
|
||||
MqttPublish(stopic);
|
||||
}
|
||||
|
@ -1155,7 +1155,7 @@ bool Xdrv12(uint8_t function)
|
|||
if (hass_tele_period >= Settings.tele_period)
|
||||
{
|
||||
hass_tele_period = 0;
|
||||
mqtt_data[0] = '\0';
|
||||
ResponseClear();
|
||||
HAssPublishStatus();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1034,7 +1034,7 @@ void DisplayLogBufferInit(void)
|
|||
DisplayReAllocLogBuffer();
|
||||
|
||||
char buffer[40];
|
||||
snprintf_P(buffer, sizeof(buffer), PSTR(D_VERSION " %s%s"), my_version, my_image);
|
||||
snprintf_P(buffer, sizeof(buffer), PSTR(D_VERSION " %s%s"), TasmotaGlobal.version, TasmotaGlobal.image_name);
|
||||
DisplayLogBufferAdd(buffer);
|
||||
snprintf_P(buffer, sizeof(buffer), PSTR("Display mode %d"), Settings.display_mode);
|
||||
DisplayLogBufferAdd(buffer);
|
||||
|
@ -1045,7 +1045,7 @@ void DisplayLogBufferInit(void)
|
|||
DisplayLogBufferAdd(buffer);
|
||||
snprintf_P(buffer, sizeof(buffer), PSTR("IP %s"), NetworkAddress().toString().c_str());
|
||||
DisplayLogBufferAdd(buffer);
|
||||
if (!global_state.wifi_down) {
|
||||
if (!TasmotaGlobal.global_state.wifi_down) {
|
||||
snprintf_P(buffer, sizeof(buffer), PSTR(D_JSON_SSID " %s"), SettingsText(SET_STASSID1 + Settings.sta_active));
|
||||
DisplayLogBufferAdd(buffer);
|
||||
snprintf_P(buffer, sizeof(buffer), PSTR(D_JSON_RSSI " %d%%"), WifiGetRssiAsQuality(WiFi.RSSI()));
|
||||
|
@ -1264,8 +1264,8 @@ void DisplayLocalSensor(void)
|
|||
{
|
||||
if ((Settings.display_mode &0x02) && (0 == TasmotaGlobal.tele_period)) {
|
||||
char no_topic[1] = { 0 };
|
||||
// DisplayAnalyzeJson(mqtt_topic, mqtt_data); // Add local topic
|
||||
DisplayAnalyzeJson(no_topic, mqtt_data); // Discard any topic
|
||||
// DisplayAnalyzeJson(TasmotaGlobal.mqtt_topic, TasmotaGlobal.mqtt_data); // Add local topic
|
||||
DisplayAnalyzeJson(no_topic, TasmotaGlobal.mqtt_data); // Discard any topic
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1288,13 +1288,13 @@ void DisplayInitDriver(void)
|
|||
// AddLog_P2(LOG_LEVEL_DEBUG, PSTR(D_LOG_DEBUG "Display model %d"), Settings.display_model);
|
||||
|
||||
if (Settings.display_model) {
|
||||
devices_present++;
|
||||
TasmotaGlobal.devices_present++;
|
||||
if (!PinUsed(GPIO_BACKLIGHT)) {
|
||||
if (light_type && (4 == Settings.display_model)) {
|
||||
devices_present--; // Assume PWM channel is used for backlight
|
||||
if (TasmotaGlobal.light_type && (4 == Settings.display_model)) {
|
||||
TasmotaGlobal.devices_present--; // Assume PWM channel is used for backlight
|
||||
}
|
||||
}
|
||||
disp_device = devices_present;
|
||||
disp_device = TasmotaGlobal.devices_present;
|
||||
|
||||
#ifndef USE_DISPLAY_MODES1TO5
|
||||
Settings.display_mode = 0;
|
||||
|
@ -2196,7 +2196,7 @@ bool Xdrv13(uint8_t function)
|
|||
{
|
||||
bool result = false;
|
||||
|
||||
if ((i2c_flg || spi_flg || soft_spi_flg) && XdspPresent()) {
|
||||
if ((TasmotaGlobal.i2c_enabled || TasmotaGlobal.spi_enabled || TasmotaGlobal.soft_spi_enabled) && XdspPresent()) {
|
||||
switch (function) {
|
||||
case FUNC_PRE_INIT:
|
||||
DisplayInitDriver();
|
||||
|
|
|
@ -93,12 +93,12 @@ void (* const TuyaCommand[])(void) PROGMEM = {
|
|||
\*********************************************************************************************/
|
||||
bool IsModuleTuya(void)
|
||||
{
|
||||
return ((TUYA_DIMMER == my_module_type) || (SK03_TUYA == my_module_type));
|
||||
return ((TUYA_DIMMER == TasmotaGlobal.module_type) || (SK03_TUYA == TasmotaGlobal.module_type));
|
||||
}
|
||||
|
||||
bool AsModuleTuyaMS(void) // ModeSet Layout
|
||||
{
|
||||
return ((light_type > LT_RGB) && TuyaGetDpId(TUYA_MCU_FUNC_MODESET) != 0);
|
||||
return ((TasmotaGlobal.light_type > LT_RGB) && TuyaGetDpId(TUYA_MCU_FUNC_MODESET) != 0);
|
||||
}
|
||||
|
||||
bool IsTuyaFanCtrl(void) // Fan Speed Controller Layout
|
||||
|
@ -317,15 +317,15 @@ void TuyaSendCmd(uint8_t cmd, uint8_t payload[] = nullptr, uint16_t payload_len
|
|||
TuyaSerial->write(cmd); // Tuya command
|
||||
TuyaSerial->write(payload_len >> 8); // following data length (Hi)
|
||||
TuyaSerial->write(payload_len & 0xFF); // following data length (Lo)
|
||||
snprintf_P(log_data, sizeof(log_data), PSTR("TYA: Send \"55aa00%02x%02x%02x"), cmd, payload_len >> 8, payload_len & 0xFF);
|
||||
snprintf_P(TasmotaGlobal.log_data, sizeof(TasmotaGlobal.log_data), PSTR("TYA: Send \"55aa00%02x%02x%02x"), cmd, payload_len >> 8, payload_len & 0xFF);
|
||||
for (uint32_t i = 0; i < payload_len; ++i) {
|
||||
TuyaSerial->write(payload[i]);
|
||||
checksum += payload[i];
|
||||
snprintf_P(log_data, sizeof(log_data), PSTR("%s%02x"), log_data, payload[i]);
|
||||
snprintf_P(TasmotaGlobal.log_data, sizeof(TasmotaGlobal.log_data), PSTR("%s%02x"), TasmotaGlobal.log_data, payload[i]);
|
||||
}
|
||||
TuyaSerial->write(checksum);
|
||||
TuyaSerial->flush();
|
||||
snprintf_P(log_data, sizeof(log_data), PSTR("%s%02x\""), log_data, checksum);
|
||||
snprintf_P(TasmotaGlobal.log_data, sizeof(TasmotaGlobal.log_data), PSTR("%s%02x\""), TasmotaGlobal.log_data, checksum);
|
||||
AddLog(LOG_LEVEL_DEBUG);
|
||||
}
|
||||
|
||||
|
@ -419,12 +419,12 @@ bool TuyaSetChannels(void)
|
|||
uint8_t idx = 0;
|
||||
snprintf_P(hex_char, sizeof(hex_char), PSTR("000000000000"));
|
||||
|
||||
if (LT_SERIAL1 == light_type) {
|
||||
if (LT_SERIAL1 == TasmotaGlobal.light_type) {
|
||||
Tuya.Snapshot[0] = light_state.getDimmer();
|
||||
}
|
||||
if (LT_SERIAL2 == light_type || LT_RGBWC == light_type) {
|
||||
if (LT_SERIAL2 == TasmotaGlobal.light_type || LT_RGBWC == TasmotaGlobal.light_type) {
|
||||
idx = 1;
|
||||
if (LT_SERIAL2 == light_type && Settings.flag3.pwm_multi_channels && (TuyaGetDpId(TUYA_MCU_FUNC_DIMMER2) != 0)) {
|
||||
if (LT_SERIAL2 == TasmotaGlobal.light_type && Settings.flag3.pwm_multi_channels && (TuyaGetDpId(TUYA_MCU_FUNC_DIMMER2) != 0)) {
|
||||
// Special setup for dual dimmer (like the MOES 2 Way Dimmer) emulating 2 PWM channels
|
||||
Tuya.Snapshot[0] = changeUIntScale(Light.current_color[0], 0, 255, 0, 100);
|
||||
Tuya.Snapshot[1] = changeUIntScale(Light.current_color[1], 0, 255, 0, 100);
|
||||
|
@ -434,15 +434,15 @@ bool TuyaSetChannels(void)
|
|||
Tuya.Snapshot[1] = light_state.getCT();
|
||||
}
|
||||
}
|
||||
if (LT_RGBW == light_type) {
|
||||
if (LT_RGBW == TasmotaGlobal.light_type) {
|
||||
idx = 1;
|
||||
Tuya.Snapshot[0] = light_state.getDimmer(1);
|
||||
Tuya.Snapshot[1] = light_state.getDimmer(2);
|
||||
}
|
||||
|
||||
if (light_type > LT_BASIC) {
|
||||
if (TasmotaGlobal.light_type > LT_BASIC) {
|
||||
|
||||
if (LT_RGB != light_type) {
|
||||
if (LT_RGB != TasmotaGlobal.light_type) {
|
||||
for (uint8_t i = 0; i <= idx; i++) {
|
||||
if (Tuya.Snapshot[i] != Tuya.Levels[i]) {
|
||||
if (i == 0 && LightMode && Tuya.ModeSet ) { noupd = true;}
|
||||
|
@ -455,13 +455,13 @@ bool TuyaSetChannels(void)
|
|||
}
|
||||
}
|
||||
|
||||
if (light_type >= LT_RGB) {
|
||||
if (TasmotaGlobal.light_type >= LT_RGB) {
|
||||
|
||||
light_state.getHSB(&hue, &sat, &bri);
|
||||
sat = changeUIntScale(sat, 0, 255, 0, 100);
|
||||
bri = changeUIntScale(bri, 0, 255, 0, 100);
|
||||
if (hue != Tuya.Snapshot[2] || sat != Tuya.Snapshot[3] || bri != Tuya.Snapshot[4]) {
|
||||
if ((LightMode && Tuya.ModeSet) || LT_RGB == light_type) {
|
||||
if ((LightMode && Tuya.ModeSet) || LT_RGB == TasmotaGlobal.light_type) {
|
||||
snprintf_P(hex_char, sizeof(hex_char), PSTR("%04X%04X%04X"), hue, sat * 10, bri * 10); // Create a TuyaMCU readable RGB payload
|
||||
LightSerialDuty(0, &hex_char[0], 3);
|
||||
memcpy_P(Tuya.HSBColor, hex_char, strlen(hex_char));
|
||||
|
@ -496,7 +496,7 @@ void LightSerialDuty(uint16_t duty, char *hex_char, uint8_t TuyaIdx)
|
|||
|
||||
if (duty < Settings.dimmer_hw_min) { duty = Settings.dimmer_hw_min; } // dimming acts odd below 25(10%) - this mirrors the threshold set on the faceplate itself
|
||||
Tuya.ignore_dimmer_cmd_timeout = millis() + 250; // Ignore serial received dim commands for the next 250ms
|
||||
if (Tuya.ModeSet && (TuyaGetDpId(TUYA_MCU_FUNC_MODESET) != 0) && light_type > LT_RGB) {
|
||||
if (Tuya.ModeSet && (TuyaGetDpId(TUYA_MCU_FUNC_MODESET) != 0) && TasmotaGlobal.light_type > LT_RGB) {
|
||||
TuyaSendEnum(TuyaGetDpId(TUYA_MCU_FUNC_MODESET), 0);
|
||||
}
|
||||
TuyaSendValue(dpid, duty);
|
||||
|
@ -518,7 +518,7 @@ void LightSerialDuty(uint16_t duty, char *hex_char, uint8_t TuyaIdx)
|
|||
|
||||
if (TuyaIdx == 3) {
|
||||
dpid = TuyaGetDpId(TUYA_MCU_FUNC_RGB);
|
||||
if (!Tuya.ModeSet && (TuyaGetDpId(TUYA_MCU_FUNC_MODESET) != 0) && light_type > LT_RGB) {
|
||||
if (!Tuya.ModeSet && (TuyaGetDpId(TUYA_MCU_FUNC_MODESET) != 0) && TasmotaGlobal.light_type > LT_RGB) {
|
||||
TuyaSendEnum(TuyaGetDpId(TUYA_MCU_FUNC_MODESET), 1);
|
||||
}
|
||||
TuyaSendString(dpid, hex_char);
|
||||
|
@ -587,7 +587,7 @@ void TuyaProcessStatePacket(void) {
|
|||
}
|
||||
}
|
||||
else if (Tuya.buffer[dpidStart + 1] == 2) { // Data Type 2
|
||||
bool tuya_energy_enabled = (XNRG_32 == energy_flg);
|
||||
bool tuya_energy_enabled = (XNRG_32 == TasmotaGlobal.energy_driver);
|
||||
uint16_t packetValue = Tuya.buffer[dpidStart + 6] << 8 | Tuya.buffer[dpidStart + 7];
|
||||
uint8_t dimIndex;
|
||||
if ((fnId == TUYA_MCU_FUNC_FAN3) || (fnId == TUYA_MCU_FUNC_FAN4) ||
|
||||
|
@ -616,7 +616,7 @@ void TuyaProcessStatePacket(void) {
|
|||
if ((TasmotaGlobal.power || Settings.flag3.tuya_apply_o20) && ((Tuya.Levels[dimIndex] > 0) && (Tuya.Levels[dimIndex] != Tuya.Snapshot[dimIndex]))) { // SetOption54 - Apply SetOption20 settings to Tuya device
|
||||
|
||||
Tuya.ignore_dim = true;
|
||||
skip_light_fade = true;
|
||||
TasmotaGlobal.skip_light_fade = true;
|
||||
|
||||
scmnd[0] = '\0';
|
||||
if ((fnId == TUYA_MCU_FUNC_DIMMER) || (fnId == TUYA_MCU_FUNC_REPORT1)) {
|
||||
|
@ -809,13 +809,13 @@ bool TuyaModuleSelected(void)
|
|||
if ((Settings.tuya_fnid_map[i].fnid >= TUYA_MCU_FUNC_REL1 && Settings.tuya_fnid_map[i].fnid <= TUYA_MCU_FUNC_REL8 ) ||
|
||||
(Settings.tuya_fnid_map[i].fnid >= TUYA_MCU_FUNC_REL1_INV && Settings.tuya_fnid_map[i].fnid <= TUYA_MCU_FUNC_REL8_INV )) {
|
||||
relaySet = true;
|
||||
devices_present++;
|
||||
TasmotaGlobal.devices_present++;
|
||||
}
|
||||
}
|
||||
|
||||
if (!relaySet && TuyaGetDpId(TUYA_MCU_FUNC_DUMMY) == 0) { //by default the first relay is created automatically the dummy let remove it if not needed
|
||||
TuyaAddMcuFunc(TUYA_MCU_FUNC_REL1, 1);
|
||||
devices_present++;
|
||||
TasmotaGlobal.devices_present++;
|
||||
SettingsSaveAll();
|
||||
}
|
||||
|
||||
|
@ -831,17 +831,17 @@ bool TuyaModuleSelected(void)
|
|||
if (TuyaGetDpId(TUYA_MCU_FUNC_DIMMER) != 0) {
|
||||
if (TuyaGetDpId(TUYA_MCU_FUNC_RGB) != 0) {
|
||||
if (TuyaGetDpId(TUYA_MCU_FUNC_CT) != 0) {
|
||||
light_type = LT_RGBWC;
|
||||
TasmotaGlobal.light_type = LT_RGBWC;
|
||||
} else if (TuyaGetDpId(TUYA_MCU_FUNC_WHITE) != 0) {
|
||||
light_type = LT_RGBW;
|
||||
} else { light_type = LT_RGB; }
|
||||
TasmotaGlobal.light_type = LT_RGBW;
|
||||
} else { TasmotaGlobal.light_type = LT_RGB; }
|
||||
} else if (TuyaGetDpId(TUYA_MCU_FUNC_CT) != 0 || TuyaGetDpId(TUYA_MCU_FUNC_DIMMER2) != 0) {
|
||||
if (TuyaGetDpId(TUYA_MCU_FUNC_RGB) != 0) {
|
||||
light_type = LT_RGBWC;
|
||||
} else { light_type = LT_SERIAL2; }
|
||||
} else { light_type = LT_SERIAL1; }
|
||||
TasmotaGlobal.light_type = LT_RGBWC;
|
||||
} else { TasmotaGlobal.light_type = LT_SERIAL2; }
|
||||
} else { TasmotaGlobal.light_type = LT_SERIAL1; }
|
||||
} else {
|
||||
light_type = LT_BASIC;
|
||||
TasmotaGlobal.light_type = LT_BASIC;
|
||||
}
|
||||
|
||||
if (TuyaGetDpId(TUYA_MCU_FUNC_LOWPOWER_MODE) != 0) {
|
||||
|
@ -963,7 +963,7 @@ void TuyaSerialInput(void)
|
|||
if (Settings.flag3.tuya_serial_mqtt_publish) { // SetOption66 - Enable TuyaMcuReceived messages over Mqtt
|
||||
MqttPublishPrefixTopic_P(RESULT_OR_TELE, PSTR(D_JSON_TUYA_MCU_RECEIVED));
|
||||
} else {
|
||||
AddLog_P(LOG_LEVEL_DEBUG, mqtt_data);
|
||||
AddLog_P(LOG_LEVEL_DEBUG, TasmotaGlobal.mqtt_data);
|
||||
}
|
||||
XdrvRulesProcess();
|
||||
|
||||
|
@ -1071,7 +1071,7 @@ bool Xnrg32(uint8_t function)
|
|||
{
|
||||
bool result = false;
|
||||
|
||||
if (TUYA_DIMMER == my_module_type) {
|
||||
if (TUYA_DIMMER == TasmotaGlobal.module_type) {
|
||||
if (FUNC_PRE_INIT == function) {
|
||||
if (TuyaGetDpId(TUYA_MCU_FUNC_POWER) != 0) {
|
||||
if (TuyaGetDpId(TUYA_MCU_FUNC_CURRENT) == 0) {
|
||||
|
@ -1080,7 +1080,7 @@ bool Xnrg32(uint8_t function)
|
|||
if (TuyaGetDpId(TUYA_MCU_FUNC_VOLTAGE) == 0) {
|
||||
Energy.voltage_available = false;
|
||||
}
|
||||
energy_flg = XNRG_32;
|
||||
TasmotaGlobal.energy_driver = XNRG_32;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1096,7 +1096,7 @@ bool Xdrv16(uint8_t function)
|
|||
{
|
||||
bool result = false;
|
||||
|
||||
if (TUYA_DIMMER == my_module_type) {
|
||||
if (TUYA_DIMMER == TasmotaGlobal.module_type) {
|
||||
switch (function) {
|
||||
case FUNC_LOOP:
|
||||
if (TuyaSerial) { TuyaSerialInput(); }
|
||||
|
|
|
@ -86,8 +86,8 @@ void ArmtronixRequestState(void)
|
|||
|
||||
bool ArmtronixModuleSelected(void)
|
||||
{
|
||||
devices_present++;
|
||||
light_type = LT_SERIAL2;
|
||||
TasmotaGlobal.devices_present++;
|
||||
TasmotaGlobal.light_type = LT_SERIAL2;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -168,7 +168,7 @@ bool Xdrv18(uint8_t function)
|
|||
{
|
||||
bool result = false;
|
||||
|
||||
if (ARMTRONIX_DIMMERS == my_module_type) {
|
||||
if (ARMTRONIX_DIMMERS == TasmotaGlobal.module_type) {
|
||||
switch (function) {
|
||||
case FUNC_LOOP:
|
||||
if (ArmtronixSerial) { ArmtronixSerialInput(); }
|
||||
|
|
|
@ -196,8 +196,8 @@ void PS16DZInit(void)
|
|||
|
||||
bool PS16DZModuleSelected(void)
|
||||
{
|
||||
devices_present++;
|
||||
light_type = LT_SERIAL1;
|
||||
TasmotaGlobal.devices_present++;
|
||||
TasmotaGlobal.light_type = LT_SERIAL1;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -210,7 +210,7 @@ bool Xdrv19(uint8_t function)
|
|||
{
|
||||
bool result = false;
|
||||
|
||||
if (PS_16_DZ == my_module_type) {
|
||||
if (PS_16_DZ == TasmotaGlobal.module_type) {
|
||||
switch (function) {
|
||||
case FUNC_LOOP:
|
||||
if (PS16DZSerial) { PS16DZSerialInput(); }
|
||||
|
|
|
@ -305,7 +305,7 @@ char prev_x_str[24] = "\0"; // store previously set xy by Alexa app
|
|||
char prev_y_str[24] = "\0";
|
||||
|
||||
uint8_t getLocalLightSubtype(uint8_t device) {
|
||||
if (light_type) {
|
||||
if (TasmotaGlobal.light_type) {
|
||||
if (device >= Light.device) {
|
||||
if (Settings.flag3.pwm_multi_channels) { // SetOption68 - Enable multi-channels PWM instead of Color PWM
|
||||
return LST_SINGLE; // If SetOption68, each channel acts like a dimmer
|
||||
|
@ -343,7 +343,7 @@ void HueLightStatus1(uint8_t device, String *response)
|
|||
}
|
||||
#endif
|
||||
|
||||
if (light_type) {
|
||||
if (TasmotaGlobal.light_type) {
|
||||
light_state.getHSB(&hue, &sat, nullptr);
|
||||
if (sat > 254) sat = 254; // Philips Hue only accepts 254 as max hue
|
||||
hue = changeUIntScale(hue, 0, 360, 0, 65535);
|
||||
|
@ -517,7 +517,7 @@ void HueAuthentication(String *path)
|
|||
|
||||
// refactored to remove code duplicates
|
||||
void CheckHue(String * response, bool &appending) {
|
||||
uint8_t maxhue = (devices_present > MAX_HUE_DEVICES) ? MAX_HUE_DEVICES : devices_present;
|
||||
uint8_t maxhue = (TasmotaGlobal.devices_present > MAX_HUE_DEVICES) ? MAX_HUE_DEVICES : TasmotaGlobal.devices_present;
|
||||
for (uint32_t i = 1; i <= maxhue; i++) {
|
||||
if (HueActive(i)) {
|
||||
if (appending) { *response += ","; }
|
||||
|
@ -576,7 +576,7 @@ void HueLightsCommand(uint8_t device, uint32_t device_id, String &response) {
|
|||
#endif // USE_SHUTTER
|
||||
}
|
||||
|
||||
if (light_type && (local_light_subtype >= LST_SINGLE)) {
|
||||
if (TasmotaGlobal.light_type && (local_light_subtype >= LST_SINGLE)) {
|
||||
if (!Settings.flag3.pwm_multi_channels) { // SetOption68 - Enable multi-channels PWM instead of Color PWM
|
||||
light_state.getHSB(&hue, &sat, nullptr);
|
||||
bri = light_state.getBri(); // get the combined bri for CT and RGB, not only the RGB one
|
||||
|
@ -699,7 +699,7 @@ void HueLightsCommand(uint8_t device, uint32_t device_id, String &response) {
|
|||
ShutterSetPosition(device, bri * 100.0f );
|
||||
} else
|
||||
#endif
|
||||
if (light_type && (local_light_subtype > LST_NONE)) { // not relay
|
||||
if (TasmotaGlobal.light_type && (local_light_subtype > LST_NONE)) { // not relay
|
||||
if (!Settings.flag3.pwm_multi_channels) { // SetOption68 - Enable multi-channels PWM instead of Color PWM
|
||||
if (g_gotct) {
|
||||
light_controller.changeCTB(ct, bri);
|
||||
|
@ -739,7 +739,7 @@ void HueLights(String *path)
|
|||
int code = 200;
|
||||
uint8_t device = 1;
|
||||
uint32_t device_id; // the raw device_id used by Hue emulation
|
||||
uint8_t maxhue = (devices_present > MAX_HUE_DEVICES) ? MAX_HUE_DEVICES : devices_present;
|
||||
uint8_t maxhue = (TasmotaGlobal.devices_present > MAX_HUE_DEVICES) ? MAX_HUE_DEVICES : TasmotaGlobal.devices_present;
|
||||
|
||||
path->remove(0,path->indexOf(F("/lights"))); // Remove until /lights
|
||||
if (path->endsWith(F("/lights"))) { // Got /lights
|
||||
|
@ -768,7 +768,7 @@ void HueLights(String *path)
|
|||
#endif // USE_ZIGBEE
|
||||
|
||||
#ifdef USE_SCRIPT_HUE
|
||||
if (device > devices_present) {
|
||||
if (device > TasmotaGlobal.devices_present) {
|
||||
return Script_Handle_Hue(path);
|
||||
}
|
||||
#endif
|
||||
|
@ -792,8 +792,8 @@ void HueLights(String *path)
|
|||
#endif // USE_ZIGBEE
|
||||
|
||||
#ifdef USE_SCRIPT_HUE
|
||||
if (device > devices_present) {
|
||||
Script_HueStatus(&response, device-devices_present - 1);
|
||||
if (device > TasmotaGlobal.devices_present) {
|
||||
Script_HueStatus(&response, device-TasmotaGlobal.devices_present - 1);
|
||||
goto exit;
|
||||
}
|
||||
#endif
|
||||
|
@ -820,7 +820,7 @@ void HueGroups(String *path)
|
|||
* http://tasmota/api/username/groups?1={"name":"Woonkamer","lights":[],"type":"Room","class":"Living room"})
|
||||
*/
|
||||
String response = "{}";
|
||||
uint8_t maxhue = (devices_present > MAX_HUE_DEVICES) ? MAX_HUE_DEVICES : devices_present;
|
||||
uint8_t maxhue = (TasmotaGlobal.devices_present > MAX_HUE_DEVICES) ? MAX_HUE_DEVICES : TasmotaGlobal.devices_present;
|
||||
//AddLog_P2(LOG_LEVEL_DEBUG_MORE, PSTR(D_LOG_HTTP D_HUE " HueGroups (%s)"), path->c_str());
|
||||
|
||||
if (path->endsWith("/0")) {
|
||||
|
@ -893,7 +893,7 @@ bool Xdrv20(uint8_t function)
|
|||
#if defined(USE_SCRIPT_HUE) || defined(USE_ZIGBEE)
|
||||
if ((EMUL_HUE == Settings.flag2.emulation)) {
|
||||
#else
|
||||
if (devices_present && (EMUL_HUE == Settings.flag2.emulation)) {
|
||||
if (TasmotaGlobal.devices_present && (EMUL_HUE == Settings.flag2.emulation)) {
|
||||
#endif
|
||||
switch (function) {
|
||||
case FUNC_WEB_ADD_HANDLER:
|
||||
|
|
|
@ -292,15 +292,15 @@ void HandleUpnpEvent(void)
|
|||
power = POWER_OFF;
|
||||
}
|
||||
if (power != POWER_TOGGLE) {
|
||||
uint8_t device = (light_type) ? devices_present : 1; // Select either a configured light or relay1
|
||||
uint8_t device = (TasmotaGlobal.light_type) ? TasmotaGlobal.devices_present : 1; // Select either a configured light or relay1
|
||||
ExecuteCommandPower(device, power, SRC_WEMO);
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef USE_UNISHOX_COMPRESSION
|
||||
snprintf_P(event, sizeof(event), Decompress(WEMO_RESPONSE_STATE_SOAP, WEMO_RESPONSE_STATE_SOAP_SIZE).c_str(), state, bitRead(TasmotaGlobal.power, devices_present -1), state);
|
||||
snprintf_P(event, sizeof(event), Decompress(WEMO_RESPONSE_STATE_SOAP, WEMO_RESPONSE_STATE_SOAP_SIZE).c_str(), state, bitRead(TasmotaGlobal.power, TasmotaGlobal.devices_present -1), state);
|
||||
#else
|
||||
snprintf_P(event, sizeof(event), WEMO_RESPONSE_STATE_SOAP, state, bitRead(TasmotaGlobal.power, devices_present -1), state);
|
||||
snprintf_P(event, sizeof(event), WEMO_RESPONSE_STATE_SOAP, state, bitRead(TasmotaGlobal.power, TasmotaGlobal.devices_present -1), state);
|
||||
#endif
|
||||
WSSend(200, CT_XML, event);
|
||||
}
|
||||
|
@ -350,7 +350,7 @@ bool Xdrv21(uint8_t function)
|
|||
{
|
||||
bool result = false;
|
||||
|
||||
if (devices_present && (EMUL_WEMO == Settings.flag2.emulation)) {
|
||||
if (TasmotaGlobal.devices_present && (EMUL_WEMO == Settings.flag2.emulation)) {
|
||||
switch (function) {
|
||||
case FUNC_WEB_ADD_HANDLER:
|
||||
WebServer_on(PSTR("/upnp/control/basicevent1"), HandleUpnpEvent, HTTP_POST);
|
||||
|
|
|
@ -45,7 +45,7 @@ bool ifan_restart_flag = true;
|
|||
|
||||
bool IsModuleIfan(void)
|
||||
{
|
||||
return ((SONOFF_IFAN02 == my_module_type) || (SONOFF_IFAN03 == my_module_type));
|
||||
return ((SONOFF_IFAN02 == TasmotaGlobal.module_type) || (SONOFF_IFAN03 == TasmotaGlobal.module_type));
|
||||
}
|
||||
|
||||
uint8_t MaxFanspeed(void)
|
||||
|
@ -82,7 +82,7 @@ void SonoffIFanSetFanspeed(uint8_t fanspeed, bool sequence)
|
|||
if (fanspeed == fanspeed_now) { return; }
|
||||
|
||||
uint8_t fans = kIFan02Speed[fanspeed];
|
||||
if (SONOFF_IFAN03 == my_module_type) {
|
||||
if (SONOFF_IFAN03 == TasmotaGlobal.module_type) {
|
||||
if (sequence) {
|
||||
fanspeed = kIFan03Sequence[fanspeed_now][ifan_fanspeed_goal];
|
||||
if (fanspeed != ifan_fanspeed_goal) {
|
||||
|
@ -112,8 +112,8 @@ void SonoffIfanReceived(void)
|
|||
{
|
||||
char svalue[32];
|
||||
|
||||
uint8_t mode = serial_in_buffer[3];
|
||||
uint8_t action = serial_in_buffer[6];
|
||||
uint8_t mode = TasmotaGlobal.serial_in_buffer[3];
|
||||
uint8_t action = TasmotaGlobal.serial_in_buffer[6];
|
||||
|
||||
if (4 == mode) {
|
||||
if (action < 4) {
|
||||
|
@ -146,24 +146,24 @@ void SonoffIfanReceived(void)
|
|||
|
||||
// Send Acknowledge - Copy first 5 bytes, reset byte 6 and store crc in byte 7
|
||||
// AA 55 01 04 00 00 05
|
||||
serial_in_buffer[5] = 0; // Ack
|
||||
serial_in_buffer[6] = 0; // Crc
|
||||
TasmotaGlobal.serial_in_buffer[5] = 0; // Ack
|
||||
TasmotaGlobal.serial_in_buffer[6] = 0; // Crc
|
||||
for (uint32_t i = 0; i < 7; i++) {
|
||||
if ((i > 1) && (i < 6)) { serial_in_buffer[6] += serial_in_buffer[i]; }
|
||||
Serial.write(serial_in_buffer[i]);
|
||||
if ((i > 1) && (i < 6)) { TasmotaGlobal.serial_in_buffer[6] += TasmotaGlobal.serial_in_buffer[i]; }
|
||||
Serial.write(TasmotaGlobal.serial_in_buffer[i]);
|
||||
}
|
||||
}
|
||||
|
||||
bool SonoffIfanSerialInput(void)
|
||||
{
|
||||
if (SONOFF_IFAN03 != my_module_type) { return false; }
|
||||
if (SONOFF_IFAN03 != TasmotaGlobal.module_type) { return false; }
|
||||
|
||||
if (0xAA == serial_in_byte) { // 0xAA - Start of text
|
||||
if (0xAA == TasmotaGlobal.serial_in_byte) { // 0xAA - Start of text
|
||||
TasmotaGlobal.serial_in_byte_counter = 0;
|
||||
ifan_receive_flag = true;
|
||||
}
|
||||
if (ifan_receive_flag) {
|
||||
serial_in_buffer[TasmotaGlobal.serial_in_byte_counter++] = serial_in_byte;
|
||||
TasmotaGlobal.serial_in_buffer[TasmotaGlobal.serial_in_byte_counter++] = TasmotaGlobal.serial_in_byte;
|
||||
if (TasmotaGlobal.serial_in_byte_counter == 8) {
|
||||
// AA 55 01 01 00 01 01 04 - Wifi long press - start wifi setup
|
||||
// AA 55 01 01 00 01 02 05 - Rf and Wifi short press
|
||||
|
@ -177,15 +177,15 @@ bool SonoffIfanSerialInput(void)
|
|||
AddLogSerial(LOG_LEVEL_DEBUG);
|
||||
uint8_t crc = 0;
|
||||
for (uint32_t i = 2; i < 7; i++) {
|
||||
crc += serial_in_buffer[i];
|
||||
crc += TasmotaGlobal.serial_in_buffer[i];
|
||||
}
|
||||
if (crc == serial_in_buffer[7]) {
|
||||
if (crc == TasmotaGlobal.serial_in_buffer[7]) {
|
||||
SonoffIfanReceived();
|
||||
ifan_receive_flag = false;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
serial_in_byte = 0;
|
||||
TasmotaGlobal.serial_in_byte = 0;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
@ -216,7 +216,7 @@ void CmndFanspeed(void)
|
|||
|
||||
bool SonoffIfanInit(void)
|
||||
{
|
||||
if (SONOFF_IFAN03 == my_module_type) {
|
||||
if (SONOFF_IFAN03 == TasmotaGlobal.module_type) {
|
||||
SetSerial(9600, TS_SERIAL_8N1);
|
||||
}
|
||||
return false; // Continue init chain
|
||||
|
@ -224,7 +224,7 @@ bool SonoffIfanInit(void)
|
|||
|
||||
void SonoffIfanUpdate(void)
|
||||
{
|
||||
if (SONOFF_IFAN03 == my_module_type) {
|
||||
if (SONOFF_IFAN03 == TasmotaGlobal.module_type) {
|
||||
if (ifan_fanspeed_timer) {
|
||||
ifan_fanspeed_timer--;
|
||||
if (!ifan_fanspeed_timer) {
|
||||
|
@ -233,7 +233,7 @@ void SonoffIfanUpdate(void)
|
|||
}
|
||||
}
|
||||
|
||||
if (ifan_restart_flag && (4 == TasmotaGlobal.uptime) && (SONOFF_IFAN02 == my_module_type)) { // Microcontroller needs 3 seconds before accepting commands
|
||||
if (ifan_restart_flag && (4 == TasmotaGlobal.uptime) && (SONOFF_IFAN02 == TasmotaGlobal.module_type)) { // Microcontroller needs 3 seconds before accepting commands
|
||||
ifan_restart_flag = false;
|
||||
SetDevicePower(1, SRC_RETRY); // Sync with default power on state microcontroller being Light ON and Fan OFF
|
||||
SetDevicePower(TasmotaGlobal.power, SRC_RETRY); // Set required power on state
|
||||
|
|
|
@ -514,28 +514,28 @@ void Z_Devices::jsonPublishFlush(uint16_t shortaddr) {
|
|||
gZbLastMessage.groupaddr = attr_list.group_id; // %zbgroup%
|
||||
gZbLastMessage.endpoint = attr_list.src_ep; // %zbendpoint%
|
||||
|
||||
mqtt_data[0] = 0; // clear string
|
||||
TasmotaGlobal.mqtt_data[0] = 0; // clear string
|
||||
// Do we prefix with `ZbReceived`?
|
||||
if (!Settings.flag4.remove_zbreceived) {
|
||||
Response_P(PSTR("{\"" D_JSON_ZIGBEE_RECEIVED "\":"));
|
||||
}
|
||||
// What key do we use, shortaddr or name?
|
||||
if (use_fname) {
|
||||
Response_P(PSTR("%s{\"%s\":{"), mqtt_data, fname);
|
||||
Response_P(PSTR("%s{\"%s\":{"), TasmotaGlobal.mqtt_data, fname);
|
||||
} else {
|
||||
Response_P(PSTR("%s{\"0x%04X\":{"), mqtt_data, shortaddr);
|
||||
Response_P(PSTR("%s{\"0x%04X\":{"), TasmotaGlobal.mqtt_data, shortaddr);
|
||||
}
|
||||
// Add "Device":"0x...."
|
||||
Response_P(PSTR("%s\"" D_JSON_ZIGBEE_DEVICE "\":\"0x%04X\","), mqtt_data, shortaddr);
|
||||
ResponseAppend_P(PSTR("\"" D_JSON_ZIGBEE_DEVICE "\":\"0x%04X\","), shortaddr);
|
||||
// Add "Name":"xxx" if name is present
|
||||
if (fname) {
|
||||
Response_P(PSTR("%s\"" D_JSON_ZIGBEE_NAME "\":\"%s\","), mqtt_data, EscapeJSONString(fname).c_str());
|
||||
ResponseAppend_P(PSTR("\"" D_JSON_ZIGBEE_NAME "\":\"%s\","), EscapeJSONString(fname).c_str());
|
||||
}
|
||||
// Add all other attributes
|
||||
Response_P(PSTR("%s%s}}"), mqtt_data, attr_list.toString().c_str());
|
||||
ResponseAppend_P(PSTR("%s}}"), attr_list.toString().c_str());
|
||||
|
||||
if (!Settings.flag4.remove_zbreceived) {
|
||||
Response_P(PSTR("%s}"), mqtt_data);
|
||||
ResponseAppend_P(PSTR("}"));
|
||||
}
|
||||
attr_list.reset(); // clear the attributes
|
||||
|
||||
|
|
|
@ -706,7 +706,7 @@ public:
|
|||
if (Settings.flag3.tuya_serial_mqtt_publish) {
|
||||
MqttPublishPrefixTopicRulesProcess_P(TELE, PSTR(D_RSLT_SENSOR));
|
||||
} else {
|
||||
AddLog_P2(LOG_LEVEL_DEBUG, PSTR(D_LOG_ZIGBEE "%s"), mqtt_data);
|
||||
AddLog_P2(LOG_LEVEL_DEBUG, PSTR(D_LOG_ZIGBEE "%s"), TasmotaGlobal.mqtt_data);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1404,7 +1404,7 @@ void Z_AutoConfigReportingForCluster(uint16_t shortaddr, uint16_t groupaddr, uin
|
|||
ResponseAppend_P(PSTR("}}"));
|
||||
|
||||
if (buf.len() > 0) {
|
||||
AddLog_P2(LOG_LEVEL_INFO, PSTR(D_LOG_ZIGBEE "auto-bind `%s`"), mqtt_data);
|
||||
AddLog_P2(LOG_LEVEL_INFO, PSTR(D_LOG_ZIGBEE "auto-bind `%s`"), TasmotaGlobal.mqtt_data);
|
||||
ZigbeeZCLSend_Raw(ZigbeeZCLSendMessage({
|
||||
shortaddr,
|
||||
0x0000, /* group */
|
||||
|
|
|
@ -156,7 +156,7 @@ void ZigbeeInputLoop(void) {
|
|||
if (Settings.flag3.tuya_serial_mqtt_publish) {
|
||||
MqttPublishPrefixTopicRulesProcess_P(TELE, PSTR(D_RSLT_SENSOR));
|
||||
} else {
|
||||
AddLog_P2(LOG_LEVEL_DEBUG, PSTR(D_LOG_ZIGBEE "%s"), mqtt_data);
|
||||
AddLog_P2(LOG_LEVEL_DEBUG, PSTR(D_LOG_ZIGBEE "%s"), TasmotaGlobal.mqtt_data);
|
||||
}
|
||||
// now process the message
|
||||
ZigbeeProcessInput(znp_buffer);
|
||||
|
@ -293,13 +293,13 @@ void ZigbeeInitSerial(void)
|
|||
zigbee.active = false;
|
||||
if (PinUsed(GPIO_ZIGBEE_RX) && PinUsed(GPIO_ZIGBEE_TX)) {
|
||||
AddLog_P2(LOG_LEVEL_DEBUG_MORE, PSTR(D_LOG_ZIGBEE "GPIOs Rx:%d Tx:%d"), Pin(GPIO_ZIGBEE_RX), Pin(GPIO_ZIGBEE_TX));
|
||||
// if seriallog_level is 0, we allow GPIO 13/15 to switch to Hardware Serial
|
||||
ZigbeeSerial = new TasmotaSerial(Pin(GPIO_ZIGBEE_RX), Pin(GPIO_ZIGBEE_TX), seriallog_level ? 1 : 2, 0, 256); // set a receive buffer of 256 bytes
|
||||
// if TasmotaGlobal.seriallog_level is 0, we allow GPIO 13/15 to switch to Hardware Serial
|
||||
ZigbeeSerial = new TasmotaSerial(Pin(GPIO_ZIGBEE_RX), Pin(GPIO_ZIGBEE_TX), TasmotaGlobal.seriallog_level ? 1 : 2, 0, 256); // set a receive buffer of 256 bytes
|
||||
ZigbeeSerial->begin(115200);
|
||||
if (ZigbeeSerial->hardwareSerial()) {
|
||||
ClaimSerial();
|
||||
uint32_t aligned_buffer = ((uint32_t)serial_in_buffer + 3) & ~3;
|
||||
zigbee_buffer = new PreAllocatedSBuffer(sizeof(serial_in_buffer) - 3, (char*) aligned_buffer);
|
||||
uint32_t aligned_buffer = ((uint32_t)TasmotaGlobal.serial_in_buffer + 3) & ~3;
|
||||
zigbee_buffer = new PreAllocatedSBuffer(sizeof(TasmotaGlobal.serial_in_buffer) - 3, (char*) aligned_buffer);
|
||||
} else {
|
||||
// AddLog_P2(LOG_LEVEL_INFO, PSTR("ZigbeeInit Mem2 = %d"), ESP_getFreeHeap());
|
||||
zigbee_buffer = new SBuffer(ZIGBEE_BUFFER_SIZE);
|
||||
|
@ -609,7 +609,7 @@ int32_t ZigbeeProcessInputEZSP(class SBuffer &buf) {
|
|||
log_level = LOG_LEVEL_DEBUG;
|
||||
break;
|
||||
}
|
||||
AddLog_P2(log_level, PSTR(D_LOG_ZIGBEE "%s"), mqtt_data); // TODO move to LOG_LEVEL_DEBUG when stable
|
||||
AddLog_P2(log_level, PSTR(D_LOG_ZIGBEE "%s"), TasmotaGlobal.mqtt_data); // TODO move to LOG_LEVEL_DEBUG when stable
|
||||
}
|
||||
|
||||
// Pass message to state machine
|
||||
|
|
|
@ -1305,7 +1305,7 @@ void ZigbeeGlowPermitJoinLight(void) {
|
|||
// change the led state
|
||||
uint32_t led_pin = Pin(GPIO_LEDLNK);
|
||||
if (led_pin < 99) {
|
||||
analogWrite(led_pin, ledlnk_inverted ? 1023 - led_power : led_power);
|
||||
analogWrite(led_pin, TasmotaGlobal.ledlnk_inverted ? 1023 - led_power : led_power);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -114,7 +114,7 @@ void ShutterLogPos(uint32_t i)
|
|||
void ExecuteCommandPowerShutter(uint32_t device, uint32_t state, uint32_t source)
|
||||
{
|
||||
// first implementation for virtual relays. Avoid switching relay numbers that do not exist.
|
||||
if (device <= devices_present) ExecuteCommandPower(device,state,source);
|
||||
if (device <= TasmotaGlobal.devices_present) ExecuteCommandPower(device,state,source);
|
||||
}
|
||||
|
||||
void ShutterUpdateVelocity(uint8_t i)
|
||||
|
@ -128,7 +128,7 @@ void ShutterUpdateVelocity(uint8_t i)
|
|||
void ShutterRtc50mS(void)
|
||||
{
|
||||
// No Logging allowed. RTC Timer
|
||||
for (uint8_t i = 0; i < shutters_present; i++) {
|
||||
for (uint8_t i = 0; i < TasmotaGlobal.shutters_present; i++) {
|
||||
if (Shutter[i].direction) {
|
||||
// update position data before increasing counter
|
||||
Shutter[i].real_position = ShutterCalculatePosition(i);
|
||||
|
@ -218,7 +218,7 @@ uint8_t ShutterRealToPercentPosition(int32_t realpos, uint32_t index)
|
|||
|
||||
void ShutterInit(void)
|
||||
{
|
||||
shutters_present = 0;
|
||||
TasmotaGlobal.shutters_present = 0;
|
||||
ShutterGlobal.RelayShutterMask = 0;
|
||||
//Initialize to get relay that changed
|
||||
ShutterGlobal.RelayOldMask = TasmotaGlobal.power;
|
||||
|
@ -232,7 +232,7 @@ void ShutterInit(void)
|
|||
// set startrelay to 1 on first init, but only to shutter 1. 90% usecase
|
||||
Settings.shutter_startrelay[i] = (Settings.shutter_startrelay[i] == 0 && i == 0? 1 : Settings.shutter_startrelay[i]);
|
||||
if (Settings.shutter_startrelay[i] && (Settings.shutter_startrelay[i] < 9)) {
|
||||
shutters_present++;
|
||||
TasmotaGlobal.shutters_present++;
|
||||
|
||||
// Add the two relays to the mask to knaw they belong to shutters
|
||||
ShutterGlobal.RelayShutterMask |= 3 << (Settings.shutter_startrelay[i] -1) ;
|
||||
|
@ -330,7 +330,7 @@ void ShutterReportPosition(bool always, uint32_t index)
|
|||
Response_P(PSTR("{"));
|
||||
TasmotaGlobal.rules_flag.shutter_moving = 0;
|
||||
uint32_t i = 0;
|
||||
uint32_t n = shutters_present;
|
||||
uint32_t n = TasmotaGlobal.shutters_present;
|
||||
if( index != MAX_SHUTTERS) {
|
||||
i = index;
|
||||
n = index+1;
|
||||
|
@ -446,14 +446,14 @@ void ShutterPowerOff(uint8_t i) {
|
|||
case SHT_PULSE:
|
||||
uint8_t cur_relay = Settings.shutter_startrelay[i] + (Shutter[i].direction == 1 ? 0 : (uint8_t)(ShutterGlobal.position_mode == SHT_TIME)) ;
|
||||
// we have a momentary switch here. Needs additional pulse on same relay after the end
|
||||
if ((SRC_PULSETIMER == last_source || SRC_SHUTTER == last_source || SRC_WEBGUI == last_source)) {
|
||||
if ((SRC_PULSETIMER == TasmotaGlobal.last_source || SRC_SHUTTER == TasmotaGlobal.last_source || SRC_WEBGUI == TasmotaGlobal.last_source)) {
|
||||
ExecuteCommandPowerShutter(cur_relay, 1, SRC_SHUTTER);
|
||||
// switch off direction relay to make it power less
|
||||
if ((1 << (Settings.shutter_startrelay[i])) & TasmotaGlobal.power) {
|
||||
ExecuteCommandPowerShutter(Settings.shutter_startrelay[i]+1, 0, SRC_SHUTTER);
|
||||
}
|
||||
} else {
|
||||
last_source = SRC_SHUTTER;
|
||||
TasmotaGlobal.last_source = SRC_SHUTTER;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
@ -472,7 +472,7 @@ void ShutterUpdatePosition(void)
|
|||
|
||||
char scommand[CMDSZ];
|
||||
char stopic[TOPSZ];
|
||||
for (uint32_t i = 0; i < shutters_present; i++) {
|
||||
for (uint32_t i = 0; i < TasmotaGlobal.shutters_present; i++) {
|
||||
if (Shutter[i].direction != 0) {
|
||||
if (!ShutterGlobal.start_reported) {
|
||||
ShutterReportPosition(true, i);
|
||||
|
@ -496,7 +496,7 @@ void ShutterUpdatePosition(void)
|
|||
|
||||
// sending MQTT result to broker
|
||||
snprintf_P(scommand, sizeof(scommand),PSTR(D_SHUTTER "%d"), i+1);
|
||||
GetTopic_P(stopic, STAT, mqtt_topic, scommand);
|
||||
GetTopic_P(stopic, STAT, TasmotaGlobal.mqtt_topic, scommand);
|
||||
Response_P("%d", (Settings.shutter_options[i] & 1) ? 100 - Settings.shutter_position[i]: Settings.shutter_position[i]);
|
||||
MqttPublish(stopic, Settings.flag.mqtt_power_retain); // CMND_POWERRETAIN
|
||||
ShutterReportPosition(true, i);
|
||||
|
@ -596,12 +596,12 @@ void ShutterRelayChanged(void)
|
|||
// relays_changed = bool if one of the relays that belong to the shutter changed not by shutter or pulsetimer
|
||||
char stemp1[10];
|
||||
|
||||
for (uint32_t i = 0; i < shutters_present; i++) {
|
||||
for (uint32_t i = 0; i < TasmotaGlobal.shutters_present; i++) {
|
||||
power_t powerstate_local = (TasmotaGlobal.power >> (Settings.shutter_startrelay[i] -1)) & 3;
|
||||
// SRC_IGNORE added because INTERLOCK function bite causes this as last source for changing the relay.
|
||||
//uint8 manual_relays_changed = ((ShutterGlobal.RelayCurrentMask >> (Settings.shutter_startrelay[i] -1)) & 3) && SRC_IGNORE != last_source && SRC_SHUTTER != last_source && SRC_PULSETIMER != last_source ;
|
||||
uint8 manual_relays_changed = ((ShutterGlobal.RelayCurrentMask >> (Settings.shutter_startrelay[i] -1)) & 3) && SRC_SHUTTER != last_source && SRC_PULSETIMER != last_source ;
|
||||
AddLog_P2(LOG_LEVEL_DEBUG_MORE, PSTR("SHT: Shutter %d: source: %s, powerstate_local %ld, ShutterGlobal.RelayCurrentMask %d, manual change %d"), i+1, GetTextIndexed(stemp1, sizeof(stemp1), last_source, kCommandSource), powerstate_local,ShutterGlobal.RelayCurrentMask,manual_relays_changed);
|
||||
//uint8 manual_relays_changed = ((ShutterGlobal.RelayCurrentMask >> (Settings.shutter_startrelay[i] -1)) & 3) && SRC_IGNORE != TasmotaGlobal.last_source && SRC_SHUTTER != TasmotaGlobal.last_source && SRC_PULSETIMER != TasmotaGlobal.last_source ;
|
||||
uint8 manual_relays_changed = ((ShutterGlobal.RelayCurrentMask >> (Settings.shutter_startrelay[i] -1)) & 3) && SRC_SHUTTER != TasmotaGlobal.last_source && SRC_PULSETIMER != TasmotaGlobal.last_source ;
|
||||
AddLog_P2(LOG_LEVEL_DEBUG_MORE, PSTR("SHT: Shutter %d: source: %s, powerstate_local %ld, ShutterGlobal.RelayCurrentMask %d, manual change %d"), i+1, GetTextIndexed(stemp1, sizeof(stemp1), TasmotaGlobal.last_source, kCommandSource), powerstate_local,ShutterGlobal.RelayCurrentMask,manual_relays_changed);
|
||||
if (manual_relays_changed) {
|
||||
//ShutterGlobal.skip_relay_change = true;
|
||||
ShutterLimitRealAndTargetPositions(i);
|
||||
|
@ -610,11 +610,11 @@ void ShutterRelayChanged(void)
|
|||
if (Shutter[i].direction != 0 && powerstate_local) {
|
||||
Shutter[i].target_position = Shutter[i].real_position;
|
||||
powerstate_local = 0;
|
||||
AddLog_P2(LOG_LEVEL_DEBUG_MORE, PSTR("SHT: Shutter %d: Switch OFF motor. Target: %ld, source: %s, powerstate_local %ld, ShutterGlobal.RelayCurrentMask %d, manual change %d"), i+1, Shutter[i].target_position, GetTextIndexed(stemp1, sizeof(stemp1), last_source, kCommandSource), powerstate_local,ShutterGlobal.RelayCurrentMask,manual_relays_changed);
|
||||
AddLog_P2(LOG_LEVEL_DEBUG_MORE, PSTR("SHT: Shutter %d: Switch OFF motor. Target: %ld, source: %s, powerstate_local %ld, ShutterGlobal.RelayCurrentMask %d, manual change %d"), i+1, Shutter[i].target_position, GetTextIndexed(stemp1, sizeof(stemp1), TasmotaGlobal.last_source, kCommandSource), powerstate_local,ShutterGlobal.RelayCurrentMask,manual_relays_changed);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
last_source = SRC_SHUTTER; // avoid switch off in the next loop
|
||||
TasmotaGlobal.last_source = SRC_SHUTTER; // avoid switch off in the next loop
|
||||
if (Shutter[i].direction != 0 ) ShutterPowerOff(i);
|
||||
}
|
||||
switch (ShutterGlobal.position_mode) {
|
||||
|
@ -663,7 +663,7 @@ void ShutterRelayChanged(void)
|
|||
} // switch (ShutterGlobal.position_mode)
|
||||
AddLog_P2(LOG_LEVEL_DEBUG_MORE, PSTR("SHT: Shutter %d: Target: %ld, powerstatelocal %d"), i+1, Shutter[i].target_position, powerstate_local);
|
||||
} // if (manual_relays_changed)
|
||||
} // for (uint32_t i = 0; i < shutters_present; i++)
|
||||
} // for (uint32_t i = 0; i < TasmotaGlobal.shutters_present; i++)
|
||||
}
|
||||
|
||||
bool ShutterButtonIsSimultaneousHold(uint32_t button_index, uint32_t shutter_index) {
|
||||
|
@ -809,7 +809,7 @@ void ShutterButtonHandler(void)
|
|||
if (pos_press_index>3) pos_press_index=3;
|
||||
AddLog_P2(LOG_LEVEL_DEBUG_MORE, PSTR("SHT: shutter %d, button %d = %d (single=1, double=2, tripple=3, hold=4)"), shutter_index+1, button_index+1, pos_press_index+1);
|
||||
XdrvMailbox.index = shutter_index +1;
|
||||
last_source = SRC_BUTTON;
|
||||
TasmotaGlobal.last_source = SRC_BUTTON;
|
||||
XdrvMailbox.data_len = 0;
|
||||
char databuf[1] = "";
|
||||
XdrvMailbox.data = databuf;
|
||||
|
@ -870,7 +870,7 @@ void ShutterToggle(bool dir)
|
|||
if ((1 == XdrvMailbox.index) && (XdrvMailbox.payload != -99)) {
|
||||
XdrvMailbox.index = XdrvMailbox.payload;
|
||||
}
|
||||
if ((XdrvMailbox.index > 0) && (XdrvMailbox.index <= shutters_present)) {
|
||||
if ((XdrvMailbox.index > 0) && (XdrvMailbox.index <= TasmotaGlobal.shutters_present)) {
|
||||
uint32_t index = XdrvMailbox.index-1;
|
||||
if (dir) {
|
||||
XdrvMailbox.payload = (Shutter[index].lastdirection > 0) ? 0 : 100;
|
||||
|
@ -879,7 +879,7 @@ void ShutterToggle(bool dir)
|
|||
XdrvMailbox.payload = (50 < ShutterRealToPercentPosition(Shutter[index].real_position, index)) ? 0 : 100;
|
||||
}
|
||||
XdrvMailbox.data_len = 0;
|
||||
last_source = SRC_WEBGUI;
|
||||
TasmotaGlobal.last_source = SRC_WEBGUI;
|
||||
CmndShutterPosition();
|
||||
}
|
||||
}
|
||||
|
@ -895,13 +895,13 @@ void CmndShutterOpen(void)
|
|||
XdrvMailbox.index = XdrvMailbox.payload;
|
||||
}
|
||||
XdrvMailbox.payload = 100;
|
||||
last_source = SRC_WEBGUI;
|
||||
TasmotaGlobal.last_source = SRC_WEBGUI;
|
||||
CmndShutterPosition();
|
||||
}
|
||||
|
||||
void CmndShutterStopOpen(void)
|
||||
{
|
||||
if ((XdrvMailbox.index > 0) && (XdrvMailbox.index <= shutters_present)) {
|
||||
if ((XdrvMailbox.index > 0) && (XdrvMailbox.index <= TasmotaGlobal.shutters_present)) {
|
||||
uint32_t index = XdrvMailbox.index-1;
|
||||
if (Shutter[index].direction) {
|
||||
CmndShutterStop();
|
||||
|
@ -919,13 +919,13 @@ void CmndShutterClose(void)
|
|||
}
|
||||
XdrvMailbox.payload = 0;
|
||||
XdrvMailbox.data_len = 0;
|
||||
last_source = SRC_WEBGUI;
|
||||
TasmotaGlobal.last_source = SRC_WEBGUI;
|
||||
CmndShutterPosition();
|
||||
}
|
||||
|
||||
void CmndShutterStopClose(void)
|
||||
{
|
||||
if ((XdrvMailbox.index > 0) && (XdrvMailbox.index <= shutters_present)) {
|
||||
if ((XdrvMailbox.index > 0) && (XdrvMailbox.index <= TasmotaGlobal.shutters_present)) {
|
||||
uint32_t index = XdrvMailbox.index-1;
|
||||
if (Shutter[index].direction) {
|
||||
CmndShutterStop();
|
||||
|
@ -947,7 +947,7 @@ void CmndShutterToggleDir(void)
|
|||
|
||||
void CmndShutterStopToggle(void)
|
||||
{
|
||||
if ((XdrvMailbox.index > 0) && (XdrvMailbox.index <= shutters_present)) {
|
||||
if ((XdrvMailbox.index > 0) && (XdrvMailbox.index <= TasmotaGlobal.shutters_present)) {
|
||||
uint32_t index = XdrvMailbox.index-1;
|
||||
if (Shutter[index].direction) {
|
||||
CmndShutterStop();
|
||||
|
@ -959,7 +959,7 @@ void CmndShutterStopToggle(void)
|
|||
|
||||
void CmndShutterStopToggleDir(void)
|
||||
{
|
||||
if ((XdrvMailbox.index > 0) && (XdrvMailbox.index <= shutters_present)) {
|
||||
if ((XdrvMailbox.index > 0) && (XdrvMailbox.index <= TasmotaGlobal.shutters_present)) {
|
||||
uint32_t index = XdrvMailbox.index-1;
|
||||
if (Shutter[index].direction) {
|
||||
CmndShutterStop();
|
||||
|
@ -971,7 +971,7 @@ void CmndShutterStopToggleDir(void)
|
|||
|
||||
void CmndShutterStop(void)
|
||||
{
|
||||
if ((XdrvMailbox.index > 0) && (XdrvMailbox.index <= shutters_present)) {
|
||||
if ((XdrvMailbox.index > 0) && (XdrvMailbox.index <= TasmotaGlobal.shutters_present)) {
|
||||
if (!(Settings.shutter_options[XdrvMailbox.index-1] & 2)) {
|
||||
if ((1 == XdrvMailbox.index) && (XdrvMailbox.payload != -99)) {
|
||||
XdrvMailbox.index = XdrvMailbox.payload;
|
||||
|
@ -983,7 +983,7 @@ void CmndShutterStop(void)
|
|||
|
||||
int32_t temp_realpos = ShutterCalculatePosition(i);
|
||||
XdrvMailbox.payload = ShutterRealToPercentPosition(temp_realpos, i);
|
||||
last_source = SRC_WEBGUI;
|
||||
TasmotaGlobal.last_source = SRC_WEBGUI;
|
||||
CmndShutterPosition();
|
||||
} else {
|
||||
if (XdrvMailbox.command)
|
||||
|
@ -998,8 +998,8 @@ void CmndShutterStop(void)
|
|||
|
||||
void CmndShutterIncDec(void)
|
||||
{
|
||||
//AddLog_P2(LOG_LEVEL_DEBUG_MORE, PSTR("SHT: Change in: payload %s (%d), payload %d, idx %d, src %d"), XdrvMailbox.data , XdrvMailbox.data_len, XdrvMailbox.payload , XdrvMailbox.index, last_source );
|
||||
if ((XdrvMailbox.index > 0) && (XdrvMailbox.index <= shutters_present)) {
|
||||
//AddLog_P2(LOG_LEVEL_DEBUG_MORE, PSTR("SHT: Change in: payload %s (%d), payload %d, idx %d, src %d"), XdrvMailbox.data , XdrvMailbox.data_len, XdrvMailbox.payload , XdrvMailbox.index, TasmotaGlobal.last_source );
|
||||
if ((XdrvMailbox.index > 0) && (XdrvMailbox.index <= TasmotaGlobal.shutters_present)) {
|
||||
if (XdrvMailbox.data_len > 0) {
|
||||
XdrvMailbox.payload = ShutterRealToPercentPosition(Shutter[XdrvMailbox.index-1].target_position, XdrvMailbox.index-1)+XdrvMailbox.payload;
|
||||
// limit position to boundaries
|
||||
|
@ -1012,11 +1012,11 @@ void CmndShutterIncDec(void)
|
|||
|
||||
void CmndShutterPosition(void)
|
||||
{
|
||||
if ((XdrvMailbox.index > 0) && (XdrvMailbox.index <= shutters_present)) {
|
||||
if ((XdrvMailbox.index > 0) && (XdrvMailbox.index <= TasmotaGlobal.shutters_present)) {
|
||||
if (!(Settings.shutter_options[XdrvMailbox.index-1] & 2)) {
|
||||
uint32_t index = XdrvMailbox.index-1;
|
||||
//limit the payload
|
||||
AddLog_P2(LOG_LEVEL_DEBUG_MORE, PSTR("SHT: Pos. in: payload %s (%d), payload %d, idx %d, src %d"), XdrvMailbox.data , XdrvMailbox.data_len, XdrvMailbox.payload , XdrvMailbox.index, last_source );
|
||||
AddLog_P2(LOG_LEVEL_DEBUG_MORE, PSTR("SHT: Pos. in: payload %s (%d), payload %d, idx %d, src %d"), XdrvMailbox.data , XdrvMailbox.data_len, XdrvMailbox.payload , XdrvMailbox.index, TasmotaGlobal.last_source );
|
||||
|
||||
// value 0 with data_len > 0 can mean Open
|
||||
// special handling fo UP,DOWN,TOGGLE,STOP command comming with payload -99
|
||||
|
@ -1047,13 +1047,13 @@ void CmndShutterPosition(void)
|
|||
|
||||
int8_t target_pos_percent = (XdrvMailbox.payload < 0) ? (XdrvMailbox.payload == -99 ? ShutterRealToPercentPosition(Shutter[index].real_position, index) : 0) : ((XdrvMailbox.payload > 100) ? 100 : XdrvMailbox.payload);
|
||||
// webgui still send also on inverted shutter the native position.
|
||||
target_pos_percent = ((Settings.shutter_options[index] & 1) && (SRC_WEBGUI != last_source)) ? 100 - target_pos_percent : target_pos_percent;
|
||||
target_pos_percent = ((Settings.shutter_options[index] & 1) && (SRC_WEBGUI != TasmotaGlobal.last_source)) ? 100 - target_pos_percent : target_pos_percent;
|
||||
if (XdrvMailbox.payload != -99) {
|
||||
//target_pos_percent = (Settings.shutter_options[index] & 1) ? 100 - target_pos_percent : target_pos_percent;
|
||||
Shutter[index].target_position = ShutterPercentToRealPosition(target_pos_percent, index);
|
||||
//Shutter[i].accelerator[index] = ShutterGlobal.open_velocity_max / ((Shutter[i].motordelay[index] > 0) ? Shutter[i].motordelay[index] : 1);
|
||||
//Shutter[i].target_position[index] = XdrvMailbox.payload < 5 ? Settings.shuttercoeff[2][index] * XdrvMailbox.payload : Settings.shuttercoeff[1][index] * XdrvMailbox.payload + Settings.shuttercoeff[0,index];
|
||||
AddLog_P2(LOG_LEVEL_DEBUG_MORE, PSTR("SHT: lastsource %d:, real %d, target %d, payload %d"), last_source, Shutter[index].real_position ,Shutter[index].target_position,target_pos_percent);
|
||||
AddLog_P2(LOG_LEVEL_DEBUG_MORE, PSTR("SHT: lastsource %d:, real %d, target %d, payload %d"), TasmotaGlobal.last_source, Shutter[index].real_position ,Shutter[index].target_position,target_pos_percent);
|
||||
}
|
||||
if ( (target_pos_percent >= 0) && (target_pos_percent <= 100) && abs(Shutter[index].target_position - Shutter[index].real_position ) / Shutter[index].close_velocity > 2) {
|
||||
if (Settings.shutter_options[index] & 4) {
|
||||
|
@ -1123,7 +1123,7 @@ void CmndShutterPosition(void)
|
|||
|
||||
void CmndShutterStopPosition(void)
|
||||
{
|
||||
if ((XdrvMailbox.index > 0) && (XdrvMailbox.index <= shutters_present)) {
|
||||
if ((XdrvMailbox.index > 0) && (XdrvMailbox.index <= TasmotaGlobal.shutters_present)) {
|
||||
uint32_t index = XdrvMailbox.index-1;
|
||||
if (Shutter[index].direction) {
|
||||
XdrvMailbox.payload = -99;
|
||||
|
@ -1135,7 +1135,7 @@ void CmndShutterStopPosition(void)
|
|||
}
|
||||
void CmndShutterOpenTime(void)
|
||||
{
|
||||
if ((XdrvMailbox.index > 0) && (XdrvMailbox.index <= shutters_present)) {
|
||||
if ((XdrvMailbox.index > 0) && (XdrvMailbox.index <= TasmotaGlobal.shutters_present)) {
|
||||
if (XdrvMailbox.data_len > 0) {
|
||||
Settings.shutter_opentime[XdrvMailbox.index -1] = (uint16_t)(10 * CharToFloat(XdrvMailbox.data));
|
||||
ShutterInit();
|
||||
|
@ -1148,7 +1148,7 @@ void CmndShutterOpenTime(void)
|
|||
|
||||
void CmndShutterCloseTime(void)
|
||||
{
|
||||
if ((XdrvMailbox.index > 0) && (XdrvMailbox.index <= shutters_present)) {
|
||||
if ((XdrvMailbox.index > 0) && (XdrvMailbox.index <= TasmotaGlobal.shutters_present)) {
|
||||
if (XdrvMailbox.data_len > 0) {
|
||||
Settings.shutter_closetime[XdrvMailbox.index -1] = (uint16_t)(10 * CharToFloat(XdrvMailbox.data));
|
||||
ShutterInit();
|
||||
|
@ -1161,7 +1161,7 @@ void CmndShutterCloseTime(void)
|
|||
|
||||
void CmndShutterMotorDelay(void)
|
||||
{
|
||||
if ((XdrvMailbox.index > 0) && (XdrvMailbox.index <= shutters_present)) {
|
||||
if ((XdrvMailbox.index > 0) && (XdrvMailbox.index <= TasmotaGlobal.shutters_present)) {
|
||||
if (XdrvMailbox.data_len > 0) {
|
||||
Settings.shutter_motordelay[XdrvMailbox.index -1] = (uint16_t)(STEPS_PER_SECOND * CharToFloat(XdrvMailbox.data));
|
||||
ShutterInit();
|
||||
|
@ -1339,7 +1339,7 @@ void CmndShutterButton(void)
|
|||
|
||||
void CmndShutterSetHalfway(void)
|
||||
{
|
||||
if ((XdrvMailbox.index > 0) && (XdrvMailbox.index <= shutters_present)) {
|
||||
if ((XdrvMailbox.index > 0) && (XdrvMailbox.index <= TasmotaGlobal.shutters_present)) {
|
||||
if ((XdrvMailbox.payload >= 0) && (XdrvMailbox.payload <= 100)) {
|
||||
Settings.shutter_set50percent[XdrvMailbox.index -1] = (Settings.shutter_options[XdrvMailbox.index -1] & 1) ? 100 - XdrvMailbox.payload : XdrvMailbox.payload;
|
||||
Settings.shuttercoeff[0][XdrvMailbox.index -1] = 0;
|
||||
|
@ -1353,7 +1353,7 @@ void CmndShutterFrequency(void)
|
|||
{
|
||||
if ((XdrvMailbox.payload > 0) && (XdrvMailbox.payload <= 20000)) {
|
||||
ShutterGlobal.open_velocity_max = XdrvMailbox.payload;
|
||||
if (shutters_present < 4) {
|
||||
if (TasmotaGlobal.shutters_present < 4) {
|
||||
Settings.shuttercoeff[4][3] = ShutterGlobal.open_velocity_max;
|
||||
}
|
||||
ShutterInit();
|
||||
|
@ -1363,7 +1363,7 @@ void CmndShutterFrequency(void)
|
|||
|
||||
void CmndShutterSetClose(void)
|
||||
{
|
||||
if ((XdrvMailbox.index > 0) && (XdrvMailbox.index <= shutters_present)) {
|
||||
if ((XdrvMailbox.index > 0) && (XdrvMailbox.index <= TasmotaGlobal.shutters_present)) {
|
||||
Shutter[XdrvMailbox.index -1].real_position = 0;
|
||||
ShutterStartInit(XdrvMailbox.index -1, 0, 0);
|
||||
Settings.shutter_position[XdrvMailbox.index -1] = 0;
|
||||
|
@ -1373,7 +1373,7 @@ void CmndShutterSetClose(void)
|
|||
|
||||
void CmndShutterSetOpen(void)
|
||||
{
|
||||
if ((XdrvMailbox.index > 0) && (XdrvMailbox.index <= shutters_present)) {
|
||||
if ((XdrvMailbox.index > 0) && (XdrvMailbox.index <= TasmotaGlobal.shutters_present)) {
|
||||
Shutter[XdrvMailbox.index -1].real_position = Shutter[XdrvMailbox.index -1].open_max;
|
||||
ShutterStartInit(XdrvMailbox.index -1, 0, Shutter[XdrvMailbox.index -1].open_max);
|
||||
Settings.shutter_position[XdrvMailbox.index -1] = 100;
|
||||
|
@ -1383,7 +1383,7 @@ void CmndShutterSetOpen(void)
|
|||
|
||||
void CmndShutterPwmRange(void)
|
||||
{
|
||||
if ((XdrvMailbox.index > 0) && (XdrvMailbox.index <= shutters_present)) {
|
||||
if ((XdrvMailbox.index > 0) && (XdrvMailbox.index <= TasmotaGlobal.shutters_present)) {
|
||||
if (XdrvMailbox.data_len > 0) {
|
||||
uint8_t i = 0;
|
||||
char *str_ptr;
|
||||
|
@ -1413,7 +1413,7 @@ void CmndShutterPwmRange(void)
|
|||
|
||||
void CmndShutterCalibration(void)
|
||||
{
|
||||
if ((XdrvMailbox.index > 0) && (XdrvMailbox.index <= shutters_present)) {
|
||||
if ((XdrvMailbox.index > 0) && (XdrvMailbox.index <= TasmotaGlobal.shutters_present)) {
|
||||
if (XdrvMailbox.data_len > 0) {
|
||||
uint8_t i = 0;
|
||||
char *str_ptr;
|
||||
|
@ -1446,7 +1446,7 @@ void CmndShutterCalibration(void)
|
|||
}
|
||||
|
||||
void ShutterOptionsSetHelper(uint16_t option){
|
||||
if ((XdrvMailbox.index > 0) && (XdrvMailbox.index <= shutters_present)) {
|
||||
if ((XdrvMailbox.index > 0) && (XdrvMailbox.index <= TasmotaGlobal.shutters_present)) {
|
||||
if (XdrvMailbox.payload == 0) {
|
||||
Settings.shutter_options[XdrvMailbox.index -1] &= ~(option);
|
||||
} else if (XdrvMailbox.payload == 1) {
|
||||
|
@ -1497,7 +1497,7 @@ bool Xdrv27(uint8_t function)
|
|||
result = DecodeCommand(kShutterCommands, ShutterCommand);
|
||||
break;
|
||||
case FUNC_JSON_APPEND:
|
||||
for (uint8_t i = 0; i < shutters_present; i++) {
|
||||
for (uint8_t i = 0; i < TasmotaGlobal.shutters_present; i++) {
|
||||
uint8_t position = (Settings.shutter_options[i] & 1) ? 100 - Settings.shutter_position[i] : Settings.shutter_position[i];
|
||||
uint8_t target = (Settings.shutter_options[i] & 1) ? 100 - ShutterRealToPercentPosition(Shutter[i].target_position, i) : ShutterRealToPercentPosition(Shutter[i].target_position, i);
|
||||
|
||||
|
@ -1514,14 +1514,14 @@ bool Xdrv27(uint8_t function)
|
|||
char stemp1[10];
|
||||
// extract the number of the relay that was switched and save for later in Update Position.
|
||||
ShutterGlobal.RelayCurrentMask = XdrvMailbox.index ^ ShutterGlobal.RelayOldMask;
|
||||
AddLog_P2(LOG_LEVEL_DEBUG_MORE, PSTR("SHT: Switched relay: %d by %s"), ShutterGlobal.RelayCurrentMask,GetTextIndexed(stemp1, sizeof(stemp1), last_source, kCommandSource));
|
||||
AddLog_P2(LOG_LEVEL_DEBUG_MORE, PSTR("SHT: Switched relay: %d by %s"), ShutterGlobal.RelayCurrentMask,GetTextIndexed(stemp1, sizeof(stemp1), TasmotaGlobal.last_source, kCommandSource));
|
||||
ShutterRelayChanged();
|
||||
ShutterGlobal.RelayOldMask = XdrvMailbox.index;
|
||||
break;
|
||||
case FUNC_SET_DEVICE_POWER:
|
||||
if (ShutterGlobal.skip_relay_change ) {
|
||||
uint8_t i;
|
||||
for (i = 0; i < devices_present; i++) {
|
||||
for (i = 0; i < TasmotaGlobal.devices_present; i++) {
|
||||
if (ShutterGlobal.RelayCurrentMask &1) {
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -45,7 +45,7 @@ struct PCF8574 {
|
|||
|
||||
void Pcf8574SwitchRelay(void)
|
||||
{
|
||||
for (uint32_t i = 0; i < devices_present; i++) {
|
||||
for (uint32_t i = 0; i < TasmotaGlobal.devices_present; i++) {
|
||||
uint8_t relay_state = bitRead(XdrvMailbox.index, i);
|
||||
|
||||
//AddLog_P2(LOG_LEVEL_DEBUG, PSTR("PCF: Pcf8574.max_devices %d requested pin %d"), Pcf8574.max_devices,Pcf8574.pin[i]);
|
||||
|
@ -111,7 +111,7 @@ void Pcf8574Init(void)
|
|||
for (uint32_t i = 0; i < sizeof(Pcf8574.pin); i++) {
|
||||
Pcf8574.pin[i] = 99;
|
||||
}
|
||||
devices_present = devices_present - Pcf8574.max_connected_ports; // reset no of devices to avoid duplicate ports on duplicate init.
|
||||
TasmotaGlobal.devices_present = TasmotaGlobal.devices_present - Pcf8574.max_connected_ports; // reset no of devices to avoid duplicate ports on duplicate init.
|
||||
Pcf8574.max_connected_ports = 0; // reset no of devices to avoid duplicate ports on duplicate init.
|
||||
for (uint32_t idx = 0; idx < Pcf8574.max_devices; idx++) { // suport up to 8 boards PCF8574
|
||||
|
||||
|
@ -119,11 +119,11 @@ void Pcf8574Init(void)
|
|||
|
||||
for (uint32_t i = 0; i < 8; i++) {
|
||||
uint8_t _result = Settings.pcf8574_config[idx] >> i &1;
|
||||
//AddLog_P2(LOG_LEVEL_DEBUG, PSTR("PCF: I2C shift i %d: %d. Powerstate: %d, devices_present: %d"), i,_result, Settings.power>>i&1, devices_present);
|
||||
//AddLog_P2(LOG_LEVEL_DEBUG, PSTR("PCF: I2C shift i %d: %d. Powerstate: %d, TasmotaGlobal.devices_present: %d"), i,_result, Settings.power>>i&1, TasmotaGlobal.devices_present);
|
||||
if (_result > 0) {
|
||||
Pcf8574.pin[devices_present] = i + 8 * idx;
|
||||
bitWrite(TasmotaGlobal.rel_inverted, devices_present, Settings.flag3.pcf8574_ports_inverted); // SetOption81 - Invert all ports on PCF8574 devices
|
||||
devices_present++;
|
||||
Pcf8574.pin[TasmotaGlobal.devices_present] = i + 8 * idx;
|
||||
bitWrite(TasmotaGlobal.rel_inverted, TasmotaGlobal.devices_present, Settings.flag3.pcf8574_ports_inverted); // SetOption81 - Invert all ports on PCF8574 devices
|
||||
TasmotaGlobal.devices_present++;
|
||||
Pcf8574.max_connected_ports++;
|
||||
}
|
||||
}
|
||||
|
@ -203,8 +203,8 @@ void Pcf8574SaveSettings(void)
|
|||
n = n&(n-1);
|
||||
count++;
|
||||
}
|
||||
if (count <= devices_present) {
|
||||
devices_present = devices_present - count;
|
||||
if (count <= TasmotaGlobal.devices_present) {
|
||||
TasmotaGlobal.devices_present = TasmotaGlobal.devices_present - count;
|
||||
}
|
||||
for (byte i = 0; i < 8; i++) {
|
||||
snprintf_P(stemp, sizeof(stemp), PSTR("i2cs%d"), i+8*idx);
|
||||
|
@ -212,7 +212,7 @@ void Pcf8574SaveSettings(void)
|
|||
byte _value = (!strlen(tmp)) ? 0 : atoi(tmp);
|
||||
if (_value) {
|
||||
Settings.pcf8574_config[idx] = Settings.pcf8574_config[idx] | 1 << i;
|
||||
devices_present++;
|
||||
TasmotaGlobal.devices_present++;
|
||||
Pcf8574.max_connected_ports++;
|
||||
} else {
|
||||
Settings.pcf8574_config[idx] = Settings.pcf8574_config[idx] & ~(1 << i );
|
||||
|
|
|
@ -124,12 +124,12 @@ void ExsSerialSend(const uint8_t data[] = nullptr, uint16_t len = 0)
|
|||
char rc;
|
||||
|
||||
#ifdef EXS_DEBUG
|
||||
snprintf_P(log_data, sizeof(log_data), PSTR("EXS: Tx Packet: \""));
|
||||
snprintf_P(TasmotaGlobal.log_data, sizeof(TasmotaGlobal.log_data), PSTR("EXS: Tx Packet: \""));
|
||||
for (uint32_t i = 0; i < len; i++)
|
||||
{
|
||||
snprintf_P(log_data, sizeof(log_data), PSTR("%s%02x"), log_data, data[i]);
|
||||
snprintf_P(TasmotaGlobal.log_data, sizeof(TasmotaGlobal.log_data), PSTR("%s%02x"), TasmotaGlobal.log_data, data[i]);
|
||||
}
|
||||
snprintf_P(log_data, sizeof(log_data), PSTR("%s\""), log_data);
|
||||
snprintf_P(TasmotaGlobal.log_data, sizeof(TasmotaGlobal.log_data), PSTR("%s\""), TasmotaGlobal.log_data);
|
||||
AddLog(LOG_LEVEL_DEBUG_MORE);
|
||||
#endif
|
||||
|
||||
|
@ -360,20 +360,20 @@ bool ExsModuleSelected(void)
|
|||
Settings.flag3.pwm_multi_channels = 1; // SetOption68 - Enable multi-channels PWM instead of Color PWM
|
||||
SetSeriallog(LOG_LEVEL_NONE);
|
||||
|
||||
devices_present = +2;
|
||||
light_type = LT_SERIAL2;
|
||||
TasmotaGlobal.devices_present = +2;
|
||||
TasmotaGlobal.light_type = LT_SERIAL2;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ExsSetChannels(void)
|
||||
{
|
||||
#ifdef EXS_DEBUG
|
||||
snprintf_P(log_data, sizeof(log_data), PSTR("EXS: SetChannels: \""));
|
||||
snprintf_P(TasmotaGlobal.log_data, sizeof(TasmotaGlobal.log_data), PSTR("EXS: SetChannels: \""));
|
||||
for (int i = 0; i < XdrvMailbox.data_len; i++)
|
||||
{
|
||||
snprintf_P(log_data, sizeof(log_data), PSTR("%s%02x"), log_data, ((uint8_t *)XdrvMailbox.data)[i]);
|
||||
snprintf_P(TasmotaGlobal.log_data, sizeof(TasmotaGlobal.log_data), PSTR("%s%02x"), TasmotaGlobal.log_data, ((uint8_t *)XdrvMailbox.data)[i]);
|
||||
}
|
||||
snprintf_P(log_data, sizeof(log_data), PSTR("%s\""), log_data);
|
||||
snprintf_P(TasmotaGlobal.log_data, sizeof(TasmotaGlobal.log_data), PSTR("%s\""), TasmotaGlobal.log_data);
|
||||
AddLog(LOG_LEVEL_DEBUG_MORE);
|
||||
#endif
|
||||
|
||||
|
@ -466,12 +466,12 @@ void ExsSerialInput(void)
|
|||
Exs.cmd_status = 0;
|
||||
|
||||
#ifdef EXS_DEBUG
|
||||
snprintf_P(log_data, sizeof(log_data), PSTR("EXS: RX Packet: \""));
|
||||
snprintf_P(TasmotaGlobal.log_data, sizeof(TasmotaGlobal.log_data), PSTR("EXS: RX Packet: \""));
|
||||
for (uint32_t i = 0; i < Exs.byte_counter; i++)
|
||||
{
|
||||
snprintf_P(log_data, sizeof(log_data), PSTR("%s%02x"), log_data, Exs.buffer[i]);
|
||||
snprintf_P(TasmotaGlobal.log_data, sizeof(TasmotaGlobal.log_data), PSTR("%s%02x"), TasmotaGlobal.log_data, Exs.buffer[i]);
|
||||
}
|
||||
snprintf_P(log_data, sizeof(log_data), PSTR("%s\", CRC: 0x%02x"), log_data, crc);
|
||||
snprintf_P(TasmotaGlobal.log_data, sizeof(TasmotaGlobal.log_data), PSTR("%s\", CRC: 0x%02x"), TasmotaGlobal.log_data, crc);
|
||||
AddLog(LOG_LEVEL_DEBUG_MORE);
|
||||
#endif
|
||||
|
||||
|
@ -604,7 +604,7 @@ bool Xdrv30(uint8_t function)
|
|||
{
|
||||
bool result = false;
|
||||
|
||||
if (EXS_DIMMER == my_module_type)
|
||||
if (EXS_DIMMER == TasmotaGlobal.module_type)
|
||||
{
|
||||
switch (function)
|
||||
{
|
||||
|
|
|
@ -543,7 +543,7 @@ void TasmotaClient_ProcessIn(void) {
|
|||
Response_P(PSTR("{\"TasmotaClient\":"));
|
||||
ResponseAppend_P("%s", inbuf);
|
||||
ResponseJsonEnd();
|
||||
MqttPublishPrefixTopicRulesProcess_P(RESULT_OR_TELE, mqtt_data);
|
||||
MqttPublishPrefixTopicRulesProcess_P(RESULT_OR_TELE, TasmotaGlobal.mqtt_data);
|
||||
}
|
||||
if (CMND_EXECUTE_CMND == TClientCommand.command) { // We need to execute the incoming command
|
||||
ExecuteCommand(inbuf, SRC_IGNORE);
|
||||
|
|
|
@ -126,8 +126,8 @@ void PWMModulePreInit(void)
|
|||
first_device_group_is_local = false;
|
||||
|
||||
// Back out the changes made in the light module under the assumtion we have a relay or PWM.
|
||||
devices_present--;
|
||||
light_type = 0;
|
||||
TasmotaGlobal.devices_present--;
|
||||
TasmotaGlobal.light_type = 0;
|
||||
}
|
||||
|
||||
for (uint8_t i = 0; i < MAX_PWM_DIMMER_KEYS; i++) {
|
||||
|
@ -148,7 +148,7 @@ void PWMDimmerSetBrightnessLeds(int32_t bri)
|
|||
uint32_t leds = 0;
|
||||
uint32_t mask = 1;
|
||||
int32_t led;
|
||||
for (led = 0; led < leds_present; led++) {
|
||||
for (led = 0; led < TasmotaGlobal.leds_present; led++) {
|
||||
if (Settings.ledmask & mask) leds++;
|
||||
mask <<= 1;
|
||||
}
|
||||
|
@ -185,7 +185,7 @@ void PWMDimmerSetPoweredOffLed(void)
|
|||
// Set the powered-off LED state.
|
||||
if (PinUsed(GPIO_LEDLNK)) {
|
||||
bool power_off_led_on = !TasmotaGlobal.power && Settings.flag4.powered_off_led;
|
||||
if (ledlnk_inverted) power_off_led_on ^= 1;
|
||||
if (TasmotaGlobal.ledlnk_inverted) power_off_led_on ^= 1;
|
||||
digitalWrite(Pin(GPIO_LEDLNK), power_off_led_on);
|
||||
}
|
||||
}
|
||||
|
@ -502,13 +502,13 @@ void PWMDimmerHandleButton(uint32_t button_index, bool pressed)
|
|||
}
|
||||
else {
|
||||
#endif // USE_PWM_DIMMER_REMOTE
|
||||
skip_light_fade = true;
|
||||
TasmotaGlobal.skip_light_fade = true;
|
||||
#ifdef USE_DEVICE_GROUPS
|
||||
ignore_dgr_sends = true;
|
||||
#endif // USE_DEVICE_GROUPS
|
||||
light_state.setBri(new_bri);
|
||||
LightAnimate();
|
||||
skip_light_fade = false;
|
||||
TasmotaGlobal.skip_light_fade = false;
|
||||
#ifdef USE_DEVICE_GROUPS
|
||||
ignore_dgr_sends = false;
|
||||
#endif // USE_DEVICE_GROUPS
|
||||
|
@ -599,7 +599,7 @@ void PWMDimmerHandleButton(uint32_t button_index, bool pressed)
|
|||
// If we need to publish an MQTT trigger, do it.
|
||||
if (mqtt_trigger) {
|
||||
char topic[TOPSZ];
|
||||
sprintf_P(mqtt_data, PSTR("Trigger%u"), mqtt_trigger);
|
||||
sprintf_P(TasmotaGlobal.mqtt_data, PSTR("Trigger%u"), mqtt_trigger);
|
||||
#ifdef USE_PWM_DIMMER_REMOTE
|
||||
if (active_remote_pwm_dimmer) {
|
||||
snprintf_P(topic, sizeof(topic), PSTR("cmnd/%s/EVENT"), device_groups[power_button_index].group_name);
|
||||
|
@ -704,7 +704,7 @@ bool Xdrv35(uint8_t function)
|
|||
{
|
||||
bool result = false;
|
||||
|
||||
if (PWM_DIMMER != my_module_type) return result;
|
||||
if (PWM_DIMMER != TasmotaGlobal.module_type) return result;
|
||||
|
||||
switch (function) {
|
||||
case FUNC_EVERY_SECOND:
|
||||
|
@ -717,7 +717,7 @@ bool Xdrv35(uint8_t function)
|
|||
// the LED will be set to a blinking state and will be turned off when the connection is
|
||||
// restored. If the state is blinking now, set a flag so we know that we need to restore it
|
||||
// when it stops blinking.
|
||||
if (global_state.data)
|
||||
if (TasmotaGlobal.global_state.data)
|
||||
restore_powered_off_led_counter = 5;
|
||||
else if (restore_powered_off_led_counter) {
|
||||
PWMDimmerSetPoweredOffLed();
|
||||
|
|
|
@ -46,7 +46,7 @@ void SonoffD1Received(void)
|
|||
{
|
||||
if (TasmotaGlobal.serial_in_byte_counter < 8) { return; } // Received ack from Rf chip (aa 55 01 04 00 00 05)
|
||||
|
||||
uint8_t action = serial_in_buffer[6] & 1;
|
||||
uint8_t action = TasmotaGlobal.serial_in_buffer[6] & 1;
|
||||
if (action != SnfD1.power) {
|
||||
SnfD1.power = action;
|
||||
|
||||
|
@ -55,7 +55,7 @@ void SonoffD1Received(void)
|
|||
ExecuteCommandPower(1, action, SRC_SWITCH);
|
||||
}
|
||||
|
||||
uint8_t dimmer = serial_in_buffer[7];
|
||||
uint8_t dimmer = TasmotaGlobal.serial_in_buffer[7];
|
||||
if (dimmer != SnfD1.dimmer) {
|
||||
SnfD1.dimmer = dimmer;
|
||||
|
||||
|
@ -69,25 +69,25 @@ void SonoffD1Received(void)
|
|||
/*
|
||||
// Send Acknowledge - Copy first 5 bytes, reset byte 6 and store crc in byte 7
|
||||
// AA 55 01 04 00 00 05
|
||||
serial_in_buffer[5] = 0; // Ack
|
||||
serial_in_buffer[6] = 0; // Crc
|
||||
TasmotaGlobal.serial_in_buffer[5] = 0; // Ack
|
||||
TasmotaGlobal.serial_in_buffer[6] = 0; // Crc
|
||||
for (uint32_t i = 0; i < 7; i++) {
|
||||
if ((i > 1) && (i < 6)) { serial_in_buffer[6] += serial_in_buffer[i]; }
|
||||
Serial.write(serial_in_buffer[i]);
|
||||
if ((i > 1) && (i < 6)) { TasmotaGlobal.serial_in_buffer[6] += TasmotaGlobal.serial_in_buffer[i]; }
|
||||
Serial.write(TasmotaGlobal.serial_in_buffer[i]);
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
bool SonoffD1SerialInput(void)
|
||||
{
|
||||
if (0xAA == serial_in_byte) { // 0xAA - Start of text
|
||||
if (0xAA == TasmotaGlobal.serial_in_byte) { // 0xAA - Start of text
|
||||
TasmotaGlobal.serial_in_byte_counter = 0;
|
||||
SnfD1.receive_len = 7;
|
||||
}
|
||||
if (SnfD1.receive_len) {
|
||||
serial_in_buffer[TasmotaGlobal.serial_in_byte_counter++] = serial_in_byte;
|
||||
TasmotaGlobal.serial_in_buffer[TasmotaGlobal.serial_in_byte_counter++] = TasmotaGlobal.serial_in_byte;
|
||||
if (6 == TasmotaGlobal.serial_in_byte_counter) {
|
||||
SnfD1.receive_len += serial_in_byte; // 8 or 17
|
||||
SnfD1.receive_len += TasmotaGlobal.serial_in_byte; // 8 or 17
|
||||
}
|
||||
if (TasmotaGlobal.serial_in_byte_counter == SnfD1.receive_len) {
|
||||
|
||||
|
@ -102,15 +102,15 @@ bool SonoffD1SerialInput(void)
|
|||
AddLogSerial(LOG_LEVEL_DEBUG);
|
||||
uint8_t crc = 0;
|
||||
for (uint32_t i = 2; i < SnfD1.receive_len -1; i++) {
|
||||
crc += serial_in_buffer[i];
|
||||
crc += TasmotaGlobal.serial_in_buffer[i];
|
||||
}
|
||||
if (crc == serial_in_buffer[SnfD1.receive_len -1]) {
|
||||
if (crc == TasmotaGlobal.serial_in_buffer[SnfD1.receive_len -1]) {
|
||||
SonoffD1Received();
|
||||
SnfD1.receive_len = 0;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
serial_in_byte = 0;
|
||||
TasmotaGlobal.serial_in_byte = 0;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
@ -163,8 +163,8 @@ bool SonoffD1ModuleSelected(void)
|
|||
{
|
||||
SetSerial(9600, TS_SERIAL_8N1);
|
||||
|
||||
devices_present++;
|
||||
light_type = LT_SERIAL1;
|
||||
TasmotaGlobal.devices_present++;
|
||||
TasmotaGlobal.light_type = LT_SERIAL1;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -177,7 +177,7 @@ bool Xdrv37(uint8_t function)
|
|||
{
|
||||
bool result = false;
|
||||
|
||||
if (SONOFF_D1 == my_module_type) {
|
||||
if (SONOFF_D1 == TasmotaGlobal.module_type) {
|
||||
switch (function) {
|
||||
case FUNC_SERIAL:
|
||||
result = SonoffD1SerialInput();
|
||||
|
|
|
@ -1328,7 +1328,7 @@ void ThermostatDebug(uint8_t ctr_output)
|
|||
#endif // DEBUG_THERMOSTAT
|
||||
|
||||
void ThermostatGetLocalSensor(uint8_t ctr_output) {
|
||||
String buf = mqtt_data; // copy the string into a new buffer that will be modified
|
||||
String buf = TasmotaGlobal.mqtt_data; // copy the string into a new buffer that will be modified
|
||||
JsonParser parser((char*)buf.c_str());
|
||||
JsonParserObject root = parser.getRootObject();
|
||||
if (root) {
|
||||
|
|
|
@ -304,7 +304,7 @@ String TelegramExecuteCommand(const char *svalue) {
|
|||
char* JSON = (char*)memchr(tmp, '{', len);
|
||||
if (JSON) { // Is it a JSON message (and not only [15:26:08 MQT: stat/wemos5/POWER = O])
|
||||
size_t JSONlen = len - (JSON - tmp);
|
||||
if (JSONlen > sizeof(mqtt_data)) { JSONlen = sizeof(mqtt_data); }
|
||||
if (JSONlen > sizeof(TasmotaGlobal.mqtt_data)) { JSONlen = sizeof(TasmotaGlobal.mqtt_data); }
|
||||
char stemp[JSONlen];
|
||||
strlcpy(stemp, JSON +1, JSONlen -2);
|
||||
if (cflg) { response += F(","); }
|
||||
|
@ -325,7 +325,7 @@ String TelegramExecuteCommand(const char *svalue) {
|
|||
}
|
||||
|
||||
void TelegramLoop(void) {
|
||||
if (!global_state.network_down && (Telegram.recv_enable || Telegram.echo_enable)) {
|
||||
if (!TasmotaGlobal.global_state.network_down && (Telegram.recv_enable || Telegram.echo_enable)) {
|
||||
switch (Telegram.state) {
|
||||
case 0:
|
||||
TelegramInit();
|
||||
|
@ -412,7 +412,7 @@ void CmndTmState(void) {
|
|||
}
|
||||
}
|
||||
}
|
||||
snprintf_P (mqtt_data, sizeof(mqtt_data), PSTR("{\"%s\":{\"Send\":\"%s\",\"Receive\":\"%s\",\"Echo\":\"%s\"}}"),
|
||||
snprintf_P (TasmotaGlobal.mqtt_data, sizeof(TasmotaGlobal.mqtt_data), PSTR("{\"%s\":{\"Send\":\"%s\",\"Receive\":\"%s\",\"Echo\":\"%s\"}}"),
|
||||
XdrvMailbox.command, GetStateText(Telegram.send_enable), GetStateText(Telegram.recv_enable), GetStateText(Telegram.echo_enable));
|
||||
}
|
||||
|
||||
|
|
|
@ -130,7 +130,7 @@ void TCPInit(void) {
|
|||
if (!tcp_buf) { AddLog_P2(LOG_LEVEL_ERROR, PSTR(D_LOG_TCP "could not allocate buffer")); return; }
|
||||
|
||||
if (!Settings.tcp_baudrate) { Settings.tcp_baudrate = 115200 / 1200; }
|
||||
TCPSerial = new TasmotaSerial(Pin(GPIO_TCP_RX), Pin(GPIO_TCP_TX), seriallog_level ? 1 : 2, 0, TCP_BRIDGE_BUF_SIZE); // set a receive buffer of 256 bytes
|
||||
TCPSerial = new TasmotaSerial(Pin(GPIO_TCP_RX), Pin(GPIO_TCP_TX), TasmotaGlobal.seriallog_level ? 1 : 2, 0, TCP_BRIDGE_BUF_SIZE); // set a receive buffer of 256 bytes
|
||||
TCPSerial->begin(Settings.tcp_baudrate * 1200);
|
||||
if (TCPSerial->hardwareSerial()) {
|
||||
ClaimSerial();
|
||||
|
|
|
@ -1044,7 +1044,7 @@ miel_hvac_pre_init(void)
|
|||
SetSerial(baudrate, TS_SERIAL_8E1);
|
||||
}
|
||||
|
||||
sc->sc_device = devices_present++; /* claim a POWER device slot */
|
||||
sc->sc_device = TasmotaGlobal.devices_present++; /* claim a POWER device slot */
|
||||
|
||||
miel_hvac_sc = sc;
|
||||
return;
|
||||
|
|
|
@ -807,7 +807,7 @@ void HandleWebcamRoot(void) {
|
|||
/*********************************************************************************************/
|
||||
|
||||
uint32_t WcSetStreamserver(uint32_t flag) {
|
||||
if (global_state.network_down) { return 0; }
|
||||
if (TasmotaGlobal.global_state.network_down) { return 0; }
|
||||
|
||||
Wc.stream_active = 0;
|
||||
|
||||
|
@ -857,7 +857,7 @@ void WcLoop(void) {
|
|||
|
||||
#ifdef ENABLE_RTSPSERVER
|
||||
|
||||
if (!rtsp_start && !global_state.wifi_down && Wc.up) {
|
||||
if (!rtsp_start && !TasmotaGlobal.global_state.wifi_down && Wc.up) {
|
||||
rtspServer.begin();
|
||||
rtsp_start = 1;
|
||||
AddLog_P2(LOG_LEVEL_INFO, PSTR("CAM: RTSP init"));
|
||||
|
|
|
@ -80,7 +80,7 @@
|
|||
|
||||
#include <ETH.h>
|
||||
|
||||
char eth_hostname[sizeof(my_hostname)];
|
||||
char eth_hostname[sizeof(TasmotaGlobal.hostname)];
|
||||
|
||||
void EthernetEvent(WiFiEvent_t event) {
|
||||
switch (event) {
|
||||
|
@ -98,15 +98,15 @@ void EthernetEvent(WiFiEvent_t event) {
|
|||
Settings.ip_address[1] = (uint32_t)ETH.gatewayIP();
|
||||
Settings.ip_address[2] = (uint32_t)ETH.subnetMask();
|
||||
Settings.ip_address[3] = (uint32_t)ETH.dnsIP();
|
||||
global_state.eth_down = 0;
|
||||
TasmotaGlobal.global_state.eth_down = 0;
|
||||
break;
|
||||
case SYSTEM_EVENT_ETH_DISCONNECTED:
|
||||
AddLog_P2(LOG_LEVEL_INFO, PSTR("ETH: Disconnected"));
|
||||
global_state.eth_down = 1;
|
||||
TasmotaGlobal.global_state.eth_down = 1;
|
||||
break;
|
||||
case SYSTEM_EVENT_ETH_STOP:
|
||||
AddLog_P2(LOG_LEVEL_DEBUG, PSTR("ETH: Stopped"));
|
||||
global_state.eth_down = 1;
|
||||
TasmotaGlobal.global_state.eth_down = 1;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
@ -120,8 +120,8 @@ void EthernetInit(void) {
|
|||
return;
|
||||
}
|
||||
|
||||
// snprintf_P(Eth.hostname, sizeof(Eth.hostname), PSTR("%s_eth"), my_hostname);
|
||||
strlcpy(eth_hostname, my_hostname, sizeof(eth_hostname) -5); // Make sure there is room for "_eth"
|
||||
// snprintf_P(Eth.hostname, sizeof(Eth.hostname), PSTR("%s_eth"), TasmotaGlobal.hostname);
|
||||
strlcpy(eth_hostname, TasmotaGlobal.hostname, sizeof(eth_hostname) -5); // Make sure there is room for "_eth"
|
||||
strcat(eth_hostname, "_eth");
|
||||
|
||||
WiFi.onEvent(EthernetEvent);
|
||||
|
|
|
@ -259,21 +259,21 @@ void DebugRtcDump(char* parms)
|
|||
|
||||
for (row = srow; row < maxrow; row++) {
|
||||
idx = row * CFG_COLS;
|
||||
snprintf_P(log_data, sizeof(log_data), PSTR("%03X:"), idx);
|
||||
snprintf_P(TasmotaGlobal.log_data, sizeof(TasmotaGlobal.log_data), PSTR("%03X:"), idx);
|
||||
for (col = 0; col < CFG_COLS; col++) {
|
||||
if (!(col%4)) {
|
||||
snprintf_P(log_data, sizeof(log_data), PSTR("%s "), log_data);
|
||||
snprintf_P(TasmotaGlobal.log_data, sizeof(TasmotaGlobal.log_data), PSTR("%s "), TasmotaGlobal.log_data);
|
||||
}
|
||||
snprintf_P(log_data, sizeof(log_data), PSTR("%s %02X"), log_data, buffer[idx + col]);
|
||||
snprintf_P(TasmotaGlobal.log_data, sizeof(TasmotaGlobal.log_data), PSTR("%s %02X"), TasmotaGlobal.log_data, buffer[idx + col]);
|
||||
}
|
||||
snprintf_P(log_data, sizeof(log_data), PSTR("%s |"), log_data);
|
||||
snprintf_P(TasmotaGlobal.log_data, sizeof(TasmotaGlobal.log_data), PSTR("%s |"), TasmotaGlobal.log_data);
|
||||
for (col = 0; col < CFG_COLS; col++) {
|
||||
// if (!(col%4)) {
|
||||
// snprintf_P(log_data, sizeof(log_data), PSTR("%s "), log_data);
|
||||
// snprintf_P(TasmotaGlobal.log_data, sizeof(TasmotaGlobal.log_data), PSTR("%s "), TasmotaGlobal.log_data);
|
||||
// }
|
||||
snprintf_P(log_data, sizeof(log_data), PSTR("%s%c"), log_data, ((buffer[idx + col] > 0x20) && (buffer[idx + col] < 0x7F)) ? (char)buffer[idx + col] : ' ');
|
||||
snprintf_P(TasmotaGlobal.log_data, sizeof(TasmotaGlobal.log_data), PSTR("%s%c"), TasmotaGlobal.log_data, ((buffer[idx + col] > 0x20) && (buffer[idx + col] < 0x7F)) ? (char)buffer[idx + col] : ' ');
|
||||
}
|
||||
snprintf_P(log_data, sizeof(log_data), PSTR("%s|"), log_data);
|
||||
snprintf_P(TasmotaGlobal.log_data, sizeof(TasmotaGlobal.log_data), PSTR("%s|"), TasmotaGlobal.log_data);
|
||||
AddLog(LOG_LEVEL_INFO);
|
||||
}
|
||||
#endif // ESP8266
|
||||
|
@ -311,21 +311,21 @@ void DebugCfgDump(char* parms)
|
|||
|
||||
for (row = srow; row < maxrow; row++) {
|
||||
idx = row * CFG_COLS;
|
||||
snprintf_P(log_data, sizeof(log_data), PSTR("%03X:"), idx);
|
||||
snprintf_P(TasmotaGlobal.log_data, sizeof(TasmotaGlobal.log_data), PSTR("%03X:"), idx);
|
||||
for (col = 0; col < CFG_COLS; col++) {
|
||||
if (!(col%4)) {
|
||||
snprintf_P(log_data, sizeof(log_data), PSTR("%s "), log_data);
|
||||
snprintf_P(TasmotaGlobal.log_data, sizeof(TasmotaGlobal.log_data), PSTR("%s "), TasmotaGlobal.log_data);
|
||||
}
|
||||
snprintf_P(log_data, sizeof(log_data), PSTR("%s %02X"), log_data, buffer[idx + col]);
|
||||
snprintf_P(TasmotaGlobal.log_data, sizeof(TasmotaGlobal.log_data), PSTR("%s %02X"), TasmotaGlobal.log_data, buffer[idx + col]);
|
||||
}
|
||||
snprintf_P(log_data, sizeof(log_data), PSTR("%s |"), log_data);
|
||||
snprintf_P(TasmotaGlobal.log_data, sizeof(TasmotaGlobal.log_data), PSTR("%s |"), TasmotaGlobal.log_data);
|
||||
for (col = 0; col < CFG_COLS; col++) {
|
||||
// if (!(col%4)) {
|
||||
// snprintf_P(log_data, sizeof(log_data), PSTR("%s "), log_data);
|
||||
// snprintf_P(TasmotaGlobal.log_data, sizeof(TasmotaGlobal.log_data), PSTR("%s "), TasmotaGlobal.log_data);
|
||||
// }
|
||||
snprintf_P(log_data, sizeof(log_data), PSTR("%s%c"), log_data, ((buffer[idx + col] > 0x20) && (buffer[idx + col] < 0x7F)) ? (char)buffer[idx + col] : ' ');
|
||||
snprintf_P(TasmotaGlobal.log_data, sizeof(TasmotaGlobal.log_data), PSTR("%s%c"), TasmotaGlobal.log_data, ((buffer[idx + col] > 0x20) && (buffer[idx + col] < 0x7F)) ? (char)buffer[idx + col] : ' ');
|
||||
}
|
||||
snprintf_P(log_data, sizeof(log_data), PSTR("%s|"), log_data);
|
||||
snprintf_P(TasmotaGlobal.log_data, sizeof(TasmotaGlobal.log_data), PSTR("%s|"), TasmotaGlobal.log_data);
|
||||
AddLog(LOG_LEVEL_INFO);
|
||||
delay(1);
|
||||
}
|
||||
|
@ -344,15 +344,15 @@ void DebugCfgPeek(char* parms)
|
|||
uint16_t data16 = (buffer[address +1] << 8) + buffer[address];
|
||||
uint32_t data32 = (buffer[address +3] << 24) + (buffer[address +2] << 16) + data16;
|
||||
|
||||
snprintf_P(log_data, sizeof(log_data), PSTR("%03X:"), address);
|
||||
snprintf_P(TasmotaGlobal.log_data, sizeof(TasmotaGlobal.log_data), PSTR("%03X:"), address);
|
||||
for (uint32_t i = 0; i < 4; i++) {
|
||||
snprintf_P(log_data, sizeof(log_data), PSTR("%s %02X"), log_data, buffer[address +i]);
|
||||
snprintf_P(TasmotaGlobal.log_data, sizeof(TasmotaGlobal.log_data), PSTR("%s %02X"), TasmotaGlobal.log_data, buffer[address +i]);
|
||||
}
|
||||
snprintf_P(log_data, sizeof(log_data), PSTR("%s |"), log_data);
|
||||
snprintf_P(TasmotaGlobal.log_data, sizeof(TasmotaGlobal.log_data), PSTR("%s |"), TasmotaGlobal.log_data);
|
||||
for (uint32_t i = 0; i < 4; i++) {
|
||||
snprintf_P(log_data, sizeof(log_data), PSTR("%s%c"), log_data, ((buffer[address +i] > 0x20) && (buffer[address +i] < 0x7F)) ? (char)buffer[address +i] : ' ');
|
||||
snprintf_P(TasmotaGlobal.log_data, sizeof(TasmotaGlobal.log_data), PSTR("%s%c"), TasmotaGlobal.log_data, ((buffer[address +i] > 0x20) && (buffer[address +i] < 0x7F)) ? (char)buffer[address +i] : ' ');
|
||||
}
|
||||
snprintf_P(log_data, sizeof(log_data), PSTR("%s| 0x%02X (%d), 0x%04X (%d), 0x%0LX (%lu)"), log_data, data8, data8, data16, data16, data32, data32);
|
||||
snprintf_P(TasmotaGlobal.log_data, sizeof(TasmotaGlobal.log_data), PSTR("%s| 0x%02X (%d), 0x%04X (%d), 0x%0LX (%lu)"), TasmotaGlobal.log_data, data8, data8, data16, data16, data32, data32);
|
||||
AddLog(LOG_LEVEL_INFO);
|
||||
}
|
||||
|
||||
|
@ -551,7 +551,7 @@ void CmndFlashDump(void)
|
|||
void CmndI2cWrite(void)
|
||||
{
|
||||
// I2cWrite <address>,<data>..
|
||||
if (i2c_flg) {
|
||||
if (TasmotaGlobal.i2c_enabled) {
|
||||
char* parms = XdrvMailbox.data;
|
||||
uint8_t buffer[100];
|
||||
uint32_t index = 0;
|
||||
|
@ -580,7 +580,7 @@ void CmndI2cWrite(void)
|
|||
void CmndI2cRead(void)
|
||||
{
|
||||
// I2cRead <address>,<size>
|
||||
if (i2c_flg) {
|
||||
if (TasmotaGlobal.i2c_enabled) {
|
||||
char* parms = XdrvMailbox.data;
|
||||
uint8_t buffer[100];
|
||||
uint32_t index = 0;
|
||||
|
@ -613,7 +613,7 @@ void CmndI2cRead(void)
|
|||
void CmndI2cStretch(void)
|
||||
{
|
||||
#ifdef ESP8266
|
||||
if (i2c_flg && (XdrvMailbox.payload > 0)) {
|
||||
if (TasmotaGlobal.i2c_enabled && (XdrvMailbox.payload > 0)) {
|
||||
Wire.setClockStretchLimit(XdrvMailbox.payload);
|
||||
}
|
||||
ResponseCmndDone();
|
||||
|
@ -622,7 +622,7 @@ void CmndI2cStretch(void)
|
|||
|
||||
void CmndI2cClock(void)
|
||||
{
|
||||
if (i2c_flg && (XdrvMailbox.payload > 0)) {
|
||||
if (TasmotaGlobal.i2c_enabled && (XdrvMailbox.payload > 0)) {
|
||||
Wire.setClock(XdrvMailbox.payload);
|
||||
}
|
||||
ResponseCmndDone();
|
||||
|
|
|
@ -256,7 +256,7 @@ bool Xdsp04(uint8_t function)
|
|||
{
|
||||
bool result = false;
|
||||
|
||||
if (spi_flg) {
|
||||
if (TasmotaGlobal.spi_enabled) {
|
||||
if (FUNC_DISPLAY_INIT_DRIVER == function) {
|
||||
Ili9341InitDriver();
|
||||
}
|
||||
|
|
|
@ -491,11 +491,11 @@ void Ws2812ModuleSelected(void)
|
|||
Light.max_scheme += WS2812_SCHEMES;
|
||||
|
||||
#if (USE_WS2812_CTYPE > NEO_3LED)
|
||||
light_type = LT_RGBW;
|
||||
TasmotaGlobal.light_type = LT_RGBW;
|
||||
#else
|
||||
light_type = LT_RGB;
|
||||
TasmotaGlobal.light_type = LT_RGB;
|
||||
#endif
|
||||
light_flg = XLGT_01;
|
||||
TasmotaGlobal.light_driver = XLGT_01;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -125,19 +125,19 @@ void My92x1ModuleSelected(void)
|
|||
digitalWrite(My92x1.pdcki_pin, LOW);
|
||||
|
||||
My92x1.model = 2;
|
||||
light_type = LT_RGBW; // RGBW (2 chips) as used in Lohas
|
||||
if (AILIGHT == my_module_type) { // RGBW (1 chip) as used in Ailight
|
||||
TasmotaGlobal.light_type = LT_RGBW; // RGBW (2 chips) as used in Lohas
|
||||
if (AILIGHT == TasmotaGlobal.module_type) { // RGBW (1 chip) as used in Ailight
|
||||
My92x1.model = 0;
|
||||
// light_type = LT_RGBW;
|
||||
// TasmotaGlobal.light_type = LT_RGBW;
|
||||
}
|
||||
else if (SONOFF_B1 == my_module_type) { // RGBWC (2 chips) as used in Sonoff B1
|
||||
else if (SONOFF_B1 == TasmotaGlobal.module_type) { // RGBWC (2 chips) as used in Sonoff B1
|
||||
My92x1.model = 1;
|
||||
light_type = LT_RGBWC;
|
||||
TasmotaGlobal.light_type = LT_RGBWC;
|
||||
}
|
||||
|
||||
LightMy92x1Init();
|
||||
|
||||
light_flg = XLGT_02;
|
||||
TasmotaGlobal.light_driver = XLGT_02;
|
||||
AddLog_P2(LOG_LEVEL_DEBUG, PSTR("DBG: MY29x1 Found"));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -124,7 +124,7 @@ bool Sm16716SetChannels(void)
|
|||
for (uint32_t i = 3; i < Light.subtype; i++) {
|
||||
if (PinUsed(GPIO_PWM1, i-3)) {
|
||||
//AddLog_P2(LOG_LEVEL_DEBUG, PSTR(D_LOG_APPLICATION "Cur_Col%d 10 bits %d, Pwm%d %d"), i, cur_col[i], i+1, curcol);
|
||||
analogWrite(Pin(GPIO_PWM1, i-3), bitRead(pwm_inverted, i-3) ? Settings.pwm_range - cur_col_10bits[i] : cur_col_10bits[i]);
|
||||
analogWrite(Pin(GPIO_PWM1, i-3), bitRead(TasmotaGlobal.pwm_inverted, i-3) ? Settings.pwm_range - cur_col_10bits[i] : cur_col_10bits[i]);
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
@ -174,8 +174,8 @@ void Sm16716ModuleSelected(void)
|
|||
}
|
||||
|
||||
LightPwmOffset(LST_RGB); // Handle any PWM pins, skipping the first 3 color values for sm16716
|
||||
light_type += LST_RGB; // Add RGB to be controlled by sm16716
|
||||
light_flg = XLGT_03;
|
||||
TasmotaGlobal.light_type += LST_RGB; // Add RGB to be controlled by sm16716
|
||||
TasmotaGlobal.light_driver = XLGT_03;
|
||||
AddLog_P2(LOG_LEVEL_DEBUG, PSTR("DBG: SM16716 Found"));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -176,8 +176,8 @@ void Sm2135ModuleSelected(void)
|
|||
|
||||
Sm2135Init();
|
||||
|
||||
light_type = LT_RGBWC;
|
||||
light_flg = XLGT_04;
|
||||
TasmotaGlobal.light_type = LT_RGBWC;
|
||||
TasmotaGlobal.light_driver = XLGT_04;
|
||||
AddLog_P2(LOG_LEVEL_DEBUG, PSTR("DBG: SM2135 (%s) Found"), (SM2135_WCBGR == Sm2135.model) ? PSTR("BGR") : PSTR("GRB"));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -66,29 +66,29 @@ void SnfL1SerialSendOk(void)
|
|||
|
||||
bool SnfL1SerialInput(void)
|
||||
{
|
||||
if (serial_in_byte != 0x1B) {
|
||||
if (TasmotaGlobal.serial_in_byte != 0x1B) {
|
||||
if (TasmotaGlobal.serial_in_byte_counter >= 140) {
|
||||
TasmotaGlobal.serial_in_byte_counter = 0;
|
||||
}
|
||||
if (TasmotaGlobal.serial_in_byte_counter || (!TasmotaGlobal.serial_in_byte_counter && ('A' == serial_in_byte))) { // A from AT
|
||||
serial_in_buffer[TasmotaGlobal.serial_in_byte_counter++] = serial_in_byte;
|
||||
if (TasmotaGlobal.serial_in_byte_counter || (!TasmotaGlobal.serial_in_byte_counter && ('A' == TasmotaGlobal.serial_in_byte))) { // A from AT
|
||||
TasmotaGlobal.serial_in_buffer[TasmotaGlobal.serial_in_byte_counter++] = TasmotaGlobal.serial_in_byte;
|
||||
}
|
||||
} else {
|
||||
serial_in_buffer[TasmotaGlobal.serial_in_byte_counter++] = 0x00;
|
||||
TasmotaGlobal.serial_in_buffer[TasmotaGlobal.serial_in_byte_counter++] = 0x00;
|
||||
|
||||
// AT+RESULT="sequence":"1554682835320"
|
||||
// AT+UPDATE="sequence":"34906","switch":"on","light_type":1,"colorR":0,"colorG":16,"colorB":0,"bright":6,"mode":1
|
||||
// AT+UPDATE="switch":"on","light_type":1,"colorR":255,"colorG":0,"colorB":0,"bright":6,"mode":1,"speed":100,"sensitive":10
|
||||
// AddLog_P2(LOG_LEVEL_DEBUG, PSTR("SL1: Rcvd %s"), serial_in_buffer);
|
||||
// AddLog_P2(LOG_LEVEL_DEBUG, PSTR("SL1: Rcvd %s"), TasmotaGlobal.serial_in_buffer);
|
||||
|
||||
if (!strncmp(serial_in_buffer +3, "RESULT", 6)) {
|
||||
if (!strncmp(TasmotaGlobal.serial_in_buffer +3, "RESULT", 6)) {
|
||||
Snfl1.receive_ready = true;
|
||||
}
|
||||
else if (!strncmp(serial_in_buffer +3, "UPDATE", 6)) {
|
||||
else if (!strncmp(TasmotaGlobal.serial_in_buffer +3, "UPDATE", 6)) {
|
||||
char cmnd_dimmer[20];
|
||||
char cmnd_color[20];
|
||||
char *end_str;
|
||||
char *string = serial_in_buffer +10;
|
||||
char *string = TasmotaGlobal.serial_in_buffer +10;
|
||||
char *token = strtok_r(string, ",", &end_str);
|
||||
|
||||
bool color_updated[3] = { false, false, false };
|
||||
|
@ -190,7 +190,7 @@ bool SnfL1SerialInput(void)
|
|||
|
||||
return true;
|
||||
}
|
||||
serial_in_byte = 0;
|
||||
TasmotaGlobal.serial_in_byte = 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -220,12 +220,12 @@ bool SnfL1SetChannels(void)
|
|||
|
||||
void SnfL1ModuleSelected(void)
|
||||
{
|
||||
if (SONOFF_L1 == my_module_type) {
|
||||
if (SONOFF_L1 == TasmotaGlobal.module_type) {
|
||||
if (PinUsed(GPIO_RXD) && PinUsed(GPIO_TXD)) {
|
||||
SetSerial(19200, TS_SERIAL_8N1);
|
||||
|
||||
light_type = LT_RGB;
|
||||
light_flg = XLGT_05;
|
||||
TasmotaGlobal.light_type = LT_RGB;
|
||||
TasmotaGlobal.light_driver = XLGT_05;
|
||||
AddLog_P2(LOG_LEVEL_DEBUG, PSTR("LGT: Sonoff L1 Found"));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -72,8 +72,8 @@ void ElectriqMoodLModuleSelected(void)
|
|||
{
|
||||
if (PinUsed(GPIO_ELECTRIQ_MOODL_TX)) {
|
||||
SetSerial(9600, TS_SERIAL_8N1);
|
||||
light_type = LT_RGBW;
|
||||
light_flg = XLGT_06;
|
||||
TasmotaGlobal.light_type = LT_RGBW;
|
||||
TasmotaGlobal.light_driver = XLGT_06;
|
||||
AddLog_P2(LOG_LEVEL_DEBUG, PSTR("LGT: ElectriQ Mood Lamp Found"));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -101,13 +101,13 @@ bool XlgtCall(uint8_t function)
|
|||
if (FUNC_MODULE_INIT == function) {
|
||||
for (uint32_t x = 0; x < xlgt_present; x++) {
|
||||
xlgt_func_ptr[x](function);
|
||||
if (light_flg) {
|
||||
if (TasmotaGlobal.light_driver) {
|
||||
xlgt_active = x;
|
||||
return true; // Stop further driver investigation
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (light_flg) {
|
||||
else if (TasmotaGlobal.light_driver) {
|
||||
return xlgt_func_ptr[xlgt_active](function);
|
||||
}
|
||||
return false;
|
||||
|
|
|
@ -270,7 +270,7 @@ void HlwDrvInit(void)
|
|||
Energy.voltage_available = false;
|
||||
}
|
||||
|
||||
energy_flg = XNRG_01;
|
||||
TasmotaGlobal.energy_driver = XNRG_01;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -231,7 +231,7 @@ void CseSnsInit(void) {
|
|||
}
|
||||
Cse.power_invalid = Settings.param[P_CSE7766_INVALID_POWER];
|
||||
} else {
|
||||
energy_flg = ENERGY_NONE;
|
||||
TasmotaGlobal.energy_driver = ENERGY_NONE;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -240,7 +240,7 @@ void CseDrvInit(void) {
|
|||
if (PinUsed(GPIO_CSE7766_RX)) {
|
||||
Cse.rx_buffer = (uint8_t*)(malloc(CSE_BUFFER_SIZE));
|
||||
if (Cse.rx_buffer != nullptr) {
|
||||
energy_flg = XNRG_02;
|
||||
TasmotaGlobal.energy_driver = XNRG_02;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -250,14 +250,14 @@ void PzemSnsInit(void)
|
|||
Pzem.phase = 0;
|
||||
Pzem.read_state = 1;
|
||||
} else {
|
||||
energy_flg = ENERGY_NONE;
|
||||
TasmotaGlobal.energy_driver = ENERGY_NONE;
|
||||
}
|
||||
}
|
||||
|
||||
void PzemDrvInit(void)
|
||||
{
|
||||
if (PinUsed(GPIO_PZEM004_RX) && PinUsed(GPIO_PZEM0XX_TX)) { // Any device with a Pzem004T
|
||||
energy_flg = XNRG_03;
|
||||
TasmotaGlobal.energy_driver = XNRG_03;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -566,13 +566,13 @@ void McpSnsInit(void)
|
|||
if (McpSerial->begin(MCP_BAUDRATE)) {
|
||||
if (McpSerial->hardwareSerial()) {
|
||||
ClaimSerial();
|
||||
mcp_buffer = serial_in_buffer; // Use idle serial buffer to save RAM
|
||||
mcp_buffer = TasmotaGlobal.serial_in_buffer; // Use idle serial buffer to save RAM
|
||||
} else {
|
||||
mcp_buffer = (char*)(malloc(MCP_BUFFER_SIZE));
|
||||
}
|
||||
DigitalWrite(GPIO_MCP39F5_RST, 0, 1); // MCP enable
|
||||
} else {
|
||||
energy_flg = ENERGY_NONE;
|
||||
TasmotaGlobal.energy_driver = ENERGY_NONE;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -586,7 +586,7 @@ void McpDrvInit(void)
|
|||
mcp_calibrate = 0;
|
||||
mcp_timeout = 2; // Initial wait
|
||||
mcp_init = 2; // Initial setup steps
|
||||
energy_flg = XNRG_04;
|
||||
TasmotaGlobal.energy_driver = XNRG_04;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -124,14 +124,14 @@ void PzemAcSnsInit(void)
|
|||
Energy.phase_count = 3; // Start off with three phases
|
||||
PzemAc.phase = 0;
|
||||
} else {
|
||||
energy_flg = ENERGY_NONE;
|
||||
TasmotaGlobal.energy_driver = ENERGY_NONE;
|
||||
}
|
||||
}
|
||||
|
||||
void PzemAcDrvInit(void)
|
||||
{
|
||||
if (PinUsed(GPIO_PZEM016_RX) && PinUsed(GPIO_PZEM0XX_TX)) {
|
||||
energy_flg = XNRG_05;
|
||||
TasmotaGlobal.energy_driver = XNRG_05;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -121,14 +121,14 @@ void PzemDcSnsInit(void)
|
|||
Energy.phase_count = 3; // Start off with three channels
|
||||
PzemDc.channel = 0;
|
||||
} else {
|
||||
energy_flg = ENERGY_NONE;
|
||||
TasmotaGlobal.energy_driver = ENERGY_NONE;
|
||||
}
|
||||
}
|
||||
|
||||
void PzemDcDrvInit(void)
|
||||
{
|
||||
if (PinUsed(GPIO_PZEM017_RX) && PinUsed(GPIO_PZEM0XX_TX)) {
|
||||
energy_flg = XNRG_06;
|
||||
TasmotaGlobal.energy_driver = XNRG_06;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -213,7 +213,7 @@ void Ade7953DrvInit(void)
|
|||
Energy.phase_count = 2; // Handle two channels as two phases
|
||||
Energy.voltage_common = true; // Use common voltage
|
||||
Energy.frequency_common = true; // Use common frequency
|
||||
energy_flg = XNRG_07;
|
||||
TasmotaGlobal.energy_driver = XNRG_07;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -181,14 +181,14 @@ void Sdm120SnsInit(void)
|
|||
if (result) {
|
||||
if (2 == result) { ClaimSerial(); }
|
||||
} else {
|
||||
energy_flg = ENERGY_NONE;
|
||||
TasmotaGlobal.energy_driver = ENERGY_NONE;
|
||||
}
|
||||
}
|
||||
|
||||
void Sdm120DrvInit(void)
|
||||
{
|
||||
if (PinUsed(GPIO_SDM120_RX) && PinUsed(GPIO_SDM120_TX)) {
|
||||
energy_flg = XNRG_08;
|
||||
TasmotaGlobal.energy_driver = XNRG_08;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -96,14 +96,14 @@ void Dds2382SnsInit(void)
|
|||
if (result) {
|
||||
if (2 == result) { ClaimSerial(); }
|
||||
} else {
|
||||
energy_flg = ENERGY_NONE;
|
||||
TasmotaGlobal.energy_driver = ENERGY_NONE;
|
||||
}
|
||||
}
|
||||
|
||||
void Dds2382DrvInit(void)
|
||||
{
|
||||
if (PinUsed(GPIO_DDS2382_RX) && PinUsed(GPIO_DDS2382_TX)) {
|
||||
energy_flg = XNRG_09;
|
||||
TasmotaGlobal.energy_driver = XNRG_09;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -221,14 +221,14 @@ void Sdm630SnsInit(void)
|
|||
Energy.phase_count = 3;
|
||||
Energy.frequency_common = true; // Use common frequency
|
||||
} else {
|
||||
energy_flg = ENERGY_NONE;
|
||||
TasmotaGlobal.energy_driver = ENERGY_NONE;
|
||||
}
|
||||
}
|
||||
|
||||
void Sdm630DrvInit(void)
|
||||
{
|
||||
if (PinUsed(GPIO_SDM630_RX) && PinUsed(GPIO_SDM630_TX)) {
|
||||
energy_flg = XNRG_10;
|
||||
TasmotaGlobal.energy_driver = XNRG_10;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -138,14 +138,14 @@ void Ddsu666SnsInit(void)
|
|||
if (result) {
|
||||
if (2 == result) { ClaimSerial(); }
|
||||
} else {
|
||||
energy_flg = ENERGY_NONE;
|
||||
TasmotaGlobal.energy_driver = ENERGY_NONE;
|
||||
}
|
||||
}
|
||||
|
||||
void Ddsu666DrvInit(void)
|
||||
{
|
||||
if (PinUsed(GPIO_DDSU666_RX) && PinUsed(GPIO_DDSU666_TX)) {
|
||||
energy_flg = XNRG_11;
|
||||
TasmotaGlobal.energy_driver = XNRG_11;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -414,14 +414,14 @@ void solaxX1SnsInit(void)
|
|||
if (solaxX1Serial->begin(SOLAXX1_SPEED)) {
|
||||
if (solaxX1Serial->hardwareSerial()) { ClaimSerial(); }
|
||||
} else {
|
||||
energy_flg = ENERGY_NONE;
|
||||
TasmotaGlobal.energy_driver = ENERGY_NONE;
|
||||
}
|
||||
}
|
||||
|
||||
void solaxX1DrvInit(void)
|
||||
{
|
||||
if (PinUsed(GPIO_SOLAXX1_RX) && PinUsed(GPIO_SOLAXX1_TX)) {
|
||||
energy_flg = XNRG_12;
|
||||
TasmotaGlobal.energy_driver = XNRG_12;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -218,14 +218,14 @@ void FifLESnsInit(void)
|
|||
if (result) {
|
||||
if (2 == result) { ClaimSerial(); }
|
||||
} else {
|
||||
energy_flg = ENERGY_NONE;
|
||||
TasmotaGlobal.energy_driver = ENERGY_NONE;
|
||||
}
|
||||
}
|
||||
|
||||
void FifLEDrvInit(void)
|
||||
{
|
||||
if (PinUsed(GPIO_LE01MR_RX) && PinUsed(GPIO_LE01MR_TX)) {
|
||||
energy_flg = XNRG_13;
|
||||
TasmotaGlobal.energy_driver = XNRG_13;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -229,7 +229,7 @@ void Bl0940SnsInit(void) {
|
|||
}
|
||||
|
||||
} else {
|
||||
energy_flg = ENERGY_NONE;
|
||||
TasmotaGlobal.energy_driver = ENERGY_NONE;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -237,7 +237,7 @@ void Bl0940DrvInit(void) {
|
|||
if (PinUsed(GPIO_BL0940_RX) && PinUsed(GPIO_TXD)) {
|
||||
Bl0940.rx_buffer = (uint8_t*)(malloc(BL0940_BUFFER_SIZE));
|
||||
if (Bl0940.rx_buffer != nullptr) {
|
||||
energy_flg = XNRG_14;
|
||||
TasmotaGlobal.energy_driver = XNRG_14;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -152,7 +152,7 @@ void ADPSCallback(uint8_t phase)
|
|||
}
|
||||
|
||||
Response_P(PSTR("{"));
|
||||
ResponseAppend_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"%s\":{\"ADPS\":%i}}"), serialNumber, phase );
|
||||
ResponseAppend_P(TasmotaGlobal.mqtt_data, sizeof(TasmotaGlobal.mqtt_data), PSTR("{\"%s\":{\"ADPS\":%i}}"), serialNumber, phase );
|
||||
ResponseJsonEnd();
|
||||
|
||||
// Publish adding ADCO serial number into the topic
|
||||
|
@ -422,7 +422,7 @@ Comments: -
|
|||
====================================================================== */
|
||||
void TInfoDrvInit(void) {
|
||||
if (PinUsed(GPIO_TELEINFO_RX)) {
|
||||
energy_flg = XNRG_15;
|
||||
TasmotaGlobal.energy_driver = XNRG_15;
|
||||
Energy.voltage_available = false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -171,14 +171,14 @@ void Iem3000SnsInit(void)
|
|||
Energy.phase_count = 3;
|
||||
Energy.frequency_common = true; // Use common frequency
|
||||
} else {
|
||||
energy_flg = ENERGY_NONE;
|
||||
TasmotaGlobal.energy_driver = ENERGY_NONE;
|
||||
}
|
||||
}
|
||||
|
||||
void Iem3000DrvInit(void)
|
||||
{
|
||||
if (PinUsed(GPIO_IEM3000_RX) && PinUsed(GPIO_IEM3000_TX)) {
|
||||
energy_flg = XNRG_16;
|
||||
TasmotaGlobal.energy_driver = XNRG_16;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -195,14 +195,14 @@ void We517SnsInit(void)
|
|||
Energy.phase_count = 3;
|
||||
Energy.frequency_common = true; // Use common frequency
|
||||
} else {
|
||||
energy_flg = ENERGY_NONE;
|
||||
TasmotaGlobal.energy_driver = ENERGY_NONE;
|
||||
}
|
||||
}
|
||||
|
||||
void We517DrvInit(void)
|
||||
{
|
||||
if (PinUsed(GPIO_WE517_RX) && PinUsed(GPIO_WE517_TX)) {
|
||||
energy_flg = XNRG_17;
|
||||
TasmotaGlobal.energy_driver = XNRG_17;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -165,13 +165,13 @@ bool XnrgCall(uint8_t function)
|
|||
if (FUNC_PRE_INIT == function) {
|
||||
for (uint32_t x = 0; x < xnrg_present; x++) {
|
||||
xnrg_func_ptr[x](function);
|
||||
if (energy_flg) {
|
||||
if (TasmotaGlobal.energy_driver) {
|
||||
xnrg_active = x;
|
||||
return true; // Stop further driver investigation
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (energy_flg) {
|
||||
else if (TasmotaGlobal.energy_driver) {
|
||||
return xnrg_func_ptr[xnrg_active](function);
|
||||
}
|
||||
return false;
|
||||
|
|
|
@ -152,7 +152,7 @@ bool Xsns04(uint8_t function)
|
|||
{
|
||||
bool result = false;
|
||||
|
||||
if (SONOFF_SC == my_module_type) {
|
||||
if (SONOFF_SC == TasmotaGlobal.module_type) {
|
||||
switch (function) {
|
||||
case FUNC_JSON_APPEND:
|
||||
SonoffScShow(1);
|
||||
|
|
|
@ -1787,7 +1787,7 @@ void APDS9960_loop(void) {
|
|||
enableGestureSensor();
|
||||
APDS9960_overload = false;
|
||||
Response_P(PSTR("{\"Gesture\":\"On\"}"));
|
||||
MqttPublishPrefixTopic_P(RESULT_OR_TELE, mqtt_data); // only after the long break we report, that we are online again
|
||||
MqttPublishPrefixTopic_P(RESULT_OR_TELE, TasmotaGlobal.mqtt_data); // only after the long break we report, that we are online again
|
||||
gesture_mode = 1;
|
||||
}
|
||||
|
||||
|
@ -1799,7 +1799,7 @@ void APDS9960_loop(void) {
|
|||
disableGestureSensor();
|
||||
recovery_loop_counter = APDS9960_LONG_RECOVERY; // long pause after overload/long press - number of stateloops
|
||||
Response_P(PSTR("{\"Gesture\":\"Off\"}"));
|
||||
MqttPublishPrefixTopic_P(RESULT_OR_TELE, mqtt_data);
|
||||
MqttPublishPrefixTopic_P(RESULT_OR_TELE, TasmotaGlobal.mqtt_data);
|
||||
gesture_mode = 0;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -196,7 +196,7 @@ void MCP230xx_ApplySettings(void)
|
|||
I2cWrite8(USE_MCP230xx_ADDR, MCP230xx_GPIO+mcp230xx_port, reg_portpins);
|
||||
#endif // USE_MCP230xx_OUTPUT
|
||||
}
|
||||
devices_present -= mcp230xx_oldoutpincount;
|
||||
TasmotaGlobal.devices_present -= mcp230xx_oldoutpincount;
|
||||
mcp230xx_oldoutpincount = 0;
|
||||
for (uint32_t idx=0;idx<mcp230xx_pincount;idx++) {
|
||||
if (Settings.mcp230xx_config[idx].pinmode >= 5) {
|
||||
|
@ -205,7 +205,7 @@ void MCP230xx_ApplySettings(void)
|
|||
}
|
||||
int_millis[idx]=millis();
|
||||
}
|
||||
devices_present += mcp230xx_oldoutpincount;
|
||||
TasmotaGlobal.devices_present += mcp230xx_oldoutpincount;
|
||||
mcp230xx_int_en = int_en;
|
||||
MCP230xx_CheckForIntCounter(); // update register on whether or not we should be counting interrupts
|
||||
MCP230xx_CheckForIntRetainer(); // update register on whether or not we should be retaining interrupt events for teleperiod
|
||||
|
@ -649,7 +649,7 @@ bool MCP230xx_Command(void)
|
|||
for (relay_no = 0; relay_no < mcp230xx_pincount ; relay_no ++) {
|
||||
if ( mcp230xx_outpinmapping[relay_no] == pin) break;
|
||||
}
|
||||
relay_no = devices_present - mcp230xx_oldoutpincount + relay_no +1;
|
||||
relay_no = TasmotaGlobal.devices_present - mcp230xx_oldoutpincount + relay_no +1;
|
||||
if ((!strcmp(subStr(sub_string, XdrvMailbox.data, ",", 2), "ON")) || (!strcmp(subStr(sub_string, XdrvMailbox.data, ",", 2), "1"))) {
|
||||
ExecuteCommandPower(relay_no, 1, SRC_IGNORE);
|
||||
return serviced;
|
||||
|
@ -797,8 +797,8 @@ void MCP230xx_Interrupt_Retain_Report(void) {
|
|||
|
||||
#ifdef USE_MCP230xx_OUTPUT
|
||||
void MCP230xx_SwitchRelay() {
|
||||
for (uint32_t i = devices_present - mcp230xx_oldoutpincount; i < devices_present; i++) {
|
||||
uint8_t pin = mcp230xx_outpinmapping[i - (devices_present - mcp230xx_oldoutpincount)];
|
||||
for (uint32_t i = TasmotaGlobal.devices_present - mcp230xx_oldoutpincount; i < TasmotaGlobal.devices_present; i++) {
|
||||
uint8_t pin = mcp230xx_outpinmapping[i - (TasmotaGlobal.devices_present - mcp230xx_oldoutpincount)];
|
||||
uint8_t pincmd = Settings.mcp230xx_config[pin].pinmode - 5;
|
||||
uint8_t relay_state = bitRead(XdrvMailbox.index, i);
|
||||
AddLog_P2(LOG_LEVEL_DEBUG, PSTR("MCP: relay %d pin_no %d state %d"), i,pin, relay_state);
|
||||
|
|
|
@ -362,7 +362,7 @@ void Mpr121Show(struct mpr121 *pS, uint8_t function)
|
|||
if ((FUNC_EVERY_50_MSECOND == function)
|
||||
&& (BITC(i, j) != BITP(i, j))) {
|
||||
Response_P(PSTR("{\"MPR121%c\":{\"Button%i\":%i}}"), pS->id[i], j, BITC(i, j));
|
||||
MqttPublishPrefixTopic_P(RESULT_OR_STAT, mqtt_data);
|
||||
MqttPublishPrefixTopic_P(RESULT_OR_STAT, TasmotaGlobal.mqtt_data);
|
||||
}
|
||||
// Add buttons to web string
|
||||
#ifdef USE_WEBSERVER
|
||||
|
|
|
@ -131,7 +131,7 @@ void DS3231EverySecond(void)
|
|||
{
|
||||
TIME_T tmpTime;
|
||||
if (!ds3231ReadStatus && Rtc.utc_time < START_VALID_TIME ) { // We still did not sync with NTP (time not valid) , so, read time from DS3231
|
||||
ntp_force_sync = true; //force to sync with ntp
|
||||
TasmotaGlobal.ntp_force_sync = true; //force to sync with ntp
|
||||
Rtc.utc_time = ReadFromDS3231(); //we read UTC TIME from DS3231
|
||||
// from this line, we just copy the function from "void RtcSecond()" at the support.ino ,line 2143 and above
|
||||
// We need it to set rules etc.
|
||||
|
|
|
@ -395,7 +395,7 @@ void HxEvery100mSecond(void)
|
|||
Hx.weight_changed = true;
|
||||
}
|
||||
else if (Hx.weight_changed && (Hx.weight == Hx.weight_diff)) {
|
||||
mqtt_data[0] = '\0';
|
||||
ResponseClear();
|
||||
ResponseAppendTime();
|
||||
HxShow(true);
|
||||
ResponseJsonEnd();
|
||||
|
|
|
@ -763,7 +763,7 @@ ADS1115 adc;
|
|||
void ADS1115_init(void) {
|
||||
|
||||
ads1115_up=0;
|
||||
if (!i2c_flg) return;
|
||||
if (!TasmotaGlobal.i2c_enabled) return;
|
||||
|
||||
adc.begin();
|
||||
adc.set_data_rate(ADS1115_DATA_RATE_128_SPS);
|
||||
|
@ -818,31 +818,31 @@ uint8_t dchars[16];
|
|||
if (dump2log&8) {
|
||||
// combo mode
|
||||
while (SML_SAVAILABLE) {
|
||||
log_data[index]=':';
|
||||
TasmotaGlobal.log_data[index]=':';
|
||||
index++;
|
||||
log_data[index]=' ';
|
||||
TasmotaGlobal.log_data[index]=' ';
|
||||
index++;
|
||||
d_lastms=millis();
|
||||
while ((millis()-d_lastms)<40) {
|
||||
if (SML_SAVAILABLE) {
|
||||
uint8_t c=SML_SREAD;
|
||||
sprintf(&log_data[index],"%02x ",c);
|
||||
sprintf(&TasmotaGlobal.log_data[index],"%02x ",c);
|
||||
dchars[hcnt]=c;
|
||||
index+=3;
|
||||
hcnt++;
|
||||
if (hcnt>15) {
|
||||
// line complete, build asci chars
|
||||
log_data[index]='=';
|
||||
TasmotaGlobal.log_data[index]='=';
|
||||
index++;
|
||||
log_data[index]='>';
|
||||
TasmotaGlobal.log_data[index]='>';
|
||||
index++;
|
||||
log_data[index]=' ';
|
||||
TasmotaGlobal.log_data[index]=' ';
|
||||
index++;
|
||||
for (uint8_t ccnt=0; ccnt<16; ccnt++) {
|
||||
if (isprint(dchars[ccnt])) {
|
||||
log_data[index]=dchars[ccnt];
|
||||
TasmotaGlobal.log_data[index]=dchars[ccnt];
|
||||
} else {
|
||||
log_data[index]=' ';
|
||||
TasmotaGlobal.log_data[index]=' ';
|
||||
}
|
||||
index++;
|
||||
}
|
||||
|
@ -851,7 +851,7 @@ uint8_t dchars[16];
|
|||
}
|
||||
}
|
||||
if (index>0) {
|
||||
log_data[index]=0;
|
||||
TasmotaGlobal.log_data[index]=0;
|
||||
AddLog(LOG_LEVEL_INFO);
|
||||
index=0;
|
||||
hcnt=0;
|
||||
|
@ -863,24 +863,24 @@ uint8_t dchars[16];
|
|||
while (SML_SAVAILABLE) {
|
||||
char c=SML_SREAD&0x7f;
|
||||
if (c=='\n' || c=='\r') {
|
||||
log_data[sml_logindex]=0;
|
||||
TasmotaGlobal.log_data[sml_logindex]=0;
|
||||
AddLog(LOG_LEVEL_INFO);
|
||||
sml_logindex=2;
|
||||
log_data[0]=':';
|
||||
log_data[1]=' ';
|
||||
TasmotaGlobal.log_data[0]=':';
|
||||
TasmotaGlobal.log_data[1]=' ';
|
||||
break;
|
||||
}
|
||||
log_data[sml_logindex]=c;
|
||||
if (sml_logindex<sizeof(log_data)-2) {
|
||||
TasmotaGlobal.log_data[sml_logindex]=c;
|
||||
if (sml_logindex<sizeof(TasmotaGlobal.log_data)-2) {
|
||||
sml_logindex++;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
//while (SML_SAVAILABLE) {
|
||||
index=0;
|
||||
log_data[index]=':';
|
||||
TasmotaGlobal.log_data[index]=':';
|
||||
index++;
|
||||
log_data[index]=' ';
|
||||
TasmotaGlobal.log_data[index]=' ';
|
||||
index++;
|
||||
d_lastms=millis();
|
||||
while ((millis()-d_lastms)<40) {
|
||||
|
@ -889,7 +889,7 @@ uint8_t dchars[16];
|
|||
if (meter_desc_p[(dump2log&7)-1].type=='e') {
|
||||
// ebus
|
||||
c=SML_SREAD;
|
||||
sprintf(&log_data[index],"%02x ",c);
|
||||
sprintf(&TasmotaGlobal.log_data[index],"%02x ",c);
|
||||
index+=3;
|
||||
if (c==EBUS_SYNC) break;
|
||||
} else {
|
||||
|
@ -904,13 +904,13 @@ uint8_t dchars[16];
|
|||
}
|
||||
}
|
||||
c=SML_SREAD;
|
||||
sprintf(&log_data[index],"%02x ",c);
|
||||
sprintf(&TasmotaGlobal.log_data[index],"%02x ",c);
|
||||
index+=3;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (index>2) {
|
||||
log_data[index]=0;
|
||||
TasmotaGlobal.log_data[index]=0;
|
||||
AddLog(LOG_LEVEL_INFO);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -206,7 +206,7 @@ void Ina226Init()
|
|||
//AddLog_P2( LOG_LEVEL_NONE, "Ina226Init");
|
||||
// AddLog_P2( LOG_LEVEL_NONE, "Size of Settings: %d bytes", sizeof(Settings));
|
||||
|
||||
// if (!i2c_flg)
|
||||
// if (!TasmotaGlobal.i2c_enabled)
|
||||
// AddLog_P2(LOG_LEVEL_DEBUG, "INA226: Initialization failed: No I2C support");
|
||||
|
||||
|
||||
|
|
|
@ -340,7 +340,7 @@ void UBXsendCFGLine(uint8_t _line)
|
|||
|
||||
void UBXTriggerTele(void)
|
||||
{
|
||||
mqtt_data[0] = '\0';
|
||||
ResponseClear();
|
||||
if (MqttShowSensor()) {
|
||||
MqttPublishPrefixTopic_P(TELE, PSTR(D_RSLT_SENSOR), Settings.flag.mqtt_sensor_retain);
|
||||
#ifdef USE_RULES
|
||||
|
|
|
@ -1159,7 +1159,7 @@ void MINRFconfirmSensors(void){
|
|||
*/
|
||||
void MINRFtriggerTele(void){
|
||||
MINRF.mode.triggeredTele= true;
|
||||
mqtt_data[0] = '\0';
|
||||
ResponseClear();
|
||||
if (MqttShowSensor()) {
|
||||
MqttPublishPrefixTopic_P(TELE, PSTR(D_RSLT_SENSOR), Settings.flag.mqtt_sensor_retain);
|
||||
#ifdef USE_RULES
|
||||
|
@ -1710,7 +1710,7 @@ void MINRFShow(bool json)
|
|||
|
||||
ResponseAppend_P(PSTR(",\"%s-%02x%02x%02x\":"),kMINRFDeviceType[MIBLEsensors[i].type-1],MIBLEsensors[i].MAC[3],MIBLEsensors[i].MAC[4],MIBLEsensors[i].MAC[5]);
|
||||
|
||||
uint32_t _positionCurlyBracket = strlen(mqtt_data); // ... this will be a ',' first, but later be replaced
|
||||
uint32_t _positionCurlyBracket = strlen(TasmotaGlobal.mqtt_data); // ... this will be a ',' first, but later be replaced
|
||||
|
||||
if((!MINRF.mode.triggeredTele && !MINRF.option.minimalSummary)||MINRF.mode.triggeredTele){
|
||||
bool tempHumSended = false;
|
||||
|
@ -1814,9 +1814,9 @@ void MINRFShow(bool json)
|
|||
}
|
||||
}
|
||||
}
|
||||
if(_positionCurlyBracket==strlen(mqtt_data)) ResponseAppend_P(PSTR(",")); // write some random char, to be overwritten in the next step
|
||||
if(_positionCurlyBracket==strlen(TasmotaGlobal.mqtt_data)) ResponseAppend_P(PSTR(",")); // write some random char, to be overwritten in the next step
|
||||
ResponseAppend_P(PSTR("}"));
|
||||
mqtt_data[_positionCurlyBracket] = '{';
|
||||
TasmotaGlobal.mqtt_data[_positionCurlyBracket] = '{';
|
||||
MIBLEsensors[i].eventType.raw = 0;
|
||||
if(MIBLEsensors[i].shallSendMQTT==1){
|
||||
MIBLEsensors[i].shallSendMQTT = 0;
|
||||
|
|
|
@ -609,7 +609,7 @@ int MI32_decryptPacket(char *_buf, uint16_t _bufSize, uint32_t _type){
|
|||
*/
|
||||
|
||||
void MI32nullifyEndOfMQTT_DATA(){
|
||||
char *p = mqtt_data + strlen(mqtt_data);
|
||||
char *p = TasmotaGlobal.mqtt_data + strlen(TasmotaGlobal.mqtt_data);
|
||||
while(true){
|
||||
*p--;
|
||||
if(p[0]==':'){
|
||||
|
@ -721,7 +721,7 @@ uint32_t MIBLEgetSensorSlot(uint8_t (&_MAC)[6], uint16_t _type, uint8_t counter)
|
|||
*/
|
||||
void MI32triggerTele(void){
|
||||
MI32.mode.triggeredTele = 1;
|
||||
mqtt_data[0] = '\0';
|
||||
ResponseClear();
|
||||
if (MqttShowSensor()) {
|
||||
MqttPublishPrefixTopic_P(TELE, PSTR(D_RSLT_SENSOR), Settings.flag.mqtt_sensor_retain);
|
||||
#ifdef USE_RULES
|
||||
|
@ -1921,7 +1921,7 @@ void MI32Show(bool json)
|
|||
kMI32DeviceType[MIBLEsensors[i].type-1],
|
||||
MIBLEsensors[i].MAC[3], MIBLEsensors[i].MAC[4], MIBLEsensors[i].MAC[5]);
|
||||
|
||||
uint32_t _positionCurlyBracket = strlen(mqtt_data); // ... this will be a ',' first, but later be replaced
|
||||
uint32_t _positionCurlyBracket = strlen(TasmotaGlobal.mqtt_data); // ... this will be a ',' first, but later be replaced
|
||||
|
||||
if((!MI32.mode.triggeredTele && !MI32.option.minimalSummary)||MI32.mode.triggeredTele){
|
||||
bool tempHumSended = false;
|
||||
|
@ -2053,9 +2053,9 @@ void MI32Show(bool json)
|
|||
}
|
||||
if (MI32.option.showRSSI) ResponseAppend_P(PSTR(",\"RSSI\":%d"), MIBLEsensors[i].RSSI);
|
||||
|
||||
if(_positionCurlyBracket==strlen(mqtt_data)) ResponseAppend_P(PSTR(",")); // write some random char, to be overwritten in the next step
|
||||
if(_positionCurlyBracket==strlen(TasmotaGlobal.mqtt_data)) ResponseAppend_P(PSTR(",")); // write some random char, to be overwritten in the next step
|
||||
ResponseAppend_P(PSTR("}"));
|
||||
mqtt_data[_positionCurlyBracket] = '{';
|
||||
TasmotaGlobal.mqtt_data[_positionCurlyBracket] = '{';
|
||||
MIBLEsensors[i].eventType.raw = 0;
|
||||
if(MIBLEsensors[i].shallSendMQTT==1){
|
||||
MIBLEsensors[i].shallSendMQTT = 0;
|
||||
|
|
|
@ -1375,7 +1375,7 @@ bool HM10Cmd(void) {
|
|||
*/
|
||||
void HM10triggerTele(void){
|
||||
HM10.mode.triggeredTele = 1;
|
||||
mqtt_data[0] = '\0';
|
||||
ResponseClear();
|
||||
if (MqttShowSensor()) {
|
||||
MqttPublishPrefixTopic_P(TELE, PSTR(D_RSLT_SENSOR), Settings.flag.mqtt_sensor_retain);
|
||||
#ifdef USE_RULES
|
||||
|
@ -1410,7 +1410,7 @@ void HM10Show(bool json)
|
|||
kHM10DeviceType[MIBLEsensors[i].type-1],
|
||||
MIBLEsensors[i].MAC[3], MIBLEsensors[i].MAC[4], MIBLEsensors[i].MAC[5]);
|
||||
|
||||
uint32_t _positionCurlyBracket = strlen(mqtt_data); // ... this will be a ',' first, but later be replaced
|
||||
uint32_t _positionCurlyBracket = strlen(TasmotaGlobal.mqtt_data); // ... this will be a ',' first, but later be replaced
|
||||
|
||||
if((!HM10.mode.triggeredTele && !HM10.option.minimalSummary)||HM10.mode.triggeredTele){
|
||||
bool tempHumSended = false;
|
||||
|
@ -1499,9 +1499,9 @@ void HM10Show(bool json)
|
|||
if (HM10.option.showRSSI && HM10.mode.triggeredTele) ResponseAppend_P(PSTR(",\"RSSI\":%d"), MIBLEsensors[i].rssi);
|
||||
|
||||
|
||||
if(_positionCurlyBracket==strlen(mqtt_data)) ResponseAppend_P(PSTR(",")); // write some random char, to be overwritten in the next step
|
||||
if(_positionCurlyBracket==strlen(TasmotaGlobal.mqtt_data)) ResponseAppend_P(PSTR(",")); // write some random char, to be overwritten in the next step
|
||||
ResponseAppend_P(PSTR("}"));
|
||||
mqtt_data[_positionCurlyBracket] = '{';
|
||||
TasmotaGlobal.mqtt_data[_positionCurlyBracket] = '{';
|
||||
MIBLEsensors[i].eventType.raw = 0;
|
||||
if(MIBLEsensors[i].shallSendMQTT==1){
|
||||
MIBLEsensors[i].shallSendMQTT = 0;
|
||||
|
|
|
@ -274,7 +274,7 @@ void WindMeterShow(bool json)
|
|||
|
||||
void WindMeterTriggerTele(void)
|
||||
{
|
||||
mqtt_data[0] = '\0';
|
||||
ResponseClear();
|
||||
if (MqttShowSensor()) {
|
||||
MqttPublishPrefixTopic_P(TELE, PSTR(D_RSLT_SENSOR), Settings.flag.mqtt_sensor_retain);
|
||||
#ifdef USE_RULES
|
||||
|
|
|
@ -498,7 +498,7 @@ void sns_opentherm_flags_cmd(void)
|
|||
sns_opentherm_init_boiler_status();
|
||||
}
|
||||
bool addComma = false;
|
||||
mqtt_data[0] = 0;
|
||||
TasmotaGlobal.mqtt_data[0] = 0;
|
||||
for (int pos = 0; pos < OT_FLAGS_COUNT; ++pos)
|
||||
{
|
||||
int mask = 1 << pos;
|
||||
|
@ -507,9 +507,9 @@ void sns_opentherm_flags_cmd(void)
|
|||
{
|
||||
if (addComma)
|
||||
{
|
||||
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s,"), mqtt_data);
|
||||
snprintf_P(TasmotaGlobal.mqtt_data, sizeof(TasmotaGlobal.mqtt_data), PSTR("%s,"), TasmotaGlobal.mqtt_data);
|
||||
}
|
||||
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s%s"), mqtt_data, sns_opentherm_flag_text(mode));
|
||||
snprintf_P(TasmotaGlobal.mqtt_data, sizeof(TasmotaGlobal.mqtt_data), PSTR("%s%s"), TasmotaGlobal.mqtt_data, sns_opentherm_flag_text(mode));
|
||||
addComma = true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -37,7 +37,7 @@ void HandleMetrics(void)
|
|||
|
||||
// Pseudo-metric providing metadata about the running firmware version.
|
||||
WSContentSend_P(PSTR("# TYPE tasmota_info gauge\ntasmota_info{version=\"%s\",image=\"%s\",build_timestamp=\"%s\"} 1\n"),
|
||||
my_version, my_image, GetBuildDateAndTime().c_str());
|
||||
TasmotaGlobal.version, TasmotaGlobal.image_name, GetBuildDateAndTime().c_str());
|
||||
WSContentSend_P(PSTR("# TYPE tasmota_uptime_seconds gauge\ntasmota_uptime_seconds %d\n"), TasmotaGlobal.uptime);
|
||||
WSContentSend_P(PSTR("# TYPE tasmota_boot_count counter\ntasmota_boot_count %d\n"), Settings.bootcount);
|
||||
WSContentSend_P(PSTR("# TYPE tasmota_flash_writes_total counter\ntasmota_flash_writes_total %d\n"), Settings.save_flag);
|
||||
|
@ -78,10 +78,10 @@ void HandleMetrics(void)
|
|||
/*
|
||||
// Alternative method using the complete sensor JSON data
|
||||
// For prometheus it may need to be decoded to # TYPE messages
|
||||
mqtt_data[0] = '\0';
|
||||
ResponseClear();
|
||||
MqttShowSensor();
|
||||
char json[strlen(mqtt_data) +1];
|
||||
snprintf_P(json, sizeof(json), mqtt_data);
|
||||
char json[strlen(TasmotaGlobal.mqtt_data) +1];
|
||||
snprintf_P(json, sizeof(json), TasmotaGlobal.mqtt_data);
|
||||
|
||||
// Do your Prometheus specific processing here.
|
||||
// Look at function DisplayAnalyzeJson() in file xdrv_13_display.ino as an example how to decode the JSON message
|
||||
|
|
|
@ -414,7 +414,7 @@ const uint8_t kI2cList[] = {
|
|||
|
||||
bool I2cEnabled(uint32_t i2c_index)
|
||||
{
|
||||
return (i2c_flg && bitRead(Settings.i2c_drivers[i2c_index / 32], i2c_index % 32));
|
||||
return (TasmotaGlobal.i2c_enabled && bitRead(Settings.i2c_drivers[i2c_index / 32], i2c_index % 32));
|
||||
}
|
||||
|
||||
void I2cDriverState(void)
|
||||
|
|
Loading…
Reference in New Issue