pengfei wu
/
ESP8266Program
For test
Diff: ESP8266.cpp
- Revision:
- 14:40b1decf03f3
- Parent:
- 12:4e4e72f18047
- Child:
- 17:c449356787f1
diff -r 808afe3f612d -r 40b1decf03f3 ESP8266.cpp --- a/ESP8266.cpp Tue Feb 03 07:57:28 2015 +0000 +++ b/ESP8266.cpp Tue Feb 03 09:10:16 2015 +0000 @@ -1,16 +1,7 @@ #include "ESP8266.h" -#define ESP8266_DEBUG - -#ifdef ESP8266_DEBUG -#define DBG(message) printf(message) -#else -#define DBG(message) do{}while(0) -#endif - ESP8266::ESP8266(PinName tx, PinName rx):esp_uart(tx, rx) { - } int ESP8266::get_chlID(void) { @@ -25,14 +16,14 @@ esp_uart.flush(); esp_uart.setTimeout(5000); esp_uart.println("AT+RST"); - DBG("AT+RST\r\n"); + logInfo("AT+RST\r\n"); result = esp_uart.find("eady"); if(result) - DBG("Module is ready\r\n"); + logInfo("Module is ready\r\n"); else { - DBG("Module have no response\r\n"); + logInfo("Module have no response\r\n"); while(1); } @@ -203,29 +194,27 @@ } int iSize; - //DBG(data); - //DBG("\r\n"); if(found ==true) { String _id = data.substring(4, j); chlID = _id.toInt(); String _size = data.substring(j+1, i); iSize = _size.toInt(); - //DBG(_size); + String str = data.substring(i+1, i+1+iSize); strcpy(buf, str.c_str()); - //DBG(str); + } else { String _size = data.substring(4, i); iSize = _size.toInt(); - //DBG(iSize); - //DBG("\r\n"); + + String str = data.substring(i+1, i+1+iSize); strcpy(buf, str.c_str()); - //DBG(str); + } return iSize; } @@ -251,7 +240,7 @@ while (millis()-start<5000) { if(esp_uart.find("ready")==true) { - DBG("reboot wifi is OK\r\n"); + logInfo("reboot wifi is OK\r\n"); break; } } @@ -422,7 +411,7 @@ break; } } - //DBG(("data = [%s]\r\n", data.c_str())); + char head[4] = {0x0D,0x0A}; char tail[7] = {0x0D,0x0A,0x0D,0x0A}; data.replace("AT+CWJAP?",""); @@ -963,7 +952,7 @@ { String data; unsigned long start; - //DBG("AT+CIFSR\r\n"); + for(int a=0; a<3;a++) { esp_uart.println("AT+CIFSR"); @@ -985,8 +974,8 @@ } data = ""; } - //DBG(data); - //DBG("\r\n"); + + char head[4] = {0x0D,0x0A}; char tail[7] = {0x0D,0x0D,0x0A}; data.replace("AT+CIFSR","");