My WIFI module ESP8266 is not connecting to WIFI

Hi Everyone,

I am doing project "Track A Vehicle on Google Maps using Arduino, ESP8266 & GPS"

In this case my WIFI module ESP8266 is not connecting to WIFI. The LCD got stuck on "WIFI

CONNECTING........" .

In serial monitor, it shows AT+CWMODE=3 ERROR.

The code for the project is here

[/#include<SoftwareSerial.h>
SoftwareSerial Serial1(2,3);     //make RX arduino line is pin 2, make TX arduino line is pin 3.
SoftwareSerial gps(10,11);
#include<LiquidCrystal.h>
LiquidCrystal lcd(14,15,16,17,18,19);
boolean No_IP=false;
String IP="";
String webpage="";
int i=0,k=0;
int  gps_status=0;
String name="<p>1. Name: Your Name </p>";   //22
String dob="<p>2. DOB: 12 feb 1993</p>";     //21
String number="<p>4. Vehicle No.: RJ05 XY 4201</p>";//29
String cordinat="<p>Coordinates:</p>";          //17
String latitude=""; 
String logitude="";                       
String gpsString="";
char *test="$GPGGA";
void check4IP(int t1)
{
  int t2=millis();
  while(t2+t1>millis())
  {
    while(Serial1.available()>0)
    {
      if(Serial1.find("WIFI GOT IP"))
      {
        No_IP=true;
      }
    }
  }
}
void get_ip()
{
  IP="";
  char ch=0;
  while(1)
  {
    Serial1.println("AT+CIFSR");
    while(Serial1.available()>0)
    {
      if(Serial1.find("STAIP,"))
      {
        delay(1000);
        Serial.print("IP Address:");
        while(Serial1.available()>0)
        {
          ch=Serial1.read();
          if(ch=='+')
          break;
          IP+=ch;
        }
      }
      if(ch=='+')
      break;
    }
    if(ch=='+')
    break;
    delay(1000);
  }
  lcd.clear();
  lcd.print(IP);
  lcd.setCursor(0,1);
  lcd.print("Port: 80");
  Serial.print(IP);
  Serial.print("Port:");
  Serial.println(80);
  delay(1000);
}
void connect_wifi(String cmd, int t)
{
  int temp=0,i=0;
  while(1)
  {
    Serial.println(cmd);
    Serial1.println(cmd); 
    while(Serial1.available()>0)
    {
      if(Serial1.find("OK"))
      {
      i=8;
      }
    }
    delay(t);
    if(i>5)
    break;
    i++;
  }
  if(i==8)
  {
    Serial.println("OK");
  }
  else
  {
  Serial.println("Error");
  }
  delay(1000);
}
void setup() 
{
  Serial1.begin(9600);
  Serial.begin(9600);
  lcd.begin(16,2);  
  lcd.print("Vehicle Tracking");
  lcd.setCursor(0,1);
  lcd.print("     System     ");
  delay(2000);
  lcd.clear();
  lcd.print("WIFI Connecting..");
//  lcd.setCursor(0,1);
//  lcd.print("Please Wait...");
  delay(1000);
  connect_wifi("AT",1000);
  connect_wifi("AT+CWMODE=3",1000);
  connect_wifi("AT+CWQAP",1000);  
  connect_wifi("AT+RST",5000);
  check4IP(5000);
  if(!No_IP)
      {
        Serial.println("Connecting Wifi....");
        connect_wifi("AT+CWJAP=\"1st floor\",\"muda1884\"",7000);   //AT+CWJAP=”wifi_username”,”wifi_password”
      }
      else
        {
        }
      Serial.println("Wifi Connected");
      lcd.clear();
      lcd.print("WIFI Connected");
      delay(2000);
      lcd.clear();
      lcd.print("Getting IP"); 
      get_ip();
      delay(2000);
      connect_wifi("AT+CIPMUX=1",100);
      connect_wifi("AT+CIPSERVER=1,80",100);
      Serial1.end();
      lcd.clear();
      lcd.print("Waiting For GPS");
      lcd.setCursor(0,1);
      lcd.print("     Signal    ");
      delay(2000);
      gps.begin(9600);
      get_gps();
      show_coordinate();
      gps.end();
      Serial1.begin(9600);
      delay(2000);
      lcd.clear();
      lcd.print("GPS is Ready");
      delay(1000);
      lcd.clear();
      lcd.print("System Ready");
      Serial.println("System Ready..");
}
void loop() 
{
  k=0;
  Serial.println("Please Refresh Ur Page");
  lcd.setCursor(0,0);
  lcd.print("Please Refresh  ");
  lcd.setCursor(0,1);
  lcd.print("Your Web Page..  ");
  while(k<1000)
  {
    k++;
   while(Serial1.available())
   {
    if(Serial1.find("0,CONNECT"))
    {
      Serial1.end();
  gps.begin(9600);
  get_gps();
  gps.end();
  Serial1.begin(9600);
  Serial1.flush();
   /* lcd.clear();
      lcd.print("Sending Data to ");
      lcd.setCursor(0,1);
      lcd.print("    Web Page     ");*/
      Serial.println("Start Printing");
      Send();
      show_coordinate();
      Serial.println("Done Printing");
      delay(5000);
      lcd.clear();
      lcd.print("System Ready");
      delay(1000);
      k=1200;
      break;
    }
  }
  delay(1);
 }
}
void gpsEvent()
{
  gpsString="";
  while(1)
  {
   while (gps.available()>0)                //Serial incoming data from GPS
   {
    char inChar = (char)gps.read();
     gpsString+= inChar;                    //store incoming data from GPS to temporary string str[]
     i++;
     if (i < 7)                      
     {
      if(gpsString[i-1] != test[i-1])       //check for right string
      {
        i=0;
        gpsString="";
      }
     }
    if(inChar=='\r')
    {
     if(i>65)
     {
       gps_status=1;
       break;
     }
     else
     {
       i=0;
     }
    }
  }
   if(gps_status)
    break;
  }
}
void get_gps()
{
   gps_status=0;
   int x=0;
   while(gps_status==0)
   {
    gpsEvent();
    int str_lenth=i;
    latitude="";
    logitude="";
    coordinate2dec();
        i=0;x=0;
    str_lenth=0;
   }
}
void show_coordinate()
{
    lcd.clear();
    lcd.print("Latitide:");
    lcd.print(latitude);
    lcd.setCursor(0,1);
    lcd.print("Longitude:");
    lcd.print(logitude);
    Serial.print("Latitude:");
    Serial.println(latitude);
    Serial.print("Longitude:");
    Serial.println(logitude);
}
void coordinate2dec()
{
    
    //j=0;
    String lat_degree="";
    for(i=18;i<20;i++)          //extract latitude from string
      lat_degree+=gpsString[i];
    
    String lat_minut="";
    for(i=20;i<28;i++)
      lat_minut+=gpsString[i];
    
    String long_degree="";
    for(i=30;i<33;i++)          //extract longitude from string
      long_degree+=gpsString[i];
      
    String long_minut="";
    for(i=33;i<41;i++)
      long_minut+=gpsString[i];
      
     float minut= lat_minut.toFloat();
     minut=minut/60;
     float degree=lat_degree.toFloat();
     latitude=degree+minut;
     
     minut= long_minut.toFloat();
     minut=minut/60;
     degree=long_degree.toFloat();
     logitude=degree+minut;
}
void Send()
{
     
      webpage = "<h1>Welcome to Saddam Khan's Page</h1><body bgcolor=f0f0f0>";
      webpage+=name;
      webpage+=dob;
      webpage+=number;
      webpage+=cordinat;
      webpage+="<p>Latitude:";
      webpage+=latitude;
      webpage+="</p>";
      webpage+="<p>Longitude:";
      webpage+=logitude;
      webpage+="</p>";
     webpage+= "<a href=\"http://maps.google.com/maps?&z=15&mrt=yp&t=k&q=";
     webpage+=latitude;
     webpage+='+';              //28.612953, 77.231545   //28.612953,77.2293563
     webpage+=logitude;
     webpage+="\">Click Here for google map</a>";
     sendwebdata();
       webpage="";
     while(1)
     {
      Serial.println("AT+CIPCLOSE=0");
      Serial1.println("AT+CIPCLOSE=0");
      while(Serial1.available())
      {
        //Serial.print(Serial1.read());
        if(Serial1.find("0,CLOSE"))
        {
          return;
        }
      }
      delay(500);
      i++;
      if(i>5)
      {
        i=0;
      }
      if(i==0)
      break;
     }
}
void sendwebdata()
{
     i=0;
     while(1)
     {
      unsigned int l=webpage.length();
      Serial1.print("AT+CIPSEND=0,");
      Serial1.println(l+2);
      Serial.println(l+2);
      Serial.println(webpage);
      Serial1.println(webpage);
      while(Serial1.available())
      {
        if(Serial1.find("OK"))
        {
         return;
        }
      }
            i++;
      if(i>5)
        i=0;
        if(i==0)
        break;
      delay(200);
}
}

I replaced WIFI name and password with mine . Pls someone help me to solve this.

The error that I am getting is here.

[/AT
OK
AT+CWMODE=3
AT+CWMODE=3
AT+CWMODE=3
AT+CWMODE=3
AT+CWMODE=3
AT+CWMODE=3
AT+CWMODE=3
Error
AT+CWQAP
OK
AT+RST
OK
code]

Too dumb to help you, but I think original firmware /AT commands are overwritten once you upload an Arduino sketch.
leo..

So pls tell what to do for that

I'd say that since you got the first 'OK' response to the "AT" command "AT", it is neither a firmware problem nor a connection problem. You are using AT commands and not the alternative of the Arduino Core Software loaded onto the ESP device.

The first thing I'd suggest is using the Arduino serial monitor to issue the AT commands and see what happens. Example
You may have to alter your wiring to use pins 0 & 1.

The full list of commands is here.

Maybe try CWMODE=1 to start with. If that works, it could be something to do with the default name/password for the Access Point mode, but that is just a guess.

The below code works for me (Arduino IDE - it seems you're using that rather than the Lua option). Set up your ssid and password and you should be good to go.
Connect the Serial monitor to see your IP address, then point your browser to that address, and you can switch the LED on and off (set variable ledPin to where-ever you want to connect an LED).

#include <ESP8266WiFi.h>
 
const char* ssid = "ssid";
const char* password = "password";
 
int ledPin = D5;
WiFiServer server(80);
 
void setup() {
  Serial.begin(9600);
  delay(10);
 
 
  pinMode(ledPin, OUTPUT);
  digitalWrite(ledPin, LOW);
 
  // Connect to WiFi network
  Serial.println();
  Serial.println();
  Serial.print("Connecting to ");
  Serial.println(ssid);
 
  WiFi.begin(ssid, password);
 
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("");
  Serial.println("WiFi connected");
 
  // Start the server
  server.begin();
  Serial.println("Server started");
 
  // Print the IP address
  Serial.print("Use this URL : ");
  Serial.print("http://");
  Serial.print(WiFi.localIP());
  Serial.println("/");
 
}
 
void loop() {
  // Check if a client has connected
  WiFiClient client = server.available();
  if (!client) {
    return;
  }
 
  // Wait until the client sends some data
  Serial.println("new client");
  while(!client.available()){
    delay(1);
  }
 
  // Read the first line of the request
  String request = client.readStringUntil('\r');
  Serial.println(request);
  client.flush();
 
  // Match the request
 
  int value = LOW;
  if (request.indexOf("/LED=ON") != -1) {
    digitalWrite(ledPin, HIGH);
    value = HIGH;
  } 
  if (request.indexOf("/LED=OFF") != -1){
    digitalWrite(ledPin, LOW);
    value = LOW;
  }
 
 
 
  // Return the response
  client.println("HTTP/1.1 200 OK");
  client.println("Content-Type: text/html");
  client.println(""); //  do not forget this one
  client.println("<!DOCTYPE HTML>");
  client.println("<html>");
 
  client.print("Led pin is now: ");
 
  if(value == HIGH) {
    client.print("On");  
  } else {
    client.print("Off");
  }
  client.println("

");
  client.println("Click <a href=\"/LED=ON\">here</a> turn the LED on pin 5 ON
");
  client.println("Click <a href=\"/LED=OFF\">here</a> turn the LED on pin 5 OFF
");
  client.println("</html>");
 
  delay(1);
  Serial.println("Client disconnected");
  Serial.println("");
 
}

I'd another look at your code.
The "OK" message is not the one generated from the ESP8266 directly, it is created in connect_wifi()
It is unfortunate your code can print only "OK" or "error" and not the string returned by the AT command from the ESP8266. This prevents you using commands like AT+CWMODE? and seeing the result as you would if you were using the serial monitor.

Depending on the exact ESP model, you may have to set the baud rate to 115200 instead of 9600. Since your code only does a crude check to see if it gets some sort response to the commands it issues to the ESP, it might sometimes appear to work even with the wrong baud rate.

The code wvmarle supplied is intended to run directly on the ESP device and one where the Arduino Core Software is loaded. This is not the case for you. Your software runs on an Arduino and sends AT commands to the ESP for execution.

6v6gt:
The code wvmarle supplied is intended to run directly on the ESP device

Indeed. OP may be able to do the same, to make sure at least the ESP module can connect.

Thanks everyone for replying.

Before using my ESP8266 device for this project, I did AT command test. It shows the correct result.

As 6v6gt suggested ,I will try with different baud rate.Then I will check . Thank you very much 6v6gt for

giving me the suggestions

According to the code given by MWMARLE , I did this before and got the output also.My module got

connected to WIFI also. But it is different code for the project I am working on. Anyway thanks

MWMARLE

Even after changing baud rate to 115200, there is still error. When I did AT command test, my ESp8266

responds correctly. But not reponding in this case. Pls help me

The error that I am getting is here (after changing baud rate to 115200)

[AT
AT
AT
AT
AT
AT
AT
Error
AT+CWMODE=3
AT+CWMODE=3
AT+CWMODE=3
AT+CWMODE=3
AT+CWMODE=3
AT+CWMODE=3
AT+CWMODE=3
Error
AT+CWQAP
AT+CWQAP
AT+CWQAP
AT+CWQAP
AT+CWQAP
AT+CWQAP
AT+CWQAP
Error
AT+RST
AT+RST
AT+RST
AT+RST
AT+RST
AT+RST
AT+RST
Error
Connecting Wifi....
AT+CWJAP="SRINIKETANAM","VARDULASA_258293"
AT+CWJAP="SRINIKETANAM","VARDULASA_258293"
AT+CWJAP="SRINIKETANAM","VARDULASA_258293"
AT+CWJAP="SRINIKETANAM","VARDULASA_258293"
AT+CWJAP="SRINIKETANAM","VARDULASA_258293"
AT+CWJAP="SRINIKETANAM","VARDULASA_258293"
AT+CWJAP="SRINIKETANAM","VARDULASA_258293"
Error
Wifi Connected
]

OK. 9600 is correct for your model of ESP8266. Which one is it, incidentally ?

Can you print all the messages the program is delivering up to the point it writes "Waiting For GPS" on the LCD or "System Ready". If it hangs somewhere, wait a few minutes before giving up.

Describe the test you did here:

When I did AT command test, my ESp8266 responds correctly.

My LCD got stuck on "WIFI Connecting............". It wont go beyond that. The results of AT command

tests are here

[ü ]ˆÌ
ÿaÀFó’Ç}Ëd|äØaa3ÜH‡ÊÇ}b
[Vendor:www.ai-thinker.com Version:0.9.2.4]

ready
AT


OK
AT+GMR

0018000902-AI03

OK
AT+CWMODE?

+CWMODE:3

OK
AT+CWLAP

+CWLAP:(3,"SRINIKETANAM",-56,"ec:08:6b:5b:fd:7a",1)

OK
AT+CWJAP="SRINIKETANAM","VARDULASA_258293"


OK
AT+CIPMUX=1


OK
AT+CIPSERVER=1,8888


OK
AT+CIFSR

192.168.4.1
192.168.1.103

OK
Link

+IPD,0,382:GET / HTTP/1.1
Host: 192.168.1.103:8888
Connection: keep-alive
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
Accept-Encoding: gzip, deflate, sdch
Accept-Language: en-US,en;q=0.8


OK
Link
]

OK.

Can you try "AT+CWMODE=3" in the serial console and see (a) how long it takes to respond and (b) if it gives a return code of, say, OK.

Also try AT+CWJAP="wifi_username","wifi_password" and check the time and the returned string (which in this case is checked and must be OK).

Your code is looking for the string "WIFI GOT IP" in the response after it issues the command "AT+RST" . I don't see this in your serial monitor output and this could be firmware version dependent. You are using apparently an ESP-12 module.
Just to be sure, can you go through a successful connection in the serial console, then issue an "AT+RST" to see what the response is.

Your code will hang in function get_ip() if the response to the command "AT+CIFSR" does not contain the string STAIP because 'ch' will not be set, so none of the break statements out of the while loop will be activated.
The output from the serial monitor in the previous post does not show this (STAIP), only the 2 IP address. One of the ESP's Access point and the other of the access point in your local network. Since the IP address 'IP' appears to be used only as information in your code, you should comment out the call to get_ip() to see if you get past the hang.

I don't understand this if you are using the same code as in the OP:

My LCD got stuck on "WIFI Connecting............".

If it prints "Wifi Connected" to the serial console (as in your post #9 ) then it should have written "WIFI Connected" to the LCD according to this code:

     Serial.println("Wifi Connected");
     lcd.clear();
     lcd.print("WIFI Connected");

If you've modified the code in the mean time, post your new code.

Problem with AT+CWMODE is solved. During AT command test , I checked my ESP8266 which mode it is in using AT_CWMODE? command. It shows +CWMODE:3. It means it is already in mode 3. When I gave AT+CWMODE=3, it shows "no change" in the serial monitor. But my program is looking for OK which is not there . Thats why I was getting error. Now I changed it to AT+CWMODE?. It is working now.

Then it is also got connected to wifi within few seconds. It shows the output immediately.

My LCD also shows WIFI Connected.

As you suggested STAIP is not contained in the output, I removed that If Statement.. Now it is working fine.

Still there is one problem . My program is not outputting IP Address. Pls help me. If I get IP address, I am done with the project.

The output after replacing AT+CWMODE =3 by AT+CWMODE? and removing IF Statement (STAIP)
is here

[AT
OK
AT+CWMODE?
OK
AT+CWQAP
OK
AT+RST
OK
Connecting Wifi....
AT+CWJAP="SRINIKETANAM","VARDULASA_258293"
AT+CWJAP="SRINIKETANAM","VARDULASA_258293"
OK
Wifi Connected
IP Address:
OK
ATPort:
80
AT+CIPMUX=1
AT+CIPMUX=1
OK
AT+CIPSERVER=1,80
OK
Latitude:12.80
Longitude:75.33
System Ready..
Please Refresh Ur Page
Please Refresh Ur Page
Please Refresh Ur Page
Please Refresh Ur Page
Please Refresh Ur Page
Please Refresh Ur Page
]

OK. That sounds good.

Try AT+CIPSTA? in the serial console to see if you get the IP address you want. I guess you want the IP address your ESP has acquired from your local network and not the IP address of the ESP's access point.

If that works, post your updated code for a suggestion as how to integrate this command in it.

Getting Error for AT+CIPSTA? , AT+CIPSTA_CUR?, AT+CIPSTA_DEF?

The output is here

[AT


OK
AT+CWLAP

+CWLAP:(3,"SRINIKETANAM",-58,"ec:08:6b:5b:fd:7a",1)

OK
AT+CWJAP="SRINIKETANAM","VARDULASA_258293"


OK
AT+CIFSR

192.168.4.1
192.168.1.100

OK
AT+CIPSTA?


ERROR
AT+CIPSTA_CUR?


ERROR
AT+CIPSTA_DEF?


ERROR
AT+CIPAP?


ERRO]

For crying out loud, why would anyone use AT commands for something​ like this?
Just program the ESP directly using the Arduino core.

Pieter

I added these three lines in my code

#include<WiFi.h>
Serial.print("IP address allotted to ESP : ");
Serial.println(WiFi.localIP());

But still it does not show IP address.
The output corresponding to the above code is below

[IP address allotted to ESP : 0.0.0.0
]

PieterP:
For crying out loud, why would anyone use AT commands for something like this?
Just program the ESP directly using the Arduino core.

Pieter

That is a rather emotional announcement of a valid alternative to the route that the OP has already chosen.
I personally would also have chosen to replace the standard ESP firmware with the Arduino Core code. However, I also see the attraction of using the AT commands, especially where a one line AT entered on the serial console command can replace maybe 50 or so lines of C++.
Also, some ESP modules only break out a very small number of pins which dictates a role for these as a 'network appendage' to something like a Uno which has enough pins to do something useful.

OP please post your latest code

My code is here

[#include<SoftwareSerial.h>
#include<WiFi.h>
SoftwareSerial Serial1(2,3);     //make RX arduino line is pin 2, make TX arduino line is pin 3.
SoftwareSerial gps(10,11);
#include<LiquidCrystal.h>
LiquidCrystal lcd(14,15,16,17,18,19);
boolean No_IP=false;
String IP="";
String webpage="";
int i=0,k=0;
int  gps_status=0;
String name="<p>1. Name: Pavamana K J </p>";   //22
String dob="<p>2. DOB: 15 October 1994</p>";     //21
String number="<p>4. Vehicle No.: RJ05 XY 4201</p>";//29
String cordinat="<p>Coordinates:</p>";          //17
String latitude=""; 
String logitude="";                       
String gpsString="";
char *test="$GPGGA";
void check4IP(int t1)
{
  int t2=millis();
  while(t2+t1>millis())
  {
    while(Serial1.available()>0)
    {
      if(Serial1.find("WIFI GOT IP"))
      {
        No_IP=true;
      }
    }
  }
}
void get_ip()
{
   IP="";
  char ch=0;
  while(1)
  {
    Serial1.print("AT+CIFSR");
    while(Serial1.available()>0)
    {
      //if(Serial1.find("STAIP,"))
      
        //delay(1000);
        Serial.print("IP Address:");
        while(Serial1.available()>0)
        {
          ch=Serial1.read();
          if(ch=='+')
          break;
          IP+=ch;
        }
      
      if(ch=='+')
      break;
    }
    if(ch=='+')
    break;
    delay(1000);
  }
  lcd.clear();
  lcd.print(IP);
  lcd.setCursor(0,1);
  lcd.print("Port: 80");
  Serial.print(ch);
  Serial.print("Port:");
  Serial.println(80);
  delay(1000);
}
void connect_wifi(String cmd, int t)
{
  int temp=0,i=0;
  while(1)
  {
    Serial.println(cmd);
    Serial1.println(cmd); 
    while(Serial1.available()>0)
    {
      if(Serial1.find("OK"))
      {
      i=8;
      }
    }
    delay(t);
    if(i>5)
    break;
    i++;
  }
  if(i==8)
  {
    Serial.println("OK");
  }
  else
  {
  Serial.println("Error");
  }
  delay(1000);
}
void setup() 
{
  Serial1.begin(9600);
  Serial.begin(9600);
  lcd.begin(16,2);  
  lcd.print("Vehicle Tracking");
  lcd.setCursor(0,1);
  lcd.print("     System     ");
  delay(2000);
  lcd.clear();
  lcd.print("WIFI Connecting..");
//  lcd.setCursor(0,1);
//  lcd.print("Please Wait...");
  delay(1000);
  connect_wifi("AT",1000);
  connect_wifi("AT+CWMODE?",1000);
 // connect_wifi("AT+CWLAP",1000);
  connect_wifi("AT+CWQAP",1000);  
  connect_wifi("AT+RST",5000);
  check4IP(5000);
  if(!No_IP)
      {
        Serial.println("Connecting Wifi....");
        connect_wifi("AT+CWJAP=\"SRINIKETANAM\",\"VARDULASA_258293\"",7000);   //AT+CWJAP=”wifi_username”,”wifi_password”
      }
      else
        {
        }
      Serial.println("Wifi Connected");
      lcd.clear();
      lcd.print("WIFI Connected");
      delay(2000);
      lcd.clear();
      lcd.print("Getting IP"); 
      get_ip();
      Serial.print("IP address allotted to ESP : ");
      Serial.println(WiFi.localIP());
      delay(2000);
      connect_wifi("AT+CIPMUX=1",100);
      connect_wifi("AT+CIPSERVER=1,80",100);
      Serial1.end();
      lcd.clear();
      lcd.print("Waiting For GPS");
      lcd.setCursor(0,1);
      lcd.print("     Signal    ");
      delay(2000);
      gps.begin(9600);
      get_gps();
      show_coordinate();
      gps.end();
      Serial1.begin(9600);
      delay(2000);
      lcd.clear();
      lcd.print("GPS is Ready");
      delay(1000);
      lcd.clear();
      lcd.print("System Ready");
      Serial.println("System Ready..");
}
void loop() 
{
  k=0;
  Serial.println("Please Refresh Ur Page");
  lcd.setCursor(0,0);
  lcd.print("Please Refresh  ");
  lcd.setCursor(0,1);
  lcd.print("Your Web Page..  ");
  while(k<1000)
  {
    k++;
   while(Serial1.available())
   {
    if(Serial1.find("0,CONNECT"))
    {
      Serial1.end();
  gps.begin(9600);
  get_gps();
  gps.end();
  Serial1.begin(9600);
  Serial1.flush();
   /* lcd.clear();
      lcd.print("Sending Data to ");
      lcd.setCursor(0,1);
      lcd.print("    Web Page     ");*/
      Serial.println("Start Printing");
      Send();
      show_coordinate();
      Serial.println("Done Printing");
      delay(5000);
      lcd.clear();
      lcd.print("System Ready");
      delay(1000);
      k=1200;
      break;
    }
  }
  delay(1);
 }
}
void gpsEvent()
{
  gpsString="";
  while(1)
  {
   while (gps.available()>0)                //Serial incoming data from GPS
   {
    char inChar = (char)gps.read();
     gpsString+= inChar;                    //store incoming data from GPS to temporary string str[]
     i++;
     if (i < 7)                      
     {
      if(gpsString[i-1] != test[i-1])       //check for right string
      {
        i=0;
        gpsString="";
      }
     }
    if(inChar=='\r')
    {
     if(i>65)
     {
       gps_status=1;
       break;
     }
     else
     {
       i=0;
     }
    }
  }
   if(gps_status)
    break;
  }
}
void get_gps()
{
   gps_status=0;
   int x=0;
   while(gps_status==0)
   {
    gpsEvent();
    int str_lenth=i;
    latitude="";
    logitude="";
    coordinate2dec();
        i=0;x=0;
    str_lenth=0;
   }
}
void show_coordinate()
{
    lcd.clear();
    lcd.print("Latitide:");
    lcd.print(latitude);
    lcd.setCursor(0,1);
    lcd.print("Longitude:");
    lcd.print(logitude);
    Serial.print("Latitude:");
    Serial.println(latitude);
    Serial.print("Longitude:");
    Serial.println(logitude);
}
void coordinate2dec()
{
    
    //j=0;
    String lat_degree="";
    for(i=18;i<20;i++)          //extract latitude from string
      lat_degree+=gpsString[i];
    
    String lat_minut="";
    for(i=20;i<28;i++)
      lat_minut+=gpsString[i];
    
    String long_degree="";
    for(i=30;i<33;i++)          //extract longitude from string
      long_degree+=gpsString[i];
      
    String long_minut="";
    for(i=33;i<41;i++)
      long_minut+=gpsString[i];
      
     float minut= lat_minut.toFloat();
     minut=minut/60;
     float degree=lat_degree.toFloat();
     latitude=degree+minut;
     
     minut= long_minut.toFloat();
     minut=minut/60;
     degree=long_degree.toFloat();
     logitude=degree+minut;
}
void Send()
{
     
      webpage = "<h1>Welcome to Saddam Khan's Page</h1><body bgcolor=f0f0f0>";
      webpage+=name;
      webpage+=dob;
      webpage+=number;
      webpage+=cordinat;
      webpage+="<p>Latitude:";
      webpage+=latitude;
      webpage+="</p>";
      webpage+="<p>Longitude:";
      webpage+=logitude;
      webpage+="</p>";
     webpage+= "<a href=\"http://maps.google.com/maps?&z=15&mrt=yp&t=k&q=";
     webpage+=latitude;
     webpage+='+';              //28.612953, 77.231545   //28.612953,77.2293563
     webpage+=logitude;
     webpage+="\">Click Here for google map</a>";
     sendwebdata();
       webpage="";
     while(1)
     {
      Serial.println("AT+CIPCLOSE=0");
      Serial1.println("AT+CIPCLOSE=0");
      while(Serial1.available())
      {
        //Serial.print(Serial1.read());
        if(Serial1.find("0,CLOSE"))
        {
          return;
        }
      }
      delay(500);
      i++;
      if(i>5)
      {
        i=0;
      }
      if(i==0)
      break;
     }
}
void sendwebdata()
{
     i=0;
     while(1)
     {
      unsigned int l=webpage.length();
      Serial1.print("AT+CIPSEND=0,");
      Serial1.println(l+2);
      Serial.println(l+2);
      Serial.println(webpage);
      Serial1.println(webpage);
      while(Serial1.available())
      {
        if(Serial1.find("OK"))
        {
         return;
        }
      }
            i++;
      if(i>5)
        i=0;
        if(i==0)
        break;
      delay(200);
     }
}]