diff --git a/README.md b/README.md index 8f1b01512..2627f6459 100644 --- a/README.md +++ b/README.md @@ -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 **3.9.11** - See ```sonoff/_releasenotes.ino``` for change information. +Current version is **3.9.12** - See ```sonoff/_releasenotes.ino``` for change information. - This version provides all (Sonoff) modules in one file and starts up with Sonoff Basic. - Once uploaded select module using the configuration webpage or the commands ```Modules``` and ```Module```. diff --git a/api/arduino/sonoff.ino.bin b/api/arduino/sonoff.ino.bin index 644b8b625..21faa3ebb 100644 Binary files a/api/arduino/sonoff.ino.bin and b/api/arduino/sonoff.ino.bin differ diff --git a/sonoff/_releasenotes.ino b/sonoff/_releasenotes.ino index 34fd07615..ef9fdd6ac 100644 --- a/sonoff/_releasenotes.ino +++ b/sonoff/_releasenotes.ino @@ -1,5 +1,7 @@ -/* 3.9.11a +/* 3.9.12 20170208 * Fix compile error when webserver is disabled (#30) + * Fix possible ESP8285 flash problem by updating Flash Chip Mode to DOUT during OTA upload + * Fix hostname issues by not allowing user entry of string formatting and removing from user_config.h (#36) * * 3.9.11 20170204 * Fix command I2Cscan diff --git a/sonoff/sonoff.ino b/sonoff/sonoff.ino index b6bc9eecf..d03751cb7 100644 --- a/sonoff/sonoff.ino +++ b/sonoff/sonoff.ino @@ -10,7 +10,7 @@ * ==================================================== */ -#define VERSION 0x03090B00 // 3.9.11 +#define VERSION 0x03090C00 // 3.9.12 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}; @@ -58,7 +58,7 @@ enum emul_t {EMUL_NONE, EMUL_WEMO, EMUL_HUE, EMUL_MAX}; #define WS2812_LEDS 30 // [Pixels] Number of LEDs #endif -#define DEF_WIFI_HOSTNAME "%s-%04d" // Expands to - +#define WIFI_HOSTNAME "%s-%04d" // Expands to - #define HLW_PREF_PULSE 12530 // was 4975us = 201Hz = 1000W #define HLW_UREF_PULSE 1950 // was 1666us = 600Hz = 220V @@ -1087,7 +1087,7 @@ void mqttDataCb(char* topic, byte* data, unsigned int data_len) uint16_t i = 0, grpflg = 0, index; char topicBuf[TOPSZ], dataBuf[data_len+1], dataBufUc[MESSZ]; char *p, *mtopic = NULL, *type = NULL; - char stopic[TOPSZ], stemp1[TOPSZ], stemp2[10]; + char stemp1[TOPSZ], stemp2[10]; strncpy(topicBuf, topic, sizeof(topicBuf)); memcpy(dataBuf, data, sizeof(dataBuf)); @@ -1306,6 +1306,12 @@ void mqttDataCb(char* topic, byte* data, unsigned int data_len) } snprintf_P(svalue, sizeof(svalue), PSTR("{\"Sleep\":\"%d%s (%d%s)\"}"), sleep, (sysCfg.value_units) ? " mS" : "", sysCfg.sleep, (sysCfg.value_units) ? " mS" : ""); } + else if (!strcmp(type,"FLASHCHIPMODE")) { + if ((data_len > 0) && (payload >= 2) && (payload <= 3)) { + if (ESP.getFlashChipMode() != payload) setFlashChipMode(0, payload &3); + } + snprintf_P(svalue, sizeof(svalue), PSTR("{\"FlashChipMode\":%d}"), ESP.getFlashChipMode()); + } else if (!strcmp(type,"UPGRADE") || !strcmp(type,"UPLOAD")) { if ((data_len > 0) && (payload == 1)) { otaflag = 3; @@ -1383,8 +1389,7 @@ void mqttDataCb(char* topic, byte* data, unsigned int data_len) else if (!grpflg && !strcmp(type,"HOSTNAME")) { if ((data_len > 0) && (data_len < sizeof(sysCfg.hostname))) { strlcpy(sysCfg.hostname, (payload == 1) ? WIFI_HOSTNAME : dataBuf, sizeof(sysCfg.hostname)); - if (strstr(sysCfg.hostname,"%")) - strlcpy(sysCfg.hostname, DEF_WIFI_HOSTNAME, sizeof(sysCfg.hostname)); + if (strstr(sysCfg.hostname,"%")) strlcpy(sysCfg.hostname, WIFI_HOSTNAME, sizeof(sysCfg.hostname)); restartflag = 2; } snprintf_P(svalue, sizeof(svalue), PSTR("{\"Hostname\":\"%s\"}"), sysCfg.hostname); @@ -1838,9 +1843,7 @@ void do_cmnd(char *cmnd) void publish_status(uint8_t payload) { - char svalue[MESSZ], stemp1[TOPSZ], stemp2[10], stemp3[10]; - float ped, pi, pc; - uint16_t pe, pw, pu; + char svalue[MESSZ]; uint8_t option = 0; // Workaround MQTT - TCP/IP stack queueing when SUB_PREFIX = PUB_PREFIX @@ -1966,7 +1969,7 @@ void every_second_cb() void every_second() { - char log[LOGSZ], stopic[TOPSZ], svalue[MESSZ], stime[21]; + char svalue[MESSZ], stime[21]; snprintf_P(stime, sizeof(stime), PSTR("%04d-%02d-%02dT%02d:%02d:%02d"), rtcTime.Year, rtcTime.Month, rtcTime.Day, rtcTime.Hour, rtcTime.Minute, rtcTime.Second); @@ -2246,6 +2249,7 @@ void stateloop() if (otaflag == 10) { // Allow MQTT to reconnect otaflag = 0; if (otaok) { + if ((sysCfg.module == SONOFF_TOUCH) || (sysCfg.module == SONOFF_4CH)) setFlashChipMode(1, 3); // DOUT - ESP8285 snprintf_P(svalue, sizeof(svalue), PSTR("Successful. Restarting")); restartflag = 2; } else { @@ -2508,8 +2512,8 @@ void setup() Serial.println(); } - if (strstr(sysCfg.hostname, "%")) strlcpy(sysCfg.hostname, DEF_WIFI_HOSTNAME, sizeof(sysCfg.hostname)); - if (!strcmp(sysCfg.hostname, DEF_WIFI_HOSTNAME)) { + if (strstr(sysCfg.hostname, "%")) { + strlcpy(sysCfg.hostname, WIFI_HOSTNAME, sizeof(sysCfg.hostname)); snprintf_P(Hostname, sizeof(Hostname)-1, sysCfg.hostname, sysCfg.mqtt_topic, ESP.getChipId() & 0x1FFF); } else { snprintf_P(Hostname, sizeof(Hostname)-1, sysCfg.hostname); diff --git a/sonoff/support.ino b/sonoff/support.ino index 3442cd31c..0fd393e78 100644 --- a/sonoff/support.ino +++ b/sonoff/support.ino @@ -275,26 +275,40 @@ void initSpiffs() } #endif // USE_SPIFFS +#include "eboot_command.h" + /* -void setFlashChipMode(byte mode) + * Based on cores/esp8266/Updater.cpp + */ +void setFlashChipMode(byte option, byte mode) { char log[LOGSZ]; - uint32_t data; - - uint8_t * bytes = (uint8_t *) &data; - // read first 4 byte (magic byte + flash config) - if (spi_flash_read(0x0000, &data, 4) == SPI_FLASH_RESULT_OK) { + uint8_t *_buffer; + uint32_t address; - snprintf_P(log, sizeof(log), PSTR("FLSH: Magic byte and flash config %08X"), data); - addLog(LOG_LEVEL_DEBUG, log); - - if (bytes[2] != mode) { - bytes[2] = mode &3; -// spi_flash_write(0x0000, &data, 4); + 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_read(address, (uint32_t*)_buffer, FLASH_SECTOR_SIZE) == SPI_FLASH_RESULT_OK) { + if (_buffer[2] != mode) { + _buffer[2] = mode &3; + noInterrupts(); + if (spi_flash_erase_sector(address / FLASH_SECTOR_SIZE) == SPI_FLASH_RESULT_OK) { + spi_flash_write(address, (uint32_t*)_buffer, FLASH_SECTOR_SIZE); + } + interrupts(); + snprintf_P(log, sizeof(log), PSTR("FLSH: Updated Flash Chip Mode to %d"), (option) ? mode : ESP.getFlashChipMode()); + addLog(LOG_LEVEL_DEBUG, log); } } + delete[] _buffer; } -*/ + /*********************************************************************************************\ * Wifi \*********************************************************************************************/ @@ -629,7 +643,6 @@ void IPtoCharArray(IPAddress address, char *ip_str, size_t size) int32_t i2c_read(uint8_t addr, uint8_t reg, uint8_t size) { - char log[LOGSZ]; byte x = 0; int32_t data = 0; @@ -646,10 +659,6 @@ int32_t i2c_read(uint8_t addr, uint8_t reg, uint8_t size) } x++; } while (Wire.endTransmission(true) != 0 && x <= I2C_RETRY_COUNTER); // end transmission - -// snprintf_P(log, sizeof(log), PSTR("I2C: received %X, retries %d"), data, x -1); -// addLog(LOG_LEVEL_DEBUG_MORE, log); - return data; } diff --git a/sonoff/user_config.h b/sonoff/user_config.h index fae221352..435b352d7 100644 --- a/sonoff/user_config.h +++ b/sonoff/user_config.h @@ -21,7 +21,6 @@ #define STA_PASS1 "VnsqrtnrsddbrN" // [Password1] Wifi password #define STA_SSID2 "indebuurt2" // [Ssid2] Optional alternate AP Wifi SSID #define STA_PASS2 "VnsqrtnrsddbrN" // [Password2] Optional alternate AP Wifi password -#define WIFI_HOSTNAME "%s-%04d" // [Hostname] Expands to - #define WIFI_CONFIG_TOOL WIFI_WPSCONFIG // [WifiConfig] Default tool if wifi fails to connect // (WIFI_RESTART, WIFI_SMARTCONFIG, WIFI_MANAGER, WIFI_WPSCONFIG, WIFI_RETRY) // -- Syslog -------------------------------------- @@ -37,7 +36,7 @@ // -- MQTT ---------------------------------------- #define MQTT_USE 1 // [Mqtt] Select default MQTT use (0 = Off, 1 = On) // !!! TLS uses a LOT OF MEMORY (20k) so be careful to enable other options at the same time !!! -//#define USE_MQTT_TLS // EXPERIMENTAL Use TLS for MQTT connection (+53k code, +20k mem) +//#define USE_MQTT_TLS // EXPERIMENTAL Use TLS for MQTT connection (+53k code, +20k mem) - Disable by // // Needs Fingerprint, TLS Port, UserId and Password #ifdef USE_MQTT_TLS #define MQTT_HOST "m20.cloudmqtt.com" // [MqttHost] @@ -72,20 +71,20 @@ #define TELE_PERIOD 300 // [TelePeriod] Telemetry (0 = disable, 10 - 3600 seconds) // -- MQTT - Domoticz ----------------------------- -#define USE_DOMOTICZ // Enable Domoticz (+5k code, +0.3k mem) - Disable by // +#define USE_DOMOTICZ // Enable Domoticz (+7k code, +0.3k mem) - Disable by // #define DOMOTICZ_IN_TOPIC "domoticz/in" // [DomoticzInTopic] #define DOMOTICZ_OUT_TOPIC "domoticz/out" // [DomoticzOutTopic] #define DOMOTICZ_UPDATE_TIMER 0 // [DomoticzUpdateTimer] Send relay status (0 = disable, 1 - 3600 seconds) (Optional) // -- HTTP ---------------------------------------- -#define USE_WEBSERVER // Enable web server and wifi manager (+43k code, +2k mem) - Disable by // +#define USE_WEBSERVER // Enable web server and wifi manager (+60k code, +4k mem) - Disable by // #define FRIENDLY_NAME "Sonoff" // [FriendlyName] Friendlyname up to 32 characters used by webpages and Alexa #define WEB_SERVER 2 // [WebServer] Web server (0 = Off, 1 = Start as User, 2 = Start as Admin) #define USE_EMULATION // Enable Belkin WeMo and Hue Bridge emulation for Alexa (+11k code, +2k mem) #define EMULATION EMUL_NONE // [Emulation] Select Belkin WeMo or Hue Bridge emulation (EMUL_NONE, EMUL_WEMO or EMUL_HUE) // -- mDNS ---------------------------------------- -#define USE_DISCOVERY // Enable mDNS for the following services (+8k code, +0.3k mem) +#define USE_DISCOVERY // Enable mDNS for the following services (+8k code, +0.3k mem) - Disable by // #define WEBSERVER_ADVERTISE // Provide access to webserver by name .local/ #define MQTT_HOST_DISCOVERY // Find MQTT host server (overrides MQTT_HOST if found) @@ -121,12 +120,12 @@ //#define USE_DHT2 // Optional using Adafruit DHT library //#define USE_DS18x20 // Optional using OneWire library for multiple DS18B20 and/or DS18S20 -#define USE_I2C // I2C Support (+10k code, 0.2k mem) +#define USE_I2C // I2C using library wire (+10k code, 0.2k mem) - Disable by // #define USE_BH1750 // Add I2C code for BH1750 sensor #define USE_BMP // Add I2C code for BMP/BME280 sensor #define USE_HTU // Add I2C code for HTU21 sensor -#define USE_WS2812 // WS2812 Led string support (+8k code, +1k mem) +#define USE_WS2812 // WS2812 Led string using library NeoPixelBus (+8k code, +1k mem) - Disable by // #define USE_WS2812_CTYPE 1 // WS2812 Color type (0 - RGB, 1 - GRB) // #define USE_WS2812_DMA // DMA supports only GPIO03 (= Serial TXD) (+1k mem) // When USE_WS2812_DMA is enabled expect Exceptions on Pow diff --git a/sonoff/webserver.ino b/sonoff/webserver.ino index 204d0510d..554993209 100644 --- a/sonoff/webserver.ino +++ b/sonoff/webserver.ino @@ -130,7 +130,7 @@ const char HTTP_FORM_WIFI[] PROGMEM = "
AP1 Password

" "
AP2 SSId (" STA_SSID2 ")

" "
AP2 Password

" - "
Hostname ({h0})

"; + "
Hostname (" WIFI_HOSTNAME ")

"; const char HTTP_FORM_MQTT[] PROGMEM = "
 MQTT parameters 
" "" @@ -414,7 +414,6 @@ void showPage(String &page) { page.replace("{ha}", my_module.name); page.replace("{h}", String(sysCfg.friendlyname[0])); -// page.replace("{ha}", Hostname); if (_httpflag == HTTP_MANAGER) { if (WIFI_configCounter()) { page.replace("", ""); @@ -557,7 +556,6 @@ void handleModule() for (byte i = 0; i < MAX_GPIO_PIN; i++) { if (cmodule.gp.io[i] == GPIO_USER) { page += F("
GPIO"); page += String(i); page += F("