An SMS based GPS tracker using the Adafruit Ultimate GPS module http://www.adafruit.com/products/746 and the Seeed Studio GPRS shield (Sim900 chipset) http://www.seeedstudio.com/depot/gprs-shield-p-779.html?cPath=132_134

Dependencies:   GPS MODSERIAL mbed-rtos mbed

SMS based GPS tracker

This is an SMS based GPS tracker using using the Adafruit Ultimate GPS module and the Seeed studio GPRS arduino shield [SIM900 chipset]. The idea of this project is to leverage the free SMS between Virgin mobile prepaid SIM cards in Australia for long distance communication.

Currently the GPRS shield is switched on manually, and should be done about 10 seconds before powering the mbed/GPS in order to disable echo properly during start up. This could easily be fixed by switching the GPRS shield with the mbed at start up, waiting the 10 seconds, set the echo then flush the buffer.

The mbed can read all 160 ASCII chars sent in a message for control.

http://i47.tinypic.com/35alpue.png http://i48.tinypic.com/2mi3y0z.png http://i45.tinypic.com/jkeyvt.png

The Seeed GPRS shield http://www.seeedstudio.com/depot/gprs-shield-p-779.html?cPath=132_134

The Adafruit Ultimate GPS http://www.adafruit.com/products/746

Committer:
SamClarke
Date:
Sun Oct 07 20:28:32 2012 +0000
Revision:
3:a5df4bd224ad
Parent:
2:2b2c785c6627
Child:
4:0e55a4620f5e
;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
SamClarke 0:5b4bcbd69509 1 #include "mbed.h"
SamClarke 0:5b4bcbd69509 2 #include "GPS.h"
SamClarke 0:5b4bcbd69509 3 #include "rtos.h"
SamClarke 0:5b4bcbd69509 4 #include "MODSERIAL.h"
SamClarke 0:5b4bcbd69509 5 #include <string>
SamClarke 0:5b4bcbd69509 6 #include <iostream>
SamClarke 0:5b4bcbd69509 7
SamClarke 0:5b4bcbd69509 8 using namespace std;
SamClarke 0:5b4bcbd69509 9
SamClarke 0:5b4bcbd69509 10 const string GoogleChunk = "https://maps.google.com.au/maps?q=";
SamClarke 0:5b4bcbd69509 11 const string GoogleExtras = "&z=20";
SamClarke 0:5b4bcbd69509 12 char GPRSbuffer[512];
SamClarke 3:a5df4bd224ad 13 string dump;
SamClarke 0:5b4bcbd69509 14 int index;
SamClarke 0:5b4bcbd69509 15 int i = 0;
SamClarke 0:5b4bcbd69509 16
SamClarke 0:5b4bcbd69509 17 GPS gps(p9,p10);
SamClarke 0:5b4bcbd69509 18 MODSERIAL GPRS(p13,p14); // MODSERIAL for rxBufferFlush()
SamClarke 0:5b4bcbd69509 19 MODSERIAL pc(USBTX,USBRX);
SamClarke 0:5b4bcbd69509 20
SamClarke 0:5b4bcbd69509 21 DigitalOut myled1(LED1);
SamClarke 0:5b4bcbd69509 22 DigitalOut myled2(LED2);
SamClarke 0:5b4bcbd69509 23 DigitalOut myled3(LED3);
SamClarke 0:5b4bcbd69509 24 DigitalOut myled4(LED4);
SamClarke 0:5b4bcbd69509 25
SamClarke 0:5b4bcbd69509 26 void led_thread(void const *argument) // Some light jazz in a thread
SamClarke 0:5b4bcbd69509 27 {
SamClarke 0:5b4bcbd69509 28 while (true) {
SamClarke 0:5b4bcbd69509 29 DigitalOut leds[4] = {myled1, myled2, myled3, myled4};
SamClarke 0:5b4bcbd69509 30 int pattern[6][4] = {{1,0,0,0},{0,1,0,0},{0,0,1,0},{0,0,0,1},{0,0,1,0},{0,1,0,0}};
SamClarke 0:5b4bcbd69509 31 int i=0;
SamClarke 0:5b4bcbd69509 32 while(1) {
SamClarke 0:5b4bcbd69509 33 leds[0] = pattern[i][0];
SamClarke 0:5b4bcbd69509 34 leds[1] = pattern[i][1];
SamClarke 0:5b4bcbd69509 35 leds[2] = pattern[i][2];
SamClarke 0:5b4bcbd69509 36 leds[3] = pattern[i][3];
SamClarke 0:5b4bcbd69509 37 wait(0.2);
SamClarke 0:5b4bcbd69509 38 i++;
SamClarke 0:5b4bcbd69509 39 i == 6? i=0:0;
SamClarke 0:5b4bcbd69509 40 }
SamClarke 0:5b4bcbd69509 41 }
SamClarke 0:5b4bcbd69509 42 }
SamClarke 0:5b4bcbd69509 43
SamClarke 0:5b4bcbd69509 44 void sendSms()
SamClarke 0:5b4bcbd69509 45 {
SamClarke 0:5b4bcbd69509 46 // Set message mode to ASCII
SamClarke 0:5b4bcbd69509 47 GPRS.printf("AT+CMGF=1\r\n");
SamClarke 0:5b4bcbd69509 48 wait(1);
SamClarke 0:5b4bcbd69509 49 // Set the phone number
SamClarke 3:a5df4bd224ad 50 GPRS.printf("AT+CMGS=\"+61435404829\"\r\n");
SamClarke 0:5b4bcbd69509 51 wait(1);
SamClarke 0:5b4bcbd69509 52 // Write out the GPS data in a message
SamClarke 0:5b4bcbd69509 53 GPRS.printf("Time: %4.2f \nAltitude: %3.2fm\nSpeed: %3.2f Kn\nHeading: %3.2f Deg\nValidity: %c\nFix: %s\nSatellites: %d", gps.time, gps.altitude, gps.speed, gps.heading,gps.validity,gps.fixtype,gps.satellites);
SamClarke 0:5b4bcbd69509 54 wait(1);
SamClarke 0:5b4bcbd69509 55 // Send it...
SamClarke 0:5b4bcbd69509 56 GPRS.putc(0x1A);
SamClarke 0:5b4bcbd69509 57 wait(3);
SamClarke 0:5b4bcbd69509 58 GPRS.printf("AT+CMGF=1\r\n");
SamClarke 0:5b4bcbd69509 59 wait(1);
SamClarke 3:a5df4bd224ad 60 GPRS.printf("AT+CMGS=\"+61435404829\"\r\n");
SamClarke 0:5b4bcbd69509 61 wait(1);
SamClarke 0:5b4bcbd69509 62 GPRS.printf("Find me at....\n %s%f,%f%s", GoogleChunk, gps.latitude, gps.longitude, GoogleExtras);
SamClarke 0:5b4bcbd69509 63 wait(1);
SamClarke 0:5b4bcbd69509 64 GPRS.putc(0x1A);
SamClarke 3:a5df4bd224ad 65 wait(1);
SamClarke 0:5b4bcbd69509 66 }
SamClarke 0:5b4bcbd69509 67
SamClarke 0:5b4bcbd69509 68 void parseSms()
SamClarke 0:5b4bcbd69509 69 {
SamClarke 0:5b4bcbd69509 70 // If theres a char waiting in the MODSERIAL buffer
SamClarke 0:5b4bcbd69509 71 while (GPRS.readable()) {
SamClarke 0:5b4bcbd69509 72 // Assign it to 'c'
SamClarke 0:5b4bcbd69509 73 char c = GPRS.getc();
SamClarke 0:5b4bcbd69509 74 // Replace all returns and or line endings with money!
SamClarke 0:5b4bcbd69509 75 if (c == '\r' || c == '\n') c = '$';
SamClarke 0:5b4bcbd69509 76 // Put it in the array
SamClarke 0:5b4bcbd69509 77 GPRSbuffer[i] = c;
SamClarke 0:5b4bcbd69509 78 // Repeat if possible
SamClarke 0:5b4bcbd69509 79 i++;
SamClarke 0:5b4bcbd69509 80 }
SamClarke 0:5b4bcbd69509 81 // Uncomment the following to debug
SamClarke 0:5b4bcbd69509 82
SamClarke 1:00c7dc0c1761 83 pc.printf("buffer = %s", GPRSbuffer);
SamClarke 1:00c7dc0c1761 84
SamClarke 0:5b4bcbd69509 85
SamClarke 0:5b4bcbd69509 86 // If we get an SMS notification....
SamClarke 0:5b4bcbd69509 87 if (sscanf(GPRSbuffer, "$$+CMTI: \"SM\",%d", &index)>0) {
SamClarke 1:00c7dc0c1761 88 pc.printf("\nSMS recieved @ index [%d]", index);
SamClarke 0:5b4bcbd69509 89 // Do the send SMS routine...
SamClarke 0:5b4bcbd69509 90 sendSms();
SamClarke 0:5b4bcbd69509 91 // Wait for the cascade of \r\nOK\r\n\r\nOK\r\n's from the SMS's to finish
SamClarke 0:5b4bcbd69509 92 wait(4);
SamClarke 0:5b4bcbd69509 93 // Flush out any left in the serial buffer
SamClarke 0:5b4bcbd69509 94 GPRS.rxBufferFlush();
SamClarke 0:5b4bcbd69509 95 // Reset the GPRS buffer
SamClarke 0:5b4bcbd69509 96 memset(GPRSbuffer, '0', 512);
SamClarke 0:5b4bcbd69509 97 // Reset the char counter
SamClarke 0:5b4bcbd69509 98 i = 0;
SamClarke 3:a5df4bd224ad 99 }
SamClarke 3:a5df4bd224ad 100 if (sscanf(GPRSbuffer, "$$NO CARRIER%s%*d", &dump)>0) {
SamClarke 3:a5df4bd224ad 101 //dump = "fixed";
SamClarke 3:a5df4bd224ad 102 // GPRS.printf("ATH0\r\n");
SamClarke 3:a5df4bd224ad 103 wait(1);
SamClarke 3:a5df4bd224ad 104 GPRS.rxBufferFlush();
SamClarke 3:a5df4bd224ad 105 wait(1);
SamClarke 3:a5df4bd224ad 106 pc.printf("\nCall recieved");
SamClarke 3:a5df4bd224ad 107 wait(3);
SamClarke 3:a5df4bd224ad 108 // Do the send SMS routine...
SamClarke 3:a5df4bd224ad 109 sendSms();
SamClarke 3:a5df4bd224ad 110 // Wait for the cascade of \r\nOK\r\n\r\nOK\r\n's from the SMS's to finish
SamClarke 3:a5df4bd224ad 111 //wait(4);
SamClarke 3:a5df4bd224ad 112 // Flush out any left in the serial buffer
SamClarke 3:a5df4bd224ad 113 //GPRS.rxBufferFlush();
SamClarke 3:a5df4bd224ad 114 // Reset the GPRS buffer
SamClarke 3:a5df4bd224ad 115 //memset(GPRSbuffer, '0', 512);
SamClarke 3:a5df4bd224ad 116 // Reset the char counter
SamClarke 3:a5df4bd224ad 117 //i = 0;
SamClarke 1:00c7dc0c1761 118 } else {
SamClarke 1:00c7dc0c1761 119 GPRS.rxBufferFlush();
SamClarke 1:00c7dc0c1761 120 // Reset the GPRS buffer
SamClarke 1:00c7dc0c1761 121 memset(GPRSbuffer, '0', 512);
SamClarke 1:00c7dc0c1761 122 // Reset the char counter
SamClarke 1:00c7dc0c1761 123 i = 0;
SamClarke 3:a5df4bd224ad 124 pc.printf("\nWaiting for SMS or call...\n");
SamClarke 1:00c7dc0c1761 125 }
SamClarke 0:5b4bcbd69509 126 }
SamClarke 0:5b4bcbd69509 127
SamClarke 0:5b4bcbd69509 128 int main()
SamClarke 0:5b4bcbd69509 129 {
SamClarke 0:5b4bcbd69509 130 pc.baud(115200);
SamClarke 0:5b4bcbd69509 131 GPRS.baud(19200);
SamClarke 0:5b4bcbd69509 132 Thread thread(led_thread);
SamClarke 0:5b4bcbd69509 133 pc.printf("I'm Alive...\n");
SamClarke 0:5b4bcbd69509 134 // Setup the GPS
SamClarke 0:5b4bcbd69509 135 gps.Init();
SamClarke 0:5b4bcbd69509 136 // Set the GPRS AT echo off
SamClarke 0:5b4bcbd69509 137 GPRS.printf("ATE0\r\n");
SamClarke 0:5b4bcbd69509 138 pc.printf("GPRS Echo OFF\n");
SamClarke 0:5b4bcbd69509 139 wait(1);
SamClarke 0:5b4bcbd69509 140 // Delete all messages on the sim card
SamClarke 0:5b4bcbd69509 141 GPRS.printf("AT+CMGDA=\"DEL ALL\"\r\n");
SamClarke 0:5b4bcbd69509 142 wait(1);
SamClarke 0:5b4bcbd69509 143 pc.printf("Messages Cleared...\n");
SamClarke 0:5b4bcbd69509 144 wait(1);
SamClarke 0:5b4bcbd69509 145 // Flush out any \r\nOK\r\n's
SamClarke 0:5b4bcbd69509 146 GPRS.rxBufferFlush();
SamClarke 0:5b4bcbd69509 147 // Get in a while loop
SamClarke 0:5b4bcbd69509 148 while (1) {
SamClarke 0:5b4bcbd69509 149 // Process any recieved data
SamClarke 0:5b4bcbd69509 150 parseSms();
SamClarke 0:5b4bcbd69509 151 // Process / check GPS data
SamClarke 3:a5df4bd224ad 152 gps.parseData();
SamClarke 0:5b4bcbd69509 153 }
SamClarke 0:5b4bcbd69509 154 }