I am trying to read the gps coordinates and send them to a PHP file on my server.
The following code below does the following When it picks up a location it then sends it to the php file and then adds
it to a text file, I have tried .httpGET by itself and added the the value and it saves to the text file.
When i try the code blow it says Sending Data and then it says Data sent and when I check the text file there is no
information in there. When i check the print out the buffer and past that information into my web browser url bar and then check the text file the information has been saved.
What can cause this to happen?
#include <MemoryFree.h>
#include <TinyGPS++.h>
#include "SIM900.h"
#include <SoftwareSerial.h>
#include "inetGSM.h"
InetGSM inet;
TinyGPSPlus gps;
char msg[50];
int numdata;
int i=0;
boolean started=false;
char APN_Server[50] = "general.t-mobile.uk";
char APN_User[50] = "t-mobile";
char APN_Pass[50] = "tm";
int lat1,lat2;
int lon1,lon2;
char buffer[70];
SoftwareSerial ss(7, 6);
void setup()
{
Serial.begin(9600);
ss.begin(9600);
Serial.println("Starting...");
if (gsm.begin(2400)){
Serial.println("\nstatus=READY");
started=true;
}else{
Serial.println("\nstatus=IDLE");
}
if(started){
if (inet.attachGPRS(APN_Server, APN_User, APN_Pass)){
Serial.println("status=ATTACHED");
}else{
Serial.println("status=ERROR");
}
}
};
void loop()
{
ss.listen();
while (ss.available() > 0) {
char inByte = ss.read();
if (gps.encode(inByte++)){
Serial.print(F("Location: "));
if (gps.location.isValid()){
float flat = gps.location.lat();
float flon = gps.location.lng();
lat1 = (int)flat;
lat2 = (flat - lat1)*10000;
lon1 = (int)flon;
lon2 = (flon - lon1)*10000;
sprintf(buffer, "/system/gps.php?uid=123&lat=%d.%d&lon=%d.%d", lat1, lat2, lon1, lon2);
Serial.println("Sending Data...");
inet.httpGET("websiteURL.com", 80, buffer, msg,0);
//Serial.println(buffer);
Serial.println("Data Sent!");
//Serial.print(gps.location.lat(), 6);
//Serial.print(F(","));
//Serial.print(gps.location.lng(), 6);
}else{
Serial.print(F("INVALID"));
}
Serial.println();
}
}
delay(1000);
};
Thanks