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

euripedes
Posts: 7
Joined: Tue May 15, 2018 12:04 pm

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

Postby euripedes » Tue May 15, 2018 12:36 pm

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.

S3BDEV
Posts: 1
Joined: Fri May 18, 2018 12:31 pm

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

Postby S3BDEV » Fri May 18, 2018 12:38 pm

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);

euripedes
Posts: 7
Joined: Tue May 15, 2018 12:04 pm

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

Postby euripedes » Mon May 21, 2018 4:32 pm

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.

euripedes
Posts: 7
Joined: Tue May 15, 2018 12:04 pm

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

Postby euripedes » Tue May 22, 2018 5:13 pm

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.

User avatar
fly135
Posts: 606
Joined: Wed Jan 03, 2018 8:33 pm
Location: Orlando, FL

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

Postby fly135 » Tue May 22, 2018 8:50 pm

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

woolstrand
Posts: 1
Joined: Sun Feb 25, 2024 9:47 am

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

Postby woolstrand » Sun Feb 25, 2024 10:09 am

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.

Who is online

Users browsing this forum: Baidu [Spider] and 457 guests