Unstable AP on ESP8266

Hi!

I'm using NodeMCU in AP mode to host a webpage. The code to the same is given below. I am unable to get a stable connection with my mobile phone whereas my laptop gets connected to it without any issue.

#include <EEPROM.h>
#include <ESP8266WiFi.h>
#include <WiFiClient.h> 
#include <ESP8266WebServer.h>
//Defining Web Server
ESP8266WebServer server(80);
/* Configuration Variables for the AP name and IP. */
const char *ssid = "Test";
const char *password = "Password";
IPAddress ap_local_IP(192,168,1,123);
IPAddress ap_gateway(192,168,1,1);
IPAddress ap_subnet(255,255,255,0);



//Creating the input form
const char INDEX_HTML[] =
"<!DOCTYPE HTML>"
"<html>"
"<head>"
"<meta content=\"text/html; charset=ISO-8859-1\""
" http-equiv=\"content-type\">"
"<meta name = \"viewport\" content = \"width = device-width, initial-scale = 1.0, maximum-scale = 1.0, user-scalable=0\">"
"<title>ESP8266 Web Form Demo</title>"
"<style>"
"\"body { background-color: #808080; font-family: Arial, Helvetica, Sans-Serif; Color: #000000; }\""
"</style>"
"</head>"
"<body>"
"<h1>ESP8266 Web Form Demo</h1>"
"<FORM action=\"/\" method=\"post\">"
"<P>"
"<label>ssid:&nbsp;</label>"
"<input maxlength=\"30\" name=\"ssid\">
"
"<label>Password:&nbsp;</label><input maxlength=\"30\" name=\"Password\">
"
"<label>IP:&nbsp;</label><input maxlength=\"15\" name=\"IP\">
"
"<label>Gateway:&nbsp;</label><input maxlength=\"3\" name=\"GW\">
"
"<INPUT type=\"submit\" value=\"Send\"> <INPUT type=\"reset\">"
"</P>"
"</FORM>"
"</body>"
"</html>";





void setup() {
	delay(1000);
	Serial.begin(115200);//Starting serial comunication
  EEPROM.begin(512);//Starting and setting size of the EEPROM
	Serial.println();
	Serial.print("Configuring access point...");
	Serial.print("Setting soft-AP configuration ... ");
  WiFi.softAPConfig(ap_local_IP, ap_gateway, ap_subnet);
  Serial.print("Setting soft-AP ... ");
  WiFi.softAP(ssid, password);
  Serial.print("Soft-AP IP address = ");
  Serial.println(WiFi.softAPIP());
	

	/**IPAddress myIP = WiFi.softAPIP();
	Serial.print("AP IP address: ");
	Serial.println(myIP);**/
  //Configuring the web server
	server.on("/", handleRoot);
  server.onNotFound(handleNotFound);
	server.begin();
	Serial.println("HTTP server started");
}



void loop() {
	server.handleClient();//Checks for web server activity
  
}
//Dealing with the call to root
void handleRoot() {
   if (server.hasArg("ssid")&& server.hasArg("Password")&& server.hasArg("IP")&&server.hasArg("GW") ) {//If all form fields contain data call handelSubmit()
    handleSubmit();
  }
  else {//Redisplay the form
    server.send(200, "text/html", INDEX_HTML);
  }
}
void handleSubmit(){//dispaly values and write to memmory
  String response="<p>The ssid is ";
 response += server.arg("ssid");
 response +="
";
 response +="And the password is ";
 response +=server.arg("Password");
 response +="
";
 response +="And the IP Address is ";
 response +=server.arg("IP");
 response +="</P>
";
 response +="<H2><a href=\"/\">go home</a></H2>
";

 server.send(200, "text/html", response);
 //calling function that writes data to memory 
 write_to_Memory(String(server.arg("ssid")),String(server.arg("Password")),String(server.arg("IP")),String(server.arg("GW")));
}
//Write data to memory
/**
 * We prepping the data strings by adding the end of line symbol I decided to use ";". 
 * Then we pass it off to the write_EEPROM function to actually write it to memmory
 */
void write_to_Memory(String s,String p,String i, String g){
 s+=";";
 write_EEPROM(s,0);
 p+=";";
 write_EEPROM(p,100);
 i+=";";
 write_EEPROM(i,200); 
 g+=";";
 write_EEPROM(g,220); 
 EEPROM.commit();
}
//write to memory
void write_EEPROM(String x,int pos){
  for(int n=pos;n<x.length()+pos;n++){
     EEPROM.write(n,x[n-pos]);
  }
}
//Shows when we get a misformt or wrong request for the web server
void handleNotFound()
{
  String message = "File Not Found\n\n";
  message += "URI: ";
  message += server.uri();
  message += "\nMethod: ";
  message += (server.method() == HTTP_GET)?"GET":"POST";
  message += "\nArguments: ";
  message += server.args();
  message += "\n";
  for (uint8_t i=0; i<server.args(); i++){
    message += " " + server.argName(i) + ": " + server.arg(i) + "\n";
  }
  message +="<H2><a href=\"/\">go home</a></H2>
";
  server.send(404, "text/plain", message);
}

Any help is appreciated...

I can't really see any issue, but i do wonder why you create a complete html page including header & body and & for the 'form' , but for the response you only bother a

but none of the other tags, it is very possible that your phone's browser gets a little confused by all that (where as your laptop may still be able to deal with it). Also if you going to configure the ESP as an AccessPoint, there is no need to set the IP, Gateway & subnet, you could just leave the IP at the default 192.168.4.1 and log into that.

Thanks for the reply.

My issue is that I am unable to connect to the Access point created by the ESP from my mobile phone using the ESP8266WebServer library.

ESP8266WebServer server(80);

This creates no issue if we do not use the ESP AP but connect the ESP to a router.

When the same is being created using the ESP8266WiFi library, it creates no issue, even with the AP of ESP.

WiFiServer server(80);

As of now, I'm not concerned with the webpage.
I hope this time, I am clear with my issue.

Your issue is unknown to me, but i suggest you comment out this lineWiFi.softAPConfig(ap_local_IP, ap_gateway, ap_subnet) and see if that helps, or get a new phone. btw your browser will crash at some point if you send it inaccurate html or text as html.