Wifi-connect 4 - Additional code that manually sets IP in github, not in video #72
Answered
by
Mair
swimleftproducts
asked this question in
Course Qeustions
-
|
The git hub for Wifi-connect 4 has some additional code in it, particularly lines 165- 170 of the wifi component connect.c file. I do not think this code was covered in this section. Can you point me to where this code is covered? Thanks! |
Beta Was this translation helpful? Give feedback.
Answered by
Mair
Apr 11, 2022
Replies: 1 comment
-
|
@swimleftproducts Good catch. I have commented those lines out now but I left them in as this is how you can force the ESP32 to use a static IP. esp_err_t wifi_connect_sta(const char *ssid, const char *pass, int timeout)
{
Wifi_events = xEventGroupCreate();
wifi_config_t wifi_config;
memset(&wifi_config, 0, sizeof(wifi_config_t));
strncpy((char *)wifi_config.sta.ssid, ssid, sizeof(wifi_config.sta.ssid) - 1);
strncpy((char *)wifi_config.sta.password, pass, sizeof(wifi_config.sta.password) - 1);
esp_netif = esp_netif_create_default_wifi_sta();
// for static ip...
// esp_netif_dhcpc_stop(esp_netif);
// esp_netif_ip_info_t ip_info;
// ip_info.ip.addr = ipaddr_addr("192.168.0.222");
// ip_info.gw.addr = ipaddr_addr("192.168.0.1");
// ip_info.netmask.addr = ipaddr_addr("255.255.255.0");
// esp_netif_set_ip_info(esp_netif, &ip_info);
ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_STA));
ESP_ERROR_CHECK(esp_wifi_set_config(ESP_IF_WIFI_STA, &wifi_config));
ESP_ERROR_CHECK(esp_wifi_start());
EventBits_t result = xEventGroupWaitBits(Wifi_events, CONNECTED_GOT_IP | DISCONNECTED, pdTRUE, pdFALSE, pdMS_TO_TICKS(timeout));
if (result == CONNECTED_GOT_IP)
return 0;
return -1;
} |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
Mair
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@swimleftproducts Good catch.
I have commented those lines out now but I left them in as this is how you can force the ESP32 to use a static IP.
new code as follows