Skip to content

Commit

Permalink
v6.6.1b - Change wifi options
Browse files Browse the repository at this point in the history
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
  • Loading branch information
arendst committed Jul 15, 2018
1 parent f75ab4f commit afdb197
Show file tree
Hide file tree
Showing 8 changed files with 74 additions and 61 deletions.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -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:
Expand Down
18 changes: 12 additions & 6 deletions 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
Expand All @@ -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
Expand Down
4 changes: 3 additions & 1 deletion sonoff/i18n.h
Expand Up @@ -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"
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion sonoff/sonoff.h
Expand Up @@ -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};

Expand Down
6 changes: 3 additions & 3 deletions sonoff/sonoff.ino
Expand Up @@ -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 <core_version.h> // Arduino_Esp8266 version information (ARDUINO_ESP8266_RELEASE and ARDUINO_ESP8266_RELEASE_2_3_0)
Expand Down Expand Up @@ -992,15 +992,15 @@ 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;
}
snprintf_P(mqtt_data, sizeof(mqtt_data), S_JSON_COMMAND_INDEX_SVALUE, command, index, Settings.sta_ssid[index -1]);
}
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]);
Expand Down
1 change: 1 addition & 0 deletions sonoff/sonoff_post.h
Expand Up @@ -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
Expand Down
91 changes: 45 additions & 46 deletions sonoff/support.ino
Expand Up @@ -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

/*********************************************************************************************/

Expand Down Expand Up @@ -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()) {
Expand Down Expand Up @@ -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
Expand All @@ -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
}
Expand All @@ -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:
Expand Down Expand Up @@ -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) {
Expand All @@ -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;
}
Expand All @@ -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:
Expand All @@ -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;
Expand All @@ -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;
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -1243,9 +1244,7 @@ int WifiState()
if ((WL_CONNECTED == WiFi.status()) && (static_cast<uint32_t>(WiFi.localIP()) != 0)) {
state = WIFI_RESTART;
}
if (wifi_config_type) {
state = wifi_config_type;
}
if (wifi_config_type) { state = wifi_config_type; }
return state;
}

Expand Down
11 changes: 8 additions & 3 deletions sonoff/user_config.h
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit afdb197

Please sign in to comment.