Real-time bike tracker using Adafruit Ultimate GPS, Huzzah wifi, and Pubnub
Dependencies: MBed_Adafruit-GPS-Library mbed
Revision 2:834f8d2ebe3f, committed 2017-04-20
- Comitter:
- ECE4180
- Date:
- Thu Apr 20 22:09:06 2017 +0000
- Parent:
- 1:0701bf58c9fa
- Child:
- 3:ceca81e8ac2b
- Commit message:
- Working with comparison, cleaning code after this;
Changed in this revision
--- a/Huzzah.cpp Wed Apr 19 01:00:53 2017 +0000 +++ b/Huzzah.cpp Thu Apr 20 22:09:06 2017 +0000 @@ -62,7 +62,7 @@ string r("conn:send(\""); r += request + "\")\r\n"; - sprintf(cmdbuff, "conn=net.createConnection(net.TCP, false)\r\n" ); + sprintf(cmdbuff, "conn=net.createConnection(net.TCP, false)\r\n"); send_cmd(); getreply(); wait(0.2); @@ -77,13 +77,17 @@ sprintf(cmdbuff, conn.c_str()); send_cmd(); getreply(); - wait(3.0); + wait(2.0); sprintf(cmdbuff, r.c_str()); send_cmd(); wait(1.0); send_cmd(); getreply(); - wait(0.2); + wait(0.5); + + sprintf(cmdbuff, "conn.close()\r\n"); + send_cmd(); + getreply(); } @@ -263,16 +267,5 @@ pc.printf(configbuf); wait(1); - - pc.printf("\n---------- Get Connection Status ----------\r\n"); - strcpy(configsnd, "print(wifi.sta.status())\r\n"); - espsendcmd(); - timeout=5; - getreply(); - pc.printf(configbuf); - - pc.printf("\n\n\n If you get a valid (non zero) IP, ESP8266 has been set up.\r\n"); - pc.printf(" Run this if you want to reconfig the ESP8266 at any time.\r\n"); - pc.printf(" It saves the SSID and password settings internally\r\n"); - wait(10); + return; } \ No newline at end of file
--- a/PubNub.h Wed Apr 19 01:00:53 2017 +0000 +++ b/PubNub.h Thu Apr 20 22:09:06 2017 +0000 @@ -4,9 +4,6 @@ #include "string" -extern Serial pc; - - class PubNub { public:
--- 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