Page 1 of 1

Wifi can't connect with ssid loaded from file.(NO_AP_FOUND)

Posted: Tue May 15, 2018 12:36 pm
by euripedes
I'm trying to solve a strange issue.

When the ssid and password are configured at compile time, the connection work. When the SSID is set from a file the connection fails with a 201 - NO_AP_FOUND. I can reproduce the problem here using the simple_wifi example. changing it to:

Code: Select all

  
  wifi_config_t wifi_config;
  memcpy(wifi_config.sta.ssid, ssid, sizeof(wifi_config.sta.ssid));
  memcpy(wifi_config.sta.password, password, sizeof(wifi_config.sta.password));
Both ssid and password are globals defined as:

Code: Select all

static const char ssid[] = "MySSID";
static const char password[]= "MyPassword";
The event handler needs to be modified to LOG the disconnect reason also.

The example works fine without the modification.
I couldn't figure out the issue in the code above.

Re: Wifi can't connect with ssid loaded from file.(NO_AP_FOUND)

Posted: Fri May 18, 2018 12:38 pm
by S3BDEV
Hello
Similar problem for me ( random )
But only after I force to pass to STA_MODE

Code: Select all

const int lengthBufferWifi = 35;
char bufferTxtSSID[lengthBufferWifi];
char bufferTxtPASS[lengthBufferWifi];

if ((WiFi.getMode() != WIFI_STA))
{
      WiFi.disconnect();
      delay(100);
      WiFi.mode(WIFI_STA);
      delay(100);
}
if (WiFi.status() != WL_CONNECTED) 
{
	WiFi.begin(bufferTxtSSID,bufferTxtPASS);
}
and resolved with (const char*) cast:

Code: Select all

WiFi.begin((const char*)bufferTxtSSID,(const char*)bufferTxtPASS);

Re: Wifi can't connect with ssid loaded from file.(NO_AP_FOUND)

Posted: Mon May 21, 2018 4:32 pm
by euripedes
I don't understand why the cast solves the issue for you, but I'm glad it worked.

I'm using memcpy there and it's parameters are void*. The arduino-esp32(which I believe you are using) use strcpy, hence the char * method interface.

The cast itself, shouldn't be a source of trouble since all expected char are in the char/unsigned char range(please someone correct me If I'm wrong, signed/unsigned rules in C are confusing).

I've made a lot of changes and actually verified the config using esp_wifi_get_config. Both SSID and password are correct.

Re: Wifi can't connect with ssid loaded from file.(NO_AP_FOUND)

Posted: Tue May 22, 2018 5:13 pm
by euripedes
Solving my own problem:
The issue was that the config has other parameters and they need to be correctly seted.
Providing the correct values solved the issue. Seems that for the other parameters by zeroizing the union is enough. I had to set the scan for all channels and after that the connection works.

Re: Wifi can't connect with ssid loaded from file.(NO_AP_FOUND)

Posted: Tue May 22, 2018 8:50 pm
by fly135

Code: Select all

wifi_config_t wifi_config;
  memcpy(wifi_config.sta.ssid, ssid, sizeof(wifi_config.sta.ssid));
  memcpy(wifi_config.sta.password, password, sizeof(wifi_config.sta.password));
This code doesn't put a terminating zero on the strings.

John A

Re: Wifi can't connect with ssid loaded from file.(NO_AP_FOUND)

Posted: Sun Feb 25, 2024 10:09 am
by woolstrand
In my case the reason was carriage return symbols in file. The file was created with "\r\n"s at the end of each line, and while newlines were visible in console when I printed strings for comparison, carriage returns were not visible. So they slipped through and made that difference between hardcoded data and data read from file.