Big thank you to Liudr and Holmes for their help.
I am really amazed at the enthusiasm and reactivity of this community.
I have overcome the GPS no data problem by switching between software serial for the GSM shield and GPS.
I am however slightly puzzled at the GPS readings I'm getting. When the GPS is on the window sill it can pick up a signal and find my location, but when I place the device inside the room it still reports seeing multiple satellites and receiving data. I think I need a way of clearing cached GPS info between GPS searches.
here is my latest code a lot neater than earlier.
#include <SoftwareSerial.h>
#include <String.h>
#include <Adafruit_GPS.h>
#include <ADXL345.h>
#include <Wire.h>
//GSM Shield vars
const String APN = "giffgaff.com";
const String server = "blue.appspot.com/updateArduinoCoords";
boolean sent;
SoftwareSerial gprsSerial(7, 8);
//accelerometer
ADXL345 adxl;
//GPS variables
boolean isSignal;
int latitude;
int longitude;
String time;
SoftwareSerial gpsSerial(3, 2);
Adafruit_GPS GPS(&gpsSerial);
void setup(){
// Serial.begin(115200); // remove commenting to get print trace
//GSM
gprsSerial.begin(19200);
//GPS
GPS.begin(9600);
GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCGGA);
GPS.sendCommand(PMTK_SET_NMEA_UPDATE_1HZ);
delay(500);
//Accelerometer
adxl.powerOn();
delay(500);
adxl.setActivityThreshold(75); //62.5mg per increment
adxl.setInactivityThreshold(75); //62.5mg per increment
adxl.setTimeInactivity(10); // how many seconds of no activity is inactive?
//look of inactivity movement on this axes - 1 == on; 0 == off
adxl.setInactivityX(1);
adxl.setInactivityY(1);
adxl.setInactivityZ(1);
//look of tap movement on this axes - 1 == on; 0 == off
adxl.setTapDetectionOnX(0);
adxl.setTapDetectionOnY(0);
adxl.setTapDetectionOnZ(1);
//set values for what is a tap (0-255)
adxl.setTapThreshold(50); //62.5mg per increment
adxl.setTapDuration(15); //625?s per increment
//setting all interupts to take place on int pin 1
//I had issues with int pin 2, was unable to reset it
adxl.setInterruptMapping( ADXL345_INT_SINGLE_TAP_BIT, ADXL345_INT1_PIN );
adxl.setInterruptMapping( ADXL345_INT_INACTIVITY_BIT, ADXL345_INT1_PIN );
//register interupt actions - 1 == on; 0 == off
adxl.setInterrupt( ADXL345_INT_SINGLE_TAP_BIT, 1);
adxl.setInterrupt( ADXL345_INT_INACTIVITY_BIT, 1);
}
void loop(){
byte interrup = adxl.getInterruptSource();
if (adxl.triggered(interrup, ADXL345_INACTIVITY)){
// Serial.println("nothing going on here");
delay(1000);
return;
}
if (adxl.triggered(interrup, ADXL345_SINGLE_TAP)){
// Serial.println("movement detected");
gpsSerial.listen();
isSignal = false;
getCoordinates();
while(!isSignal){
delay(1000);
}
powerUp();
gprsSerial.listen();
sent = false;
sendCoordinates();
while(!sent){
delay(1000);
}
}
}
void getCoordinates(){
while(!isSignal){
char c = GPS.read();
if (GPS.newNMEAreceived()) {
// Serial.println("new NMEA");
if (!GPS.parse(GPS.lastNMEA())){
// Serial.println("parse failed");
}
else{
if(GPS.fix){
longitude = GPS.longitude;
latitude = GPS.latitude;
time = ""+(GPS.hour, DEC)+':'+(GPS.minute, DEC)+':'+(GPS.seconds, DEC);
// Serial.println(GPS.latitude, 6); Serial.print(GPS.lat);
// Serial.print(", ");
// Serial.print(GPS.longitude, 6); Serial.println(GPS.lon);
// Serial.print(GPS.hour, DEC); Serial.print(':');
// Serial.print(GPS.minute, DEC); Serial.print(':');
// Serial.print(GPS.seconds, DEC); Serial.print('.');
// Serial.print(" quality: "); Serial.println((int)GPS.fixquality);
// Serial.print("Satellites: "); Serial.println((int)GPS.satellites);
// Serial.println("\n");
delay(500);
isSignal = true;
}
}
}
}
}
void sendCoordinates(){
// Serial.println("sending HTTP request");
gprsSerial.println("AT+CSQ");
delay(100);
ShowSerialData();// this code is to show the data from gprs shield, in order to easily see the process of how the gprs shield submit a http request, and the following is for this purpose too.
gprsSerial.println("AT+CGATT?");
delay(100);
ShowSerialData();
gprsSerial.println("AT+SAPBR=3,1,\"CONTYPE\",\"GPRS\"");//setting the SAPBR, the connection type is using gprs
delay(1000);
ShowSerialData();
gprsSerial.println("AT+SAPBR=3,1,\"APN\",\""+APN+"\"");//setting the APN, the second need you fill in your local apn server
delay(4000);
ShowSerialData();
gprsSerial.println("AT+SAPBR=1,1");//setting the SAPBR, for detail you can refer to the AT command mamual
delay(2000);
ShowSerialData();
gprsSerial.println("AT+HTTPINIT"); //init the HTTP request
delay(2000);
ShowSerialData();
gprsSerial.println("AT+HTTPPARA=\"URL\",\""+server+"?serial=1&lat="+latitude+"&lng="+longitude+"×tamp="+time+"\"");// setting the httppara, the second parameter is the website you want to access
delay(2000);
ShowSerialData();
gprsSerial.println("AT+HTTPACTION=0");//submit the request
delay(10000);//the delay is very important, the delay time is base on the return from the website, if the return datas are very large, the time required longer.
ShowSerialData();
gprsSerial.println("AT+HTTPREAD");// read the data from the website you access
delay(300);
ShowSerialData();
gprsSerial.println("");
delay(100);
powerDown();
sent = true;
}
void ShowSerialData()
{
// while(gprsSerial.available()!=0)
// Serial.write(gprsSerial.read());
}
/*
turn on the GPRS Shield
*/
void powerUp()
{
pinMode(9, OUTPUT);
digitalWrite(9,LOW);
delay(1000);
digitalWrite(9,HIGH);
delay(2000);
digitalWrite(9,LOW);
delay(3000);
}
/*
turn off the GPRS Shield
*/
void powerDown()
{
pinMode(9, OUTPUT);
digitalWrite(9,LOW);
delay(1000);
digitalWrite(9,HIGH);
delay(2000);
digitalWrite(9,LOW);
delay(3000);
}