Browse Source

wifi: Add DNS server configuration

Helmut Pozimski 1 year ago
parent
commit
83026a05b3
1 changed files with 6 additions and 2 deletions
  1. 6 2
      main/wifi.c

+ 6 - 2
main/wifi.c

@@ -48,8 +48,6 @@ static void wifi_event_handler(void *arg, esp_event_base_t event_base, int32_t e
 
 void wifi_init() {
     wifi_event_group = xEventGroupCreate();
-    ESP_ERROR_CHECK(esp_netif_init());
-    ESP_ERROR_CHECK(esp_event_loop_create_default());
     esp_netif_t* netif = esp_netif_create_default_wifi_sta();
     esp_netif_dhcpc_stop(netif);
 
@@ -59,6 +57,12 @@ void wifi_init() {
     ipaddr_aton(NETMASK, (struct ip_addr *) &ip_info.netmask);
 
     esp_netif_set_ip_info(netif, &ip_info);
+    
+    esp_netif_dns_info_t dns_info;
+    ipaddr_aton(DNS_SERVER, (struct ip_addr *) &dns_info.ip.u_addr.ip4.addr);
+    dns_info.ip.type = IPADDR_TYPE_V4;
+
+    esp_netif_set_dns_info(netif, ESP_NETIF_DNS_MAIN, &dns_info);
 
     wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
     ESP_ERROR_CHECK(esp_wifi_init(&cfg));