mirror of
https://github.com/arendst/Tasmota.git
synced 2025-07-27 04:36:31 +00:00
v5.2.0
5.2.0 20170619 * Add command SetOption12 1 to disable newly released configuration flash rotate to reduce flash wear * Fix command CounterDebounce by removing test for active GPIO (#524) * Add command SetOption33 1..250 to allow user configure POW Max_Power_Retry count (#525)
This commit is contained in:
parent
d763fd52eb
commit
b88ec7f5a9
@ -1,7 +1,7 @@
|
|||||||
## Sonoff-Tasmota
|
## Sonoff-Tasmota
|
||||||
Provide ESP8266 based Sonoff by [iTead Studio](https://www.itead.cc/) and ElectroDragon IoT Relay with Serial, Web and MQTT control allowing 'Over the Air' or OTA firmware updates using Arduino IDE.
|
Provide ESP8266 based Sonoff by [iTead Studio](https://www.itead.cc/) and ElectroDragon IoT Relay with Serial, Web and MQTT control allowing 'Over the Air' or OTA firmware updates using Arduino IDE.
|
||||||
|
|
||||||
Current version is **5.1.7** - See [sonoff/_releasenotes.ino](https://github.com/arendst/Sonoff-Tasmota/blob/master/sonoff/_releasenotes.ino) for change information.
|
Current version is **5.2.0** - See [sonoff/_releasenotes.ino](https://github.com/arendst/Sonoff-Tasmota/blob/master/sonoff/_releasenotes.ino) for change information.
|
||||||
|
|
||||||
### **** ATTENTION Version 5.x.x specific information ****
|
### **** ATTENTION Version 5.x.x specific information ****
|
||||||
|
|
||||||
|
@ -1,4 +1,9 @@
|
|||||||
/* 5.1.7 20170616
|
/* 5.2.0 20170619
|
||||||
|
* Add command SetOption12 1 to disable newly released configuration flash rotate to reduce flash wear
|
||||||
|
* Fix command CounterDebounce by removing test for active GPIO (#524)
|
||||||
|
* Add command SetOption33 1..250 to allow user configure POW Max_Power_Retry count (#525)
|
||||||
|
*
|
||||||
|
* 5.1.7 20170616
|
||||||
* Prep removal of SetOptions alternatives
|
* Prep removal of SetOptions alternatives
|
||||||
* Restore webpage upgrade error messages removed in 5.1.5
|
* Restore webpage upgrade error messages removed in 5.1.5
|
||||||
* Add hold button functionality to buttons 2 to 4
|
* Add hold button functionality to buttons 2 to 4
|
||||||
|
@ -34,7 +34,7 @@ typedef union { // Restricted by MISRA-C Rule 18.4 bu
|
|||||||
uint32_t mqtt_sensor_retain : 1;
|
uint32_t mqtt_sensor_retain : 1;
|
||||||
uint32_t mqtt_offline : 1; // bit 10
|
uint32_t mqtt_offline : 1; // bit 10
|
||||||
uint32_t button_swap : 1; // bit 11 (v5.1.6)
|
uint32_t button_swap : 1; // bit 11 (v5.1.6)
|
||||||
uint32_t spare12 : 1;
|
uint32_t stop_flash_rotate : 1; // bit 12 (v5.2.0)
|
||||||
uint32_t spare13 : 1;
|
uint32_t spare13 : 1;
|
||||||
uint32_t spare14 : 1;
|
uint32_t spare14 : 1;
|
||||||
uint32_t spare15 : 1;
|
uint32_t spare15 : 1;
|
||||||
|
@ -124,13 +124,13 @@ extern "C" uint32_t _SPIFFS_end;
|
|||||||
|
|
||||||
#define SPIFFS_END ((uint32_t)&_SPIFFS_end - 0x40200000) / SPI_FLASH_SEC_SIZE
|
#define SPIFFS_END ((uint32_t)&_SPIFFS_end - 0x40200000) / SPI_FLASH_SEC_SIZE
|
||||||
|
|
||||||
// Version 3.x config
|
|
||||||
#define CFG_LOCATION_3 SPIFFS_END - 4
|
|
||||||
|
|
||||||
// Version 4.2 config = eeprom area
|
// Version 4.2 config = eeprom area
|
||||||
#define CFG_LOCATION SPIFFS_END // No need for SPIFFS as it uses EEPROM area
|
#define CFG_LOCATION SPIFFS_END // No need for SPIFFS as it uses EEPROM area
|
||||||
|
// Version 5.2 allow for more flash space
|
||||||
|
#define CFG_ROTATES 8 // Number of additional flash sectors used (handles uploads)
|
||||||
|
|
||||||
uint32_t _cfgHash = 0;
|
uint32_t _cfgHash = 0;
|
||||||
|
uint32_t _cfgLocation = CFG_LOCATION;
|
||||||
|
|
||||||
/********************************************************************************************/
|
/********************************************************************************************/
|
||||||
/*
|
/*
|
||||||
@ -192,18 +192,38 @@ uint32_t getHash()
|
|||||||
* Config Save - Save parameters to Flash ONLY if any parameter has changed
|
* Config Save - Save parameters to Flash ONLY if any parameter has changed
|
||||||
\*********************************************************************************************/
|
\*********************************************************************************************/
|
||||||
|
|
||||||
void CFG_Save()
|
void CFG_Save(byte force)
|
||||||
{
|
{
|
||||||
char log[LOGSZ];
|
char log[LOGSZ];
|
||||||
|
|
||||||
#ifndef BE_MINIMAL
|
#ifndef BE_MINIMAL
|
||||||
if (getHash() != _cfgHash) {
|
if ((getHash() != _cfgHash) || force) {
|
||||||
noInterrupts();
|
if (sysCfg.flag.stop_flash_rotate) {
|
||||||
|
_cfgLocation = CFG_LOCATION;
|
||||||
|
} else {
|
||||||
|
if (force) {
|
||||||
|
_cfgLocation = CFG_LOCATION;
|
||||||
|
} else {
|
||||||
|
_cfgLocation--;
|
||||||
|
if (_cfgLocation <= (CFG_LOCATION - CFG_ROTATES)) {
|
||||||
|
_cfgLocation = CFG_LOCATION;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
sysCfg.saveFlag++;
|
sysCfg.saveFlag++;
|
||||||
spi_flash_erase_sector(CFG_LOCATION);
|
noInterrupts();
|
||||||
spi_flash_write(CFG_LOCATION * SPI_FLASH_SEC_SIZE, (uint32*)&sysCfg, sizeof(SYSCFG));
|
spi_flash_erase_sector(_cfgLocation);
|
||||||
|
spi_flash_write(_cfgLocation * SPI_FLASH_SEC_SIZE, (uint32*)&sysCfg, sizeof(SYSCFG));
|
||||||
interrupts();
|
interrupts();
|
||||||
snprintf_P(log, sizeof(log), PSTR("Config: Saved configuration (%d bytes) to flash at %X and count %d"), sizeof(SYSCFG), CFG_LOCATION, sysCfg.saveFlag);
|
if (!sysCfg.flag.stop_flash_rotate && force) {
|
||||||
|
for (byte i = 1; i < CFG_ROTATES; i++) {
|
||||||
|
noInterrupts();
|
||||||
|
spi_flash_erase_sector(_cfgLocation -i); // Delete previous configurations by resetting to 0xFF
|
||||||
|
interrupts();
|
||||||
|
delay(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
snprintf_P(log, sizeof(log), PSTR("Cnfg: %s (%d bytes) to flash at %X and count %d"), (force) ? "Backup" : "Save", sizeof(SYSCFG), _cfgLocation, sysCfg.saveFlag);
|
||||||
addLog(LOG_LEVEL_DEBUG, log);
|
addLog(LOG_LEVEL_DEBUG, log);
|
||||||
_cfgHash = getHash();
|
_cfgHash = getHash();
|
||||||
}
|
}
|
||||||
@ -220,28 +240,26 @@ void CFG_Load()
|
|||||||
unsigned long saveFlag;
|
unsigned long saveFlag;
|
||||||
} _sysCfgH;
|
} _sysCfgH;
|
||||||
|
|
||||||
|
_cfgLocation = CFG_LOCATION +1;
|
||||||
|
for (byte i = 0; i < CFG_ROTATES; i++) {
|
||||||
|
_cfgLocation--;
|
||||||
noInterrupts();
|
noInterrupts();
|
||||||
spi_flash_read(CFG_LOCATION * SPI_FLASH_SEC_SIZE, (uint32*)&sysCfg, sizeof(SYSCFG));
|
spi_flash_read(_cfgLocation * SPI_FLASH_SEC_SIZE, (uint32*)&sysCfg, sizeof(SYSCFG));
|
||||||
|
spi_flash_read((_cfgLocation -1) * SPI_FLASH_SEC_SIZE, (uint32*)&_sysCfgH, sizeof(SYSCFGH));
|
||||||
interrupts();
|
interrupts();
|
||||||
snprintf_P(log, sizeof(log), PSTR("Config: Loaded configuration from flash at %X and count %d"), CFG_LOCATION, sysCfg.saveFlag);
|
|
||||||
addLog(LOG_LEVEL_DEBUG, log);
|
|
||||||
|
|
||||||
if (sysCfg.cfg_holder != CFG_HOLDER) {
|
// snprintf_P(log, sizeof(log), PSTR("Cnfg: Check at %X with count %d and holder %X"), _cfgLocation -1, _sysCfgH.saveFlag, _sysCfgH.cfg_holder);
|
||||||
if ((sysCfg.version < 0x04020000) || (sysCfg.version > 0x06000000)) {
|
// addLog(LOG_LEVEL_DEBUG, log);
|
||||||
noInterrupts();
|
|
||||||
spi_flash_read((CFG_LOCATION_3) * SPI_FLASH_SEC_SIZE, (uint32*)&sysCfg, sizeof(SYSCFG));
|
if (sysCfg.flag.stop_flash_rotate || (sysCfg.cfg_holder != _sysCfgH.cfg_holder) || (sysCfg.saveFlag > _sysCfgH.saveFlag)) {
|
||||||
spi_flash_read((CFG_LOCATION_3 + 1) * SPI_FLASH_SEC_SIZE, (uint32*)&_sysCfgH, sizeof(SYSCFGH));
|
break;
|
||||||
if (sysCfg.saveFlag < _sysCfgH.saveFlag)
|
}
|
||||||
spi_flash_read((CFG_LOCATION_3 + 1) * SPI_FLASH_SEC_SIZE, (uint32*)&sysCfg, sizeof(SYSCFG));
|
delay(1);
|
||||||
interrupts();
|
}
|
||||||
|
snprintf_P(log, sizeof(log), PSTR("Cnfg: Load from flash at %X and count %d"), _cfgLocation, sysCfg.saveFlag);
|
||||||
|
addLog(LOG_LEVEL_DEBUG, log);
|
||||||
if (sysCfg.cfg_holder != CFG_HOLDER) {
|
if (sysCfg.cfg_holder != CFG_HOLDER) {
|
||||||
CFG_Default();
|
CFG_Default();
|
||||||
} else {
|
|
||||||
sysCfg.saveFlag = 0;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
CFG_Default();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
_cfgHash = getHash();
|
_cfgHash = getHash();
|
||||||
|
|
||||||
@ -257,7 +275,7 @@ void CFG_Erase()
|
|||||||
uint32_t _sectorEnd = ESP.getFlashChipRealSize() / SPI_FLASH_SEC_SIZE;
|
uint32_t _sectorEnd = ESP.getFlashChipRealSize() / SPI_FLASH_SEC_SIZE;
|
||||||
boolean _serialoutput = (LOG_LEVEL_DEBUG_MORE <= seriallog_level);
|
boolean _serialoutput = (LOG_LEVEL_DEBUG_MORE <= seriallog_level);
|
||||||
|
|
||||||
snprintf_P(log, sizeof(log), PSTR("Config: Erasing %d flash sectors"), _sectorEnd - _sectorStart);
|
snprintf_P(log, sizeof(log), PSTR("Cnfg: Erase %d flash sectors"), _sectorEnd - _sectorStart);
|
||||||
addLog(LOG_LEVEL_DEBUG, log);
|
addLog(LOG_LEVEL_DEBUG, log);
|
||||||
|
|
||||||
for (uint32_t _sector = _sectorStart; _sector < _sectorEnd; _sector++) {
|
for (uint32_t _sector = _sectorStart; _sector < _sectorEnd; _sector++) {
|
||||||
@ -325,10 +343,10 @@ void CFG_Dump(uint16_t srow, uint16_t mrow)
|
|||||||
|
|
||||||
void CFG_Default()
|
void CFG_Default()
|
||||||
{
|
{
|
||||||
addLog_P(LOG_LEVEL_NONE, PSTR("Config: Use default configuration"));
|
addLog_P(LOG_LEVEL_NONE, PSTR("Cnfg: Use defaults"));
|
||||||
CFG_DefaultSet1();
|
CFG_DefaultSet1();
|
||||||
CFG_DefaultSet2();
|
CFG_DefaultSet2();
|
||||||
CFG_Save();
|
CFG_Save(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CFG_DefaultSet1()
|
void CFG_DefaultSet1()
|
||||||
@ -460,6 +478,9 @@ void CFG_DefaultSet2()
|
|||||||
// 5.1.7
|
// 5.1.7
|
||||||
sysCfg.param[P_HOLD_TIME] = KEY_HOLD_TIME; // Default 4 seconds hold time
|
sysCfg.param[P_HOLD_TIME] = KEY_HOLD_TIME; // Default 4 seconds hold time
|
||||||
|
|
||||||
|
// 5.2.0
|
||||||
|
sysCfg.param[P_MAX_POWER_RETRY] = MAX_POWER_RETRY;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/********************************************************************************************/
|
/********************************************************************************************/
|
||||||
@ -657,6 +678,9 @@ void CFG_Delta()
|
|||||||
if (sysCfg.version < 0x05010700) {
|
if (sysCfg.version < 0x05010700) {
|
||||||
sysCfg.param[P_HOLD_TIME] = KEY_HOLD_TIME; // Default 4 seconds hold time
|
sysCfg.param[P_HOLD_TIME] = KEY_HOLD_TIME; // Default 4 seconds hold time
|
||||||
}
|
}
|
||||||
|
if (sysCfg.version < 0x05020000) {
|
||||||
|
sysCfg.param[P_MAX_POWER_RETRY] = MAX_POWER_RETRY;
|
||||||
|
}
|
||||||
|
|
||||||
sysCfg.version = VERSION;
|
sysCfg.version = VERSION;
|
||||||
}
|
}
|
||||||
|
@ -24,7 +24,7 @@
|
|||||||
- Select IDE Tools - Flash size: "1M (no SPIFFS)"
|
- Select IDE Tools - Flash size: "1M (no SPIFFS)"
|
||||||
====================================================*/
|
====================================================*/
|
||||||
|
|
||||||
#define VERSION 0x05010700 // 5.1.7
|
#define VERSION 0x05020000 // 5.2.0
|
||||||
|
|
||||||
enum log_t {LOG_LEVEL_NONE, LOG_LEVEL_ERROR, LOG_LEVEL_INFO, LOG_LEVEL_DEBUG, LOG_LEVEL_DEBUG_MORE, LOG_LEVEL_ALL};
|
enum log_t {LOG_LEVEL_NONE, LOG_LEVEL_ERROR, LOG_LEVEL_INFO, LOG_LEVEL_DEBUG, LOG_LEVEL_DEBUG_MORE, LOG_LEVEL_ALL};
|
||||||
enum week_t {Last, First, Second, Third, Fourth};
|
enum week_t {Last, First, Second, Third, Fourth};
|
||||||
@ -149,7 +149,7 @@ enum emul_t {EMUL_NONE, EMUL_WEMO, EMUL_HUE, EMUL_MAX};
|
|||||||
#define MAX_STATUS 11 // Max number of status lines
|
#define MAX_STATUS 11 // Max number of status lines
|
||||||
|
|
||||||
enum butt_t {PRESSED, NOT_PRESSED};
|
enum butt_t {PRESSED, NOT_PRESSED};
|
||||||
enum opt_t {P_HOLD_TIME, P_MAX_PARAM8}; // Index in sysCfg.param
|
enum opt_t {P_HOLD_TIME, P_MAX_POWER_RETRY, P_MAX_PARAM8}; // Index in sysCfg.param
|
||||||
|
|
||||||
#include "support.h" // Global support
|
#include "support.h" // Global support
|
||||||
|
|
||||||
@ -1001,13 +1001,13 @@ void mqttDataCb(char* topic, byte* data, unsigned int data_len)
|
|||||||
if (sysCfg.flag.savestate) {
|
if (sysCfg.flag.savestate) {
|
||||||
sysCfg.power = power;
|
sysCfg.power = power;
|
||||||
}
|
}
|
||||||
CFG_Save();
|
CFG_Save(0);
|
||||||
if (sysCfg.savedata > 1) {
|
if (sysCfg.savedata > 1) {
|
||||||
snprintf_P(stemp1, sizeof(stemp1), PSTR("Every %d seconds"), sysCfg.savedata);
|
snprintf_P(stemp1, sizeof(stemp1), PSTR("Every %d seconds"), sysCfg.savedata);
|
||||||
}
|
}
|
||||||
snprintf_P(svalue, sizeof(svalue), PSTR("{\"SaveData\":\"%s\"}"), (sysCfg.savedata > 1) ? stemp1 : getStateText(sysCfg.savedata));
|
snprintf_P(svalue, sizeof(svalue), PSTR("{\"SaveData\":\"%s\"}"), (sysCfg.savedata > 1) ? stemp1 : getStateText(sysCfg.savedata));
|
||||||
}
|
}
|
||||||
else if (!strcmp_P(type,PSTR("SETOPTION")) && ((index >= 0) && (index <= 11)) || ((index > 31) && (index <= P_MAX_PARAM8 +31))) {
|
else if (!strcmp_P(type,PSTR("SETOPTION")) && ((index >= 0) && (index <= 12)) || ((index > 31) && (index <= P_MAX_PARAM8 +31))) {
|
||||||
if (index <= 31) {
|
if (index <= 31) {
|
||||||
ptype = 0; // SetOption0 .. 31
|
ptype = 0; // SetOption0 .. 31
|
||||||
} else {
|
} else {
|
||||||
@ -1027,8 +1027,12 @@ void mqttDataCb(char* topic, byte* data, unsigned int data_len)
|
|||||||
case 8: // temperature_conversion
|
case 8: // temperature_conversion
|
||||||
case 10: // mqtt_offline
|
case 10: // mqtt_offline
|
||||||
case 11: // button_swap
|
case 11: // button_swap
|
||||||
|
case 12: // stop_flash_rotate
|
||||||
bitWrite(sysCfg.flag.data, index, payload);
|
bitWrite(sysCfg.flag.data, index, payload);
|
||||||
}
|
}
|
||||||
|
if (12 == index) {
|
||||||
|
CFG_Save(1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else { // SetOption32 ..
|
else { // SetOption32 ..
|
||||||
@ -1038,6 +1042,11 @@ void mqttDataCb(char* topic, byte* data, unsigned int data_len)
|
|||||||
sysCfg.param[P_HOLD_TIME] = payload;
|
sysCfg.param[P_HOLD_TIME] = payload;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case P_MAX_POWER_RETRY:
|
||||||
|
if ((payload >= 1) && (payload <= 250)) {
|
||||||
|
sysCfg.param[P_MAX_POWER_RETRY] = payload;
|
||||||
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1238,7 +1247,7 @@ void mqttDataCb(char* topic, byte* data, unsigned int data_len)
|
|||||||
snprintf_P(svalue, sizeof(svalue), PSTR("{\"CounterType%d\":%d}"), index, bitRead(sysCfg.pCounterType, index -1));
|
snprintf_P(svalue, sizeof(svalue), PSTR("{\"CounterType%d\":%d}"), index, bitRead(sysCfg.pCounterType, index -1));
|
||||||
}
|
}
|
||||||
else if (!strcmp_P(type,PSTR("COUNTERDEBOUNCE"))) {
|
else if (!strcmp_P(type,PSTR("COUNTERDEBOUNCE"))) {
|
||||||
if ((data_len > 0) && (payload16 < 32001) && (pin[GPIO_CNTR1 + index -1] < 99)) {
|
if ((data_len > 0) && (payload16 < 32001)) {
|
||||||
sysCfg.pCounterDebounce = payload16;
|
sysCfg.pCounterDebounce = payload16;
|
||||||
}
|
}
|
||||||
snprintf_P(svalue, sizeof(svalue), PSTR("{\"CounterDebounce\":%d}"), sysCfg.pCounterDebounce);
|
snprintf_P(svalue, sizeof(svalue), PSTR("{\"CounterDebounce\":%d}"), sysCfg.pCounterDebounce);
|
||||||
@ -2248,6 +2257,7 @@ void stateloop()
|
|||||||
if (2 == otaflag) {
|
if (2 == otaflag) {
|
||||||
otaretry = OTA_ATTEMPTS;
|
otaretry = OTA_ATTEMPTS;
|
||||||
ESPhttpUpdate.rebootOnUpdate(false);
|
ESPhttpUpdate.rebootOnUpdate(false);
|
||||||
|
CFG_Save(1); // Free flash for OTA update
|
||||||
}
|
}
|
||||||
if (otaflag <= 0) {
|
if (otaflag <= 0) {
|
||||||
#ifdef USE_WEBSERVER
|
#ifdef USE_WEBSERVER
|
||||||
@ -2298,7 +2308,7 @@ void stateloop()
|
|||||||
sysCfg.power = power;
|
sysCfg.power = power;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
CFG_Save();
|
CFG_Save(0);
|
||||||
savedatacounter = sysCfg.savedata;
|
savedatacounter = sysCfg.savedata;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -2319,7 +2329,7 @@ void stateloop()
|
|||||||
hlw_savestate();
|
hlw_savestate();
|
||||||
}
|
}
|
||||||
counter_savestate();
|
counter_savestate();
|
||||||
CFG_Save();
|
CFG_Save(0);
|
||||||
restartflag--;
|
restartflag--;
|
||||||
if (restartflag <= 0) {
|
if (restartflag <= 0) {
|
||||||
addLog_P(LOG_LEVEL_INFO, PSTR("APP: Restarting"));
|
addLog_P(LOG_LEVEL_INFO, PSTR("APP: Restarting"));
|
||||||
|
@ -1177,6 +1177,7 @@ void handleUploadLoop()
|
|||||||
_uploaderror = 1;
|
_uploaderror = 1;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
CFG_Save(1); // Free flash for upload
|
||||||
snprintf_P(log, sizeof(log), PSTR("Upload: File %s ..."), upload.filename.c_str());
|
snprintf_P(log, sizeof(log), PSTR("Upload: File %s ..."), upload.filename.c_str());
|
||||||
addLog(LOG_LEVEL_INFO, log);
|
addLog(LOG_LEVEL_INFO, log);
|
||||||
if (!_uploadfiletype) {
|
if (!_uploadfiletype) {
|
||||||
|
@ -380,7 +380,7 @@ void hlw_margin_chk()
|
|||||||
mqtt_publish_topic_P(1, PSTR("WARNING"), svalue);
|
mqtt_publish_topic_P(1, PSTR("WARNING"), svalue);
|
||||||
do_cmnd_power(1, 0);
|
do_cmnd_power(1, 0);
|
||||||
if (!hlw_mplr_counter) {
|
if (!hlw_mplr_counter) {
|
||||||
hlw_mplr_counter = MAX_POWER_RETRY +1;
|
hlw_mplr_counter = sysCfg.param[P_MAX_POWER_RETRY] +1;
|
||||||
}
|
}
|
||||||
hlw_mplw_counter = sysCfg.hlw_mplw;
|
hlw_mplw_counter = sysCfg.hlw_mplw;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user