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.
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
Diff: main.cpp
- Revision:
- 10:059cde049cd6
- Parent:
- 9:bec6e8f731f2
- Child:
- 11:fad4b451bec8
--- a/main.cpp Tue Oct 09 18:48:48 2012 +0000 +++ b/main.cpp Fri Oct 12 04:53:58 2012 +0000 @@ -8,15 +8,14 @@ const string GoogleChunk = "https://maps.google.com.au/maps?q="; const string GoogleExtras = "&z=20"; -char GPRSbuffer[512]; -char NUMBER[11]; +char GPRSbuffer[513]; +char NUMBER[13]; char MESSAGE[5]; int index; -long int number; int i = 0; GPS gps(p9,p10); -MODSERIAL GPRS(p13,p14); // MODSERIAL for rxBufferFlush() +MODSERIAL GPRS(p13,p14); MODSERIAL pc(USBTX,USBRX); DigitalOut myled1(LED1); @@ -48,10 +47,10 @@ GPRS.printf("AT+CMGF=1\r\n"); wait(1); // Set the phone number - GPRS.printf("AT+CMGS=\"+%s\"\r\n", NUMBER); + GPRS.printf("AT+CMGS=\"%s\"\r\n", NUMBER); wait(1); // Write out the GPS data in a message - GPRS.printf("Time: %4.2f \nAltitude: %3.2fm\nSpeed: %3.2f Kn\nHeading: %3.2f Deg\nValidity: %c\nSatellites: %d\nFix code: %d \nFix: ", gps.time, gps.altitude, gps.speed, gps.heading, gps.validity, gps.satellites, gps.fixtype); + GPRS.printf("UTC Time: %4.2f \nAltitude: %3.2fm\nSpeed: %3.2f Kn\nHeading: %3.2f Deg\nGPS data grade: [%c]\nSatellites in use: [%d]\nSatFix code: [%d] \nFix type: ", gps.time, gps.altitude, gps.speed, gps.heading, gps.validity, gps.satellites, gps.fixtype); if(gps.fixtype == 1) { GPRS.printf("Positive"); } @@ -61,10 +60,10 @@ wait(1); // Send it... GPRS.putc(0x1A); - wait(3); + wait(4); GPRS.printf("AT+CMGF=1\r\n"); wait(1); - GPRS.printf("AT+CMGS=\"+%s\"\r\n", NUMBER); + GPRS.printf("AT+CMGS=\"%s\"\r\n", NUMBER); wait(1); GPRS.printf("Find me at....\n %s%f,%f%s", GoogleChunk, gps.latitude, gps.longitude, GoogleExtras); wait(1); @@ -86,7 +85,7 @@ i++; } // Uncomment the following to debug - pc.printf("\nbuffer = %s", GPRSbuffer); + // pc.printf("\nbuffer = %s", GPRSbuffer); // If we get an SMS notification.... if (sscanf(GPRSbuffer, "$$+CMTI: \"SM\",%d", &index)>0) { @@ -94,16 +93,17 @@ memset(GPRSbuffer, '0', 512); i = 0; GPRS.printf("AT+CMGR=%d\r\n", index); - wait(1); + //wait(1); } if (strncmp(GPRSbuffer, "$$+CMGR",7) == 0 ) { - for (int k = 24; k < 35; k++) { - NUMBER[k-24] = GPRSbuffer[k]; - } - for (int k = 64; k < 68; k++) { - MESSAGE[k-64] = GPRSbuffer[k]; - } + // Get the number out + char *n = strstr(GPRSbuffer,"+6"); + strncpy(NUMBER, n, 12); + // Get the message out + char *m = strstr(GPRSbuffer,"\"$$")+3; + strncpy(MESSAGE, m, 4); + // Send the location sendSms(); // Reset the GPRS buffer memset(GPRSbuffer, '0', 512); @@ -120,21 +120,19 @@ if (strncmp(GPRSbuffer, "$$RING",6) == 0) { GPRS.printf("ATH0\r\n"); - // Flush any incoming rings in the MODSERIAL buffer - GPRS.rxBufferFlush(); pc.printf("\nCall recieved"); // Do the send SMS routine... sendSms(); // Flush out any left in the serial buffer - GPRS.rxBufferFlush(); + //GPRS.rxBufferFlush(); // Reset the GPRS buffer memset(GPRSbuffer, '0', 512); // Reset the char counter i = 0; } - pc.printf("\nWaiting for SMS or call...\n"); - pc.printf("\nThe last number was :+%s", NUMBER); - pc.printf("\nThe last message was :%s", MESSAGE); + pc.printf("\n\n\nWaiting for SMS or call...\n"); + pc.printf("\nThe last number was : %s", NUMBER); + pc.printf("\nThe last message was : %s", MESSAGE); // Reset the GPRS buffer memset(GPRSbuffer, '0', 512); // Reset the char counter @@ -159,11 +157,9 @@ wait(1); pc.printf("\nMessages Cleared...\n"); wait(1); - // Flush out any \r\nOK\r\n's - GPRS.rxBufferFlush(); // Get in a while loop while (1) { - // Process any recieved data + // Process any recieved GPRS data parseSms(); // Process / check GPS data gps.parseData();