WiFi w/ dynamic credentials

ankyankyanky
Posts: 2
Joined: Thu Aug 23, 2018 7:39 pm

WiFi w/ dynamic credentials

Postby ankyankyanky » Thu Aug 23, 2018 8:09 pm

I’m trying to figure out how to connect to an AP with credentials read from the flash storage. I’m new in C and is pretty much living on what is written in the examples. Unfortunately, all the examples are setting up WiFi with a wifi_config_t struct initialised with preprocessor directives like:

Code: Select all

wifi_config_t wifi_config = {
	.sta = {
		.ssid = EXAMPLE_ESP_WIFI_SSID,
		.password = EXAMPLE_ESP_WIFI_PASS
	},
};
How do I change this code to operate with non hardcoded values? I’ve tried to initialise with variables, and changing wifi_config with dot notation and strcpy but have been unsuccessful so far.

User avatar
kolban
Posts: 1683
Joined: Mon Nov 16, 2015 4:43 pm
Location: Texas, USA

Re: WiFi w/ dynamic credentials

Postby kolban » Fri Aug 24, 2018 4:46 pm

I think you are heading in the right lines. The wifi_config struct does have to be populated. If I remember correctly, the struct has fields called ssid and password. Both of these are arrays. What that means is that you have to copy in your desired SSID and Password.

Here is a loose example:

Code: Select all

char *ssid = "mySsid";
chat *password = "mypassword";

wifi_config_t wifi_config;
memset(wifi_config, 0, sizeof(wifi_config);
strcpy(wifi_config.sta.ssid, ssid);
strcpy(wifi_config.sta.password, password);
... rest of logic
Notice that the variables "ssid" and "password" contain your desired values which could have been read from NVS (Non volatile storage).
Free book on ESP32 available here: https://leanpub.com/kolban-ESP32

Ritesh
Posts: 1365
Joined: Tue Sep 06, 2016 9:37 am
Location: India
Contact:

Re: WiFi w/ dynamic credentials

Postby Ritesh » Mon Aug 27, 2018 6:23 pm

ankyankyanky wrote:I’m trying to figure out how to connect to an AP with credentials read from the flash storage. I’m new in C and is pretty much living on what is written in the examples. Unfortunately, all the examples are setting up WiFi with a wifi_config_t struct initialised with preprocessor directives like:

Code: Select all

wifi_config_t wifi_config = {
	.sta = {
		.ssid = EXAMPLE_ESP_WIFI_SSID,
		.password = EXAMPLE_ESP_WIFI_PASS
	},
};
How do I change this code to operate with non hardcoded values? I’ve tried to initialise with variables, and changing wifi_config with dot notation and strcpy but have been unsuccessful so far.
Hi,

Your issue or query has been resolved or still open?

Let me know so that we can help to you regarding same.
Regards,
Ritesh Prajapati

ankyankyanky
Posts: 2
Joined: Thu Aug 23, 2018 7:39 pm

Re: WiFi w/ dynamic credentials

Postby ankyankyanky » Tue Aug 28, 2018 9:57 pm

It has been resolved. Thanks kolban

Emerson Morgado
Posts: 1
Joined: Fri Aug 14, 2020 6:31 pm

Re: WiFi w/ dynamic credentials

Postby Emerson Morgado » Fri Aug 14, 2020 6:35 pm

How did you solved this question?
I have the same problem.

Who is online

Users browsing this forum: Google [Bot] and 127 guests