Giter VIP home page Giter VIP logo

esp32_lwip_nat_example's Introduction

I try to add esp32 nat features to arduino-esp32 framework based on this esp-idf nat example for esp32: https://github.com/jonask1337/esp-idf-nat-example

As those features are not fully enabled on arduino-esp32 compiled sdk. I have to recompile it enabling those features. For that porpouse I have to install esp-idf in order to use idf.py menuconfig (before used make menuconfig) to select the specific sdk.

To recompile esp-idf I have found useful the next comments:

However, I have discovered that espressif provides some tools within esp32-arduino-lib-builder to help to recompile it for arduino-esp32 framework. And since the nat feature seems to be available already here and I just need to recompile sep-if to enable those features.

So I have directly cloned on my rpi 2 the esp32-arduino-lib-builder and run the build.sh script. After I could re-conpile the sdk, I have modify the sdkconfig.esp32 file to add the LWIP ip forward and NAT featues using idf.py menuconfig and re-compile it again:

Pin Functions

It will be exported under esp32-arduino-lib-builder/dist a .gz file containning the libs that it should be placed under framework-arduinoespressif32 folder that you can find under C:\Users\<your-user>\.platformio\packages\

I have created a fork to arduino-esp32 repo containing this compiled lib, so It can be used from platformio.ini instead copiying manually with (TO BE CONFIGURED...):

platform_packages =
  framework-arduinoespressif32 @ https://github.com/paclema/arduino-esp32#lwip_enabled
...

To compile it correctly, you will need to replace the C:\Users\<your-user>\.platformio\packages\toolchain-xtensa32\ with the content of this version: https://dl.espressif.com/github_assets/espressif/crosstool-NG/releases/download/esp-2020r3/

esp32_lwip_nat_example's People

Contributors

paclema avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

oopas pvgiang396

esp32_lwip_nat_example's Issues

undefined reference to `__locale_ctype_ptr'

Linking .pio\build\mhetesp32minikit\firmware.elf
c:/users/vell0/.platformio/packages/[email protected]+2021r2-patch3/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld.exe: C:\Users\vell0.platformio\packages\framework-arduinoespressif32\tools\sdk\esp32\lib\liblwip.a(utils.c.obj):(.literal.ppp_vslprintf+0x10): undefined reference to __locale_ctype_ptr' c:/users/vell0/.platformio/packages/[email protected]+2021r2-patch3/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld.exe: C:\Users\vell0\.platformio\packages\framework-arduinoespressif32\tools\sdk\esp32\lib\liblwip.a(utils.c.obj): in function ppp_vslprintf':
/home/pi/tmp/esp32-arduino-lib-builder/build/../esp-idf/components/lwip/lwip/src/netif/ppp/utils.c:181: undefined reference to __locale_ctype_ptr' c:/users/vell0/.platformio/packages/[email protected]+2021r2-patch3/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld.exe: /home/pi/tmp/esp32-arduino-lib-builder/build/../esp-idf/components/lwip/lwip/src/netif/ppp/utils.c:193: undefined reference to __locale_ctype_ptr'
collect2.exe: error: ld returned 1 exit status
*** [.pio\build\mhetesp32minikit\firmware.elf] Error 1
========================= [FAILED] Took 11.90 seconds =========================

how to get full speed

Hi @paclema,

finally my esp was successfully activated as a wifi extender using the arduino framework, the maximum test results were 2Mbps.
my question is how to make it full speed as per specs around 15Mbps?
what parameters should be changed in order to make it fullspeed. Thank you very much.

Steps to get it working

Hi @paclema, I'm trying to follow your steps to have this working on platformio. I have built the libraries with NAT enabled, and now I have to use this libraries in Platformio. This is where I get lost because I haven't used PlatformIO before. You say that there is a folder /packages in C:/user.../.platformio, but I don't have this folder, do you know if there is something to do first to get this configured?

Manual recompile not necessary?

Hi, after failing few times by manually recompile Arduino-SDK with enabled LWIP-NAT, I have asked ChatGPT.

It told me to use this platformio.ini:

[env:esp32dev]
platform = espressif32
board = esp32dev
framework = arduino
monitor_speed = 115200
lib_deps = 
    esp32wifi
build_flags = 
    -DLWIP_FEATURES=1
    -DLWIP_IPV4_NAT=1

ChatGPTs C++ code was bullshit, but replacing it with your example file: IT WORKS!
Using these build flags, your example script works out of the box. I don't really understand, why it works without issues by using standard arduino sdk.

Do you know why?

Setting DNS IP from STA to AP side doesn't work on latest Espressif ESP32 framework

The DNS offer code and some other parts don't work with recent versions of the Espressif ESP32 framework: ver 3.0.0+ for Arduino IDE or ESP-IDF ver 5.1+. This is due to deprecated/removed features.

Here are suggested fixes using Arduino IDE:

  1. Replace existing code to "Give DNS servers to AP side" (lines 130-156), since code with tcpip_adapter_* appears to have been deprecated / removed from ESP-IDF. Can use the following:
    // This function is not in any header file, taken from code associated with WiFi.h (AP.cpp)
    esp_netif_t* get_esp_interface_netif(esp_interface_t interface);
    esp_netif_t* esp_netif_ap = get_esp_interface_netif(ESP_IF_WIFI_AP);   // Get the esp_netif reference for AP
    Serial.printf("AP esp_netif is %p\n", esp_netif_ap);
    if (esp_netif_ap != nullptr) {
        // Note this assumes IPv4
        ip_addr_t dnsip = {};
        WiFi.dnsIP(0).to_ip_addr_t(&dnsip);  // Get the main DNS server address from STA
        u32_t addr = dnsip.u_addr.ip4.addr;  // Convert to unsigned int, already in network byte order
        if (addr == 0) {
            addr = htonl(0x08080808);       // Use Google as fallback
        }
        Serial.printf("Giving DNS IP %s to AP\n", IPAddress(addr).toString().c_str());

        esp_netif_dns_info_t dns = {};
        dns.ip.u_addr.ip4.addr = addr;
        dns.ip.type = IPADDR_TYPE_V4;
        dhcps_offer_t dhcps_dns_value = OFFER_DNS;
        ESP_ERROR_CHECK(esp_netif_dhcps_stop(esp_netif_ap));
        ESP_ERROR_CHECK(esp_netif_dhcps_option(esp_netif_ap, ESP_NETIF_OP_SET, ESP_NETIF_DOMAIN_NAME_SERVER, &dhcps_dns_value, sizeof(dhcps_dns_value)));
        ESP_ERROR_CHECK(esp_netif_set_dns_info(esp_netif_ap, ESP_NETIF_DNS_MAIN, &dns));  // Only one DNS supported, not BACKUP or FALLBACK
        ESP_ERROR_CHECK(esp_netif_dhcps_start(esp_netif_ap));
    }
  1. Remove all code in loop() function, it is non-critical. Replace with delay(1000);

  2. Note to fully migrate the code away from deprecated APIs to the new Espressif APIs you will need to use 'esp_netif' style calls as in this example: https://github.com/espressif/esp-idf/tree/master/examples/wifi/softap_sta

In my testing the code here is significantly faster than using the new APIs for everything, ~10 Mbps down vs. 6 Mbps. Not sure why. All this took me several days to figure out!

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.