Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

examples/protocols/static_ip example cannot communicate with the outside (IDFGH-5523) #7251

Closed
nopnop2002 opened this issue Jul 8, 2021 · 1 comment
Labels
Resolution: Done Issue is done internally Status: Done Issue is done internally

Comments

@nopnop2002
Copy link

nopnop2002 commented Jul 8, 2021

Environment

freeRTOS version:V10.2.1
NEWLIB version:3.0.0
portTICK_RATE_MS:10 msec/tick
lwIP version:2-1-3-0
ESP-IDF version:v4.4-dev-1183-g9d34a1cd4-dirty
chip model is 2, chip with 1 CPU cores, WiFi, silicon revision 0, 2MB external flash
package is ESP32D0WDQ6
target is ESP32S2

Problem Description

This example turns off DHCP but doesn't set DNS.
Therefore, it cannot communicate with the NTP server.

Workaround

After stopping DHCP, set the DNS address.
I modiyied this

There may be better code.

static void example_set_static_ip(esp_netif_t *netif)
{
    if (esp_netif_dhcpc_stop(netif) != ESP_OK) {
        ESP_LOGE(TAG, "Failed to stop dhcp client");
        return;
    }
    esp_netif_ip_info_t ip;
    memset(&ip, 0 , sizeof(esp_netif_ip_info_t));
    ip.ip.addr = ipaddr_addr(CONFIG_STATIC_IP_ADDRESS);
    //ip.netmask.addr = ipaddr_addr(CONFIG_STATIC_NETMASK_ADDR);
    ip.netmask.addr = ipaddr_addr(CONFIG_STATIC_NM_ADDRESS);
    ip.gw.addr = ipaddr_addr(CONFIG_STATIC_GW_ADDRESS);
    if (esp_netif_set_ip_info(netif, &ip) != ESP_OK) {
        ESP_LOGE(TAG, "Failed to set ip info");
        return;
    }
    ESP_LOGD(TAG, "Success to set static ip: %s, netmask: %s, gw: %s",
        CONFIG_STATIC_IP_ADDRESS, CONFIG_STATIC_NM_ADDRESS, CONFIG_STATIC_GW_ADDRESS);

    ip_addr_t d;
    d.type = IPADDR_TYPE_V4;
    d.u_addr.ip4.addr = 0x08080808; //8.8.8.8 dns
    dns_setserver(0, &d);
    d.u_addr.ip4.addr = 0x08080404; //8.8.4.4 dns
    dns_setserver(1, &d);
}
@espressif-bot espressif-bot added the Status: Opened Issue is new label Jul 8, 2021
@github-actions github-actions bot changed the title examples/protocols/static_ip example cannot communicate with the outside examples/protocols/static_ip example cannot communicate with the outside (IDFGH-5523) Jul 8, 2021
@david-cermak
Copy link
Collaborator

Hi @nopnop2002

Thanks for letting us know about this and providing a working setup! The idea behind that example was just to demonstrate static IP configuration. I agree, though, that it might be a bit misleading if we cannot resolve hosts by default. We will add a menuconfig option to setup configurable global DNS server.

@espressif-bot espressif-bot added Status: In Progress Work is in progress and removed Status: Opened Issue is new labels Jul 9, 2021
@espressif-bot espressif-bot added Status: Done Issue is done internally Resolution: Done Issue is done internally and removed Status: In Progress Work is in progress labels Jul 21, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Resolution: Done Issue is done internally Status: Done Issue is done internally
Projects
None yet
Development

No branches or pull requests

3 participants