Page 1 of 1

Modify the IP address in WiFi_AP mode

Posted: Wed Jun 19, 2019 10:52 pm
by JeetD27
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 ()
{ }

Re: Modify the IP address in WiFi_AP mode

Posted: Thu Jun 20, 2019 1:57 pm
by JeetD27
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

Re: Modify the IP address in WiFi_AP mode

Posted: Thu Jun 20, 2019 5:57 pm
by boarchuz

Code: Select all

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

Code: Select all

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

Re: Modify the IP address in WiFi_AP mode

Posted: Fri Jun 21, 2019 1:48 pm
by JeetD27
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.