From 2959ec93412951b6b9cdf1c4673b5b170208938c Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Thu, 14 Mar 2019 16:50:56 +0100 Subject: [PATCH] Prep for release with fix some warnings Prep for release with fix some warnings --- sonoff/settings.h | 16 ++++++------- sonoff/sonoff.ino | 33 ++++++++++++--------------- sonoff/support.ino | 2 +- sonoff/xdrv_01_webserver.ino | 38 ++++++++++++------------------- sonoff/xdrv_12_home_assistant.ino | 2 +- 5 files changed, 38 insertions(+), 53 deletions(-) diff --git a/sonoff/settings.h b/sonoff/settings.h index 342ff1612..5a7827365 100644 --- a/sonoff/settings.h +++ b/sonoff/settings.h @@ -200,8 +200,8 @@ struct SYSCFG { uint8_t seriallog_level; // 09E uint8_t sta_config; // 09F uint8_t sta_active; // 0A0 - char sta_ssid[2][33]; // 0A1 - Keep together with sta_pwd as being copied as one chunck with reset 4/5 - char sta_pwd[2][65]; // 0E3 - Keep together with sta_ssid as being copied as one chunck with reset 4/5 + char sta_ssid[2][33]; // 0A1 - Keep together with sta_pwd as being copied as one chunck with reset 5 + char sta_pwd[2][65]; // 0E3 - Keep together with sta_ssid as being copied as one chunck with reset 5 char hostname[33]; // 165 char syslog_host[33]; // 186 uint8_t rule_stop; // 1A7 @@ -213,12 +213,12 @@ struct SYSCFG { uint8_t free_1D5[20]; // 1D5 Free since 5.12.0e - char mqtt_host[33]; // 1E9 - uint16_t mqtt_port; // 20A - char mqtt_client[33]; // 20C - char mqtt_user[33]; // 22D - char mqtt_pwd[33]; // 24E - char mqtt_topic[33]; // 26F + char mqtt_host[33]; // 1E9 - Keep together with below as being copied as one chunck with reset 6 + uint16_t mqtt_port; // 20A - Keep together + char mqtt_client[33]; // 20C - Keep together + char mqtt_user[33]; // 22D - Keep together + char mqtt_pwd[33]; // 24E - Keep together + char mqtt_topic[33]; // 26F - Keep together with above items as being copied as one chunck with reset 6 char button_topic[33]; // 290 char mqtt_grptopic[33]; // 2B1 uint8_t display_model; // 2D2 diff --git a/sonoff/sonoff.ino b/sonoff/sonoff.ino index 82c306c90..39f180c0b 100755 --- a/sonoff/sonoff.ino +++ b/sonoff/sonoff.ino @@ -2082,31 +2082,26 @@ void Every250mSeconds(void) } if (restart_flag && (backlog_pointer == backlog_index)) { if ((214 == restart_flag) || (215 == restart_flag) || (216 == restart_flag)) { - char storage[sizeof(Settings.sta_ssid) + sizeof(Settings.sta_pwd)]; - char storage_mqtt_host[sizeof(Settings.mqtt_host)]; - uint16_t storage_mqtt_port; - char storage_mqtt_user[sizeof(Settings.mqtt_user)]; - char storage_mqtt_pwd[sizeof(Settings.mqtt_pwd)]; - char storage_mqtt_topic[sizeof(Settings.mqtt_topic)]; - memcpy(storage, Settings.sta_ssid, sizeof(storage)); // Backup current SSIDs and Passwords + char storage_wifi[sizeof(Settings.sta_ssid) + + sizeof(Settings.sta_pwd)]; + char storage_mqtt[sizeof(Settings.mqtt_host) + + sizeof(Settings.mqtt_port) + + sizeof(Settings.mqtt_client) + + sizeof(Settings.mqtt_user) + + sizeof(Settings.mqtt_pwd) + + sizeof(Settings.mqtt_topic)]; + memcpy(storage_wifi, Settings.sta_ssid, sizeof(storage_wifi)); // Backup current SSIDs and Passwords if (216 == restart_flag) { - memcpy(storage_mqtt_host, Settings.mqtt_host, sizeof(Settings.mqtt_host)); - storage_mqtt_port = Settings.mqtt_port; - memcpy(storage_mqtt_user, Settings.mqtt_user, sizeof(Settings.mqtt_user)); - memcpy(storage_mqtt_pwd, Settings.mqtt_pwd, sizeof(Settings.mqtt_pwd)); - memcpy(storage_mqtt_topic, Settings.mqtt_topic, sizeof(Settings.mqtt_topic)); + memcpy(storage_mqtt, Settings.mqtt_host, sizeof(storage_mqtt)); // Backup mqtt host, port, client, username and password } if ((215 == restart_flag) || (216 == restart_flag)) { SettingsErase(0); // Erase all flash from program end to end of physical flash } SettingsDefault(); - memcpy(Settings.sta_ssid, storage, sizeof(storage)); // Restore current SSIDs and Passwords - if (216 == restart_flag) { // Restore the mqtt host, port, username and password - memcpy(Settings.mqtt_host, storage_mqtt_host, sizeof(Settings.mqtt_host)); - Settings.mqtt_port = storage_mqtt_port; - memcpy(Settings.mqtt_user, storage_mqtt_user, sizeof(Settings.mqtt_user)); - memcpy(Settings.mqtt_pwd, storage_mqtt_pwd, sizeof(Settings.mqtt_pwd)); - memcpy(Settings.mqtt_topic, storage_mqtt_topic, sizeof(Settings.mqtt_topic)); + memcpy(Settings.sta_ssid, storage_wifi, sizeof(storage_wifi)); // Restore current SSIDs and Passwords + if (216 == restart_flag) { + memcpy(Settings.mqtt_host, storage_mqtt, sizeof(storage_mqtt)); // Restore the mqtt host, port, client, username and password + strlcpy(Settings.mqtt_client, MQTT_CLIENT_ID, sizeof(Settings.mqtt_client)); // Set client to default } restart_flag = 2; } diff --git a/sonoff/support.ino b/sonoff/support.ino index fc2a3d853..e6068fb77 100644 --- a/sonoff/support.ino +++ b/sonoff/support.ino @@ -1278,7 +1278,7 @@ void AddLog_P2(uint8_t loglevel, PGM_P formatP, ...) { va_list arg; va_start(arg, formatP); - int len = vsnprintf_P(log_data, sizeof(log_data), formatP, arg); + vsnprintf_P(log_data, sizeof(log_data), formatP, arg); va_end(arg); AddLog(loglevel); diff --git a/sonoff/xdrv_01_webserver.ino b/sonoff/xdrv_01_webserver.ino index 9d96c480c..f243b1b11 100644 --- a/sonoff/xdrv_01_webserver.ino +++ b/sonoff/xdrv_01_webserver.ino @@ -272,7 +272,7 @@ const char HTTP_HEAD_STYLE3[] PROGMEM = #else "