In this section, we will be connecting to an existing Wi-Fi network. You should prepare a Wi-Fi hotspot for demo purposes. For Wi-Fi security, we will use WPA/WPA2 on an existing Wi-Fi network. Since we are using WPA/WPA2 authentication mode, we need the SSID name and SSID key from your Wi-Fi hotspot in order to join this Wi-Fi network.
We can now start to create a project called wificonnect. In the main entry, the app_main() function, we call the connect_to_wifi() function. The connect_to_wifi() function is the function that connects to existing Wi-Fi networks:
void app_main()
{
//Initialize NVS
esp_err_t ret = nvs_flash_init();
if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) {
ESP_ERROR_CHECK(nvs_flash_erase());
ret = nvs_flash_init();
}
ESP_ERROR_CHECK(ret);
connect_to_wifi...