kk

Dependencies:   GPS TextLCD mbed

Fork of GPS_classroom by Thanawat Phattaraworamet

Files at this revision

API Documentation at this revision

Comitter:
tomece11
Date:
Tue Jun 02 11:04:02 2015 +0000
Parent:
5:27468969d61f
Commit message:
??????????

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r 27468969d61f -r aa79fcaca263 main.cpp
--- a/main.cpp	Sun May 31 10:27:49 2015 +0000
+++ b/main.cpp	Tue Jun 02 11:04:02 2015 +0000
@@ -1,15 +1,21 @@
 #include "mbed.h"
 #include "GPS.h"
 #include "TextLCD.h"
+#define BUFFER_SIZE 100
+
 GPS gps(PA_11,PA_12);
 I2C i2c_lcd(D14,D15); 
 TextLCD_I2C lcd(&i2c_lcd, 0x4E, TextLCD::LCD16x2); 
 Serial esp(D8,D2);
-DigitalIn bt(D5);
+DigitalIn bt(D5,PullUp);
+Serial pc(USBTX, USBRX);
+char message[400];
 
 uint8_t buffer[0x100];  
 uint16_t buffer_head;  
 uint16_t buffer_tail;  
+char s1[100];
+
 
 void rxcallback(void) {  
     uint8_t chr;  
@@ -62,28 +68,45 @@
     lcd.setAddress(0,0);
     lcd.printf("Initial GPS...\n");
     esp.printf("AT+RST\r\n");
+    //lcd.printf("1\n");
     MBED_ASSERT(find_response("OK") == 0);
+    //lcd.printf("2\n");
     esp.printf("AT+CWMODE=1\r\n");
-    MBED_ASSERT(find_response("OK") == 0);
+    //MBED_ASSERT(find_response("OK") == 0);
+    //lcd.printf("3\n");
     esp.printf("AT+CWJAP=\"%s\",\"%s\"\r\n","Fookies-One(m8)","12312344");
     wait(5);
-    MBED_ASSERT(find_response("OK") == 0); 
+    //MBED_ASSERT(find_response("OK") == 0); 
+    //lcd.printf("4\n");
     esp.printf("AT+CIPMUX=0\r\n");
-    MBED_ASSERT(find_response("OK") == 0); 
+    //MBED_ASSERT(find_response("OK") == 0); 
+    //lcd.printf("5\n");
     while(1){
         if(gps.sample())
         {
-            lcd.setAddress(0,1);
-            lcd.printf("%6.3f,%7.3f",gps.latitude,gps.longitude);
+            lcd.cls();
+            lcd.printf("LAT:%6.3f\nLON:%7.3f",gps.latitude,gps.longitude);
         }
         wait(0.5);
-        if(bt==1)
+        if(bt==0)
         {
-            sprintf(message,"GET /apps/thingtweet/1/statuses/update?key=GRMKGK1CTUU7L5RD=%.3f,%.3f",gps.latitude,gps.longitude);
+            lcd.cls();
+            lcd.printf("Sending to twitter");
+            
+            sprintf(s1,"api_key=GRMKGK1CTUU7L5RD&status=LAT:%.3f,LON:%.3f",gps.latitude,gps.longitude);
+            sprintf(message,"POST /apps/thingtweet/1/statuses/update HTTP/1.1\nHost: api.thingspeak.com\nConnection: close\nContent-Type: application/x-www-form-urlencoded\nContent-Length: %d\n\n%s",strlen(s1),s1);
             esp.printf("AT+CIPSTART=\"TCP\",\"%s\",%s\r\n","184.106.153.149","80");
-            esp.printf("AT+CIPSEND=0,%d\r\n",strlen(message));
+                //lcd.cls();
+                //lcd.printf("AT+CIPSTART=\"TCP\",\"%s\",%s\r\n","184.106.153.149","80");
+            wait(2);
+            esp.printf("AT+CIPSEND=%d\r\n",strlen(message));
+                //lcd.cls();
+                //lcd.printf("AT+CIPSEND=%d\r\n",strlen(message));
+                wait(2);
             if(find_response(">") == 0) 
             {
+                //lcd.cls();
+                //lcd.printf(message);
                 esp.printf(message);
             }
             wait(2);  
@@ -91,6 +114,8 @@
             esp.printf("AT+CIPCLOSE\r\n");
             wait(0.5);  
             flush_fifo();
+            lcd.cls();
+            lcd.printf("Send Completed\n");
         }
     }
 }