paclema / esp32_lwip_nat_example

4 stars 2 forks source link

Compilation error: 'dhcpSoftAP' was not declared in this scope #5

Closed blackleakz closed 1 year ago

blackleakz commented 1 year ago

https://github.com/paclema/esp32_lwip_nat_example/blob/main/src/main.cpp

what i need to do to declare?

paclema commented 1 year ago

I assusme that you are trying to follow this example to compile your program for an ESP8266 board.

Looking on the Arduino core for ESP8266 repo, It seems that they removed last June the declaration of this SoftAP DhcpServer object within this commit: https://github.com/esp8266/Arduino/commit/502d9469fa022a5ce942bc2f2940f42699664ef7

So now, if what you want is to provide the DNS to the AP side, instead to use those lines:

 dhcpSoftAP.dhcps_set_dns(0, WiFi.dnsIP(0));
 dhcpSoftAP.dhcps_set_dns(1, WiFi.dnsIP(1));

You need to include LwipDhcpServer.h and change the above lines with those ones:

  auto& server = WiFi.softAPDhcpServer();
  server.setDns(WiFi.dnsIP(0));

You can also take a look to this RangeExtender-NAPT example for more information. For ESP8266 this feature is enabled by default, the example code of this repo illustrates the equivalent procedure if you use an ESP32 instead.

I have modified this repo example adding this change on this commit: https://github.com/paclema/esp32_lwip_nat_example/commit/f329c5845c353a3ea5aa1b5d3331a1caa6e6b0ae Thank you for pointing out this new change!