HOW TO SHOW DYNAMIC GPS DATA AND AUTO REFRESH PAGE ON WEB BROWSER

Hello,

I’m using ESP8266 WIFI module and GPS module. I have connected to ARDUINO UNO R3 board to read

the GPS coordinates and transmit them to webpage using ESP8266 WiFi module connected to router.

In my code the page change only when I press F5 (refresh) , and so I can see the change of Coordinates.

I want to see the changing results dynamically with out refreshing the webpage. what to I need to do

/change in order that it will change automatically?

please check my code here or in the attachment and suggest me the changes.

Thanks in advance.

CODE:

// code starts

#include <Adafruit_GPS.h>
#include<SoftwareSerial.h>

SoftwareSerial Serial1(2,3); // ESP8266 RX pin 2, TX pin 3.
SoftwareSerial gps(11, 10); // GPS RX pin 10, TX pin 11.

boolean No_IP=false;
String IP="";
String webpage="";

int i=0,k=0;
int gps_status=0;

String name="

Name: XXXXXXXX

“; //22
String date=“

DATE: DD MM YYYY

”; //21
String number=”

Vehicle No.: ABC 0000

";//29
String cordinat=“

Coordinates:

”; //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);
}
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);
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=“MountPointTech”,“MpTl2013"”,7000); //AT+CWJAP=”wifi_username”,”wifi_password”
}
else
{
}
Serial.println(“Wifi Connected”);
get_ip();
delay(2000);
connect_wifi(“AT+CIPMUX=1”,100);
connect_wifi(“AT+CIPSERVER=1,80”,100);
Serial1.end();
Serial.println(“Waiting For GPS”);
Serial.println(” Signal ");
delay(2000);
gps.begin(9600);
get_gps();
show_coordinate();
gps.end();
Serial1.begin(9600);
delay(2000);
Serial.println(“GPS is Ready”);
delay(1000);
Serial.println(“System Ready…”);
}

void loop()
{
k=0;
Serial.println(“Please Refresh Ur 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();
Serial.println(“Start Printing”);
Send();
show_coordinate();
Serial.println(“Done Printing”);
delay(5000);
//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()
{

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*;*

  • String lat_minut="";*
  • for(i=20;i<28;i++)*
    lat_minut+=gpsString*;*

* String long_degree="";
_
for(i=30;i<33;i++) //extract longitude from string*_
long_degree+=gpsString*;*

* String long_minut="";
_ for(i=33;i<41;i++)_
long_minut+=gpsString;*

* 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 = “

Welcome to MountPoint Technologies Pvt Ltd

”;*
* webpage+=name;*
* webpage+=date;*
* webpage+=number;*
* webpage+=cordinat;*
* webpage+=“

Latitude:”;*
* webpage+=latitude;*
* webpage+="

";*
* webpage+=“

Longitude:”;*
* webpage+=logitude;*
* webpage+="

";*
* 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 ";*
* 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);*
* }*
}
// end of code.
ESP8266 & GPS sketch.ino (6.23 KB)

First, please modify your post and use the code button </> so your code looks like this and is easy to copy to a text editor. See How to use the Forum Your code is too long for me to study quickly without copying to a text editor.

Second, I recommend that you figure out how to solve web programming problems using your PC as there is far more advice available on the web for that. When you know how to do that you will be able to transfer the concept to your Arduino.

IIRC it is a fairly common feature to get a browser page to refresh itself at intervals.

…R