Skip to content

Commit b88ec7f

Browse files
committed
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)
1 parent d763fd5 commit b88ec7f

File tree

7 files changed

+83
-43
lines changed

7 files changed

+83
-43
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
## Sonoff-Tasmota
22
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.
33

4-
Current version is **5.1.7** - See [sonoff/_releasenotes.ino](https://github.com/arendst/Sonoff-Tasmota/blob/master/sonoff/_releasenotes.ino) for change information.
4+
Current version is **5.2.0** - See [sonoff/_releasenotes.ino](https://github.com/arendst/Sonoff-Tasmota/blob/master/sonoff/_releasenotes.ino) for change information.
55

66
### **** ATTENTION Version 5.x.x specific information ****
77

sonoff/_releasenotes.ino

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
/* 5.1.7 20170616
1+
/* 5.2.0 20170619
2+
* Add command SetOption12 1 to disable newly released configuration flash rotate to reduce flash wear
3+
* Fix command CounterDebounce by removing test for active GPIO (#524)
4+
* Add command SetOption33 1..250 to allow user configure POW Max_Power_Retry count (#525)
5+
*
6+
* 5.1.7 20170616
27
* Prep removal of SetOptions alternatives
38
* Restore webpage upgrade error messages removed in 5.1.5
49
* Add hold button functionality to buttons 2 to 4

sonoff/settings.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ typedef union { // Restricted by MISRA-C Rule 18.4 bu
3434
uint32_t mqtt_sensor_retain : 1;
3535
uint32_t mqtt_offline : 1; // bit 10
3636
uint32_t button_swap : 1; // bit 11 (v5.1.6)
37-
uint32_t spare12 : 1;
37+
uint32_t stop_flash_rotate : 1; // bit 12 (v5.2.0)
3838
uint32_t spare13 : 1;
3939
uint32_t spare14 : 1;
4040
uint32_t spare15 : 1;

sonoff/settings.ino

Lines changed: 56 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -124,13 +124,13 @@ extern "C" uint32_t _SPIFFS_end;
124124

125125
#define SPIFFS_END ((uint32_t)&_SPIFFS_end - 0x40200000) / SPI_FLASH_SEC_SIZE
126126

127-
// Version 3.x config
128-
#define CFG_LOCATION_3 SPIFFS_END - 4
129-
130127
// Version 4.2 config = eeprom area
131128
#define CFG_LOCATION SPIFFS_END // No need for SPIFFS as it uses EEPROM area
129+
// Version 5.2 allow for more flash space
130+
#define CFG_ROTATES 8 // Number of additional flash sectors used (handles uploads)
132131

133132
uint32_t _cfgHash = 0;
133+
uint32_t _cfgLocation = CFG_LOCATION;
134134

135135
/********************************************************************************************/
136136
/*
@@ -192,18 +192,38 @@ uint32_t getHash()
192192
* Config Save - Save parameters to Flash ONLY if any parameter has changed
193193
\*********************************************************************************************/
194194

195-
void CFG_Save()
195+
void CFG_Save(byte force)
196196
{
197197
char log[LOGSZ];
198198

199199
#ifndef BE_MINIMAL
200-
if (getHash() != _cfgHash) {
201-
noInterrupts();
200+
if ((getHash() != _cfgHash) || force) {
201+
if (sysCfg.flag.stop_flash_rotate) {
202+
_cfgLocation = CFG_LOCATION;
203+
} else {
204+
if (force) {
205+
_cfgLocation = CFG_LOCATION;
206+
} else {
207+
_cfgLocation--;
208+
if (_cfgLocation <= (CFG_LOCATION - CFG_ROTATES)) {
209+
_cfgLocation = CFG_LOCATION;
210+
}
211+
}
212+
}
202213
sysCfg.saveFlag++;
203-
spi_flash_erase_sector(CFG_LOCATION);
204-
spi_flash_write(CFG_LOCATION * SPI_FLASH_SEC_SIZE, (uint32*)&sysCfg, sizeof(SYSCFG));
214+
noInterrupts();
215+
spi_flash_erase_sector(_cfgLocation);
216+
spi_flash_write(_cfgLocation * SPI_FLASH_SEC_SIZE, (uint32*)&sysCfg, sizeof(SYSCFG));
205217
interrupts();
206-
snprintf_P(log, sizeof(log), PSTR("Config: Saved configuration (%d bytes) to flash at %X and count %d"), sizeof(SYSCFG), CFG_LOCATION, sysCfg.saveFlag);
218+
if (!sysCfg.flag.stop_flash_rotate && force) {
219+
for (byte i = 1; i < CFG_ROTATES; i++) {
220+
noInterrupts();
221+
spi_flash_erase_sector(_cfgLocation -i); // Delete previous configurations by resetting to 0xFF
222+
interrupts();
223+
delay(1);
224+
}
225+
}
226+
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);
207227
addLog(LOG_LEVEL_DEBUG, log);
208228
_cfgHash = getHash();
209229
}
@@ -220,28 +240,26 @@ void CFG_Load()
220240
unsigned long saveFlag;
221241
} _sysCfgH;
222242

223-
noInterrupts();
224-
spi_flash_read(CFG_LOCATION * SPI_FLASH_SEC_SIZE, (uint32*)&sysCfg, sizeof(SYSCFG));
225-
interrupts();
226-
snprintf_P(log, sizeof(log), PSTR("Config: Loaded configuration from flash at %X and count %d"), CFG_LOCATION, sysCfg.saveFlag);
227-
addLog(LOG_LEVEL_DEBUG, log);
243+
_cfgLocation = CFG_LOCATION +1;
244+
for (byte i = 0; i < CFG_ROTATES; i++) {
245+
_cfgLocation--;
246+
noInterrupts();
247+
spi_flash_read(_cfgLocation * SPI_FLASH_SEC_SIZE, (uint32*)&sysCfg, sizeof(SYSCFG));
248+
spi_flash_read((_cfgLocation -1) * SPI_FLASH_SEC_SIZE, (uint32*)&_sysCfgH, sizeof(SYSCFGH));
249+
interrupts();
228250

229-
if (sysCfg.cfg_holder != CFG_HOLDER) {
230-
if ((sysCfg.version < 0x04020000) || (sysCfg.version > 0x06000000)) {
231-
noInterrupts();
232-
spi_flash_read((CFG_LOCATION_3) * SPI_FLASH_SEC_SIZE, (uint32*)&sysCfg, sizeof(SYSCFG));
233-
spi_flash_read((CFG_LOCATION_3 + 1) * SPI_FLASH_SEC_SIZE, (uint32*)&_sysCfgH, sizeof(SYSCFGH));
234-
if (sysCfg.saveFlag < _sysCfgH.saveFlag)
235-
spi_flash_read((CFG_LOCATION_3 + 1) * SPI_FLASH_SEC_SIZE, (uint32*)&sysCfg, sizeof(SYSCFG));
236-
interrupts();
237-
if (sysCfg.cfg_holder != CFG_HOLDER) {
238-
CFG_Default();
239-
} else {
240-
sysCfg.saveFlag = 0;
241-
}
242-
} else {
243-
CFG_Default();
251+
// snprintf_P(log, sizeof(log), PSTR("Cnfg: Check at %X with count %d and holder %X"), _cfgLocation -1, _sysCfgH.saveFlag, _sysCfgH.cfg_holder);
252+
// addLog(LOG_LEVEL_DEBUG, log);
253+
254+
if (sysCfg.flag.stop_flash_rotate || (sysCfg.cfg_holder != _sysCfgH.cfg_holder) || (sysCfg.saveFlag > _sysCfgH.saveFlag)) {
255+
break;
244256
}
257+
delay(1);
258+
}
259+
snprintf_P(log, sizeof(log), PSTR("Cnfg: Load from flash at %X and count %d"), _cfgLocation, sysCfg.saveFlag);
260+
addLog(LOG_LEVEL_DEBUG, log);
261+
if (sysCfg.cfg_holder != CFG_HOLDER) {
262+
CFG_Default();
245263
}
246264
_cfgHash = getHash();
247265

@@ -257,7 +275,7 @@ void CFG_Erase()
257275
uint32_t _sectorEnd = ESP.getFlashChipRealSize() / SPI_FLASH_SEC_SIZE;
258276
boolean _serialoutput = (LOG_LEVEL_DEBUG_MORE <= seriallog_level);
259277

260-
snprintf_P(log, sizeof(log), PSTR("Config: Erasing %d flash sectors"), _sectorEnd - _sectorStart);
278+
snprintf_P(log, sizeof(log), PSTR("Cnfg: Erase %d flash sectors"), _sectorEnd - _sectorStart);
261279
addLog(LOG_LEVEL_DEBUG, log);
262280

263281
for (uint32_t _sector = _sectorStart; _sector < _sectorEnd; _sector++) {
@@ -325,10 +343,10 @@ void CFG_Dump(uint16_t srow, uint16_t mrow)
325343

326344
void CFG_Default()
327345
{
328-
addLog_P(LOG_LEVEL_NONE, PSTR("Config: Use default configuration"));
346+
addLog_P(LOG_LEVEL_NONE, PSTR("Cnfg: Use defaults"));
329347
CFG_DefaultSet1();
330348
CFG_DefaultSet2();
331-
CFG_Save();
349+
CFG_Save(1);
332350
}
333351

334352
void CFG_DefaultSet1()
@@ -460,6 +478,9 @@ void CFG_DefaultSet2()
460478
// 5.1.7
461479
sysCfg.param[P_HOLD_TIME] = KEY_HOLD_TIME; // Default 4 seconds hold time
462480

481+
// 5.2.0
482+
sysCfg.param[P_MAX_POWER_RETRY] = MAX_POWER_RETRY;
483+
463484
}
464485

465486
/********************************************************************************************/
@@ -657,6 +678,9 @@ void CFG_Delta()
657678
if (sysCfg.version < 0x05010700) {
658679
sysCfg.param[P_HOLD_TIME] = KEY_HOLD_TIME; // Default 4 seconds hold time
659680
}
681+
if (sysCfg.version < 0x05020000) {
682+
sysCfg.param[P_MAX_POWER_RETRY] = MAX_POWER_RETRY;
683+
}
660684

661685
sysCfg.version = VERSION;
662686
}

sonoff/sonoff.ino

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
- Select IDE Tools - Flash size: "1M (no SPIFFS)"
2525
====================================================*/
2626

27-
#define VERSION 0x05010700 // 5.1.7
27+
#define VERSION 0x05020000 // 5.2.0
2828

2929
enum log_t {LOG_LEVEL_NONE, LOG_LEVEL_ERROR, LOG_LEVEL_INFO, LOG_LEVEL_DEBUG, LOG_LEVEL_DEBUG_MORE, LOG_LEVEL_ALL};
3030
enum week_t {Last, First, Second, Third, Fourth};
@@ -149,7 +149,7 @@ enum emul_t {EMUL_NONE, EMUL_WEMO, EMUL_HUE, EMUL_MAX};
149149
#define MAX_STATUS 11 // Max number of status lines
150150

151151
enum butt_t {PRESSED, NOT_PRESSED};
152-
enum opt_t {P_HOLD_TIME, P_MAX_PARAM8}; // Index in sysCfg.param
152+
enum opt_t {P_HOLD_TIME, P_MAX_POWER_RETRY, P_MAX_PARAM8}; // Index in sysCfg.param
153153

154154
#include "support.h" // Global support
155155

@@ -1001,13 +1001,13 @@ void mqttDataCb(char* topic, byte* data, unsigned int data_len)
10011001
if (sysCfg.flag.savestate) {
10021002
sysCfg.power = power;
10031003
}
1004-
CFG_Save();
1004+
CFG_Save(0);
10051005
if (sysCfg.savedata > 1) {
10061006
snprintf_P(stemp1, sizeof(stemp1), PSTR("Every %d seconds"), sysCfg.savedata);
10071007
}
10081008
snprintf_P(svalue, sizeof(svalue), PSTR("{\"SaveData\":\"%s\"}"), (sysCfg.savedata > 1) ? stemp1 : getStateText(sysCfg.savedata));
10091009
}
1010-
else if (!strcmp_P(type,PSTR("SETOPTION")) && ((index >= 0) && (index <= 11)) || ((index > 31) && (index <= P_MAX_PARAM8 +31))) {
1010+
else if (!strcmp_P(type,PSTR("SETOPTION")) && ((index >= 0) && (index <= 12)) || ((index > 31) && (index <= P_MAX_PARAM8 +31))) {
10111011
if (index <= 31) {
10121012
ptype = 0; // SetOption0 .. 31
10131013
} else {
@@ -1027,8 +1027,12 @@ void mqttDataCb(char* topic, byte* data, unsigned int data_len)
10271027
case 8: // temperature_conversion
10281028
case 10: // mqtt_offline
10291029
case 11: // button_swap
1030+
case 12: // stop_flash_rotate
10301031
bitWrite(sysCfg.flag.data, index, payload);
10311032
}
1033+
if (12 == index) {
1034+
CFG_Save(1);
1035+
}
10321036
}
10331037
}
10341038
else { // SetOption32 ..
@@ -1038,6 +1042,11 @@ void mqttDataCb(char* topic, byte* data, unsigned int data_len)
10381042
sysCfg.param[P_HOLD_TIME] = payload;
10391043
}
10401044
break;
1045+
case P_MAX_POWER_RETRY:
1046+
if ((payload >= 1) && (payload <= 250)) {
1047+
sysCfg.param[P_MAX_POWER_RETRY] = payload;
1048+
}
1049+
break;
10411050
}
10421051
}
10431052
}
@@ -1238,7 +1247,7 @@ void mqttDataCb(char* topic, byte* data, unsigned int data_len)
12381247
snprintf_P(svalue, sizeof(svalue), PSTR("{\"CounterType%d\":%d}"), index, bitRead(sysCfg.pCounterType, index -1));
12391248
}
12401249
else if (!strcmp_P(type,PSTR("COUNTERDEBOUNCE"))) {
1241-
if ((data_len > 0) && (payload16 < 32001) && (pin[GPIO_CNTR1 + index -1] < 99)) {
1250+
if ((data_len > 0) && (payload16 < 32001)) {
12421251
sysCfg.pCounterDebounce = payload16;
12431252
}
12441253
snprintf_P(svalue, sizeof(svalue), PSTR("{\"CounterDebounce\":%d}"), sysCfg.pCounterDebounce);
@@ -2248,6 +2257,7 @@ void stateloop()
22482257
if (2 == otaflag) {
22492258
otaretry = OTA_ATTEMPTS;
22502259
ESPhttpUpdate.rebootOnUpdate(false);
2260+
CFG_Save(1); // Free flash for OTA update
22512261
}
22522262
if (otaflag <= 0) {
22532263
#ifdef USE_WEBSERVER
@@ -2298,7 +2308,7 @@ void stateloop()
22982308
sysCfg.power = power;
22992309
}
23002310
}
2301-
CFG_Save();
2311+
CFG_Save(0);
23022312
savedatacounter = sysCfg.savedata;
23032313
}
23042314
}
@@ -2319,7 +2329,7 @@ void stateloop()
23192329
hlw_savestate();
23202330
}
23212331
counter_savestate();
2322-
CFG_Save();
2332+
CFG_Save(0);
23232333
restartflag--;
23242334
if (restartflag <= 0) {
23252335
addLog_P(LOG_LEVEL_INFO, PSTR("APP: Restarting"));

sonoff/webserver.ino

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1177,6 +1177,7 @@ void handleUploadLoop()
11771177
_uploaderror = 1;
11781178
return;
11791179
}
1180+
CFG_Save(1); // Free flash for upload
11801181
snprintf_P(log, sizeof(log), PSTR("Upload: File %s ..."), upload.filename.c_str());
11811182
addLog(LOG_LEVEL_INFO, log);
11821183
if (!_uploadfiletype) {

sonoff/xsns_hlw8012.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,7 @@ void hlw_margin_chk()
380380
mqtt_publish_topic_P(1, PSTR("WARNING"), svalue);
381381
do_cmnd_power(1, 0);
382382
if (!hlw_mplr_counter) {
383-
hlw_mplr_counter = MAX_POWER_RETRY +1;
383+
hlw_mplr_counter = sysCfg.param[P_MAX_POWER_RETRY] +1;
384384
}
385385
hlw_mplw_counter = sysCfg.hlw_mplw;
386386
}

0 commit comments

Comments
 (0)