Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: GPS MODSERIAL mbed-rtos mbed
Diff: main.cpp
- Revision:
- 12:3f164c88df87
- Parent:
- 11:fad4b451bec8
- Child:
- 13:d8ee6b45bd0a
diff -r fad4b451bec8 -r 3f164c88df87 main.cpp
--- a/main.cpp Fri Oct 12 04:58:17 2012 +0000
+++ b/main.cpp Sat Oct 13 02:09:33 2012 +0000
@@ -1,3 +1,34 @@
+/******************************************************
+* 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. *
+* *
+* NOTE: sendSms() sends the GPS 'extra' data *
+* (eg. speed, heading etc) in one message, and your *
+* location as a google maps URL in another message. *
+* If you are an Iphone user, you can replace the *
+* "https" in the URL with "http" and remove the ".au" *
+* to get the URL to open in the native maps app. *
+* however I have found this to be less accurate by *
+* the fact that it doesn't drop a marker on the *
+* real locataion, but looks for the nearest address. *
+* it seems that the internal GPS is the only object *
+* able to be placed unrestricted on the map. *
+* *
+* October 2012 Written by: Sam Clarke *
+******************************************************/
+/******************************************************
+* HelloCylon *
+* By Leo Febey Oct 18 2011 *
+* Displays a looping pattern on the built in LEDs on *
+* the mbed which looks somewhat like a Cylon eye *
+* scanner pattern. *
+******************************************************/
+
#include "mbed.h"
#include "GPS.h"
#include "rtos.h"
@@ -6,16 +37,16 @@
using namespace std;
-const string GoogleChunk = "https://maps.google.com.au/maps?q=";
-const string GoogleExtras = "&z=20";
-char GPRSbuffer[513];
-char NUMBER[13];
-char MESSAGE[5];
+const string GoogleChunk = "https://maps.google.com.au/maps?q="; // URL constant
+const string GoogleExtras = "&z=20"; // Zoom Level (0-20)
+char GPRSbuffer[512];
+char NUMBER[13];
+string MESSAGE;
int index;
int i = 0;
GPS gps(p9,p10);
-MODSERIAL GPRS(p13,p14);
+MODSERIAL GPRS(p13,p14);
MODSERIAL pc(USBTX,USBRX);
DigitalOut myled1(LED1);
@@ -23,7 +54,7 @@
DigitalOut myled3(LED3);
DigitalOut myled4(LED4);
-void led_thread(void const *argument) // Some light jazz in a thread
+void led_thread(void const *argument)
{
while (true) {
DigitalOut leds[4] = {myled1, myled2, myled3, myled4};
@@ -50,7 +81,8 @@
GPRS.printf("AT+CMGS=\"%s\"\r\n", NUMBER);
wait(1);
// Write out the GPS data in a message
- 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);
+ 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");
}
@@ -90,10 +122,11 @@
// If we get an SMS notification....
if (sscanf(GPRSbuffer, "$$+CMTI: \"SM\",%d", &index)>0) {
pc.printf("\nSMS recieved @ index [%d]", index);
- memset(GPRSbuffer, '0', 512);
+ memset(GPRSbuffer, '0', 511);
i = 0;
+ pc.printf("\nOpening message...");
+ // ask GPRS to read the message
GPRS.printf("AT+CMGR=%d\r\n", index);
- //wait(1);
}
if (strncmp(GPRSbuffer, "$$+CMGR",7) == 0 ) {
@@ -101,30 +134,33 @@
char *n = strstr(GPRSbuffer,"+6");
strncpy(NUMBER, n, 12);
// Get the message out
- char *m = strstr(GPRSbuffer,"\"$$")+3;
- strncpy(MESSAGE, m, 4);
+ char * pch;
+ pch = strtok (GPRSbuffer, "$$");
+ pch = strtok (NULL, "$$");
+ MESSAGE = pch;
+ pc.printf("\nDone! ");
// Send the location
sendSms();
// Reset the GPRS buffer
- memset(GPRSbuffer, '0', 512);
+ memset(GPRSbuffer, '0', 511);
// Reset the char counter
i = 0;
}
if (strncmp(GPRSbuffer, "$$+CMGS",7) == 0) {
// Reset the GPRS buffer
- memset(GPRSbuffer, '0', 512);
+ memset(GPRSbuffer, '0', 511);
// Reset the char counter
i = 0;
}
if (strncmp(GPRSbuffer, "$$RING",6) == 0) {
GPRS.printf("ATH0\r\n");
- pc.printf("\nCall recieved");
+ pc.printf("\nCall bounced!...");
// Do the send SMS routine...
sendSms();
// Reset the GPRS buffer
- memset(GPRSbuffer, '0', 512);
+ memset(GPRSbuffer, '0', 511);
// Reset the char counter
i = 0;
}
@@ -132,7 +168,7 @@
pc.printf("\nThe last number was : %s", NUMBER);
pc.printf("\nThe last message was : %s", MESSAGE);
// Reset the GPRS buffer
- memset(GPRSbuffer, '0', 512);
+ memset(GPRSbuffer, '0', 511);
// Reset the char counter
i = 0;
}
@@ -142,7 +178,7 @@
pc.baud(115200);
GPRS.baud(19200);
Thread thread(led_thread);
- memset(GPRSbuffer, '0', 512);
+ memset(GPRSbuffer, '0', 511);
pc.printf("\nI'm Alive...\n");
// Setup the GPS
gps.Init();