test
Dependencies: GPS TextLCD mbed
Fork of GPS_classroom by
main.cpp
00001 #include "mbed.h" 00002 #include "GPS.h" 00003 #include "TextLCD.h" 00004 GPS gps(PA_11,PA_12); 00005 I2C i2c_lcd(D14,D15); 00006 TextLCD_I2C lcd(&i2c_lcd, 0x4E, TextLCD::LCD16x2); 00007 Serial esp(D8,D2); 00008 DigitalIn bt(D5); 00009 00010 uint8_t buffer[0x100]; 00011 uint16_t buffer_head; 00012 uint16_t buffer_tail; 00013 00014 void rxcallback(void) { 00015 uint8_t chr; 00016 while (esp.readable()) { 00017 chr = esp.getc(); 00018 pc.putc(chr); 00019 buffer[buffer_head++] = chr; 00020 if (buffer_head == BUFFER_SIZE) 00021 { 00022 buffer_head = 0; 00023 } 00024 } 00025 } 00026 void flush_fifo(void) 00027 { 00028 while (esp.readable()) 00029 { 00030 (void)esp.getc(); 00031 } 00032 buffer_head = 0; 00033 buffer_tail = 0; 00034 } 00035 int find_response(const char *resp) { 00036 /* Give some delay for buffer to fill up */ 00037 wait_ms(10); 00038 int timeout = 0xFFFFFF; 00039 int len = strlen(resp); 00040 do 00041 { 00042 if (buffer_head > (buffer_tail + len)) 00043 { 00044 if (!memcmp(&buffer[buffer_tail], resp, len)) 00045 { 00046 flush_fifo(); 00047 return 0; 00048 } 00049 buffer_tail++; 00050 } 00051 }while(timeout--); 00052 flush_fifo(); 00053 return 1; 00054 } 00055 00056 int main() 00057 { 00058 lcd.setMode(TextLCD::DispOn); 00059 lcd.setBacklight(TextLCD::LightOff); 00060 lcd.setCursor(TextLCD::CurOff_BlkOff); 00061 esp.attach(&rxcallback, Serial::RxIrq); 00062 lcd.setAddress(0,0); 00063 lcd.printf("Initial GPS...\n"); 00064 esp.printf("AT+RST\r\n"); 00065 MBED_ASSERT(find_response("OK") == 0); 00066 esp.printf("AT+CWMODE=1\r\n"); 00067 MBED_ASSERT(find_response("OK") == 0); 00068 esp.printf("AT+CWJAP=\"%s\",\"%s\"\r\n","Fookies-One(m8)","12312344"); 00069 wait(5); 00070 MBED_ASSERT(find_response("OK") == 0); 00071 esp.printf("AT+CIPMUX=0\r\n"); 00072 MBED_ASSERT(find_response("OK") == 0); 00073 while(1){ 00074 if(gps.sample()) 00075 { 00076 lcd.setAddress(0,1); 00077 lcd.printf("%6.3f,%7.3f",gps.latitude,gps.longitude); 00078 } 00079 wait(0.5); 00080 if(bt==1) 00081 { 00082 sprintf(message,"GET /apps/thingtweet/1/statuses/update?key=T5M60A23PDCU6NIH&status=%.3f,%.3f",gps.latitude,gps.longitude); 00083 esp.printf("AT+CIPSTART=\"TCP\",\"%s\",%s\r\n","184.106.153.149","80"); 00084 esp.printf("AT+CIPSEND=0,%d\r\n",strlen(message)); 00085 if(find_response(">") == 0) 00086 { 00087 esp.printf(message); 00088 } 00089 wait(2); 00090 flush_fifo(); 00091 esp.printf("AT+CIPCLOSE\r\n"); 00092 wait(0.5); 00093 flush_fifo(); 00094 } 00095 } 00096 } 00097
Generated on Sat Jul 16 2022 00:00:07 by 1.7.2