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.
Revision 8:5573f6f70a82, committed 2015-01-06
- Comitter:
- sschocke
- Date:
- Tue Jan 06 18:44:07 2015 +0000
- Parent:
- 7:f6172ba3e807
- Child:
- 9:85554edde164
- Commit message:
- Attempted bug fix in resetModule; Use smaller buffers or dynamically allocate and free where possible; Added extra debug output for HTTP Headers being sent
Changed in this revision
| ESP8266_WebServer.cpp | Show annotated file Show diff for this revision Revisions of this file |
| ESP8266_WebServer.h | Show annotated file Show diff for this revision Revisions of this file |
--- a/ESP8266_WebServer.cpp Mon Jan 05 19:22:25 2015 +0000
+++ b/ESP8266_WebServer.cpp Tue Jan 06 18:44:07 2015 +0000
@@ -60,7 +60,7 @@
}
void ESP8266_WebServer::readBuffer(void) {
- strncpy(reply, buffer, 1024);
+ strncpy(reply, buffer, sizeof(buffer));
while(reqMode == true ) { wait_ms(10); }
rxptr = buffer;
@@ -95,18 +95,19 @@
}
void ESP8266_WebServer::ResetModule(void) {
- readBuffer();
- serial->printf("ATE0\r\n");
- while( data_waiting() == 0 ) {
- wait_ms(10);
- }
- readBuffer();
-
- readBuffer();
- serial->printf("AT+RST\r\n");
- wait_ms(1000);
- while( string_waiting("\r\nready\r\n") == 0 ) {
- wait_ms(100);
+ if( string_waiting("\r\nready\r\n") == 0 ) {
+ readBuffer();
+ serial->printf("ATE0\r\n");
+ wait_ms(1000);
+
+ if( string_waiting("\r\nready\r\n") == 0 ) {
+ readBuffer();
+ serial->printf("AT+RST\r\n");
+ wait_ms(1000);
+ while( string_waiting("\r\nready\r\n") == 0 ) {
+ wait_ms(100);
+ }
+ }
}
readBuffer();
@@ -213,6 +214,9 @@
}
void ESP8266_WebServer::SendReply(int linkID, char const* reply, int replySize, const char* mimeType, int maxAge) {
sprintf(response, "HTTP/1.1 200 OK\r\nContent-Type:%s\r\nContent-Length: %d\r\nCache-Control:max-age=%d\r\n\r\n", mimeType, replySize, maxAge);
+ if( debugSerial != NULL ) {
+ debugSerial->printf("HTTP Reply Header(%d bytes): %s\r\n", strlen(response), response);
+ }
sendResponse(linkID, strlen(response));
char const* sendPtr = reply;
int bytesSent = 0;
@@ -234,6 +238,9 @@
}
void ESP8266_WebServer::SendFile(int linkID, FileHandle* file, const char* mimeType, int maxAge) {
sprintf(response, "HTTP/1.1 200 OK\r\nContent-Type:%s\r\nContent-Length: %d\r\nCache-Control:max-age=%d\r\n\r\n", mimeType, file->flen(), maxAge);
+ if( debugSerial != NULL ) {
+ debugSerial->printf("HTTP Reply Header(%d bytes): %s\r\n", strlen(response), response);
+ }
sendResponse(linkID, strlen(response));
int numBytes = file->read(response, sizeof(response));
while( numBytes > 0) {
@@ -244,6 +251,9 @@
int ESP8266_WebServer::SendStream(int linkID, char const* reply, int StreamSize, int WindowSize, const char* mimeType, int maxAge) {
sprintf(response, "HTTP/1.1 200 OK\r\nContent-Type:%s\r\nContent-Length: %d\r\nCache-Control:max-age=%d\r\n\r\n", mimeType, StreamSize, maxAge);
+ if( debugSerial != NULL ) {
+ debugSerial->printf("HTTP Reply Header(%d bytes): %s\r\n", strlen(response), response);
+ }
sendResponse(linkID, strlen(response));
return SendStream(linkID, reply, WindowSize);
}
@@ -488,11 +498,17 @@
if( debugSerial != NULL ) {
debugSerial->printf("HTTP Packet: %s\r\n", httpPacket);
}
+ char* httpMethod = (char*)malloc(16);
+ char* httpURI = (char*)malloc(256);
+
int numMatched = sscanf(httpPacket, "%s %s HTTP/%*c.%*c", httpMethod, httpURI);
if( numMatched != 2 ) {
if( debugSerial != NULL ) {
debugSerial->printf("HTTP ERROR : Matched %d, Method=%s, URI=%s\r\n", numMatched, httpMethod, httpURI);
}
+
+ free(httpMethod);
+ free(httpURI);
return;
}
@@ -529,6 +545,9 @@
if( debugSerial != NULL ) {
debugSerial->printf("HTTP %s %s\r\n", httpMethod, httpURI);
}
+
+ free(httpMethod);
+ free(httpURI);
}
}
--- a/ESP8266_WebServer.h Mon Jan 05 19:22:25 2015 +0000
+++ b/ESP8266_WebServer.h Tue Jan 06 18:44:07 2015 +0000
@@ -24,8 +24,6 @@
class ESP8266_WebRequest
{
- char httpMethod[64];
- char httpURI[512];
char* data;
Serial *debugSerial;
@@ -42,8 +40,8 @@
class ESP8266_WebServer
{
Serial *serial;
- char buffer[1024];
- char reply[1024];
+ char buffer[128];
+ char reply[128];
char response[2048];
char reqBuffer[1024];
volatile char* rxptr;