Hi,
I am using a gps shield, arduino GSM shield and a arduinoo uno board. I am trying to send the gps data from the shield over to mysql database using wampserver. However, my connection to the server always fails even though i'm using a valid 3G SIM card on the GSM shield.
Should i set the GSM as a web client or web server?
Thanks!
Below is my code:
// libraries
#include <AltSoftSerial.h>
#include <TinyGPS.h>
#include <GSM.h>
// PIN Number
#define PINNUMBER ""
// APN data
#define GPRS_APN "my GPRS APN" // replace your GPRS APN
#define GPRS_LOGIN "LOGIN" // replace with your GPRS login
#define GPRS_PASSWORD "password" // replace with your GPRS password
// initialize the library instance
GSMClient client;
GPRS gprs;
GSM gsmAccess;
TinyGPS gps;
AltSoftSerial serialgps(0,1);
int year;
byte month, day, hour, minute, second, hundredths;
unsigned long chars;
unsigned short sentences, failed_checksum;
int deviceid = 01;
// URL, path & port (for example: arduino.cc)
char server[] = "http://119.234.137.238";
char path[] = "/gpsconnect/updategpsdb.php?";
int port = 80; // port 80 is the default for HTTP
void setup()
{
// initialize serial communications and wait for port to open:
Serial.begin(9600);
Serial.println("Starting Arduino web client.");
GSMsetup();
delay(1000);
serialgps.begin(4800);
Serial.println("");
Serial.println("GPS Shield QuickStart Example Sketch v12");
Serial.println(" ...waiting for lock... ");
Serial.println("");
}
void loop()
{
// if there are incoming bytes available
// from the server, read them and print them:
if (client.available())
{
while(serialgps.available())
{
int c = serialgps.read();
if(gps.encode(c))
{
float latitude, longitude;
unsigned long fix_age;
gps.f_get_position(&latitude, &longitude, &fix_age);
if (fix_age == TinyGPS::GPS_INVALID_AGE) {
Serial.println("No fix detected");
}
else if(fix_age >5000) { //if no data received within 5s, then stale data.
Serial.println("WARNING. Possible stale data!");
}
else {
Serial.print(deviceid);
Serial.print("latitude: ");
Serial.print(latitude,6);
Serial.print(", ");
Serial.print("longitude: ");
Serial.println(longitude,6);
Serial.println();
gps.stats(&chars, &sentences, &failed_checksum);
}
}
}
// if the server's disconnected, stop the client:
if (!client.available() && !client.connected())
{
Serial.println();
Serial.println("disconnecting.");
client.stop();
// do nothing forevermore:
for(;;)
;
}
}
}
void GSMsetup (void) {
// connection state
boolean notConnected = true;
// After starting the modem with GSM.begin()
// attach the shield to the GPRS network with the APN, login and password
while(notConnected)
{
if((gsmAccess.begin(PINNUMBER)==GSM_READY) &
(gprs.attachGPRS(GPRS_APN, GPRS_LOGIN, GPRS_PASSWORD)==GPRS_READY))
notConnected = false;
else
{
Serial.println("Not connected");
delay(1000);
}
}
Serial.println("connecting...");
// if you get a connection, report back via serial:
if (client.connect(server, port))
{
Serial.println("connected");
// Make a HTTP request:
/*client.print("GET ");
client.print(path);
client.println(" HTTP/1.1");
client.print("Host:127.0.0.1:80");
client.println(server);
client.println("Connection: close");
client.println();*/
}
else
{
// if you didn't get a connection to the server:
Serial.println("connection failed");
}
}