Arduino icon indicating copy to clipboard operation
Arduino copied to clipboard

Problem with Wifi persistent connection

Open uhfband opened this issue 2 years ago • 1 comments

Basic Infos

  • [x] This issue complies with the issue POLICY doc.
  • [x] I have read the documentation at readthedocs and the issue is not addressed there.
  • [ ] I have tested that the issue is present in current master branch (aka latest git).
  • [x] I have searched the issue tracker for a similar issue.
  • [ ] If there is a stack dump, I have decoded it.
  • [x] I have filled out all fields below.

Platform

  • Hardware: [ESP-07]
  • Core Version: [3.1.1/NONOSDK22x_191122 ]
  • Development Env: [Arduino IDE]
  • Operating System: [Windows]

Settings in IDE

  • Module: [Generic ESP8266 Module]
  • Flash Mode: [dout]
  • Flash Size: [1MB]
  • lwip Variant: [v2 Lower Memory]
  • Reset Method: [dtr]
  • Flash Frequency: [40Mhz]
  • CPU Frequency: [80Mhz]
  • Upload Using: [SERIAL]
  • Upload Speed: [115200)

Problem Description

Wifi persistent connection option did not work for me, each reconnection took a long time (4500 ms). I started debugging and found that threshold property does not preserved when station config saved to flash then loaded.

Sketch

#include "ESP8266WiFi.h"

void setup() {
  Serial.begin(115200);
  
  struct station_config conf;

  strcpy((char*)conf.ssid, "testAP");
  strcpy((char*)conf.password, "password");
  conf.bssid_set = 0;
  conf.threshold.authmode = AUTH_WPA_PSK;
  conf.threshold.rssi = -127;

  WiFi.persistent(true);
  WiFi.mode(WIFI_STA);
  int res = wifi_station_set_config(&conf);

  memset(&conf, 0, sizeof(station_config));
  
  wifi_station_get_config_default(&conf);

  Serial.print("\r\n");
  Serial.printf(PSTR("  ssid:      %s\n"), conf.ssid);
  Serial.printf(PSTR("  password:  %s\n"), conf.password);
  Serial.printf(PSTR("  bssid_set: %d\n"), conf.bssid_set);
  Serial.printf(PSTR("  bssid:     %02x:%02x:%02x:%02x:%02x\n"), 
       conf.bssid[0], conf.bssid[1], conf.bssid[2],
       conf.bssid[3], conf.bssid[4], conf.bssid[5]);
  Serial.printf(PSTR("  threshold.rssi: %d\n"), conf.threshold.rssi);
  Serial.printf(PSTR("  threshold.authmode: %d\n"), (uint8_t)conf.threshold.authmode);

}

void loop() {
  // put your main code here, to run repeatedly:

}

Debug Messages

  ssid:      testAP
  password:  password
  bssid_set: 0
  bssid:     21:66:d8:15:8c
  threshold.rssi: 0
  threshold.authmode: 0

For this reason next code always return false https://github.com/esp8266/Arduino/blob/badb407bbb7f6dec18d4dd7fd83785b88ec7e6f2/libraries/ESP8266WiFi/src/ESP8266WiFiSTA.cpp#L89-L95

I commented out this lines, and it worked as it should, reconnection become much faster (700ms). Is it bug, SDK issue, or my environment settings problem?

uhfband avatar Feb 05 '23 10:02 uhfband

Argument-less WiFi.begin() can be used instead, which won't compare existing settings? But, the issue is there, that's true. Threshold should not be compared if it is not comparable

mcspr avatar Mar 20 '23 22:03 mcspr