Modify the IP address in WiFi_AP mode

JeetD27
Posts: 3
Joined: Wed Jun 19, 2019 10:38 pm

Modify the IP address in WiFi_AP mode

Postby JeetD27 » Wed Jun 19, 2019 10:52 pm

Hi,

I'm trying to modify the IP address in the ESP32. I'm using it in the Access Point mode over WiFi.
In the serial monitor, it's showing the IP address as '1.0.0.0' instead of the one that I have defined.
If I remove the statement, 'WiFi.softAPConfig()', then I get the default '192.168.4.1' IP address in the serial monitor.
Where am I going wrong?

The following is my code:

Code: Select all

#include <WiFi.h>

char ssid[] = "Network-1";          //  your network SSID (name) 

IPAddress IP = (10, 10, 1, 1);
IPAddress gateway = (10, 10, 1, 1);
IPAddress NMask = (255, 255, 255, 0);

WiFiServer server(80);

void setup ()
{
  Serial.begin(115200);
  Serial.println();
  Serial.print("System Start");

  WiFi.mode(WIFI_AP);  
  WiFi.softAP(ssid);
  delay(1000);

  WiFi.softAPConfig(IP, IP, NMask);

  delay(1000);
  
  IPAddress myIP = WiFi.softAPIP();
  Serial.println();
  Serial.print("AP IP address: ");
  Serial.println(myIP);  

  server.begin();
}

void loop ()
{ }

JeetD27
Posts: 3
Joined: Wed Jun 19, 2019 10:38 pm

Re: Modify the IP address in WiFi_AP mode

Postby JeetD27 » Thu Jun 20, 2019 1:57 pm

Hi,

I got this solved. Instead of the circular brackets for the address in the 'IP Address IP' statement, I just used curly braces. So my code remained the same, just the address was

Code: Select all

IPAddress IP = {10, 10, 1, 1}; // curly braces
I am now getting the serial monitor to print the correct modified IP address. It actually was looking for a 'const uint16_t'
The following link might give a little info: https://github.com/espressif/arduino-es ... ress.h#L79

boarchuz
Posts: 605
Joined: Tue Aug 21, 2018 5:28 am

Re: Modify the IP address in WiFi_AP mode

Postby boarchuz » Thu Jun 20, 2019 5:57 pm

Code: Select all

IPAddress IP = (10, 10, 1, 1);
->

Code: Select all

IPAddress IP = IPAddress(10, 10, 1, 1);

JeetD27
Posts: 3
Joined: Wed Jun 19, 2019 10:38 pm

Re: Modify the IP address in WiFi_AP mode

Postby JeetD27 » Fri Jun 21, 2019 1:48 pm

Hi boarchuz,

This one works too, but I had to update the 'gateway' and 'subnet' in the same way.

Code: Select all

IPAddress IP = IPAddress (10, 10, 2, 6); // curly braces
IPAddress gateway = IPAddress (10, 10, 2, 8); // not curly braces
IPAddress NMask = IPAddress (255, 255, 255, 0); // not curly braces
Thank You for your response.

Who is online

Users browsing this forum: No registered users and 68 guests