Connection to Access Point.
Posted: Wed Nov 10, 2021 1:57 am
At esp8266 start up it tries to connect to Access Point.
Sometimes it takes a reasonable amount of time - 6-10 seconds. Sometimes it takes 30-60 seconds. Sometimes it gets out on timeout with status
WL_CONNECT_FAILED
WL_NO_SSID_AVAIL
When it's WL_NO_SSID_AVAIL I do WiFi.scanNetworks() and see my Access Point.
How can I improve the situation?
Code: Select all
uint8_t UDP_Start(char* ssid, char* pass, uint16_t loc_port)
{
uint32_t timeout = 0;
if (WiFi.status() != WL_CONNECTED)
{
rt_parameters.wifi_mode = WIFI_STA;
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, pass);
if (sys_parameters.debug)
Serial.println("Waiting for connection");
while (WiFi.status() != WL_CONNECTED)
{
delay(DELAY_TICK);
if (sys_parameters.debug)
Serial.print('.');
timeout++;
if (timeout >= sys_parameters.ap_con_timeout)
{
if (sys_parameters.debug)
Serial.println();
return UDP_WIFI_ERR;
}
}
Serial.print("\nConnection time (ms) ");
Serial.println(DELAY_TICK * timeout);
}
rt_parameters.wifi_status = WiFi.status();
IPAddress ip_addr = WiFi.localIP();
memcpy(sys_parameters.loc_ip, ip_addr, 4);
if (sys_parameters.debug)
{
Serial.print("Connected! IP address: ");
Serial.println(ip_addr);
Serial.printf("UDP server on port %d\n", loc_port);
}
if (udp.begin(loc_port) == 0)
return UDP_CONNECT_ERR;
return UDP_OK;
}
Sometimes it takes a reasonable amount of time - 6-10 seconds. Sometimes it takes 30-60 seconds. Sometimes it gets out on timeout with status
WL_CONNECT_FAILED
WL_NO_SSID_AVAIL
When it's WL_NO_SSID_AVAIL I do WiFi.scanNetworks() and see my Access Point.
How can I improve the situation?