Real-time bike tracker using Adafruit Ultimate GPS, Huzzah wifi, and Pubnub
Dependencies: MBed_Adafruit-GPS-Library mbed
Diff: main.cpp
- Revision:
- 3:ceca81e8ac2b
- Parent:
- 2:834f8d2ebe3f
- Child:
- 4:e20e2500914f
--- a/main.cpp Thu Apr 20 22:09:06 2017 +0000 +++ b/main.cpp Fri Apr 21 00:07:54 2017 +0000 @@ -41,7 +41,7 @@ while ((pnub.huz.esp.readable()) && (((rx_in + 1) % buffer_size) != rx_out)) { rx_buffer[rx_in] = pnub.huz.esp.getc(); // Uncomment to Echo to USB serial to watch data flow - //pc.putc(rx_buffer[rx_in]); + pc.putc(rx_buffer[rx_in]); rx_in = (rx_in + 1) % buffer_size; } return; @@ -81,7 +81,7 @@ float publong; float oldlat = 0.0; float oldlong = 0.0; - + char c; // Setup a serial interrupt function to receive data pnub.huz.esp.attach(&Rx_interrupt, Serial::RxIrq); @@ -94,12 +94,16 @@ wait(1); refresh_Timer.start(); //starts the clock on the timer while(true) { - myGPS.read(); //queries the GPS + c = myGPS.read(); //queries the GPS + + //if (c) { pc.printf("%c", c); } //this line will echo the GPS data if not paused //If GPS has data, parse it + + //check if we recieved a new message from GPS, if so, attempt to parse it, if ( myGPS.newNMEAreceived() ) { if ( !myGPS.parse(myGPS.lastNMEA()) ) { - continue; - } + continue; + } } //check if enough time has passed to warrant sending new GPS data @@ -108,18 +112,20 @@ if (myGPS.fix) { publat = dms_convert(myGPS.latitude); publong = dms_convert(myGPS.longitude); + pc.printf("DD Old Lat: %f, DD Old Long: %f \r\nDD New Lat %f, DD New Long %f\r\n",oldlat, oldlong, publat, publong); if (publat != oldlat || publong !=oldlong) { + //pc.printf("DMS Lat: %f%c, DMS Long: %f%c\r\n",myGPS.latitude, myGPS.lat, myGPS.longitude, myGPS.lon); oldlat = publat; oldlong = publong; DataRX = 0; sprintf(lat_buff, "%f %f", publat, publong); pnub.send_message(lat_buff); pc.printf("Message Sent\r\n"); - } + continue; + } else pc.printf("No New Data\r\n"); } else { pc.printf("No Satelite Fix\r\n"); } - wait(5); } } } \ No newline at end of file