Skip to content

Commit

Permalink
v5.12.0e - Add wifi Retry time offset
Browse files Browse the repository at this point in the history
5.12.0e
 * Add additional time offset to Wifi Retry based on device mac
address (#2089)
  • Loading branch information
arendst committed Mar 11, 2018
1 parent 4063275 commit ad40a85
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 16 deletions.
1 change: 1 addition & 0 deletions sonoff/_releasenotes.ino
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/* 5.12.0e
* Add additional time offset to Wifi Retry based on device mac address (#2089)
* Add a second TLS fingerprint to allow switching keys in TLS mode (#2033, #2102)
* Add HTML language header in local language (#2123)
* Add commands Color6 RRGGBB for Clock marker color and Rotation pixels for Clock rotation (#2092)
Expand Down
34 changes: 18 additions & 16 deletions sonoff/support.ino
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ Decoding 14 results
0x4021ffb4: snprintf_P(char*, unsigned int, char const*, ...) at C:\Data2\Arduino\arduino-1.8.1-esp-2.3.0\portable\packages\esp8266\hardware\esp8266\2.3.0\cores\esp8266/pgmspace.cpp line 146
0x40201118: atol at C:\Data2\Arduino\arduino-1.8.1-esp-2.3.0\portable\packages\esp8266\hardware\esp8266\2.3.0\cores\esp8266/core_esp8266_noniso.c line 45
0x40201128: atoi at C:\Data2\Arduino\arduino-1.8.1-esp-2.3.0\portable\packages\esp8266\hardware\esp8266\2.3.0\cores\esp8266/core_esp8266_noniso.c line 45
0x4020fafb: MqttDataCallback(char*, unsigned char*, unsigned int) at R:\Arduino\Work-ESP8266\Theo\sonoff\sonoff-4\sonoff/sonoff.ino line 679 (discriminator 1)
0x4020fafb: MqttDataHandler(char*, unsigned char*, unsigned int) at R:\Arduino\Work-ESP8266\Theo\sonoff\sonoff-4\sonoff/sonoff.ino line 679 (discriminator 1)
0x4022321b: pp_attach at ?? line ?
00:00:08 MQTT: tele/sonoff/INFO3 = {"Started":"Fatal exception:28 flag:2 (EXCEPTION) epc1:0x4000bf64 epc2:0x00000000 epc3:0x00000000 excvaddr:0x00000007 depc:0x00000000"}
Expand Down Expand Up @@ -427,11 +427,12 @@ uint32_t GetHash(const char *buffer, size_t size)
* Wifi
\*********************************************************************************************/

#define WIFI_CONFIG_SEC 180 // seconds before restart
#define WIFI_CHECK_SEC 20 // seconds
#define WIFI_RETRY_SEC 30 // seconds
#define WIFI_CONFIG_SEC 180 // seconds before restart
#define WIFI_CHECK_SEC 20 // seconds
#define WIFI_RETRY_OFFSET_SEC 20 // seconds

uint8_t wifi_counter;
uint8_t wifi_retry_init;
uint8_t wifi_retry;
uint8_t wifi_status;
uint8_t wps_result;
Expand Down Expand Up @@ -599,7 +600,7 @@ void WifiCheckIp()
{
if ((WL_CONNECTED == WiFi.status()) && (static_cast<uint32_t>(WiFi.localIP()) != 0)) {
wifi_counter = WIFI_CHECK_SEC;
wifi_retry = WIFI_RETRY_SEC;
wifi_retry = wifi_retry_init;
AddLog_P((wifi_status != WL_CONNECTED) ? LOG_LEVEL_INFO : LOG_LEVEL_DEBUG_MORE, S_LOG_WIFI, PSTR(D_CONNECTED));
if (wifi_status != WL_CONNECTED) {
// AddLog_P(LOG_LEVEL_INFO, PSTR("Wifi: Set IP addresses"));
Expand All @@ -614,15 +615,15 @@ void WifiCheckIp()
case WL_CONNECTED:
AddLog_P(LOG_LEVEL_INFO, S_LOG_WIFI, PSTR(D_CONNECT_FAILED_NO_IP_ADDRESS));
wifi_status = 0;
wifi_retry = WIFI_RETRY_SEC;
wifi_retry = wifi_retry_init;
break;
case WL_NO_SSID_AVAIL:
AddLog_P(LOG_LEVEL_INFO, S_LOG_WIFI, PSTR(D_CONNECT_FAILED_AP_NOT_REACHED));
if (WIFI_WAIT == Settings.sta_config) {
wifi_retry = WIFI_RETRY_SEC;
wifi_retry = wifi_retry_init;
} else {
if (wifi_retry > (WIFI_RETRY_SEC / 2)) {
wifi_retry = WIFI_RETRY_SEC / 2;
if (wifi_retry > (wifi_retry_init / 2)) {
wifi_retry = wifi_retry_init / 2;
}
else if (wifi_retry) {
wifi_retry = 0;
Expand All @@ -631,33 +632,33 @@ void WifiCheckIp()
break;
case WL_CONNECT_FAILED:
AddLog_P(LOG_LEVEL_INFO, S_LOG_WIFI, PSTR(D_CONNECT_FAILED_WRONG_PASSWORD));
if (wifi_retry > (WIFI_RETRY_SEC / 2)) {
wifi_retry = WIFI_RETRY_SEC / 2;
if (wifi_retry > (wifi_retry_init / 2)) {
wifi_retry = wifi_retry_init / 2;
}
else if (wifi_retry) {
wifi_retry = 0;
}
break;
default: // WL_IDLE_STATUS and WL_DISCONNECTED
if (!wifi_retry || ((WIFI_RETRY_SEC / 2) == wifi_retry)) {
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 (wifi_retry) {
if (WIFI_RETRY_SEC == wifi_retry) {
if (wifi_retry_init == wifi_retry) {
WifiBegin(3); // Select default SSID
}
if ((Settings.sta_config != WIFI_WAIT) && ((WIFI_RETRY_SEC / 2) == wifi_retry)) {
if ((Settings.sta_config != WIFI_WAIT) && ((wifi_retry_init / 2) == wifi_retry)) {
WifiBegin(2); // Select alternate SSID
}
wifi_counter = 1;
wifi_retry--;
} else {
WifiConfig(Settings.sta_config);
wifi_counter = 1;
wifi_retry = WIFI_RETRY_SEC;
wifi_retry = wifi_retry_init;
}
}
}
Expand Down Expand Up @@ -765,7 +766,8 @@ void WifiConnect()
{
WiFi.persistent(false); // Solve possible wifi init errors
wifi_status = 0;
wifi_retry = WIFI_RETRY_SEC;
wifi_retry_init = WIFI_RETRY_OFFSET_SEC + ((ESP.getChipId() & 0xF) * 2);
wifi_retry = wifi_retry_init;
wifi_counter = 1;
}

Expand Down

0 comments on commit ad40a85

Please sign in to comment.