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

meishiqi
Posts: 2
Joined: Thu Apr 22, 2021 3:00 am

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

Postby meishiqi » Thu Apr 29, 2021 3:20 am

如题

ESP_Gargamel
Posts: 786
Joined: Wed Nov 14, 2018 8:45 am

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

Postby ESP_Gargamel » Thu Apr 29, 2021 5:38 am

你说的是 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

ESP_YJM
Posts: 300
Joined: Fri Feb 26, 2021 10:30 am

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

Postby ESP_YJM » Thu Jun 17, 2021 7:26 am

目前 IDF 有静态 IP 设置的示例,https://github.com/espressif/esp-idf/tr ... /static_ip,可以参考示例代码。

Who is online

Users browsing this forum: No registered users and 53 guests