Code: Select all
tcpip_adapter_init();
ESP_ERROR_CHECK(esp_event_loop_init(event_handler, NULL));
wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
ESP_ERROR_CHECK(esp_wifi_init(&cfg));
ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_STA));
char *myssid = "myssid";
char *mypw = "mypassword";
wifi_config_t wifi_config;
strcpy((char *)wifi_config.sta.ssid,myssid);
strcpy((char *)wifi_config.sta.password, mypw);
printf("wifi_config.sta.ssid=%s\n wifi_config.sta.password=%s\n",wifi_config.sta.ssid,wifi_config.sta.password);
ESP_ERROR_CHECK(esp_wifi_set_config(WIFI_IF_STA, &wifi_config));
ESP_ERROR_CHECK(esp_wifi_start());
Further, if I use
Code: Select all
char myssid[] = "myssid";
char mypw[] = "mypassword";
Code: Select all
char *myssid = "myssid";
char *mypw = "mypassword";
What could be the reason(s)?
In fact idea is to get SSID and PASSWORD from NVS each time to connect to wifi.
If fails to connect to wifi in given time, wifi in access mode is started asking for user input of SSID and PASSWORD, save it to NVS, and again connect to wifi using values from NVS.
I have miserably failed to figure out how to use user input I get in AP mode, to connect to wifi in station mode.
I can get user input in AP mode, save and retrieve it from NVS, but those values just don't work in connecting in station mode.(though those retrieved values are correct when I get their print).
Any help please?
and sorry for such a long question