Skip to content

Commit 2195ddd

Browse files
committed
v5.2.2
5.2.2 20170625 * Add configuration SaveAddress to Status 1 and Information Page * Change Sonoff Led Color conversion from AtoH to strtol * Fix possible wrong uploads due to configuration overwrites (#542) * Fix payload negative numbers (#547)
1 parent 92958f4 commit 2195ddd

File tree

6 files changed

+45
-54
lines changed

6 files changed

+45
-54
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.2.1** - See [sonoff/_releasenotes.ino](https://github.com/arendst/Sonoff-Tasmota/blob/master/sonoff/_releasenotes.ino) for change information.
4+
Current version is **5.2.2** - 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: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
/* 5.2.1 20170622
1+
/* 5.2.2 20170625
2+
* Add configuration SaveAddress to Status 1 and Information Page
3+
* Change Sonoff Led Color conversion from AtoH to strtol
4+
* Fix possible wrong uploads due to configuration overwrites (#542)
5+
* Fix payload negative numbers (#547)
6+
*
7+
* 5.2.1 20170622
28
* Fix Restore Configuration in case of lower version
39
* Revert auto configuration upgrade allowing easy upgrade which was removed in version 5.2.0
410
* Fix config auto upgrade from versions below version 4.1.1 (#530)

sonoff/settings.ino

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -195,38 +195,42 @@ uint32_t getHash()
195195
* Config Save - Save parameters to Flash ONLY if any parameter has changed
196196
\*********************************************************************************************/
197197

198-
void CFG_Save(byte force)
198+
uint32_t CFG_Address()
199+
{
200+
return _cfgLocation * SPI_FLASH_SEC_SIZE;
201+
}
202+
203+
void CFG_Save(byte no_rotate)
199204
{
200205
char log[LOGSZ];
201206

202207
#ifndef BE_MINIMAL
203-
if ((getHash() != _cfgHash) || force) {
204-
if (sysCfg.flag.stop_flash_rotate) {
208+
if ((getHash() != _cfgHash) || no_rotate) {
209+
if (no_rotate) {
210+
stop_flash_rotate = 1; // Disable flash rotate from now on
211+
}
212+
if (stop_flash_rotate) {
205213
_cfgLocation = CFG_LOCATION;
206214
} else {
207-
if (force) {
215+
_cfgLocation--;
216+
if (_cfgLocation <= (CFG_LOCATION - CFG_ROTATES)) {
208217
_cfgLocation = CFG_LOCATION;
209-
} else {
210-
_cfgLocation--;
211-
if (_cfgLocation <= (CFG_LOCATION - CFG_ROTATES)) {
212-
_cfgLocation = CFG_LOCATION;
213-
}
214218
}
215219
}
216220
sysCfg.saveFlag++;
217221
noInterrupts();
218222
spi_flash_erase_sector(_cfgLocation);
219223
spi_flash_write(_cfgLocation * SPI_FLASH_SEC_SIZE, (uint32*)&sysCfg, sizeof(SYSCFG));
220224
interrupts();
221-
if (!sysCfg.flag.stop_flash_rotate && force) {
225+
if (!stop_flash_rotate && no_rotate) {
222226
for (byte i = 1; i < CFG_ROTATES; i++) {
223227
noInterrupts();
224228
spi_flash_erase_sector(_cfgLocation -i); // Delete previous configurations by resetting to 0xFF
225229
interrupts();
226230
delay(1);
227231
}
228232
}
229-
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);
233+
snprintf_P(log, sizeof(log), PSTR("Cnfg: Save (%d bytes) to flash at %X and count %d"), sizeof(SYSCFG), _cfgLocation, sysCfg.saveFlag);
230234
addLog(LOG_LEVEL_DEBUG, log);
231235
_cfgHash = getHash();
232236
}

sonoff/sonoff.ino

Lines changed: 16 additions & 11 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 0x05020100 // 5.2.1
27+
#define VERSION 0x05020200 // 5.2.2
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};
@@ -270,6 +270,7 @@ uint16_t syslog_timer = 0; // Timer to re-enable syslog_level
270270
byte seriallog_level; // Current copy of sysCfg.seriallog_level
271271
uint16_t seriallog_timer = 0; // Timer to disable Seriallog
272272
uint8_t sleep; // Current copy of sysCfg.sleep
273+
uint8_t stop_flash_rotate = 0; // Allow flash configuration rotation
273274

274275
int blinks = 201; // Number of LED blinks
275276
uint8_t blinkstate = 0; // LED state
@@ -915,11 +916,13 @@ void mqttDataCb(char* topic, byte* data, unsigned int data_len)
915916
if (!strcmp(dataBufUc,"?")) {
916917
data_len = 0;
917918
}
918-
int16_t payload = -1; // No payload
919-
if (data_len && isdigit(dataBuf[0])) {
920-
payload = atoi(dataBuf); // -32766 - 32767
919+
int16_t payload = -99; // No payload
920+
uint16_t payload16 = 0;
921+
long lnum = strtol(dataBuf, &p, 10);
922+
if (p != dataBuf) {
923+
payload = (int16_t) lnum; // -32766 - 32767
924+
payload16 = (uint16_t) lnum; // 0 - 65535
921925
}
922-
uint16_t payload16 = atoi(dataBuf); // 0 - 65535
923926

924927
if (!strcmp_P(dataBufUc,PSTR("OFF")) || !strcmp_P(dataBufUc,PSTR("FALSE")) || !strcmp_P(dataBufUc,PSTR("STOP")) || !strcmp_P(dataBufUc,PSTR("CELSIUS"))) {
925928
payload = 0;
@@ -937,8 +940,8 @@ void mqttDataCb(char* topic, byte* data, unsigned int data_len)
937940
payload = 4;
938941
}
939942

940-
// snprintf_P(svalue, sizeof(svalue), PSTR("RSLT: Payload %d, Payload16 %d"), payload, payload16);
941-
// addLog(LOG_LEVEL_DEBUG, svalue);
943+
snprintf_P(svalue, sizeof(svalue), PSTR("RSLT: Payload %d, Payload16 %d"), payload, payload16);
944+
addLog(LOG_LEVEL_DEBUG, svalue);
942945

943946
if (!strcmp_P(type,PSTR("POWER")) && (index > 0) && (index <= Maxdevice)) {
944947
if ((payload < 0) || (payload > 4)) {
@@ -1030,8 +1033,9 @@ void mqttDataCb(char* topic, byte* data, unsigned int data_len)
10301033
case 12: // stop_flash_rotate
10311034
bitWrite(sysCfg.flag.data, index, payload);
10321035
}
1033-
if (12 == index) {
1034-
CFG_Save(1);
1036+
if (12 == index) { // stop_flash_rotate
1037+
stop_flash_rotate = payload;
1038+
CFG_Save(stop_flash_rotate);
10351039
}
10361040
}
10371041
}
@@ -1735,8 +1739,8 @@ void publish_status(uint8_t payload)
17351739
}
17361740

17371741
if ((0 == payload) || (1 == payload)) {
1738-
snprintf_P(svalue, sizeof(svalue), PSTR("{\"StatusPRM\":{\"Baudrate\":%d, \"GroupTopic\":\"%s\", \"OtaUrl\":\"%s\", \"Uptime\":%d, \"Sleep\":%d, \"BootCount\":%d, \"SaveCount\":%d}}"),
1739-
Baudrate, sysCfg.mqtt_grptopic, sysCfg.otaUrl, uptime, sysCfg.sleep, sysCfg.bootcount, sysCfg.saveFlag);
1742+
snprintf_P(svalue, sizeof(svalue), PSTR("{\"StatusPRM\":{\"Baudrate\":%d, \"GroupTopic\":\"%s\", \"OtaUrl\":\"%s\", \"Uptime\":%d, \"Sleep\":%d, \"BootCount\":%d, \"SaveCount\":%d, \"SaveAddress\":\"%X\"}}"),
1743+
Baudrate, sysCfg.mqtt_grptopic, sysCfg.otaUrl, uptime, sysCfg.sleep, sysCfg.bootcount, sysCfg.saveFlag, CFG_Address());
17401744
mqtt_publish_topic_P(option, PSTR("STATUS1"), svalue);
17411745
}
17421746

@@ -2621,6 +2625,7 @@ void setup()
26212625
sysCfg.bootcount++;
26222626
snprintf_P(log, sizeof(log), PSTR("APP: Bootcount %d"), sysCfg.bootcount);
26232627
addLog(LOG_LEVEL_DEBUG, log);
2628+
stop_flash_rotate = sysCfg.flag.stop_flash_rotate;
26242629
savedatacounter = sysCfg.savedata;
26252630
seriallog_timer = SERIALLOG_TIMER;
26262631
seriallog_level = sysCfg.seriallog_level;

sonoff/webserver.ino

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1144,6 +1144,7 @@ void handleUploadDone()
11441144
page += error;
11451145
snprintf_P(log, sizeof(log), PSTR("Upload: %s"), error);
11461146
addLog(LOG_LEVEL_DEBUG, log);
1147+
stop_flash_rotate = sysCfg.flag.stop_flash_rotate;
11471148
} else {
11481149
page += F("<font color='green'>successful</font></b><br/><br/>Device will restart in a few seconds");
11491150
restartflag = 2;
@@ -1232,10 +1233,7 @@ void handleUploadLoop()
12321233
}
12331234
CFG_DefaultSet2();
12341235
memcpy((char*)&sysCfg +16, upload.buf +16, upload.currentSize -16);
1235-
12361236
memcpy((char*)&sysCfg +8, upload.buf +8, 4); // Restore version and auto upgrade
1237-
// CFG_Delta();
1238-
12391237
}
12401238
} else { // firmware
12411239
if (!_uploaderror && (Update.write(upload.buf, upload.currentSize) != upload.currentSize)) {
@@ -1431,7 +1429,8 @@ void handleInfo()
14311429
page += F("<tr><th>Core/SDK version</th><td>"); page += ESP.getCoreVersion(); page += F("/"); page += String(ESP.getSdkVersion()); page += F("</td></tr>");
14321430
// page += F("<tr><th>Boot version</th><td>"); page += String(ESP.getBootVersion()); page += F("</td></tr>");
14331431
page += F("<tr><th>Uptime</th><td>"); page += String(uptime); page += F(" Hours</td></tr>");
1434-
page += F("<tr><th>Flash write count</th><td>"); page += String(sysCfg.saveFlag); page += F("</td></tr>");
1432+
snprintf_P(stopic, sizeof(stopic), PSTR(" at %X"), CFG_Address());
1433+
page += F("<tr><th>Flash write count</th><td>"); page += String(sysCfg.saveFlag); page += stopic; page += F("</td></tr>");
14351434
page += F("<tr><th>Boot count</th><td>"); page += String(sysCfg.bootcount); page += F("</td></tr>");
14361435
page += F("<tr><th>Reset reason</th><td>"); page += getResetReason(); page += F("</td></tr>");
14371436
for (byte i = 0; i < Maxdevice; i++) {

sonoff/xdrv_snfled.ino

Lines changed: 3 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -49,30 +49,6 @@ uint8_t sl_wakeupActive = 0;
4949
uint8_t sl_wakeupDimmer = 0;
5050
uint16_t sl_wakeupCntr = 0;
5151

52-
uint32_t Atoh(char *s)
53-
{
54-
uint32_t value = 0;
55-
uint32_t digit;
56-
int8_t c;
57-
58-
while((c = *s++)) {
59-
if ('0' <= c && c <= '9') {
60-
digit = c - '0';
61-
}
62-
else if ('A' <= c && c <= 'F') {
63-
digit = c - 'A' + 10;
64-
}
65-
else if ('a' <= c && c <= 'f') {
66-
digit = c - 'a' + 10;
67-
}
68-
else {
69-
break;
70-
}
71-
value = (value << 4) | digit;
72-
}
73-
return value;
74-
}
75-
7652
void sl_setDim(uint8_t myDimmer)
7753
{
7854
float newDim = 100 / (float)myDimmer;
@@ -176,6 +152,7 @@ boolean sl_command(char *type, uint16_t index, char *dataBufUc, uint16_t data_le
176152
{
177153
boolean serviced = true;
178154
boolean coldim = false;
155+
char *p;
179156

180157
if (!strcmp_P(type,PSTR("COLOR"))) {
181158
uint8_t my_color[5];
@@ -185,8 +162,8 @@ boolean sl_command(char *type, uint16_t index, char *dataBufUc, uint16_t data_le
185162
ccold[2] = '\0';
186163
memcpy(cwarm, dataBufUc + 2, 2);
187164
cwarm[2] = '\0';
188-
my_color[0] = Atoh(ccold);
189-
my_color[1] = Atoh(cwarm);
165+
my_color[0] = strtol(ccold, &p, 16);
166+
my_color[1] = strtol(cwarm, &p, 16);
190167
uint16_t temp = my_color[0];
191168
if (temp < my_color[1]) {
192169
temp = my_color[1];

0 commit comments

Comments
 (0)