From f20e9b84478bb97e79bea48b15626f9d320e9ab7 Mon Sep 17 00:00:00 2001 From: Theo Arends Date: Tue, 1 May 2018 18:16:52 +0200 Subject: [PATCH] v5.13.1 Release version 5.13.1 --- sonoff/_releasenotes.ino | 7 ++++++- sonoff/sonoff.h | 2 -- sonoff/sonoff.ino | 2 +- sonoff/sonoff_post.h | 4 ++++ sonoff/user_config.h | 1 + sonoff/webserver.ino | 29 +++++++++++++++++++---------- sonoff/xdrv_09_timers.ino | 2 +- sonoff/xdrv_10_rules.ino | 2 +- 8 files changed, 33 insertions(+), 16 deletions(-) diff --git a/sonoff/_releasenotes.ino b/sonoff/_releasenotes.ino index d08e1bb39dda..95bafa5a4f90 100644 --- a/sonoff/_releasenotes.ino +++ b/sonoff/_releasenotes.ino @@ -1,4 +1,9 @@ -/* 5.13.0 20180430 +/* 5.13.1 20180501 + * Fix JSON buffers size too small for execution in some situations (#2580) + * Fix configuration restore (#2591) + * Add define MODULE for user selecting default model although it preferably should not be changed (#569, #2589) + * + * 5.13.0 20180430 * Change platformio option sonoff-ds18x20 to sonoff-allsensors enabling ds18x20 and all other sensors in one image * Change status display of Ssid and SetOption * Change default option SetOption15 from 0 to 1 providing better initial PWM experience diff --git a/sonoff/sonoff.h b/sonoff/sonoff.h index 296046c850ea..a2eecea4fc8a 100644 --- a/sonoff/sonoff.h +++ b/sonoff/sonoff.h @@ -52,8 +52,6 @@ typedef unsigned long power_t; // Power (Relay) type #define MAX_KNX_CB 10 // Max number of KNX Group Addresses to write that can be set #define MAX_RULE_SIZE 512 // Max number of characters in rules -#define MODULE SONOFF_BASIC // [Module] Select default model - #define MQTT_TOKEN_PREFIX "%prefix%" // To be substituted by mqtt_prefix[x] #define MQTT_TOKEN_TOPIC "%topic%" // To be substituted by mqtt_topic, mqtt_grptopic, mqtt_buttontopic, mqtt_switchtopic diff --git a/sonoff/sonoff.ino b/sonoff/sonoff.ino index a3f7b28668f3..a06051823104 100644 --- a/sonoff/sonoff.ino +++ b/sonoff/sonoff.ino @@ -25,7 +25,7 @@ - Select IDE Tools - Flash Size: "1M (no SPIFFS)" ====================================================*/ -#define VERSION 0x050D0000 // 5.13.0 +#define VERSION 0x050D0100 // 5.13.1 // Location specific includes #include // Arduino_Esp8266 version information (ARDUINO_ESP8266_RELEASE and ARDUINO_ESP8266_RELEASE_2_3_0) diff --git a/sonoff/sonoff_post.h b/sonoff/sonoff_post.h index 1d6ba7878998..ef1dfbfd98b9 100644 --- a/sonoff/sonoff_post.h +++ b/sonoff/sonoff_post.h @@ -46,6 +46,10 @@ void KNX_CB_Action(message_t const &msg, void *arg); * Default global defines \*********************************************************************************************/ +#ifndef MODULE +#define MODULE SONOFF_BASIC // [Module] Select default model +#endif + #define USE_DHT // Default DHT11 sensor needs no external library /*********************************************************************************************\ diff --git a/sonoff/user_config.h b/sonoff/user_config.h index 6bfa6e1cd987..83b9a346fee2 100644 --- a/sonoff/user_config.h +++ b/sonoff/user_config.h @@ -48,6 +48,7 @@ // -- Project ------------------------------------- #define PROJECT "sonoff" // PROJECT is used as the default topic delimiter +#define MODULE SONOFF_BASIC // [Module] Select default model from sonoff_template.h (Should not be changed) #define SAVE_DATA 1 // [SaveData] Save changed parameters to Flash (0 = disable, 1 - 3600 seconds) #define SAVE_STATE 1 // [SetOption0] Save changed power state to Flash (0 = disable, 1 = enable) diff --git a/sonoff/webserver.ino b/sonoff/webserver.ino index f82fa2e6d9ca..9c9be2a42948 100644 --- a/sonoff/webserver.ino +++ b/sonoff/webserver.ino @@ -328,6 +328,8 @@ uint8_t webserver_state = HTTP_OFF; uint8_t upload_error = 0; uint8_t upload_file_type; uint8_t upload_progress_dot_count; +uint8_t config_block_count = 0; +uint8_t config_xor_on = 0; // Helper function to avoid code duplication (saves 4k Flash) static void WebGetArg(const char* arg, char* out, size_t max) @@ -1317,17 +1319,14 @@ void HandleUploadLoop() } upload_progress_dot_count = 0; } else if (!upload_error && (UPLOAD_FILE_WRITE == upload.status)) { - if (0 == upload.totalSize) - { + if (0 == upload.totalSize) { if (upload_file_type) { if (upload.buf[0] != CONFIG_FILE_SIGN) { upload_error = 8; return; } - if (upload.currentSize > sizeof(Settings)) { - upload_error = 9; - return; - } + config_xor_on = upload.buf[1]; + config_block_count = 0; } else { if (upload.buf[0] != 0xE9) { upload_error = 3; @@ -1343,14 +1342,24 @@ void HandleUploadLoop() } if (upload_file_type) { // config if (!upload_error) { - if (upload.buf[1]) { + if (upload.currentSize > (sizeof(Settings) - (config_block_count * HTTP_UPLOAD_BUFLEN))) { + if (config_block_count) { SettingsDefault(); } + upload_error = 9; + return; + } + if (config_xor_on) { for (uint16_t i = 2; i < upload.currentSize; i++) { upload.buf[i] ^= (CONFIG_FILE_XOR +i); } } - SettingsDefaultSet2(); - memcpy((char*)&Settings +16, upload.buf +16, upload.currentSize -16); - memcpy((char*)&Settings +8, upload.buf +8, 4); // Restore version and auto upgrade + if (0 == config_block_count) { + SettingsDefaultSet2(); + memcpy((char*)&Settings +16, upload.buf +16, upload.currentSize -16); + memcpy((char*)&Settings +8, upload.buf +8, 4); // Restore version and auto upgrade + } else { + memcpy((char*)&Settings +(config_block_count * HTTP_UPLOAD_BUFLEN), upload.buf, upload.currentSize); + } + config_block_count++; } } else { // firmware if (!upload_error && (Update.write(upload.buf, upload.currentSize) != upload.currentSize)) { diff --git a/sonoff/xdrv_09_timers.ino b/sonoff/xdrv_09_timers.ino index aa1287f20cad..e85349da7a31 100644 --- a/sonoff/xdrv_09_timers.ino +++ b/sonoff/xdrv_09_timers.ino @@ -354,7 +354,7 @@ boolean TimerCommand() #ifndef USE_RULES if (devices_present) { #endif - StaticJsonBuffer<200> jsonBuffer; + StaticJsonBuffer<256> jsonBuffer; JsonObject& root = jsonBuffer.parseObject(dataBufUc); if (!root.success()) { snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_CMND_TIMER "%d\":\"" D_JSON_INVALID_JSON "\"}"), index); // JSON decode failed diff --git a/sonoff/xdrv_10_rules.ino b/sonoff/xdrv_10_rules.ino index f92edcf55a34..b07bea5b74b7 100644 --- a/sonoff/xdrv_10_rules.ino +++ b/sonoff/xdrv_10_rules.ino @@ -181,7 +181,7 @@ bool RulesRuleMatch(String &event, String &rule) } // Step2: Search rule_task and rule_name - StaticJsonBuffer<400> jsonBuf; + StaticJsonBuffer<1024> jsonBuf; JsonObject &root = jsonBuf.parseObject(event); if (!root.success()) { return false; } // No valid JSON data