From eab7250102e443c57786f3f8c6303d59aeafa594 Mon Sep 17 00:00:00 2001 From: Theo Arends Date: Tue, 8 Aug 2017 14:50:21 +0200 Subject: [PATCH] v5.5.1b 5.5.1b * 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) --- sonoff/_releasenotes.ino | 7 +++++-- sonoff/settings.ino | 24 +++++++----------------- sonoff/sonoff.ino | 20 ++++++-------------- sonoff/webserver.ino | 4 ++-- 4 files changed, 20 insertions(+), 35 deletions(-) diff --git a/sonoff/_releasenotes.ino b/sonoff/_releasenotes.ino index fc5ecc00b..db3d490a3 100644 --- a/sonoff/_releasenotes.ino +++ b/sonoff/_releasenotes.ino @@ -1,5 +1,8 @@ -/* 5.5.1a +/* 5.5.1b * 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 @@ -894,4 +897,4 @@ * 1.0.5 20160310 * Initial public release * Show debug info by selecting option from IDE Tools Debug port: Serial - */ + */ diff --git a/sonoff/settings.ino b/sonoff/settings.ino index e5c4b70f2..f48f05fe9 100644 --- a/sonoff/settings.ino +++ b/sonoff/settings.ino @@ -141,33 +141,23 @@ uint32_t _cfgLocation = CFG_LOCATION; /* * Based on cores/esp8266/Updater.cpp */ -void setFlashMode(byte option, byte mode) +void setFlashModeDout() { - 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; - } + eboot_command ebcmd; + eboot_command_read(&ebcmd); + address = ebcmd.args[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] != mode) { - _buffer[2] = mode &3; + if (_buffer[2] != 3) { // DOUT + _buffer[2] = 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; @@ -729,4 +719,4 @@ void CFG_Delta() } } - + diff --git a/sonoff/sonoff.ino b/sonoff/sonoff.ino index 265f952a0..0bfbf591a 100644 --- a/sonoff/sonoff.ino +++ b/sonoff/sonoff.ino @@ -25,7 +25,7 @@ - Select IDE Tools - Flash Size: "1M (no SPIFFS)" ====================================================*/ -#define VERSION 0x05050101 // 5.5.1a +#define VERSION 0x05050102 // 5.5.1b 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,14 +1282,6 @@ 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. @@ -2388,21 +2380,21 @@ void stateloop() if (otaretry) { // snprintf_P(log, sizeof(log), PSTR("OTA: Attempt %d"), OTA_ATTEMPTS - otaretry); // addLog(LOG_LEVEL_INFO, log); - otaok = (HTTP_UPDATE_OK == ESPhttpUpdate.update(sysCfg.otaUrl)); + otaok = (HTTP_UPDATE_FAILED != ESPhttpUpdate.update(sysCfg.otaUrl)); if (!otaok) { otaflag = 2; } } } - if (90 == otaflag) { // Allow MQTT to reconnect + if (90 == otaflag) { // Allow MQTT to reconnect otaflag = 0; if (otaok) { - setFlashMode(1, 3); // DOUT for both ESP8266 and ESP8285 + setFlashModeDout(); // Force 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()); } - restartflag = 2; // Restart anyway to keep memory clean webserver + restartflag = 2; // Restart anyway to keep memory clean webserver mqtt_publish_topic_P(1, PSTR("UPGRADE"), svalue); } } @@ -2876,4 +2868,4 @@ void loop() // yield(); // yield == delay(0), delay contains yield, auto yield in loop delay(sleep); // https://github.com/esp8266/Arduino/issues/2021 -} +} diff --git a/sonoff/webserver.ino b/sonoff/webserver.ino index 9f4f17f86..dce438ca6 100644 --- a/sonoff/webserver.ino +++ b/sonoff/webserver.ino @@ -1245,7 +1245,7 @@ void handleUploadLoop() _uploaderror = 4; return; } - upload.buf[2] = 3; // Force DOUT - ESP8285 + upload.buf[2] = 3; // Force DOUT - ESP8285 } } if (_uploadfiletype) { // config @@ -1615,4 +1615,4 @@ boolean isIp(String str) } return true; } -#endif // USE_WEBSERVER +#endif // USE_WEBSERVER