Thats good news. Here is my code, I hope its inserted correctly! Some of it is from the GPS shield and some from the GSM playground.
code...
/*
* Monitor signals from Accelerometer and send SMS if movement limit is reached
* turn on GPS module so that it has time to aquire signal. User may then switch
* off GPS or attempt requesting a location.
* Comment out GPIO if not needed.
* after an event.
*
*
* Functions:
* checkGPS()
* getGPS()
* readline()
* turnOnGPS()
* turnOffGPS()
*/
#include "GSM.h" // Include GSM library
#include <NewSoftSerial.h> // NewSoftSerial for GPS receiver
NewSoftSerial GPSSerial = NewSoftSerial(15, 14); //Pins 14 and 15 for GPS seria
#define powerpin 16
#define GPSRATE 4800
// Difinitions for GPS parser for 406a
#define BUFFSIZ 90 // plenty big
char buffer[BUFFSIZ];
char *parseptr;
char buffidx;
uint8_t hour, minute, second, year, month, date;
uint32_t latitude, longitude;
uint8_t groundspeed, trackangle;
char latdir, longdir;
char status;
int check;
GSM gsm; // Definition of instance of GSM class
#define xPin 5 // Define analog pins for ADXL330 accelerometer
#define yPin 4
#define zPin 3
int x = 0; // Initialise current value
int y = 0;
int z = 0;
int xinit = 0; // Initialise initial value
int yinit = 0;
int zinit = 0;
int deltax = 0; // Initialise difference between initial and current value
int deltay = 0;
int deltaz = 0;
int flag = 0; // flag=0 no sms sent, flag=1, send sms
int ledpin = 13; // for GSM Module
char string[30]; // Character array for string to send via SMS
unsigned long previous_timer;
byte timer100msec;
int val;
char position;
char phone_number[20]; // array for the phone number string
char *sms_text; // pointer to the SMS text
char *ch; // Character pointer for received SMS message
void setup()
{
//For GSM module
pinMode(ledpin, OUTPUT);
gsm.InitSerLine(115200);
gsm.TurnOn();
// set direction for GPIO pisn
gsm.SetGPIODir(GPIO10, GPIO_DIR_OUT);
gsm.SetGPIODir(GPIO11, GPIO_DIR_OUT);
// GPS Switch on from powerup
turnOnGPS();
Serial.println("GPS turned on...");
// initialization of periodic timer
timer100msec = 0;
previous_timer = millis();
// we are not registerd => disable button
gsm.DisableUserButton();
delay(1000);
xinit = analogRead(xPin);
yinit = analogRead(yPin);
zinit = analogRead(zPin);
}
void loop()
{
// -------------------
// timing of main loop
// -------------------
if ((unsigned long)(millis() - previous_timer) >= 100) {
previous_timer = millis();
//*******************************
//****** EVERY 100msec. *********
//*******************************
//read current value from accelerometer
x = analogRead(xPin);
y = analogRead(yPin);
z = analogRead(zPin);
//compare that value with initial value when powered
deltax = xinit - x;
deltax = abs(deltax);
deltay = yinit - y;
deltay = abs(deltay);
deltaz = zinit - z;
deltaz = abs(deltaz);
if((deltax > 15) || (deltay > 15) || (deltaz > 15))
{
flag = 1;
Serial.println(flag);
sprintf(string, "MOVEMENT!");
//gsm.SendSMS("07851103223", string);
deltax = 0;
deltay = 0;
deltaz = 0;
flag = 0;
delay(500);
}
}
//*******************************
//****** EVERY 500msec. *********
// +1 means - 100msec. "before" a previous 100msec. action
//*******************************
if ((timer100msec+1) % 5 == 0) {
// here it is possible to place your code which will be executed
// each 500 msec.
// ---------------------------------------------------------
digitalWrite(ledpin, LOW);
}
//*******************************
//****** EVERY 1 sec. ***********
//*******************************
if ((timer100msec+2) % 10 == 0) {
// is the GSM module registered?
// -----------------------------
gsm.CheckRegistration();
if (gsm.IsRegistered()) {
// GSM modul is still registered
// -----------------------------
gsm.EnableUserButton();
//gsm.TurnOnLED();
}
else {
// not registered - so disable button
// ----------------------------------
gsm.DisableUserButton();
//gsm.TurnOffLED();
}
}
//*******************************
//****** EVERY 3 sec. ***********
//*******************************
if ((timer100msec+3) % 30 == 0) {
// is there a new UNREAD SMS ?
// if YES - SIM position > 0 is returned
// -------------------------------------
if (gsm.IsRegistered()) {
// GSM module is registered
// Note: if there is new SMS before IsSMSPresent() is executed
// this SMS has a status UNREAD
// after calling IsSMSPresent() method status of SMS
// is automatically changed to READ
position = gsm.IsSMSPresent(SMS_ALL);
if (position > 0) {
// we have new SMS
// ---------------
gsm.GetSMS(position, phone_number, &sms_text);
// check SMS text
// --------------
// 1) e.g. text "Temp?"
// --------------------
ch = strstr(sms_text, "Temp?");
if (ch != NULL) {
// there is text Temp? => sends SMS with temperature back
// read temperature
// !!!Note: now we dont need the sms_text
// !!!but it is good to know that by the following command sms_text will be overwritten
// !!!see explanation in the library
val = gsm.GetTemp();
sprintf(string, "Temperature: %i C", val/10);
gsm.SendSMS(phone_number, string);
}
// 2) e.g. text "GPIO10 ON"
// -------------------------
ch = strstr(sms_text, "GPIO10 ON");
if (ch != NULL) {
// turn on the GPIO10
// !!!Note: now we dont need the sms_text
// !!!but it is good to know that by the following command sms_text will be overwritten
// !!!see explanation in the library
gsm.SetGPIOVal(GPIO10, 1);
// and sends confirmation back
strcpy(string, "GPIO10 turned on");
gsm.SendSMS(phone_number, string);
}
// 3) e.g. text "GPIO10 OFF"
// -------------------------
ch = strstr(sms_text, "GPIO10 OFF");
if (ch != NULL) {
// turn off the GPIO10
// !!!Note: now we dont need the sms_text
// !!!but it is good to know that by the following command sms_text will be overwritten
// !!!see explanation in the library
gsm.SetGPIOVal(GPIO10, 0);
// and sends confirmation back
strcpy(string, "GPIO10 turned off");
gsm.SendSMS(phone_number, string);
}
// and delete received SMS
// -----------------------
gsm.DeleteSMS(position);
}
}
}
//********************************************
//********WRAP AROUN COUNTER 10 sec. *********
//********************************************
timer100msec = (timer100msec + 1) % 100;
}
// Functions for GPS
int checkGPS()
{
check = 0;
for(int i=0; i<20; i++){
readline();
// check if $GPRMC (global positioning fixed data)
if ((strncmp(buffer, "$GPRMC",6) == 0) && (buffer[18] == 65))
{
check = 1;
break;
}
}
return check;
}
void getGPS()
{
uint32_t tmp;
Serial.print("\n\rread: ");
for(int i=0; i<20; i++){
readline();
//check if $GPRMC (global positioning fixed data)
if ((strncmp(buffer, "$GPRMC",6) == 0))
{
break;
}
}
// hhmmss time data
parseptr = buffer+7;
tmp = parsedecimal(parseptr);
hour = tmp / 10000;
minute = (tmp / 100) % 100;
second = tmp % 100;
parseptr = strchr(parseptr, ',') + 1;
status = parseptr[0];
parseptr += 2;
// grab latitude & long data
// latitude
latitude = parsedecimal(parseptr);
if (latitude != 0) {
latitude *= 10000;
parseptr = strchr(parseptr, '.')+1;
latitude += parsedecimal(parseptr);
}
parseptr = strchr(parseptr, ',') + 1;
// read latitude N/S data
if (parseptr[0] != ',') {
latdir = parseptr[0];
}
//Serial.println(latdir);
// longitude
parseptr = strchr(parseptr, ',')+1;
longitude = parsedecimal(parseptr);
if (longitude != 0) {
longitude *= 10000;
parseptr = strchr(parseptr, '.')+1;
longitude += parsedecimal(parseptr);
}
parseptr = strchr(parseptr, ',')+1;
// read longitude E/W data
if (parseptr[0] != ',') {
longdir = parseptr[0];
}
// groundspeed
parseptr = strchr(parseptr, ',')+1;
groundspeed = parsedecimal(parseptr);
// track angle
parseptr = strchr(parseptr, ',')+1;
trackangle = parsedecimal(parseptr);
// date
parseptr = strchr(parseptr, ',')+1;
tmp = parsedecimal(parseptr);
date = tmp / 10000;
month = (tmp / 100) % 100;
year = tmp % 100;
Serial.print("\nTime: ");
Serial.print(hour, DEC); Serial.print(':');
Serial.print(minute, DEC); Serial.print(':');
Serial.println(second, DEC);