Giter Site home page Giter Site logo

Comments (3)

Stasfe avatar Stasfe commented on July 17, 2024

I have the same issue. Is there a solution for this?

from esp32_nat_router.

maps2002 avatar maps2002 commented on July 17, 2024

Hi,
I also wanted to use@martin-ger great work but with a static IP on the STA.
I think the original code is not working because when a static ip is defined, the DNS is not properly configured.

I had success by changing a piece of code in file: esp32_nat_router.c, function: wifi_event_handler, for the switch/case of: SYSTEM_EVENT_STA_GOT_IP

This piece of original code:

if (esp_netif_get_dns_info(wifiSTA, ESP_NETIF_DNS_MAIN, &dns) == ESP_OK) {
    dhcps_dns_setserver((const ip_addr_t *)&dns.ip);
    ESP_LOGI(TAG, "DHCP: set dns to:" IPSTR, IP2STR(&dns.ip.u_addr.ip4));
}

I changed it to:

if (has_static_ip) {
    // Configure static DNS from DEFAULT DNS
    ip_addr_t dnsserver;
    dnsserver.u_addr.ip4.addr = ipaddr_addr(DEFAULT_DNS);
    dnsserver.type = IPADDR_TYPE_V4;
    dhcps_dns_setserver(&dnsserver);
    ESP_LOGI(TAG, "STATIC IP: set dns to:" IPSTR, IP2STR(&dnsserver.u_addr.ip4));
}
else {
    // Configure DNS from STA DHCP
    if (esp_netif_get_dns_info(wifiSTA, ESP_NETIF_DNS_MAIN, &dns) == ESP_OK) {
        dhcps_dns_setserver((const ip_addr_t *)&dns.ip);
        ESP_LOGI(TAG, "DHCP: set dns to:" IPSTR, IP2STR(&dns.ip.u_addr.ip4));
    }
}

In my case, I also updated the DEFAULT_DNS define, as I wanted to use my router ip address.
I am not using any of the portmap features, so I have not tested this change outside of my usage scope.

PS: The "new code" can probably be simplified to make the setserver and ESP_LOG instructions generic, and outside/after the if has_static_ip

from esp32_nat_router.

Fretwire avatar Fretwire commented on July 17, 2024

Here's a patch with the above code. Three sections:

First: Change default DNS to opennic dns server instead of Google
Second: Add (modified) above code to git source
Third: Update web page to hide STA password

esp32_nr_patch.txt

from esp32_nat_router.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.