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 "

%s " D_MODULE "

" #endif - "

%s

%s"; + "

%s

"; const char HTTP_MSG_SLIDER1[] PROGMEM = "
" D_COLDLIGHT "" D_WARMLIGHT "
" @@ -566,27 +566,6 @@ bool HttpCheckPriviledgedAccess(bool autorequestauth = true) return true; } -String WSNetworkInfo(void) -{ - String info = ""; - if (Settings.flag3.gui_hostname_ip) { - uint8_t more_ips = 0; - info += F("

"); info += my_hostname; - if (mdns_begun) { info += F(".local"); } - info += F(" ("); - if (static_cast(WiFi.localIP()) != 0) { - info += WiFi.localIP().toString(); - more_ips++; - } - if (static_cast(WiFi.softAPIP()) != 0) { - if (more_ips) { info += F(", "); } - info += WiFi.softAPIP().toString(); - } - info += F(")

"); - } - return info; -} - void WSHeaderSend(void) { WebServer->sendHeader(F("Cache-Control"), F("no-cache, no-store, must-revalidate")); @@ -701,7 +680,18 @@ void WSContentSendStyle_P(const char* style) WSContentSend_P(HTTP_HEAD_STYLE1); WSContentSend_P(HTTP_HEAD_STYLE2); WSContentSend_P(style); - WSContentSend_P(HTTP_HEAD_STYLE3, ModuleName().c_str(), Settings.friendlyname[0], WSNetworkInfo().c_str()); + WSContentSend_P(HTTP_HEAD_STYLE3, ModuleName().c_str(), Settings.friendlyname[0]); + if (Settings.flag3.gui_hostname_ip) { + bool lip = (static_cast(WiFi.localIP()) != 0); + bool sip = (static_cast(WiFi.softAPIP()) != 0); + WSContentSend_P(PSTR("

%s%s (%s%s%s)

"), // sonoff.local (192.168.2.12,192.168.4.1) + my_hostname, + (mdns_begun) ? ".local" : "", + (lip) ? WiFi.localIP().toString().c_str() : "", + (lip && sip) ? "," : "", + (sip) ? WiFi.softAPIP().toString().c_str() : ""); + } + WSContentSend_P(PSTR("")); } void WSContentSendStyle(void) @@ -812,7 +802,7 @@ void HandleRoot(void) if ((Settings.web_password[0] != 0) && !(WebServer->hasArg("USER1")) && !(WebServer->hasArg("PASS1")) && HTTP_MANAGER_RESET_ONLY != webserver_state) { HandleWifiLogin(); } else { - if (!(Settings.web_password[0] != 0) || ((WebServer->arg("USER1") == WEB_USERNAME ) && (WebServer->arg("PASS1") == Settings.web_password ) || HTTP_MANAGER_RESET_ONLY == webserver_state)) { + if (!(Settings.web_password[0] != 0) || (((WebServer->arg("USER1") == WEB_USERNAME ) && (WebServer->arg("PASS1") == Settings.web_password )) || HTTP_MANAGER_RESET_ONLY == webserver_state)) { HandleWifiConfiguration(); } else { // wrong user and pass diff --git a/sonoff/xdrv_12_home_assistant.ino b/sonoff/xdrv_12_home_assistant.ino index 5998b3585..639c74499 100644 --- a/sonoff/xdrv_12_home_assistant.ino +++ b/sonoff/xdrv_12_home_assistant.ino @@ -166,7 +166,7 @@ static void Shorten(char** s, char *prefix) } } -int try_snprintf_P(char *s, size_t n, const char *format, ... ) +void try_snprintf_P(char *s, int n, const char *format, ... ) { va_list args; va_start(args, format);