Skip to content

ESP32 AP Mode Local IP #6270

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

Closed
1 task done
Fideus opened this issue Feb 12, 2022 · 4 comments · Fixed by #6294 or #6296
Closed
1 task done

ESP32 AP Mode Local IP #6270

Fideus opened this issue Feb 12, 2022 · 4 comments · Fixed by #6294 or #6296
Assignees
Labels
Milestone

Comments

@Fideus
Copy link

Fideus commented Feb 12, 2022

Board

ESP32

Device Description

Custom Board

Hardware Configuration

not relevant

Version

v1.0.6

IDE Name

Arduino

Operating System

Windows 10

Flash frequency

80

PSRAM enabled

no

Upload speed

921600

Description

Hello all,

I got a Problem Setting up an Access Point. there seems to be an DHCP server starting at Address x.x.x.241. This will cause an Problem if setting up the local IP in this range, like the example below.
Is there a option that this would be possible?
For my actual project the local IP Address could be changed by an user, and so this could cause problems.
Actual it works if I limit the local IP to x.x.x.240 But it would me more flexible if this isn't necessarry

Sketch

#include <WiFi.h>

IPAddress local_IP(192,168,1,254);
IPAddress gateway(192,168,1,9);
IPAddress subnet(255,255,255,0);

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

  Serial.print("Setting soft-AP configuration ... ");
  Serial.println(WiFi.softAPConfig(local_IP, gateway, subnet) ? "Ready" : "Failed!");

  Serial.print("Setting soft-AP ... ");
  Serial.println(WiFi.softAP("ESPsoftAP_01") ? "Ready" : "Failed!");

  Serial.print("Soft-AP IP address = ");
  Serial.println(WiFi.softAPIP());
}

void loop() {}

Debug Message

Setting soft-AP configuration ... Failed!
Setting soft-AP ... Ready
Soft-AP IP address = 192.168.1.254

Other Steps to Reproduce

No response

I have checked existing issues, online documentation and the Troubleshooting Guide

  • I confirm I have checked existing issues, online documentation and Troubleshooting guide.
@Fideus Fideus added the Status: Awaiting triage Issue is waiting for triage label Feb 12, 2022
@SuGlider SuGlider self-assigned this Feb 15, 2022
@SuGlider SuGlider added Status: Solved Type: For reference Common questions & problems Status: In Progress ⚠️ Issue is in progress Status: To be implemented Selected for Development and removed Status: Awaiting triage Issue is waiting for triage Type: For reference Common questions & problems Status: Solved labels Feb 15, 2022
@SuGlider
Copy link
Collaborator

@Fideus

Regarding your specific question about using an IP address within DHCP Server range, you may want to set DHCP server parameters to add x.x.x.254 as a Reserved IP Address. It may be possible depending on your router options or on your Linux DHCP Server (I don't have any information about your network or DHCP server).

Or you may want to set ESP Static IP out of DHCP range, but still in the range within the same netmask.

Anyway, this is not related to ESP32 setup or ESP Arduino.

Observation:

The return (false) from softAPConfig(), although still sets the Static IP, is being fixed for the release of Arduino Core 2.0.3.
I see that you reported this issue for the Core 1.0.6.

If you want, you can try to apply the PR #6294 to your local machine with 1.0.6.

@SuGlider SuGlider reopened this Feb 16, 2022
@SuGlider SuGlider removed the Status: To be implemented Selected for Development label Feb 16, 2022
@Fideus
Copy link
Author

Fideus commented Feb 16, 2022

Hello SuGlider,

Thank you for your help.

It isn't only the false return what is the problem. I also can't connect to the ESP32 with my device.
My device which trying to connect to the esp can't resolve an IP address.
Regarding your PR #6294 it seems that the DHCP server is stopped when the Local_Ip is within the DHCP Range.

Is there a way to exclude the Local_Ip from the DHCP server which is running on the ESP32? Or reconfiguring the DHCP range?

With the AccesPoint mode on the ESP there is no external router

@SuGlider
Copy link
Collaborator

SuGlider commented Feb 17, 2022

@Fideus

Is there a way to exclude the Local_Ip from the DHCP server which is running on the ESP32? Or reconfiguring the DHCP range?

Looking the code: https://github.com/espressif/arduino-esp32/blob/master/libraries/WiFi/src/WiFiGeneric.cpp#L139-L148
It is clear that when a Static IP address is assigned to ESP32 in AP mode, it will set a DHCP range from IPaddr + 1 to IPaddr + 11.

Because your example assigns x.x.x.254, it is already at the end of network addressing space and it fails with DHCPS Set Lease Failed! 0x5001 message (in order to see it, turn "Core Debug Level:" to "Verbose").

As you already said, assigning static IP as 192.168.1.240 (instead of .254) works fine.


I will work a fix for this issue anyway.

@SuGlider
Copy link
Collaborator

SuGlider commented Feb 17, 2022

@Fideus
PR #6296 will make your example to work.
Using 192.168.1.254 as IP Address for the AP Server will move DHCP range to 192.168.1.1 -- 192.168.1.11

I think this covers your request and solves this issue.
Please let me know.

@VojtechBartoska VojtechBartoska removed the Status: In Progress ⚠️ Issue is in progress label Apr 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
3 participants