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:
arendst 2017-06-19 22:54:49 +02:00
parent d763fd52eb
commit b88ec7f5a9
7 changed files with 83 additions and 43 deletions

View File

@ -1,7 +1,7 @@
## 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.
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 ****

View File

@ -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
* Restore webpage upgrade error messages removed in 5.1.5
* Add hold button functionality to buttons 2 to 4

View File

@ -34,7 +34,7 @@ typedef union { // Restricted by MISRA-C Rule 18.4 bu
uint32_t mqtt_sensor_retain : 1;
uint32_t mqtt_offline : 1; // bit 10
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 spare14 : 1;
uint32_t spare15 : 1;

View File

@ -124,13 +124,13 @@ extern "C" uint32_t _SPIFFS_end;
#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
#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 _cfgLocation = CFG_LOCATION;
/********************************************************************************************/
/*
@ -192,18 +192,38 @@ uint32_t getHash()
* Config Save - Save parameters to Flash ONLY if any parameter has changed
\*********************************************************************************************/
void CFG_Save()
void CFG_Save(byte force)
{
char log[LOGSZ];
#ifndef BE_MINIMAL
if (getHash() != _cfgHash) {
noInterrupts();
if ((getHash() != _cfgHash) || force) {
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++;
spi_flash_erase_sector(CFG_LOCATION);
spi_flash_write(CFG_LOCATION * SPI_FLASH_SEC_SIZE, (uint32*)&sysCfg, sizeof(SYSCFG));
noInterrupts();
spi_flash_erase_sector(_cfgLocation);
spi_flash_write(_cfgLocation * SPI_FLASH_SEC_SIZE, (uint32*)&sysCfg, sizeof(SYSCFG));
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);
_cfgHash = getHash();
}
@ -220,28 +240,26 @@ void CFG_Load()
unsigned long saveFlag;
} _sysCfgH;
noInterrupts();
spi_flash_read(CFG_LOCATION * SPI_FLASH_SEC_SIZE, (uint32*)&sysCfg, sizeof(SYSCFG));
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);
_cfgLocation = CFG_LOCATION +1;
for (byte i = 0; i < CFG_ROTATES; i++) {
_cfgLocation--;
noInterrupts();
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();
if (sysCfg.cfg_holder != CFG_HOLDER) {
if ((sysCfg.version < 0x04020000) || (sysCfg.version > 0x06000000)) {
noInterrupts();
spi_flash_read((CFG_LOCATION_3) * SPI_FLASH_SEC_SIZE, (uint32*)&sysCfg, sizeof(SYSCFG));
spi_flash_read((CFG_LOCATION_3 + 1) * SPI_FLASH_SEC_SIZE, (uint32*)&_sysCfgH, sizeof(SYSCFGH));
if (sysCfg.saveFlag < _sysCfgH.saveFlag)
spi_flash_read((CFG_LOCATION_3 + 1) * SPI_FLASH_SEC_SIZE, (uint32*)&sysCfg, sizeof(SYSCFG));
interrupts();
if (sysCfg.cfg_holder != CFG_HOLDER) {
CFG_Default();
} else {
sysCfg.saveFlag = 0;
}
} else {
CFG_Default();
// snprintf_P(log, sizeof(log), PSTR("Cnfg: Check at %X with count %d and holder %X"), _cfgLocation -1, _sysCfgH.saveFlag, _sysCfgH.cfg_holder);
// addLog(LOG_LEVEL_DEBUG, log);
if (sysCfg.flag.stop_flash_rotate || (sysCfg.cfg_holder != _sysCfgH.cfg_holder) || (sysCfg.saveFlag > _sysCfgH.saveFlag)) {
break;
}
delay(1);
}
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) {
CFG_Default();
}
_cfgHash = getHash();
@ -257,7 +275,7 @@ void CFG_Erase()
uint32_t _sectorEnd = ESP.getFlashChipRealSize() / SPI_FLASH_SEC_SIZE;
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);
for (uint32_t _sector = _sectorStart; _sector < _sectorEnd; _sector++) {
@ -325,10 +343,10 @@ void CFG_Dump(uint16_t srow, uint16_t mrow)
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_DefaultSet2();
CFG_Save();
CFG_Save(1);
}
void CFG_DefaultSet1()
@ -460,6 +478,9 @@ void CFG_DefaultSet2()
// 5.1.7
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) {
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;
}

View File

@ -24,7 +24,7 @@
- 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 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
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
@ -1001,13 +1001,13 @@ void mqttDataCb(char* topic, byte* data, unsigned int data_len)
if (sysCfg.flag.savestate) {
sysCfg.power = power;
}
CFG_Save();
CFG_Save(0);
if (sysCfg.savedata > 1) {
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));
}
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) {
ptype = 0; // SetOption0 .. 31
} else {
@ -1027,8 +1027,12 @@ void mqttDataCb(char* topic, byte* data, unsigned int data_len)
case 8: // temperature_conversion
case 10: // mqtt_offline
case 11: // button_swap
case 12: // stop_flash_rotate
bitWrite(sysCfg.flag.data, index, payload);
}
if (12 == index) {
CFG_Save(1);
}
}
}
else { // SetOption32 ..
@ -1038,6 +1042,11 @@ void mqttDataCb(char* topic, byte* data, unsigned int data_len)
sysCfg.param[P_HOLD_TIME] = payload;
}
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));
}
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;
}
snprintf_P(svalue, sizeof(svalue), PSTR("{\"CounterDebounce\":%d}"), sysCfg.pCounterDebounce);
@ -2248,6 +2257,7 @@ void stateloop()
if (2 == otaflag) {
otaretry = OTA_ATTEMPTS;
ESPhttpUpdate.rebootOnUpdate(false);
CFG_Save(1); // Free flash for OTA update
}
if (otaflag <= 0) {
#ifdef USE_WEBSERVER
@ -2298,7 +2308,7 @@ void stateloop()
sysCfg.power = power;
}
}
CFG_Save();
CFG_Save(0);
savedatacounter = sysCfg.savedata;
}
}
@ -2319,7 +2329,7 @@ void stateloop()
hlw_savestate();
}
counter_savestate();
CFG_Save();
CFG_Save(0);
restartflag--;
if (restartflag <= 0) {
addLog_P(LOG_LEVEL_INFO, PSTR("APP: Restarting"));

View File

@ -1177,6 +1177,7 @@ void handleUploadLoop()
_uploaderror = 1;
return;
}
CFG_Save(1); // Free flash for upload
snprintf_P(log, sizeof(log), PSTR("Upload: File %s ..."), upload.filename.c_str());
addLog(LOG_LEVEL_INFO, log);
if (!_uploadfiletype) {

View File

@ -380,7 +380,7 @@ void hlw_margin_chk()
mqtt_publish_topic_P(1, PSTR("WARNING"), svalue);
do_cmnd_power(1, 0);
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;
}