// SuperBeacon v1.2 - James Coxon http://www.pegasushabproject.org.uk // Designed for a EM406a, Arduino Mini Pro and a Circuit Design CDP-TX-04S-R Radio // Reads the GPS, Parses, keys out the lat, lon and alt and then acts like a beacon for 3 mins // // GPS read and parsing based on ladyada's code // see http://www.ladyada.net/make/gpsshield for more info #include <stdlib.h> #include <string.h> #define GPSRATE 4800 // GPS parser for 406a #define BUFFSIZ 90 // plenty big char buffer[BUFFSIZ]; char buffidx, test; char *GGAtime, *GGAlat, *GGAlatdir, *GGAlon, *GGAlondir, *GGAalt, *token; int x, n, z, nBeeps; int p = 0; void setup() { pinMode(4, OUTPUT); pinMode(13, OUTPUT); Serial.begin(GPSRATE); // prints title with ending line break Serial.println("GPS Beacon"); Serial.println("Based on ladayada's GPS Parser"); digitalWrite(4, HIGH); // sets the Radio on digitalWrite(13, HIGH); // sets the LED on delay(1500); digitalWrite(4, LOW); // sets the Radio off digitalWrite(13, LOW); // sets the LED off delay(500); } void loop(){ while ( p < 7 ){ Serial.println("Checking GPS"); readline(); p++; // check if $GPGGA (global positioning fixed data) if (strncmp(buffer, "$GPGGA",6) == 0) { p = 10; char * ptr; token = strtok_r(buffer, ",",&ptr); token = strtok_r(NULL, ",",&ptr); GGAtime = token; Serial.println(GGAtime); token = strtok_r(NULL, ",",&ptr); GGAlat = token; Serial.println(GGAlat); token = strtok_r(NULL, ",",&ptr); GGAlatdir = token; Serial.println(GGAlatdir); token = strtok_r(NULL, ",",&ptr); GGAlon = token; Serial.println(GGAlon); token = strtok_r(NULL, ",",&ptr); GGAlondir = token; Serial.println(GGAlondir); token = strtok_r(NULL, ",",&ptr); token = strtok_r(NULL, ",",&ptr); token = strtok_r(NULL, ",",&ptr); token = strtok_r(NULL, ",",&ptr); GGAalt = token; Serial.println(GGAalt); x = strlen(GGAlat); for ( n=0 ; n<x ; n++ ) { Serial.println(GGAlat[n]); test = GGAlat[n]; nBeeps = atoi(&test); Serial.println(nBeeps); for ( z=0 ; z<nBeeps ; z++) { digitalWrite(4, HIGH); // sets the Radio on digitalWrite(13, HIGH); // sets the LED on delay(500); digitalWrite(4, LOW); // sets the Radio off digitalWrite(13, LOW); // sets the LED off delay(500); } if ( nBeeps == 0 ) { Serial.println("Got a 0"); digitalWrite(4, HIGH); // sets the Radio on digitalWrite(13, HIGH); // sets the LED on delay(1500); digitalWrite(4, LOW); // sets the Radio off digitalWrite(13, LOW); // sets the LED off delay(500); } delay(3000); } x = strlen(GGAlon); for ( n=0 ; n<x ; n++ ) { Serial.println(GGAlon[n]); test = GGAlon[n]; nBeeps = atoi(&test); Serial.println(nBeeps); for ( z=0 ; z<nBeeps ; z++) { digitalWrite(4, HIGH); // sets the Radio on digitalWrite(13, HIGH); // sets the LED on delay(500); digitalWrite(4, LOW); // sets the Radio off digitalWrite(13, LOW); // sets the LED off delay(500); } if ( nBeeps == 0 ) { Serial.println("Got a 0"); digitalWrite(4, HIGH); // sets the Radio on digitalWrite(13, HIGH); // sets the LED on delay(1500); digitalWrite(4, LOW); // sets the Radio off digitalWrite(13, LOW); // sets the LED off delay(500); } delay(3000); } x = strlen(GGAalt); for ( n=0 ; n<x ; n++ ) { Serial.println(GGAalt[n]); test = GGAalt[n]; nBeeps = atoi(&test); Serial.println(nBeeps); for ( z=0 ; z<nBeeps ; z++) { digitalWrite(4, HIGH); // sets the Radio on digitalWrite(13, HIGH); // sets the LED on delay(500); digitalWrite(4, LOW); // sets the Radio off digitalWrite(13, LOW); // sets the LED off delay(500); } if ( nBeeps == 0 ) { Serial.println("Got a 0"); digitalWrite(4, HIGH); // sets the Radio on digitalWrite(13, HIGH); // sets the LED on delay(1500); digitalWrite(4, LOW); // sets the Radio off digitalWrite(13, LOW); // sets the LED off delay(500); } delay(3000); } } } Serial.println("Beacon for 3 minutes"); p = 0; for ( z=0 ; z<40 ; z++) { digitalWrite(4, HIGH); // sets the Radio on digitalWrite(13, HIGH); // sets the LED on delay(3000); digitalWrite(4, LOW); // sets the Radio off digitalWrite(13, LOW); // sets the LED off delay(1500); } } void readline(void) { char c; buffidx = 0; // start at begeninning while (1) { c=Serial.read(); if (c == -1) continue; Serial.print(c); if (c == '\n') continue; if ((buffidx == BUFFSIZ-1) || (c == '\r')) { buffer[buffidx] = 0; return; } buffer[buffidx++]= c; } }