jegatheesan
Published © GPL3+

Own Tracking Website

Build your own tracking website to track pets, cars and even our sweet children...

AdvancedFull instructions provided3,163
Own Tracking Website

Things used in this project

Software apps and online services

Apache Tomcat server
Any Database MySQL, Access or MSSQL

Story

Read more

Code

Tracking.ino

Arduino
#include <LGPS.h>
#include <LGPRS.h>
#include <LGPRSClient.h>
#include <LGPRSServer.h>

char server[] = "ur static ip here or domain";
char path[] = "/Location/SendLocation?";   
String address1 = "/Location/SendLocation?";
String address2 = "";
int port = 8080; // HTTP
int deviceno=10;

gpsSentenceInfoStruct info;
char buff[256];
double latitude;
double longitude;

LGPRSClient client;

void setup()
{

  LGPS.powerOn();
  delay(3000);  
    
  while (!LGPRS.attachGPRS())
  {
    delay(500);
  }
}

void loop()
{
    LGPS.getData(&info);
    parseGPGGA((const char*)info.GPGGA);
    if (latitude != 0 && longitude != 0)
    {
        latitude=latitude/100;
        longitude=longitude/100;
        address2 = "";
        address2.concat("Lat=");
        address2.concat(latitude);                        
        address2.concat("&Lng=");
        address2.concat(longitude);                        
        address2.concat("&Dvno=");        
        address2.concat(deviceno);    
        Serial.println("address2");
        if (client.connect(server, port))
        {
          Serial.println("connected");
          // Make a HTTP request:
          client.print("GET ");
          client.print(address2);
          client.println(" HTTP/1.1");
          client.print("Host: ");
          client.println(server);
          client.println("Connection: close");
          client.println();
        }
        else
        {
          // if you didn't get a connection to the server:
          Serial.println("connection failed");
        }      
    }
}

void parseGPGGA(const char* GPGGAstr)
{
  int tmp;
  if(GPGGAstr[0] == '$')
  {   
    tmp = getComma(2, GPGGAstr);
    latitude = getDoubleNumber(&GPGGAstr[tmp]);
    tmp = getComma(4, GPGGAstr);
    longitude = getDoubleNumber(&GPGGAstr[tmp]);
    sprintf(buff, "latitude = %10.4f, longitude = %10.4f", latitude, longitude);
  }
  else
  {
    latitude = 0;
    longitude = 0;    
  }
}

static double getDoubleNumber(const char *s)
{
  char buf[10];
  unsigned char i;
  double rev;
  
  i=getComma(1, s);
  i = i - 1;
  strncpy(buf, s, i);
  buf[i] = 0;
  rev=atof(buf);
  return rev; 
}

static unsigned char getComma(unsigned char num,const char *str)
{
  unsigned char i,j = 0;
  int len=strlen(str);
  for(i = 0;i < len;i ++)
  {
     if(str[i] == ',')
      j++;
     if(j == num)
      return i + 1; 
  }
  return 0; 
}

Credits

jegatheesan

jegatheesan

18 projects • 66 followers
Simply A Mechatronics Lover.

Comments