Page 1 of 1

[已解决] 求大神指导。esp32 怎么禁用DHCP和设置静态IP?

Posted: Thu Apr 29, 2021 3:20 am
by meishiqi
如题

Re: 求大神指导。esp32 怎么禁用DHCP和设置静态IP?

Posted: Thu Apr 29, 2021 5:38 am
by ESP_Gargamel
你说的是 dhcp client 吧,可以这样做:

Code: Select all

const esp_netif_ip_info_t ip_info = {
        .ip = { .addr = ESP_IP4TOADDR( 192, 168, 3, 41) },
        .gw = { .addr = ESP_IP4TOADDR( 192, 168, 3, 1) },
        .netmask = { .addr = ESP_IP4TOADDR( 255, 255, 255, 0) },
};

esp_netif_t* netif = esp_netif_create_default_wifi_sta();
esp_netif_dhcpc_stop(netif);
esp_netif_set_ip_info(netif, &ip_info);    
具体你得好好再看下 esp-netif 及相关 APIs 的说明:https://docs.espressif.com/projects/esp ... netif.html

Re: 求大神指导。esp32 怎么禁用DHCP和设置静态IP?

Posted: Thu Jun 17, 2021 7:26 am
by ESP_YJM
目前 IDF 有静态 IP 设置的示例,https://github.com/espressif/esp-idf/tr ... /static_ip,可以参考示例代码。