Hello,
I just started using Arduino a week ago, my project is to use GPS shield along with GPRS/GSM (SIM900) shield and Arduino Uno in order to:
- Get GPS data
- Log GPS data in to a micro SD card.
- Send GPS data using the GPRS shield to mySQL server
I've been looking at several online examples/tutorials, since I am new to mySQL, I am having trouble sending the string containing the GPS data over to mySQL using GPRS. any Help will be appreciated: thanks. My code for GPS logger is
#include <SoftwareSerial.h>
#include <TinyGPS.h>
#include <SD.h>
#include <SPI.h>
//Add the SdFat Libraries
//#include <SdFat.h>
//#include <SdFatUtil.h>
//#include <ctype.h>
//Create the variables to be used by SdFat Library
Sd2Card card;
SdVolume volume;
SdFile root;
SdFile file;
#define BUFFSIZE 65
char buffer[BUFFSIZE]; //This will be a data buffer for writing contents to the file.
char in_char = 0;
char filename[] = "Logger.txt";
//Intialize TinyGPS and NewSoftSerial
TinyGPS gps;
SoftwareSerial nss(2, 3);
//Intialize GPS variables
long lat, lon;
float flat, flon, fspeed, falt;
unsigned long date, time, chars;
int year;
byte month, day, hour, minute, second, hundredths;
unsigned short sentences, failed;
bool newdata = false;
bool feedgps();
void setup()
{
Serial.begin(9600);
nss.begin(9600); //GPS's Buad Rate
pinMode(0, INPUT);
pinMode(1, OUTPUT);
pinMode(10, OUTPUT);
card.init(); //Initialize the SD card and configure the I/O pins.
volume.init(card); //Initialize a volume on the SD card.
root.openRoot(volume); //Open the root directory in the volume.
//Create file with defined filename
file.open(root, filename, O_CREAT | O_APPEND | O_WRITE); //Open or create the file 'name' in 'root' for writing to the end of the file
file.println();
file.println();
file.print("DD/MM/YY HH:MM:SS LATITUDE|LONGITUDE|ALTITUDE(ft) speed(mph) \n"); //Write the header array to the end of the file.
Serial.print("DD/MM/YY HH:MM:SS LATITUDE|LONGITUDE|ALTITUDE(ft) speed(mph) \n"); //Write the header array to the end of the file.
file.println();
file.close(); //Close the file.
}
void loop()
{
bool newdata = false; // check if data is coming in
if (feedgps())
newdata = true;
if (newdata)
{
//Pull gps data
gps.f_get_position(&flat, &flon);
feedgps(); //used to keep gps "awake"
gps.crack_datetime(&year, &month, &day, &hour, &minute, &second, &hundredths);
feedgps();
falt = gps.f_altitude();
fspeed = gps.f_speed_mph();
feedgps();
//Break up float values into whole numbers(var) and decimals(var1) to be added to data
int flat1 = (flat - (int)flat) * 10000;
int flon1 = (flon - (int)flon) * 100000;
int alt1 = 0;
if (falt >= 10000000.00) { //when gps cant get altitude
falt = 0; //set to 0
} else {
falt = falt * 0.032808399; //cm to feet
alt1 = (falt - (int)falt) * 10;
}
int fspeed1 = (fspeed - (int)fspeed) * 10;
//Create then write the char array "buffer" to the end of the file
file.open(root, filename, O_WRITE | O_APPEND); //Open the file in write mode and append the data to the end of the file.
sprintf(buffer, "%d/%d/%d %d:%d:%d %0d.%d |%0d.%d | %0d.%d %0d.%d\n", day, month, year, hour, minute, second, (int)flat, abs(flat1), (int)flon, abs(flon1), (int)falt, abs(alt1), (int)fspeed, abs(fspeed1));
file.println(buffer); //Write the 'contents' array to the end of the file.
Serial.println(buffer);
file.close(); //Close the file
delay(5000); // wait 10 sec before writing next data point
}
}
bool feedgps()
{
while (nss.available())
{
if (gps.encode(nss.read()))
return true;
}
return false;
}