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:
- 0:5b4bcbd69509
- Child:
- 1:00c7dc0c1761
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Sat Oct 06 22:47:34 2012 +0000 @@ -0,0 +1,128 @@ +#include "mbed.h" +#include "GPS.h" +#include "rtos.h" +#include "MODSERIAL.h" +#include <string> +#include <iostream> + +using namespace std; + +const string GoogleChunk = "https://maps.google.com.au/maps?q="; +const string GoogleExtras = "&z=20"; +char GPRSbuffer[512]; +int index; +int i = 0; + +GPS gps(p9,p10); +MODSERIAL GPRS(p13,p14); // MODSERIAL for rxBufferFlush() +MODSERIAL pc(USBTX,USBRX); + +DigitalOut myled1(LED1); +DigitalOut myled2(LED2); +DigitalOut myled3(LED3); +DigitalOut myled4(LED4); + +void led_thread(void const *argument) // Some light jazz in a thread +{ + while (true) { + DigitalOut leds[4] = {myled1, myled2, myled3, myled4}; + 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}}; + int i=0; + while(1) { + leds[0] = pattern[i][0]; + leds[1] = pattern[i][1]; + leds[2] = pattern[i][2]; + leds[3] = pattern[i][3]; + wait(0.2); + i++; + i == 6? i=0:0; + } + } +} + +void sendSms() +{ + // Set message mode to ASCII + GPRS.printf("AT+CMGF=1\r\n"); + wait(1); + // Set the phone number + GPRS.printf("AT+CMGS=\"+614<<NUMBER>>\"\r\n"); + 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\nFix: %s\nSatellites: %d", gps.time, gps.altitude, gps.speed, gps.heading,gps.validity,gps.fixtype,gps.satellites); + wait(1); + // Send it... + GPRS.putc(0x1A); + wait(3); + GPRS.printf("AT+CMGF=1\r\n"); + wait(1); + GPRS.printf("AT+CMGS=\"+614<<NUMBER>>\"\r\n"); + wait(1); + GPRS.printf("Find me at....\n %s%f,%f%s", GoogleChunk, gps.latitude, gps.longitude, GoogleExtras); + wait(1); + GPRS.putc(0x1A); +} + +void parseSms() +{ + // If theres a char waiting in the MODSERIAL buffer + while (GPRS.readable()) { + // Assign it to 'c' + char c = GPRS.getc(); + // Replace all returns and or line endings with money! + if (c == '\r' || c == '\n') c = '$'; + // Put it in the array + GPRSbuffer[i] = c; + // Repeat if possible + i++; + } + // Uncomment the following to debug + + //pc.printf("buffer = %s", GPRSbuffer); + //pc.printf("index = %d", index); + + // If we get an SMS notification.... + if (sscanf(GPRSbuffer, "$$+CMTI: \"SM\",%d", &index)>0) { + // Do the send SMS routine... + sendSms(); + // Wait for the cascade of \r\nOK\r\n\r\nOK\r\n's from the SMS's to finish + wait(4); + // Flush out any left in the serial buffer + GPRS.rxBufferFlush(); + // Reset the GPRS buffer + memset(GPRSbuffer, '0', 512); + // Reset the char counter + i = 0; + } else pc.printf("\nWaiting for SMS...\n"); +} + +int main() +{ + pc.baud(115200); + GPRS.baud(19200); + Thread thread(led_thread); + pc.printf("I'm Alive...\n"); + // Setup the GPS + gps.Init(); + // Set the GPRS AT echo off + GPRS.printf("ATE0\r\n"); + pc.printf("GPRS Echo OFF\n"); + wait(1); + // Delete all messages on the sim card + GPRS.printf("AT+CMGDA=\"DEL ALL\"\r\n"); + wait(1); + pc.printf("Messages 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 + parseSms(); + // Process / check GPS data + if(gps.parseData()) { + pc.printf("\nGo to %s%f,%f%s\n", GoogleChunk, gps.latitude, gps.longitude, GoogleExtras); + pc.printf("\n\nLocation: %f%c, %f%c \nTime: %4.2f \nSatellites: %d \nAltitude: %3.2f\nSpeed: %3.2f\nHeading: %3.2f\nValidity: %c\n",gps.latitude, gps.ns, gps.longitude, gps.ew, gps.time, gps.satellites, gps.altitude, gps.speed, gps.heading,gps.validity); + } else pc.printf("Aquiring Satellites...\n"); + } +}