MAP I/O
Wiring
Node MCU >> GPS
D1 (GPIO 5) >> RX
D2 (GPIO 4) >> TX
3V >> VCC
GND >> GND
GPS(Global Positioning system )
NMEA(National Marine Electronics Association) structure
$GPRMC,162254.00,A,3723.02837,N,12159.39853,W,0.820,188.36,110706,,,A*74
$GPVTG,188.36,T,,M,0.820,N,1.519,K,A*3F
$GPGGA,162254.00,3723.02837,N,12159.39853,W,1,03,2.36,525.6,M,-25.6,M,,*65
$GPGSA,A,2,25,01,22,,,,,,,,,,2.56,2.36,1.00*02
$GPGSV,4,1,14,25,15,175,30,14,80,041,,19,38,259,14,01,52,223,18*76
$GPGSV,4,2,14,18,16,079,,11,19,312,,14,80,041,,21,04,135,25*7D
$GPGSV,4,3,14,15,27,134,18,03,25,222,,22,51,057,16,09,07,036,*79
$GPGSV,4,4,14,07,01,181,,15,25,135,*76
$GPGLL,3723.02837,N,12159.39853,W,162254.00,A,A*7C
$GPZDA,162254.00,11,07,2006,00,00*63
In this project We need only coordinate then We need only "$GPGGA"
$GPGGA,162254.00,3723.02837,N,12159.39853,W,1,03,2.36,525.6,M,-25.6,M,,*65
GGA - essential fix data which provide 3D location and accuracy data. $GPGGA,123519,4807.038,N,01131.000,E,1,08,0.9,545.4,M,46.9,M,,*47
Where:
GGA Global Positioning System Fix Data
123519 Fix taken at 12:35:19 UTC
4807.038,N Latitude 48 deg 07.038' N
01131.000,E Longitude 11 deg 31.000' E
1 Fix quality: 0 = invalid
1 = GPS fix (SPS)
2 = DGPS fix
3 = PPS fix
4 = Real Time Kinematic
5 = Float RTK
6 = estimated (dead reckoning) (2.3 feature)
7 = Manual input mode
8 = Simulation mode
08 Number of satellites being tracked
0.9 Horizontal dilution of position
545.4,M Altitude, Meters, above mean sea level
46.9,M Height of geoid (mean sea level) above WGS84
ellipsoid
(empty field) time in seconds since last DGPS update
(empty field) DGPS station ID number
*47 the checksum data, always begins with *
If the height of geoid is missing then the altitude should be suspect. Some non-standard implementations report altitude with respect to the ellipsoid rather than geoid altitude. Some units do not report negative altitudes at all. This is the only sentence that reports altitude.
GPS module : https://goo.gl/UbMufK
GPS Module Banggood : https://goo.gl/2JmreQ
ESP8266 NodeMCU : https://goo.gl/7MoawN
ESP8266 NodeMCU Banggood : https://goo.gl/cBFyZ3
Please Donate for long life blog
ขอเชิญร่วมบริจาค เพื่อสนับสนุนทุนการทำโครงงานต่อไป
ขอเชิญร่วมบริจาค เพื่อสนับสนุนทุนการทำโครงงานต่อไป
Click Link : https://paypal.me/aarduinothai
CODE
#include <SoftwareSerial.h>
#include <TinyGPS++.h>
#include <ESP8266WiFi.h>
#include <ESP8266WiFiAP.h>
#include <ESP8266WiFiGeneric.h>
#include <ESP8266WiFiMulti.h>
#include <ESP8266WiFiScan.h>
#include <ESP8266WiFiSTA.h>
#include <ESP8266WiFiType.h>
#include <WiFiClient.h>
#include <WiFiClientSecure.h>
#include <WiFiServer.h>
#include <WiFiUdp.h>
TinyGPSPlus gps;
SoftwareSerial ss(4,5); // for connect GPS
const char* ssid = "santi";
const char* password = "santi12345678";
float latitude , longitude;
int year,month,date,hour,minute,second;
String date_str,time_str,lat_str,lng_str;
int pm;
WiFiServer server(80);
void setup()
{
Serial.begin(115200);
ss.begin(9600);
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");
server.begin();
Serial.println("Start Started");
//Show IP address
Serial.println(WiFi.localIP());
}
void loop()
{
while (ss.available()>0)
if(gps.encode(ss.read()))
{
if(gps.location.isValid())
{
latitude = gps.location.lat();
lat_str = String(latitude , 6);
longitude = gps.location.lng();
lng_str = String(longitude , 6);
}
if(gps.date.isValid())
{
date_str = "";
date = gps.date.day();
month = gps.date.month();
year = gps.date.year();
if(date<10)
date_str = '0';
date_str += String(date);
date_str += "/";
if(month < 10)
date_str += '0';
date_str += String(month);
date_str += "/";
if(year<10)
date_str += '0';
date_str += String(year);
}
if(gps.time.isValid())
{
time_str = "";
hour = gps.time.hour();
minute = gps.time.minute();
second = gps.time.second();
minute = (minute + 30);
if(minute>59)
{
minute = minute - 60;
hour = hour + 1;
}
hour = (hour + 5);
if (hour > 23)
hour = hour - 24;
if(hour>= 12)
pm = 1;
else
pm = 0;
hour = hour % 12;
if(hour < 10)
time_str ='0';
time_str += String(hour);
time_str += ":";
if(minute<10)
time_str ='0';
time_str += String(minute);
time_str += ":";
if(second<10)
time_str ='0';
time_str += String(second);
if (pm == 1)
time_str += "PM";
else
time_str += "AM";
}
}
// Check if a client has connected
WiFiClient client = server.available();
if(!client)
{
return;
}
//prepare the response
String s = "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n <!DOCTYPE html><html><head><title>GPSNodeMCU A-Arduino </title><style>";
s += "a:link {background-color: YELLOW;text-decoration: none;}";
s += "table,th,td {border: 1px solid black;}</style></head><body><h1 style=";
s += "font-size:300%;";
s += " ALIGN=CENTER> GPS Interfacing with NodeMCU</h1>";
s += "<p ALIGN=CENTER style=""font-size:150%;""";
s += "> <b>Location Details</b></p><table ALIGN=CENTER style=";
s += "width:50%";
s += "> <tr> <th>Latitude</th>";
s += "<td ALIGN=CENTER>";
s += lat_str;
s += "</td></tr><tr><th>Longitude</th><td ALIGN=CENTER>";
s += lng_str;
s += "</td></tr><tr><th>Date</th><td ALIGN=CENTER>";
s += date_str;
s += "</td></tr><tr><th>Time</th><td ALIGN=CENTER>";
s += time_str;
s += "</td></tr></table>";
if(gps.location.isValid())
{
s += "<a href=\"http://maps.google.com/maps?&z=15&mrt=yp&t=k&q=";
s += lat_str;
s += '+';
s += lng_str;
s += "\">Click here!To check the location in Google maps.</a>";
}
s += "</body> </html> \n";
client.print(s);
delay(100);
}