From afdb197a6c9f85f88fa855664b1a977fa6f44e03 Mon Sep 17 00:00:00 2001 From: Theo Arends Date: Sun, 15 Jul 2018 15:21:48 +0200 Subject: [PATCH] v6.6.1b - Change wifi options 6.1.1b * Add default Wifi Configuration tool as define WIFI_CONFIG_NO_SSID in user_config.h if no SSID is configured (#3224) * Add user selection of Wifi Smartconfig as define USE_SMARTCONFIG in user_config.h * Add user selection of WPS as define USE_WPS in user_config.h in preparation for core v2.4.2 (#3221) * Change default Wifi config option from WPS to Wifi Manager if WPS is disabled * or Wifi Smartconfig if webserver is disabled * or Wifi Serial input if Smartconfig is disabled * Remove WPS and SmartConfig from sonoff-minimal saving 56k code space --- README.md | 2 +- sonoff/_releasenotes.ino | 18 +++++--- sonoff/i18n.h | 4 +- sonoff/sonoff.h | 2 +- sonoff/sonoff.ino | 6 +-- sonoff/sonoff_post.h | 1 + sonoff/support.ino | 91 ++++++++++++++++++++-------------------- sonoff/user_config.h | 11 +++-- 8 files changed, 74 insertions(+), 61 deletions(-) diff --git a/README.md b/README.md index 1eb4c1f9e36c..8d207111d757 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ If you like **Sonoff-Tasmota**, give it a star, or fork it and contribute! ### Development [![Build Status](https://img.shields.io/travis/arendst/Sonoff-Tasmota.svg)](https://travis-ci.org/arendst/Sonoff-Tasmota) -Current version is **6.1.1a** - See [sonoff/_releasenotes.ino](https://github.com/arendst/Sonoff-Tasmota/blob/development/sonoff/_releasenotes.ino) for change information. +Current version is **6.1.1b** - See [sonoff/_releasenotes.ino](https://github.com/arendst/Sonoff-Tasmota/blob/development/sonoff/_releasenotes.ino) for change information. ### Disclaimer :warning: **DANGER OF ELECTROCUTION** :warning: diff --git a/sonoff/_releasenotes.ino b/sonoff/_releasenotes.ino index 81efab066103..bd6c1dd18f86 100644 --- a/sonoff/_releasenotes.ino +++ b/sonoff/_releasenotes.ino @@ -1,11 +1,13 @@ -/* 6.1.1a +/* 6.1.1b + * Add default Wifi Configuration tool as define WIFI_CONFIG_NO_SSID in user_config.h if no SSID is configured (#3224) + * Add user selection of Wifi Smartconfig as define USE_SMARTCONFIG in user_config.h * Add user selection of WPS as define USE_WPS in user_config.h in preparation for core v2.4.2 (#3221) - * Change default Wifi config option from WPS to Wifi Manager if WPS is disabled (or Wifi Smartconfig if webserver is disabled) - * Remove WPS from sonoff-minimal saving 33k code space - * Revert wifi changes implemented in v6.0.0a due to possible bad initial wifi connections - * Revert sonoff-minimal removals causing failure of wifi connection (#3177) + * Change default Wifi config option from WPS to Wifi Manager if WPS is disabled + * or Wifi Smartconfig if webserver is disabled + * or Wifi Serial input if Smartconfig is disabled + * Remove WPS and SmartConfig from sonoff-minimal saving 56k code space * - * 6.1.0a + * 6.1.1a * Fix TM1638 compile error (#3212) * Add TM1638 switch support (#2226) * Fix invalid response using more than 4 switches and domoticz @@ -25,6 +27,10 @@ * Add debug facilities using optional xdrv_99_debug.ino to enable in user_config.h * Remove not needed functionality from Sonoff-minimal to save space * + * 6.1.1 20180714 + * Revert wifi changes (#3177) + * Revert sonoff-minimal removals causing failure of wifi connection (#3177) + * * 6.1.0 20180706 * Remove version 3, 4 and pre 5.2 settings auto-upgrade. See https://github.com/arendst/Sonoff-Tasmota/wiki/Upgrade#migration-path * Change default CFG_HOLDER from 0x20161209 to 4617 (=0x1209) - no impact on default upgrades diff --git a/sonoff/i18n.h b/sonoff/i18n.h index 736e4290499a..fc91c0d8ed9c 100644 --- a/sonoff/i18n.h +++ b/sonoff/i18n.h @@ -215,6 +215,7 @@ #define D_WCFG_3_WPSCONFIG "WPSConfig" #define D_WCFG_4_RETRY "Retry" #define D_WCFG_5_WAIT "Wait" + #define D_WCFG_6_SERIAL "Serial" #define D_CMND_FRIENDLYNAME "FriendlyName" #define D_CMND_SWITCHMODE "SwitchMode" #define D_CMND_TELEPERIOD "TelePeriod" @@ -499,7 +500,8 @@ const char kWifiConfig[MAX_WIFI_OPTION][WCFG_MAX_STRING_LENGTH] PROGMEM = { D_WCFG_2_WIFIMANAGER, D_WCFG_3_WPSCONFIG, D_WCFG_4_RETRY, - D_WCFG_5_WAIT }; + D_WCFG_5_WAIT, + D_WCFG_6_SERIAL }; const char kPrefixes[3][PRFX_MAX_STRING_LENGTH] PROGMEM = { D_CMND, D_STAT, diff --git a/sonoff/sonoff.h b/sonoff/sonoff.h index 03a459a4e88e..1a2e6f8af4a1 100644 --- a/sonoff/sonoff.h +++ b/sonoff/sonoff.h @@ -173,7 +173,7 @@ enum GetDateAndTimeOptions { DT_LOCAL, DT_UTC, DT_RESTART, DT_UPTIME }; enum LoggingLevels {LOG_LEVEL_NONE, LOG_LEVEL_ERROR, LOG_LEVEL_INFO, LOG_LEVEL_DEBUG, LOG_LEVEL_DEBUG_MORE, LOG_LEVEL_ALL}; -enum WifiConfigOptions {WIFI_RESTART, WIFI_SMARTCONFIG, WIFI_MANAGER, WIFI_WPSCONFIG, WIFI_RETRY, WIFI_WAIT, MAX_WIFI_OPTION}; +enum WifiConfigOptions {WIFI_RESTART, WIFI_SMARTCONFIG, WIFI_MANAGER, WIFI_WPSCONFIG, WIFI_RETRY, WIFI_WAIT, WIFI_SERIAL, MAX_WIFI_OPTION}; enum SwitchModeOptions {TOGGLE, FOLLOW, FOLLOW_INV, PUSHBUTTON, PUSHBUTTON_INV, PUSHBUTTONHOLD, PUSHBUTTONHOLD_INV, PUSHBUTTON_TOGGLE, MAX_SWITCH_OPTION}; diff --git a/sonoff/sonoff.ino b/sonoff/sonoff.ino index 24c3c9ef15e7..3bb37c5e6d8b 100644 --- a/sonoff/sonoff.ino +++ b/sonoff/sonoff.ino @@ -25,7 +25,7 @@ - Select IDE Tools - Flash Size: "1M (no SPIFFS)" ====================================================*/ -#define VERSION 0x06010101 // 6.1.1a +#define VERSION 0x06010102 // 6.1.1b // Location specific includes #include // Arduino_Esp8266 version information (ARDUINO_ESP8266_RELEASE and ARDUINO_ESP8266_RELEASE_2_3_0) @@ -992,7 +992,7 @@ void MqttDataHandler(char* topic, byte* data, unsigned int data_len) } else if ((CMND_SSID == command_code) && (index > 0) && (index <= 2)) { if ((data_len > 0) && (data_len < sizeof(Settings.sta_ssid[0]))) { - strlcpy(Settings.sta_ssid[index -1], (1 == payload) ? (1 == index) ? STA_SSID1 : STA_SSID2 : dataBuf, sizeof(Settings.sta_ssid[0])); + strlcpy(Settings.sta_ssid[index -1], (!strcmp(dataBuf,"0")) ? "" : (1 == payload) ? (1 == index) ? STA_SSID1 : STA_SSID2 : dataBuf, sizeof(Settings.sta_ssid[0])); Settings.sta_active = index -1; restart_flag = 2; } @@ -1000,7 +1000,7 @@ void MqttDataHandler(char* topic, byte* data, unsigned int data_len) } else if ((CMND_PASSWORD == command_code) && (index > 0) && (index <= 2)) { if ((data_len > 0) && (data_len < sizeof(Settings.sta_pwd[0]))) { - strlcpy(Settings.sta_pwd[index -1], (1 == payload) ? (1 == index) ? STA_PASS1 : STA_PASS2 : dataBuf, sizeof(Settings.sta_pwd[0])); + strlcpy(Settings.sta_pwd[index -1], (!strcmp(dataBuf,"0")) ? "" : (1 == payload) ? (1 == index) ? STA_PASS1 : STA_PASS2 : dataBuf, sizeof(Settings.sta_pwd[0])); Settings.sta_active = index -1; restart_flag = 2; snprintf_P(mqtt_data, sizeof(mqtt_data), S_JSON_COMMAND_INDEX_SVALUE, command, index, Settings.sta_pwd[index -1]); diff --git a/sonoff/sonoff_post.h b/sonoff/sonoff_post.h index 4f8f9a19db93..929d95558c5b 100644 --- a/sonoff/sonoff_post.h +++ b/sonoff/sonoff_post.h @@ -168,6 +168,7 @@ void KNX_CB_Action(message_t const &msg, void *arg); #undef USE_ENERGY_SENSOR // Disable energy sensors #undef USE_ARDUINO_OTA // Disable support for Arduino OTA #undef USE_WPS // Disable support for WPS as initial wifi configuration tool +#undef USE_SMARTCONFIG // Disable support for Wifi SmartConfig as initial wifi configuration tool #undef USE_DOMOTICZ // Disable Domoticz #undef USE_HOME_ASSISTANT // Disable Home Assistant #undef USE_MQTT_TLS // Disable TLS support won't work as the MQTTHost is not set diff --git a/sonoff/support.ino b/sonoff/support.ino index 5dcd676a0310..4930f8e4b221 100644 --- a/sonoff/support.ino +++ b/sonoff/support.ino @@ -735,6 +735,12 @@ void GetFeatures() #ifdef USE_KNX feature_drv1 |= 0x10000000; // xdrv_11_knx.ino #endif +#ifdef USE_WPS + feature_drv1 |= 0x20000000; // support.ino +#endif +#ifdef USE_SMARTCONFIG + feature_drv1 |= 0x40000000; // support.ino +#endif /*********************************************************************************************/ @@ -954,52 +960,48 @@ boolean WifiWpsConfigDone(void) boolean WifiWpsConfigBegin(void) { wps_result = 99; - if (!wifi_wps_disable()) { - return false; - } - if (!wifi_wps_enable(WPS_TYPE_PBC)) { - return false; // so far only WPS_TYPE_PBC is supported (SDK 2.0.0) - } - if (!wifi_set_wps_cb((wps_st_cb_t) &WifiWpsStatusCallback)) { - return false; - } - if (!wifi_wps_start()) { - return false; - } + if (!wifi_wps_disable()) { return false; } + if (!wifi_wps_enable(WPS_TYPE_PBC)) { return false; } // so far only WPS_TYPE_PBC is supported (SDK 2.0.0) + if (!wifi_set_wps_cb((wps_st_cb_t) &WifiWpsStatusCallback)) { return false; } + if (!wifi_wps_start()) { return false; } return true; } void WifiConfig(uint8_t type) { if (!wifi_config_type) { - if (type >= WIFI_RETRY) { // WIFI_RETRY and WIFI_WAIT - return; - } + if ((WIFI_RETRY == type) || (WIFI_WAIT == type)) { return; } #if defined(USE_WEBSERVER) && defined(USE_EMULATION) UdpDisconnect(); #endif // USE_EMULATION - WiFi.disconnect(); // Solve possible Wifi hangs + WiFi.disconnect(); // Solve possible Wifi hangs wifi_config_type = type; + #ifndef USE_WPS - if (WIFI_WPSCONFIG == wifi_config_type) { - wifi_config_type = WIFI_MANAGER; - } + if (WIFI_WPSCONFIG == wifi_config_type) { wifi_config_type = WIFI_MANAGER; } #endif // USE_WPS #ifndef USE_WEBSERVER - if (WIFI_MANAGER == wifi_config_type) { - wifi_config_type = WIFI_SMARTCONFIG; - } + if (WIFI_MANAGER == wifi_config_type) { wifi_config_type = WIFI_SMARTCONFIG; } #endif // USE_WEBSERVER +#ifndef USE_SMARTCONFIG + if (WIFI_SMARTCONFIG == wifi_config_type) { wifi_config_type = WIFI_SERIAL; } +#endif // USE_SMARTCONFIG + wifi_config_counter = WIFI_CONFIG_SEC; // Allow up to WIFI_CONFIG_SECS seconds for phone to provide ssid/pswd wifi_counter = wifi_config_counter +5; blinks = 1999; if (WIFI_RESTART == wifi_config_type) { restart_flag = 2; } + else if (WIFI_SERIAL == wifi_config_type) { + AddLog_P(LOG_LEVEL_INFO, S_LOG_WIFI, PSTR(D_WCFG_6_SERIAL " " D_ACTIVE_FOR_3_MINUTES)); + } +#ifdef USE_SMARTCONFIG else if (WIFI_SMARTCONFIG == wifi_config_type) { AddLog_P(LOG_LEVEL_INFO, S_LOG_WIFI, PSTR(D_WCFG_1_SMARTCONFIG " " D_ACTIVE_FOR_3_MINUTES)); WiFi.beginSmartConfig(); } +#endif // USE_SMARTCONFIG #ifdef USE_WPS else if (WIFI_WPSCONFIG == wifi_config_type) { if (WifiWpsConfigBegin()) { @@ -1035,17 +1037,11 @@ void WifiBegin(uint8_t flag) WiFi.disconnect(true); // Delete SDK wifi config delay(200); WiFi.mode(WIFI_STA); // Disable AP mode - if (Settings.sleep) { -#ifndef ARDUINO_ESP8266_RELEASE_2_4_1 // See https://github.com/arendst/Sonoff-Tasmota/issues/2559 - WiFi.setSleepMode(WIFI_LIGHT_SLEEP); // Allow light sleep during idle times +#ifndef ARDUINO_ESP8266_RELEASE_2_4_1 // See https://github.com/arendst/Sonoff-Tasmota/issues/2559 - Sleep bug + if (Settings.sleep) { WiFi.setSleepMode(WIFI_LIGHT_SLEEP); } // Allow light sleep during idle times #endif - } -// if (WiFi.getPhyMode() != WIFI_PHY_MODE_11N) { -// WiFi.setPhyMode(WIFI_PHY_MODE_11N); -// } - if (!WiFi.getAutoConnect()) { - WiFi.setAutoConnect(true); - } +// if (WiFi.getPhyMode() != WIFI_PHY_MODE_11N) { WiFi.setPhyMode(WIFI_PHY_MODE_11N); } + if (!WiFi.getAutoConnect()) { WiFi.setAutoConnect(true); } // WiFi.setAutoReconnect(true); switch (flag) { case 0: // AP1 @@ -1055,9 +1051,7 @@ void WifiBegin(uint8_t flag) case 2: // Toggle Settings.sta_active ^= 1; } // 3: Current AP - if (0 == strlen(Settings.sta_ssid[1])) { - Settings.sta_active = 0; - } + if ('\0' == Settings.sta_ssid[Settings.sta_active][0]) { Settings.sta_active ^= 1; } // Skip empty SSID if (Settings.ip_address[0]) { WiFi.config(Settings.ip_address[0], Settings.ip_address[1], Settings.ip_address[2], Settings.ip_address[3]); // Set static IP } @@ -1084,6 +1078,7 @@ void WifiCheckIp() wifi_status = WL_CONNECTED; } else { global_state.wifi_down = 1; + uint8_t wifi_config_tool = Settings.sta_config; wifi_status = WiFi.status(); switch (wifi_status) { case WL_CONNECTED: @@ -1117,7 +1112,12 @@ void WifiCheckIp() if (!wifi_retry || ((wifi_retry_init / 2) == wifi_retry)) { AddLog_P(LOG_LEVEL_INFO, S_LOG_WIFI, PSTR(D_CONNECT_FAILED_AP_TIMEOUT)); } else { - AddLog_P(LOG_LEVEL_DEBUG, S_LOG_WIFI, PSTR(D_ATTEMPTING_CONNECTION)); + if (('\0' == Settings.sta_ssid[0][0]) && ('\0' == Settings.sta_ssid[1][0])) { + wifi_config_tool = WIFI_CONFIG_NO_SSID; // Skip empty SSIDs and start Wifi config tool + wifi_retry = 0; + } else { + AddLog_P(LOG_LEVEL_DEBUG, S_LOG_WIFI, PSTR(D_ATTEMPTING_CONNECTION)); + } } } if (wifi_retry) { @@ -1130,7 +1130,7 @@ void WifiCheckIp() wifi_counter = 1; wifi_retry--; } else { - WifiConfig(Settings.sta_config); + WifiConfig(wifi_config_tool); wifi_counter = 1; wifi_retry = wifi_retry_init; } @@ -1141,6 +1141,7 @@ void WifiCheck(uint8_t param) { wifi_counter--; switch (param) { + case WIFI_SERIAL: case WIFI_SMARTCONFIG: case WIFI_MANAGER: case WIFI_WPSCONFIG: @@ -1151,9 +1152,11 @@ void WifiCheck(uint8_t param) wifi_config_counter--; wifi_counter = wifi_config_counter +5; if (wifi_config_counter) { +#ifdef USE_SMARTCONFIG if ((WIFI_SMARTCONFIG == wifi_config_type) && WiFi.smartConfigDone()) { wifi_config_counter = 0; } +#endif // USE_SMARTCONFIG #ifdef USE_WPS if ((WIFI_WPSCONFIG == wifi_config_type) && WifiWpsConfigDone()) { wifi_config_counter = 0; @@ -1172,9 +1175,9 @@ void WifiCheck(uint8_t param) } } if (!wifi_config_counter) { - if (WIFI_SMARTCONFIG == wifi_config_type) { - WiFi.stopSmartConfig(); - } +#ifdef USE_SMARTCONFIG + if (WIFI_SMARTCONFIG == wifi_config_type) { WiFi.stopSmartConfig(); } +#endif // USE_SMARTCONFIG // SettingsSdkErase(); // Disabled v6.1.0b due to possible bad wifi connects restart_flag = 2; } @@ -1211,9 +1214,7 @@ void WifiCheck(uint8_t param) StopWebserver(); } #ifdef USE_EMULATION - if (Settings.flag2.emulation) { - UdpConnect(); - } + if (Settings.flag2.emulation) { UdpConnect(); } #endif // USE_EMULATION #endif // USE_WEBSERVER #ifdef USE_KNX @@ -1243,9 +1244,7 @@ int WifiState() if ((WL_CONNECTED == WiFi.status()) && (static_cast(WiFi.localIP()) != 0)) { state = WIFI_RESTART; } - if (wifi_config_type) { - state = wifi_config_type; - } + if (wifi_config_type) { state = wifi_config_type; } return state; } diff --git a/sonoff/user_config.h b/sonoff/user_config.h index c9575b126dbf..e1deca826ac3 100644 --- a/sonoff/user_config.h +++ b/sonoff/user_config.h @@ -63,9 +63,13 @@ #define STA_PASS1 "" // [Password1] Wifi password #define STA_SSID2 "" // [Ssid2] Optional alternate AP Wifi SSID #define STA_PASS2 "" // [Password2] Optional alternate AP Wifi password -#define WIFI_CONFIG_TOOL WIFI_WPSCONFIG // [WifiConfig] Default tool if wifi fails to connect - // (WIFI_RESTART, WIFI_SMARTCONFIG, WIFI_MANAGER, WIFI_WPSCONFIG, WIFI_RETRY, WIFI_WAIT) +#define WIFI_CONFIG_TOOL WIFI_WAIT // [WifiConfig] Default tool if wifi fails to connect + // (WIFI_RESTART, WIFI_SMARTCONFIG, WIFI_MANAGER, WIFI_WPSCONFIG, WIFI_RETRY, WIFI_WAIT, WIFI_SERIAL) +#define WIFI_CONFIG_NO_SSID WIFI_WPSCONFIG // [WifiConfig] Default tool if wifi fails to connect and no SSID is configured + // (WIFI_SMARTCONFIG, WIFI_MANAGER, WIFI_WPSCONFIG, WIFI_SERIAL) // *** NOTE: When WPS is disabled by USE_WPS below, WIFI_WPSCONFIG will execute WIFI_MANAGER *** + // *** NOTE: When WIFI_MANAGER is disabled by USE_WEBSERVER below, WIFI_MANAGER will execute WIFI_SMARTCONFIG *** + // *** NOTE: When WIFI_SMARTCONFIG is disabled by USE_SMARTCONFIG below, WIFI_SMARTCONFIG will execute WIFI_SERIAL *** // -- Syslog -------------------------------------- #define SYS_LOG_HOST "" // [LogHost] (Linux) syslog host @@ -201,6 +205,7 @@ // -- WPS ----------------------------------------- //#define USE_WPS // Add support for WPS as initial wifi configuration tool (+33k code, 1k mem (5k mem with core v2.4.2+)) +//#define USE_SMARTCONFIG // Add support for Wifi SmartConfig as initial wifi configuration tool (+23k code, +0.6k mem) // -- OTA ----------------------------------------- //#define USE_ARDUINO_OTA // Add optional support for Arduino OTA (+13k code) @@ -235,7 +240,7 @@ //#define USE_KNX // Enable KNX IP Protocol Support (+23k code, +3k3 mem) // -- HTTP ---------------------------------------- -#define USE_WEBSERVER // Enable web server and wifi manager (+66k code, +8k mem) +#define USE_WEBSERVER // Enable web server and Wifi Manager (+66k code, +8k mem) #define WEB_PORT 80 // Web server Port for User and Admin mode #define WEB_USERNAME "admin" // Web server Admin mode user name #define USE_EMULATION // Enable Belkin WeMo and Hue Bridge emulation for Alexa (+16k code, +2k mem)