[solved]Init Wifi ssid & pw from string

linuxpaul
Posts: 43
Joined: Thu Jul 20, 2017 6:10 pm

[solved]Init Wifi ssid & pw from string

Postby linuxpaul » Thu Apr 30, 2020 7:33 am

Hello,

I did an IDF update from an early IDF V3 to V4 and try to migrate some of my projects.

Within one of them, I do a wifi configuration from spiffs config.txt which does not work anymore,
but the current wifi sta example works fine.

This code works fine in the past:

Code: Select all

static uint8_t wifi_ssid[32] = WIFI_SSID; // init default values
static uint8_t wifi_pw[64] = WIFI_PW;

.....
// read data from config.txt
.....

    wifi_config_t sta_config;

	memcpy(sta_config.sta.ssid,wifi_ssid,sizeof(wifi_ssid));
	memcpy(sta_config.sta.password,wifi_pw,sizeof(wifi_pw));
Right now there is no warning or error from compiler or monitor, but just no login to wifi AP.

Code: Select all

	strcpy((char *)sta_config.sta.ssid,(char *)wifi_ssid);
	strcpy((char *)sta_config.sta.password,(char *)wifi_pw);
also not work but

Code: Select all

   	ESP_LOGI(TAG,"ssid: %s", sta_config.sta.ssid);
	ESP_LOGI(TAG,"pw: %s", sta_config.sta.password);
show always the right strings in Monitor.

Are there any hints what went wrong?
(I'm not so much experienced in C)
Last edited by linuxpaul on Tue May 05, 2020 1:32 pm, edited 1 time in total.

linuxpaul
Posts: 43
Joined: Thu Jul 20, 2017 6:10 pm

Re: Init Wifi ssid & pw from string

Postby linuxpaul » Tue May 05, 2020 1:31 pm

the big difference is in the initialisation of the rest of the object:

init from example:

Code: Select all

wifi_config_t sta_config = {
        .sta = {
            .ssid = "WIFI_STA",
            .password = "WIFI_PW"
        },
};
sta_config.sta.bssid_set = false;
is not similar to:

Code: Select all

wifi_config_t sta_config;
memcpy((uint8_t*)sta_config.sta.ssid,(uint8_t*)wifi_ssid,sizeof(wifi_ssid));
memcpy((uint8_t*)sta_config.sta.password,(uint8_t*)wifi_pw,sizeof(wifi_pw));
sta_config.sta.bssid_set = false;
because the rest of the values of sta_config are init randomized and need a dedicated init like

Code: Select all

sta_config.sta.channel = '\0';
sta_config.sta.listen_interval = 0;
sta_config.sta.sort_method = WIFI_CONNECT_AP_BY_SIGNAL;
sta_config.sta.threshold.rssi = '\0';
sta_config.sta.threshold.authmode = WIFI_AUTH_OPEN;
to get the same values like from example config.

(eclipse jtag debugging is indeed a funny stuff) :)

Who is online

Users browsing this forum: No registered users and 293 guests