Add quick wifi connect using saved AP parameters

Add quick wifi connect using saved AP parameters when ``SetOption56 0`` (#3189)
This commit is contained in:
Theo Arends 2020-04-07 12:19:54 +02:00
parent ffa694f80a
commit 05af60074f
4 changed files with 14 additions and 2 deletions

View File

@ -72,3 +72,4 @@ The following binary downloads have been compiled with ESP8266/Arduino library c
- Add support for up to four MQTT GroupTopics using the same optional Device Group names (#8014) - Add support for up to four MQTT GroupTopics using the same optional Device Group names (#8014)
- Add console command history (#7483, #8015) - Add console command history (#7483, #8015)
- Add support for longer template names - Add support for longer template names
- Add quick wifi connect using saved AP parameters when ``SetOption56 0`` (#3189)

View File

@ -12,6 +12,7 @@
- Add command ``Sensor10 0/1/2`` to control BH1750 resolution - 0 = High (default), 1 = High2, 2 = Low (#8016) - Add command ``Sensor10 0/1/2`` to control BH1750 resolution - 0 = High (default), 1 = High2, 2 = Low (#8016)
- Add command ``Sensor10 31..254`` to control BH1750 measurement time which defaults to 69 (#8016) - Add command ``Sensor10 31..254`` to control BH1750 measurement time which defaults to 69 (#8016)
- Add command ``SetOption91 1`` to enable fading at startup / power on - Add command ``SetOption91 1`` to enable fading at startup / power on
- Add quick wifi connect using saved AP parameters when ``SetOption56 0`` (#3189)
### 8.2.0.2 20200328 ### 8.2.0.2 20200328

View File

@ -470,8 +470,10 @@ struct SYSCFG {
uint8_t bri_preset_low; // F06 uint8_t bri_preset_low; // F06
uint8_t bri_preset_high; // F07 uint8_t bri_preset_high; // F07
int8_t hum_comp; // F08 int8_t hum_comp; // F08
uint8_t channel; // F09
uint8_t bssid[6]; // F0A
uint8_t free_f09[175]; // F09 uint8_t free_f10[168]; // F10
uint16_t pulse_counter_debounce_low; // FB8 uint16_t pulse_counter_debounce_low; // FB8
uint16_t pulse_counter_debounce_high; // FBA uint16_t pulse_counter_debounce_high; // FBA

View File

@ -401,6 +401,11 @@ void WifiCheckIp(void)
Settings.ip_address[1] = (uint32_t)WiFi.gatewayIP(); Settings.ip_address[1] = (uint32_t)WiFi.gatewayIP();
Settings.ip_address[2] = (uint32_t)WiFi.subnetMask(); Settings.ip_address[2] = (uint32_t)WiFi.subnetMask();
Settings.ip_address[3] = (uint32_t)WiFi.dnsIP(); Settings.ip_address[3] = (uint32_t)WiFi.dnsIP();
// Save current AP parameters for quick reconnect
Settings.channel = WiFi.channel();
uint8_t *bssid = WiFi.BSSID();
memcpy((void*) &Settings.bssid, (void*) bssid, sizeof(Settings.bssid));
} }
Wifi.status = WL_CONNECTED; Wifi.status = WL_CONNECTED;
#ifdef USE_DISCOVERY #ifdef USE_DISCOVERY
@ -423,6 +428,7 @@ void WifiCheckIp(void)
break; break;
case WL_NO_SSID_AVAIL: case WL_NO_SSID_AVAIL:
AddLog_P(LOG_LEVEL_INFO, S_LOG_WIFI, PSTR(D_CONNECT_FAILED_AP_NOT_REACHED)); AddLog_P(LOG_LEVEL_INFO, S_LOG_WIFI, PSTR(D_CONNECT_FAILED_AP_NOT_REACHED));
Settings.channel = 0; // Disable stored AP
if (WIFI_WAIT == Settings.sta_config) { if (WIFI_WAIT == Settings.sta_config) {
Wifi.retry = Wifi.retry_init; Wifi.retry = Wifi.retry_init;
} else { } else {
@ -462,7 +468,7 @@ void WifiCheckIp(void)
} }
} else { } else {
if (Wifi.retry_init == Wifi.retry) { if (Wifi.retry_init == Wifi.retry) {
WifiBegin(3, 0); // Select default SSID WifiBegin(3, Settings.channel); // Select default SSID
} }
if ((Settings.sta_config != WIFI_WAIT) && ((Wifi.retry_init / 2) == Wifi.retry)) { if ((Settings.sta_config != WIFI_WAIT) && ((Wifi.retry_init / 2) == Wifi.retry)) {
WifiBegin(2, 0); // Select alternate SSID WifiBegin(2, 0); // Select alternate SSID
@ -650,6 +656,8 @@ void WifiConnect(void)
Wifi.retry = Wifi.retry_init; Wifi.retry = Wifi.retry_init;
Wifi.counter = 1; Wifi.counter = 1;
memcpy((void*) &Wifi.bssid, (void*) Settings.bssid, sizeof(Wifi.bssid));
#ifdef WIFI_RF_PRE_INIT #ifdef WIFI_RF_PRE_INIT
if (rf_pre_init_flag) { if (rf_pre_init_flag) {
AddLog_P2(LOG_LEVEL_DEBUG, PSTR(D_LOG_WIFI "Pre-init done")); AddLog_P2(LOG_LEVEL_DEBUG, PSTR(D_LOG_WIFI "Pre-init done"));