How to Print serial results from GPRS shield and GPS Shield with differnet pins?
Seeed Studios GPRS (SIM900) http://www.seeedstudio.com/depot/gprs-shield-p-779.html WIKI: http://www.seeedstudio.com/wiki/GPRS_Shield
PINS: 7-8
Sparkfun GPS Shield (EM-406) SparkFun GPS Logger Shield - GPS-13750 - SparkFun Electronics
PINS:2-3
I don't know if I'm doing this wrong, but by jumping the pins and following the sample sketches from each shield I was able to send the GPS coordinates to my Server(APACHE+MYSQL - see log below).
208.54.64.140 - - [05/Jan/2013:13:12:59 -0500] "GET /tracker.php?Lat=XX.XXXXX&Long=-XX.XXXXX&Speed=0.39&Cardinal=ESE&Altitude=318.80&Course=120.85 HTTP/1.1" 200 263 "-" "SIMCOM_MODULE"
The only issue I'm having is printing the return result from the GPRS shield to serial.
Sending the command AT+CSQ should return the following:
+CSQ: 12,0
OK
The result I get on serial is:
TURNING GPRS ON
Checking Status
AT+CGATT?
U:AT+CSQ
+CSQ: 12,0
OK
$GPGGA,183755.000,3359.9443,N,08Setting the SAPBR
Setting the APN
*Setting the SAPBR
Init HTTP request
Setting the httppara
Submit the request
Read data from website
Checking Status
AT+CGATT?
?vÚµÐ?±6Ƴf?1c&3e?9ÅV?3Í?2c&e?,,2.2,1.0,1.9*30
$GPRMC,18381Setting the SAPBR
Setting the APN
*Setting the SAPBR
Init HTTP request
Setting the httppara
Submit the request
Read data from website
My code is:
#include <SoftwareSerial.h>
#include <TinyGPS.h>
#include <String.h>
#include <PString.h>
/*****************************************
* Buffers
*/
const int BUFFSIZE = 180;
char incoming_char = 0;
char buffer[BUFFSIZE];
PString myStr(buffer, sizeof(buffer));
#define RXPIN 2
#define TXPIN 3
//baud rate of GPS
#define GPSBAUD 4800
//baud rate of GPRS
#define GPRSBAUD 19200
// Create an instance of the TinyGPS object
TinyGPS gps;
SoftwareSerial uart_gps(RXPIN, TXPIN);
void getgps(TinyGPS &gps);
void setup()
{
Serial.begin(GPRSBAUD);
uart_gps.begin(GPSBAUD);
Serial.println("S: TURNING GPRS ON");
delay(4000);
}
void loop()
{
while(uart_gps.available()) // While there is data on the RX pin...
{
int c = uart_gps.read(); // load the data into a variable...
if(gps.encode(c)) // if there is a new valid sentence...
{
getgps(gps); // then grab the data.
}
}
}
// The getgps function will get and print the values we want.
static void getgps(TinyGPS &gps)
{
// Define the variables that will be used
unsigned long age;
float lat, lng, speed;
// Then call this function
gps.f_get_position(&lat, &lng);
// Acquire data from gps
gps.f_get_position(&lat, &lng, &age);
speed = gps.f_speed_mph();
Serial.println("Checking Status");
uart_gps.println("U:AT+CSQ");
delay(1000);
//ShowSerialData();
Serial.println("AT+CGATT?");
ShowSerialData();
uart_gps.println("AT+CGATT?");
ShowSerialData();
delay(1000);
//ShowSerialData();
Serial.println("Setting the SAPBR");
uart_gps.println("AT+SAPBR=3,1,\"CONTYPE\",\"GPRS\"");
delay(1000);
//ShowSerialData();
Serial.println("Setting the APN");
uart_gps.println("AT+SAPBR=3,1,\"APN\",\"epc.tmobile.com\"");
delay(2000);//4000
//ShowSerialData();
Serial.println("*Setting the SAPBR");
uart_gps.println("AT+SAPBR=1,1");
delay(1000); //2000
//ShowSerialData();
Serial.println("Init HTTP request");
uart_gps.println("AT+HTTPINIT");
delay(1000); //2000
//ShowSerialData();
Serial.println("Setting the httppara");
myStr.print("AT+HTTPPARA=\"URL\",");
myStr.print("\"www.cybercraft.org/");
myStr.print("tracker.php");
myStr.print("?Lat=");
myStr.print(lat, DEC);
myStr.print("&Long=");
myStr.print(lng, DEC);
myStr.print("&Speed=");
myStr.print(speed);
myStr.print("&Cardinal=");
myStr.print(TinyGPS::cardinal(gps.f_course()));
myStr.print("&Altitude=");
myStr.print(gps.f_altitude());
myStr.print("&Course=");
myStr.print(gps.f_course());
myStr.print("\"");
// Serial.println(myStr);
uart_gps.println(myStr);
delay(1000);
//ShowSerialData();
Serial.println("Submit the request");
uart_gps.println("AT+HTTPACTION=0");
delay(5000);//Important delay
//ShowSerialData();
Serial.println("Read data from website");
uart_gps.println("AT+HTTPREAD");
delay(300);
//ShowSerialData();
Serial.println("");
uart_gps.println("");
delay(100);
myStr.begin();
}
void ShowSerialData()
{
while(uart_gps.available()!=0)
Serial.write(uart_gps.read());
}