Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Wifi Extender Functionality in ESP32 using Arduino IDE #7188

Answered by me-no-dev
aamiralidayo asked this question in Q&A
Discussion options

Hello Everyone,

Guys, I am kinda a rookie hobbyist programmer. I want to implement Wifi Extender Functionality in ESP32 along with other tasks that it is performing. That's why I can not use https://github.com/martin-ger/esp32_nat_router like repositories, as all other code is written in Arduino IDE. Can you guys provide me the methods to get this done and an example code for NAPT/NAT for ESP32 in Arduino IDE. Help in this regard will be highly appreciated.

Board

All ESP32 modules

Device Description
ESP Dev Kit

Version
v2.0.4

IDE Name
Arduino IDE

Operating System
Windows 11

You must be logged in to vote

Here is a good example running on Arduino v3.x

#include <WiFi.h>
#define STA_SSID "YOUR-SSID"
#define STA_PASS "YOUR-PASS"
#define AP_SSID "ESP32-STA-WIFI-BRIDGE"
#define AP_PASS "password"
IPAddress ap_ip(192, 168, 4, 1);
IPAddress ap_mask(255, 255, 255, 0);
IPAddress ap_leaseStart(192, 168, 4, 2);
IPAddress ap_dns(8, 8, 4, 4);
void setup() {
 Serial.begin(115200);
 Serial.setDebugOutput(true);
 Network.onEvent(onEvent);
 
 WiFi.AP.begin();
 WiFi.AP.config(ap_ip, ap_ip, ap_mask, ap_leaseStart, ap_dns);
 WiFi.AP.create(AP_SSID, AP_PASS);
 if(!WiFi.AP.waitStatusBits(ESP_NETIF_STARTED_BIT, 1000)){
 Serial.println("Failed to start AP!");
 return;
 }
 
 WiFi.begin(STA_SSI...

Replies: 1 comment 4 replies

Comment options

Not possible at the moment since the Arduin Libs are not compiled with the options needed for. See

You must be logged in to vote
4 replies
Comment options

Seems like updated ESP32 libraries may contain relevant code. However I'm struggling to put together ESP32 code to replace the simple ESP8266 range extender Arduino example code as my knowledge of the lwip stuff is very limited Any ideas on how to proceed with this? Here is the ESP8266 code that I'm looking to replace:

#define STASSID "SSID"
#define STAPSK "PASSWORD"

#include <ESP8266WiFi.h>
#include <lwip/napt.h>
#include <lwip/dns.h>
#include <LwipDhcpServer.h>

void setup() {
Serial.begin(115200);

// Connect to STA to get a proper local DNS server
WiFi.mode(WIFI_STA);
WiFi.begin(STASSID, STAPSK);
while (WiFi.status() != WL_CONNECTED) {
Serial.print('.');
delay(500);
}

// Give DNS servers to AP side
dhcpSoftAP.dhcps_set_dns(0, WiFi.dnsIP(0));
dhcpSoftAP.dhcps_set_dns(1, WiFi.dnsIP(1));

// Enable AP mode with default IP configuration
WiFi.softAP(STASSID "-EXT", STAPSK);

// Initialize and enable NAPT
ip_napt_init(IP_NAPT_MAX, IP_PORTMAP_MAX);
ip_napt_enable_no(SOFTAP_IF, 1);

}
void loop() {
}

Has LwipDhcpServer.h an ESP32 replacement? The Napt stuff looks very diffent in the ESP8266 board libraries compared to ESP32 board libraries as well...

Comment options

Here is a good example running on Arduino v3.x

#include <WiFi.h>
#define STA_SSID "YOUR-SSID"
#define STA_PASS "YOUR-PASS"
#define AP_SSID "ESP32-STA-WIFI-BRIDGE"
#define AP_PASS "password"
IPAddress ap_ip(192, 168, 4, 1);
IPAddress ap_mask(255, 255, 255, 0);
IPAddress ap_leaseStart(192, 168, 4, 2);
IPAddress ap_dns(8, 8, 4, 4);
void setup() {
 Serial.begin(115200);
 Serial.setDebugOutput(true);
 Network.onEvent(onEvent);
 
 WiFi.AP.begin();
 WiFi.AP.config(ap_ip, ap_ip, ap_mask, ap_leaseStart, ap_dns);
 WiFi.AP.create(AP_SSID, AP_PASS);
 if(!WiFi.AP.waitStatusBits(ESP_NETIF_STARTED_BIT, 1000)){
 Serial.println("Failed to start AP!");
 return;
 }
 
 WiFi.begin(STA_SSID, STA_PASS);
}
void loop() {
 delay(20000);
}
void onEvent(arduino_event_id_t event, arduino_event_info_t info) {
 switch (event) {
 case ARDUINO_EVENT_WIFI_STA_START:
 Serial.println("STA Started");
 break;
 case ARDUINO_EVENT_WIFI_STA_CONNECTED:
 Serial.println("STA Connected");
 break;
 case ARDUINO_EVENT_WIFI_STA_GOT_IP:
 Serial.println("STA Got IP");
 Serial.println(WiFi.STA);
 WiFi.AP.enableNAPT(true);
 break;
 case ARDUINO_EVENT_WIFI_STA_LOST_IP:
 Serial.println("STA Lost IP");
 WiFi.AP.enableNAPT(false);
 break;
 case ARDUINO_EVENT_WIFI_STA_DISCONNECTED:
 Serial.println("STA Disconnected");
 WiFi.AP.enableNAPT(false);
 break;
 case ARDUINO_EVENT_WIFI_STA_STOP:
 Serial.println("STA Stopped");
 break;
 case ARDUINO_EVENT_WIFI_AP_START:
 Serial.println("AP Started");
 Serial.println(WiFi.AP);
 break;
 case ARDUINO_EVENT_WIFI_AP_STACONNECTED:
 Serial.println("AP STA Connected");
 break;
 case ARDUINO_EVENT_WIFI_AP_STADISCONNECTED:
 Serial.println("AP STA Disconnected");
 break;
 case ARDUINO_EVENT_WIFI_AP_STAIPASSIGNED:
 Serial.print("AP STA IP Assigned: ");
 Serial.println(IPAddress(info.wifi_ap_staipassigned.ip.addr));
 break;
 case ARDUINO_EVENT_WIFI_AP_PROBEREQRECVED:
 Serial.println("AP Probe Request Received");
 break;
 case ARDUINO_EVENT_WIFI_AP_STOP:
 Serial.println("AP Stopped");
 break;
 
 default:
 break;
 }
}
Answer selected by me-no-dev
Comment options

Just compiled with Arduino IDE 2.2.1 and uploaded to ESP32-S3. It works perfectly! Thanks.

Comment options

Brother thanks A lot.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

AltStyle によって変換されたページ (->オリジナル) /