Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: ESP8266_WebServer mbed
Fork of WiFiLamp by
Diff: ESP8266_WebServer/ESP8266_WebServer.cpp
- Revision:
- 13:1e8f27da036a
- Parent:
- 11:3ab606a42227
- Child:
- 18:cdfe5eb7d3ad
diff -r fbf950985e1c -r 1e8f27da036a ESP8266_WebServer/ESP8266_WebServer.cpp
--- a/ESP8266_WebServer/ESP8266_WebServer.cpp	Sun Dec 28 16:09:20 2014 +0000
+++ b/ESP8266_WebServer/ESP8266_WebServer.cpp	Mon Dec 29 11:42:53 2014 +0000
@@ -10,6 +10,8 @@
 
 void ESP8266_WebServer::rxint(void) {
     char c = serial->getc();
+    if( (c != 0x0A) && (c != 0x0D) && ((c < 0x20) || (c > 0x80)) ) return;
+    
     if( debugSerial != NULL ) {
         debugSerial->putc(c);
     }
@@ -53,7 +55,14 @@
 
 void ESP8266_WebServer::Initialize(void) {
     readBuffer();
+    serial->printf("AT+RST\r\n");
+    wait_ms(1000);
     while( string_waiting("\r\nready\r\n") == 0 ) {
+        wait_ms(100);
+    }
+    readBuffer();
+    serial->printf("ATE0\r\n");
+    while( data_waiting() == 0 ) {
         wait_ms(10);
     }
     readBuffer();
@@ -130,14 +139,14 @@
         debugSerial->printf("HTTP Reply Packet(%d bytes): %s\r\n", numBytes, response);
     }
     serial->printf("AT+CIPSEND=%d,%d\r\n", linkID, numBytes);
-    wait_ms(500);
-    if( (string_waiting("\r\n>") == 1) ) {
+    wait_ms(100);
+    if( (string_waiting(">") == 1) ) {
         for( int i=0; i<numBytes; i++ ) {
             serial->putc(response[i]);
         }
-    }
-    while( string_waiting("\r\nSEND OK\r\n") == 0 ) {
-        wait_ms(10);
+        while( string_waiting("\r\nSEND OK\r\n") == 0 ) {
+            wait_ms(10);
+        }
     }
 }
 
@@ -157,7 +166,9 @@
 }
 
 void ESP8266_WebServer::SendReply(int linkID, const char* reply, int replySize, const char* mimeType) {
-    sprintf(response, "HTTP/1.1 200 OK\r\nContent-Type:%s\r\nContent-Length: %d\r\n\r\n%s", mimeType, replySize, reply);
+    sprintf(response, "HTTP/1.1 200 OK\r\nContent-Type:%s\r\nContent-Length: %d\r\n\r\n", mimeType, replySize);
+    sendResponse(linkID, strlen(response));
+    strncpy(response, reply, replySize);
     sendResponse(linkID, strlen(response));
 }
 
    