Revert "Ota remove flash mode"

This commit is contained in:
Theo Arends 2017-08-08 16:08:08 +02:00 committed by GitHub
parent 5334b0393e
commit 05073b7ab7
5 changed files with 96 additions and 81 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.5.1b** - See [sonoff/_releasenotes.ino](https://github.com/arendst/Sonoff-Tasmota/blob/master/sonoff/_releasenotes.ino) for change information.
Current version is **5.5.1a** - See [sonoff/_releasenotes.ino](https://github.com/arendst/Sonoff-Tasmota/blob/master/sonoff/_releasenotes.ino) for change information.
### ATTENTION All versions

View File

@ -1,8 +1,5 @@
/* 5.5.1b
/* 5.5.1a
* Extent max number of WS2812 pixels from 256 to 512 (#667)
* Add OTA handling if server responds with no update available (#695)
* Removed undocumented command FlashMode (#696)
* Fix compile time error message due to increased message buffer size (#703)
*
* 5.5.1 20170805
* Fix Sonoff Rf Bridge issues

View File

@ -141,23 +141,33 @@ uint32_t _cfgLocation = CFG_LOCATION;
/*
* Based on cores/esp8266/Updater.cpp
*/
void setFlashModeDout()
void setFlashMode(byte option, byte mode)
{
char log[LOGSZ];
uint8_t *_buffer;
uint32_t address;
// option 0 - Use absolute address 0
// option 1 - Use OTA/Upgrade relative address
if (option) {
eboot_command ebcmd;
eboot_command_read(&ebcmd);
address = ebcmd.args[0];
} else {
address = 0;
}
_buffer = new uint8_t[FLASH_SECTOR_SIZE];
if (SPI_FLASH_RESULT_OK == spi_flash_read(address, (uint32_t*)_buffer, FLASH_SECTOR_SIZE)) {
if (_buffer[2] != 3) { // DOUT
_buffer[2] = 3;
if (_buffer[2] != mode) {
_buffer[2] = mode &3;
noInterrupts();
if (SPI_FLASH_RESULT_OK == spi_flash_erase_sector(address / FLASH_SECTOR_SIZE)) {
spi_flash_write(address, (uint32_t*)_buffer, FLASH_SECTOR_SIZE);
}
interrupts();
snprintf_P(log, sizeof(log), PSTR("FLSH: Set Flash Mode to %d"), (option) ? mode : ESP.getFlashChipMode());
addLog(LOG_LEVEL_DEBUG, log);
}
}
delete[] _buffer;

View File

@ -25,7 +25,7 @@
- Select IDE Tools - Flash Size: "1M (no SPIFFS)"
====================================================*/
#define VERSION 0x05050102 // 5.5.1b
#define VERSION 0x05050101 // 5.5.1a
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};
@ -1282,6 +1282,14 @@ void mqttDataCb(char* topic, byte* data, unsigned int data_len)
}
snprintf_P(svalue, sizeof(svalue), PSTR("{\"Sleep\":\"%d%s (%d%s)\"}"), sleep, (sysCfg.flag.value_units) ? " mS" : "", sysCfg.sleep, (sysCfg.flag.value_units) ? " mS" : "");
}
else if (!strcmp_P(type,PSTR("FLASHMODE"))) { // 0 = QIO, 1 = QOUT, 2 = DIO, 3 = DOUT
if ((payload >= 0) && (payload <= 3)) {
if (ESP.getFlashChipMode() != payload) {
setFlashMode(0, payload &3);
}
}
snprintf_P(svalue, sizeof(svalue), PSTR("{\"FlashMode\":%d}"), ESP.getFlashChipMode());
}
else if (!strcmp_P(type,PSTR("UPGRADE")) || !strcmp_P(type,PSTR("UPLOAD"))) {
// Check if the payload is numerically 1, and had no trailing chars.
// e.g. "1foo" or "1.2.3" could fool us.
@ -2380,7 +2388,7 @@ void stateloop()
if (otaretry) {
// snprintf_P(log, sizeof(log), PSTR("OTA: Attempt %d"), OTA_ATTEMPTS - otaretry);
// addLog(LOG_LEVEL_INFO, log);
otaok = (HTTP_UPDATE_FAILED != ESPhttpUpdate.update(sysCfg.otaUrl));
otaok = (HTTP_UPDATE_OK == ESPhttpUpdate.update(sysCfg.otaUrl));
if (!otaok) {
otaflag = 2;
}
@ -2389,7 +2397,7 @@ void stateloop()
if (90 == otaflag) { // Allow MQTT to reconnect
otaflag = 0;
if (otaok) {
setFlashModeDout(); // Force DOUT for both ESP8266 and ESP8285
setFlashMode(1, 3); // DOUT for both ESP8266 and ESP8285
snprintf_P(svalue, sizeof(svalue), PSTR("Successful. Restarting"));
} else {
snprintf_P(svalue, sizeof(svalue), PSTR("Failed %s"), ESPhttpUpdate.getLastErrorString().c_str());