Real-time bike tracker using Adafruit Ultimate GPS, Huzzah wifi, and Pubnub
Dependencies: MBed_Adafruit-GPS-Library mbed
Diff: main.cpp
- Revision:
- 2:834f8d2ebe3f
- Parent:
- 1:0701bf58c9fa
- Child:
- 3:ceca81e8ac2b
diff -r 0701bf58c9fa -r 834f8d2ebe3f main.cpp --- a/main.cpp Wed Apr 19 01:00:53 2017 +0000 +++ b/main.cpp Thu Apr 20 22:09:06 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; @@ -63,6 +63,9 @@ int main() { pc.baud(115200); //Set PC baud rate + pnub.huz.setssid("Verizon-SM-G900V-258B"); + pnub.huz.setpwd("trnd533)"); + //pnub.huz.espconfig(); gps_Serial = new Serial(p9,p10); Adafruit_GPS myGPS(gps_Serial); //object of Adafruit's GPS class Timer refresh_Timer; //Timer for updated GPS information @@ -76,6 +79,8 @@ myGPS.sendCommand(PGCMD_ANTENNA); float publat; float publong; + float oldlat = 0.0; + float oldlong = 0.0; // Setup a serial interrupt function to receive data @@ -83,7 +88,7 @@ // Setup a serial interrupt function to transmit data pnub.huz.esp.attach(&Tx_interrupt, Serial::TxIrq); - char lat_buff[20]; + char lat_buff[30]; pc.printf("Connection established at 115200 baud...\r\n"); wait(1); @@ -103,13 +108,18 @@ if (myGPS.fix) { publat = dms_convert(myGPS.latitude); publong = dms_convert(myGPS.longitude); - pc.printf("DMS Lat: %f, DD Lat: %f\r\nDMS Long:%f, DD Long: %f\r\n", myGPS.latitude, publat, myGPS.longitude, publong); - DataRX = 0; - sprintf(lat_buff, "%f", publat); - pnub.send_message(lat_buff); - pc.printf("MESSAGE SENT\r\n"); - wait(20); - } else pc.printf("No Satelite Fix\r\n"); + if (publat != oldlat || publong !=oldlong) { + oldlat = publat; + oldlong = publong; + DataRX = 0; + sprintf(lat_buff, "%f %f", publat, publong); + pnub.send_message(lat_buff); + pc.printf("Message Sent\r\n"); + } + } else { + pc.printf("No Satelite Fix\r\n"); + } + wait(5); } } } \ No newline at end of file