ESP8266 WiFi Module Web Server library
ESP8266_WebServer.cpp@8:5573f6f70a82, 2015-01-06 (annotated)
- Committer:
- sschocke
- Date:
- Tue Jan 06 18:44:07 2015 +0000
- Revision:
- 8:5573f6f70a82
- Parent:
- 7:f6172ba3e807
Attempted bug fix in resetModule; Use smaller buffers or dynamically allocate and free where possible; Added extra debug output for HTTP Headers being sent
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
sschocke | 0:56c72c87d2f5 | 1 | #include "ESP8266_WebServer.h" |
sschocke | 0:56c72c87d2f5 | 2 | |
sschocke | 5:48b7fd921bef | 3 | const char* opModes[] = {"ERROR", "Station", "SoftAP", "Station+SoftAP"}; |
sschocke | 5:48b7fd921bef | 4 | |
sschocke | 0:56c72c87d2f5 | 5 | ESP8266_WebServer::ESP8266_WebServer(Serial *espUART) { |
sschocke | 0:56c72c87d2f5 | 6 | serial = espUART; |
sschocke | 0:56c72c87d2f5 | 7 | rxptr = buffer; |
sschocke | 0:56c72c87d2f5 | 8 | debugSerial = NULL; |
sschocke | 0:56c72c87d2f5 | 9 | reqMode = false; |
sschocke | 0:56c72c87d2f5 | 10 | reqLen = 0; |
sschocke | 0:56c72c87d2f5 | 11 | } |
sschocke | 0:56c72c87d2f5 | 12 | |
sschocke | 0:56c72c87d2f5 | 13 | void ESP8266_WebServer::rxint(void) { |
sschocke | 0:56c72c87d2f5 | 14 | char c = serial->getc(); |
sschocke | 0:56c72c87d2f5 | 15 | if( (c != 0x0A) && (c != 0x0D) && ((c < 0x20) || (c > 0x80)) ) return; |
sschocke | 0:56c72c87d2f5 | 16 | if( !reqMode && c == '+' ) { |
sschocke | 0:56c72c87d2f5 | 17 | if( echoMode ) { |
sschocke | 0:56c72c87d2f5 | 18 | debugSerial->putc('~'); |
sschocke | 0:56c72c87d2f5 | 19 | } |
sschocke | 0:56c72c87d2f5 | 20 | rxptrStored = rxptr; |
sschocke | 0:56c72c87d2f5 | 21 | rxptr = reqBuffer; |
sschocke | 0:56c72c87d2f5 | 22 | reqMode = true; |
sschocke | 0:56c72c87d2f5 | 23 | } |
sschocke | 0:56c72c87d2f5 | 24 | if( echoMode ) { |
sschocke | 0:56c72c87d2f5 | 25 | debugSerial->putc(c); |
sschocke | 0:56c72c87d2f5 | 26 | } |
sschocke | 0:56c72c87d2f5 | 27 | if( reqMode && reqLen == 0 && c == ':' ) { |
sschocke | 0:56c72c87d2f5 | 28 | if( echoMode ) { |
sschocke | 0:56c72c87d2f5 | 29 | debugSerial->putc('!'); |
sschocke | 0:56c72c87d2f5 | 30 | } |
sschocke | 0:56c72c87d2f5 | 31 | int numMatched = sscanf(reqBuffer,"+IPD,%*d,%d%n", &reqLen, &ipdLen); |
sschocke | 0:56c72c87d2f5 | 32 | if( numMatched < 1 ) { |
sschocke | 0:56c72c87d2f5 | 33 | reqMode = false; |
sschocke | 0:56c72c87d2f5 | 34 | reqLen = 0; |
sschocke | 0:56c72c87d2f5 | 35 | rxptr = rxptrStored; |
sschocke | 0:56c72c87d2f5 | 36 | return; |
sschocke | 0:56c72c87d2f5 | 37 | } |
sschocke | 0:56c72c87d2f5 | 38 | reqLen += ipdLen + 1; |
sschocke | 0:56c72c87d2f5 | 39 | } |
sschocke | 0:56c72c87d2f5 | 40 | *rxptr = c; |
sschocke | 0:56c72c87d2f5 | 41 | rxptr++; |
sschocke | 0:56c72c87d2f5 | 42 | *rxptr = 0; |
sschocke | 0:56c72c87d2f5 | 43 | if( reqMode && reqLen > 0 ) { |
sschocke | 0:56c72c87d2f5 | 44 | if( echoMode ) { |
sschocke | 0:56c72c87d2f5 | 45 | debugSerial->putc('#'); |
sschocke | 0:56c72c87d2f5 | 46 | } |
sschocke | 0:56c72c87d2f5 | 47 | if( (int)(rxptr - reqBuffer) == reqLen ) { |
sschocke | 0:56c72c87d2f5 | 48 | // Process it |
sschocke | 0:56c72c87d2f5 | 49 | queueRequest(); |
sschocke | 0:56c72c87d2f5 | 50 | // Return to normal buffer mode |
sschocke | 0:56c72c87d2f5 | 51 | reqMode = false; |
sschocke | 0:56c72c87d2f5 | 52 | reqLen = 0; |
sschocke | 0:56c72c87d2f5 | 53 | rxptr = rxptrStored; |
sschocke | 0:56c72c87d2f5 | 54 | } |
sschocke | 0:56c72c87d2f5 | 55 | } |
sschocke | 0:56c72c87d2f5 | 56 | } |
sschocke | 0:56c72c87d2f5 | 57 | |
sschocke | 0:56c72c87d2f5 | 58 | void ESP8266_WebServer::debugBuffers(Serial* target) { |
sschocke | 0:56c72c87d2f5 | 59 | target->printf("\r\n\r\nRequest Buffer '%s'\r\nReqLen=%d,ReqMode=%d\r\n", reqBuffer, reqLen, reqMode); |
sschocke | 0:56c72c87d2f5 | 60 | } |
sschocke | 0:56c72c87d2f5 | 61 | |
sschocke | 0:56c72c87d2f5 | 62 | void ESP8266_WebServer::readBuffer(void) { |
sschocke | 8:5573f6f70a82 | 63 | strncpy(reply, buffer, sizeof(buffer)); |
sschocke | 0:56c72c87d2f5 | 64 | while(reqMode == true ) { wait_ms(10); } |
sschocke | 0:56c72c87d2f5 | 65 | |
sschocke | 0:56c72c87d2f5 | 66 | rxptr = buffer; |
sschocke | 0:56c72c87d2f5 | 67 | *rxptr = 0; |
sschocke | 0:56c72c87d2f5 | 68 | } |
sschocke | 0:56c72c87d2f5 | 69 | |
sschocke | 0:56c72c87d2f5 | 70 | short ESP8266_WebServer::data_waiting(void) |
sschocke | 0:56c72c87d2f5 | 71 | { |
sschocke | 0:56c72c87d2f5 | 72 | char* ok = strstr(buffer, "OK\r\n"); |
sschocke | 0:56c72c87d2f5 | 73 | char* error = strstr(buffer, "ERROR\r\n"); |
sschocke | 0:56c72c87d2f5 | 74 | char* nochange = strstr(buffer, "no change\r\n"); |
sschocke | 0:56c72c87d2f5 | 75 | |
sschocke | 0:56c72c87d2f5 | 76 | if( (ok != NULL) || (error != NULL ) || (nochange != NULL ) ) |
sschocke | 0:56c72c87d2f5 | 77 | { |
sschocke | 0:56c72c87d2f5 | 78 | return 1; |
sschocke | 0:56c72c87d2f5 | 79 | } |
sschocke | 0:56c72c87d2f5 | 80 | |
sschocke | 0:56c72c87d2f5 | 81 | return 0; |
sschocke | 0:56c72c87d2f5 | 82 | } |
sschocke | 0:56c72c87d2f5 | 83 | |
sschocke | 0:56c72c87d2f5 | 84 | short ESP8266_WebServer::string_waiting(const char* str) |
sschocke | 0:56c72c87d2f5 | 85 | { |
sschocke | 0:56c72c87d2f5 | 86 | char* pr = strstr(buffer, str); |
sschocke | 0:56c72c87d2f5 | 87 | char* error = strstr(buffer, "ERROR\r\n"); |
sschocke | 0:56c72c87d2f5 | 88 | |
sschocke | 0:56c72c87d2f5 | 89 | if( (pr != NULL) || (error != NULL ) ) |
sschocke | 0:56c72c87d2f5 | 90 | { |
sschocke | 0:56c72c87d2f5 | 91 | return 1; |
sschocke | 0:56c72c87d2f5 | 92 | } |
sschocke | 0:56c72c87d2f5 | 93 | |
sschocke | 0:56c72c87d2f5 | 94 | return 0; |
sschocke | 0:56c72c87d2f5 | 95 | } |
sschocke | 0:56c72c87d2f5 | 96 | |
sschocke | 7:f6172ba3e807 | 97 | void ESP8266_WebServer::ResetModule(void) { |
sschocke | 8:5573f6f70a82 | 98 | if( string_waiting("\r\nready\r\n") == 0 ) { |
sschocke | 8:5573f6f70a82 | 99 | readBuffer(); |
sschocke | 8:5573f6f70a82 | 100 | serial->printf("ATE0\r\n"); |
sschocke | 8:5573f6f70a82 | 101 | wait_ms(1000); |
sschocke | 8:5573f6f70a82 | 102 | |
sschocke | 8:5573f6f70a82 | 103 | if( string_waiting("\r\nready\r\n") == 0 ) { |
sschocke | 8:5573f6f70a82 | 104 | readBuffer(); |
sschocke | 8:5573f6f70a82 | 105 | serial->printf("AT+RST\r\n"); |
sschocke | 8:5573f6f70a82 | 106 | wait_ms(1000); |
sschocke | 8:5573f6f70a82 | 107 | while( string_waiting("\r\nready\r\n") == 0 ) { |
sschocke | 8:5573f6f70a82 | 108 | wait_ms(100); |
sschocke | 8:5573f6f70a82 | 109 | } |
sschocke | 8:5573f6f70a82 | 110 | } |
sschocke | 0:56c72c87d2f5 | 111 | } |
sschocke | 7:f6172ba3e807 | 112 | |
sschocke | 7:f6172ba3e807 | 113 | readBuffer(); |
sschocke | 7:f6172ba3e807 | 114 | serial->printf("ATE0\r\n"); |
sschocke | 0:56c72c87d2f5 | 115 | while( data_waiting() == 0 ) { |
sschocke | 0:56c72c87d2f5 | 116 | wait_ms(10); |
sschocke | 0:56c72c87d2f5 | 117 | } |
sschocke | 0:56c72c87d2f5 | 118 | readBuffer(); |
sschocke | 7:f6172ba3e807 | 119 | } |
sschocke | 0:56c72c87d2f5 | 120 | |
sschocke | 7:f6172ba3e807 | 121 | void ESP8266_WebServer::Initialize(void) { |
sschocke | 0:56c72c87d2f5 | 122 | if( debugSerial != NULL ) { |
sschocke | 0:56c72c87d2f5 | 123 | debugSerial->printf("Done\r\nAccept Multiple connections..."); |
sschocke | 0:56c72c87d2f5 | 124 | } |
sschocke | 0:56c72c87d2f5 | 125 | serial->printf("AT+CIPMUX=1\r\n"); |
sschocke | 0:56c72c87d2f5 | 126 | while( data_waiting() == 0 ) { |
sschocke | 0:56c72c87d2f5 | 127 | wait_ms(10); |
sschocke | 0:56c72c87d2f5 | 128 | } |
sschocke | 0:56c72c87d2f5 | 129 | readBuffer(); |
sschocke | 0:56c72c87d2f5 | 130 | |
sschocke | 0:56c72c87d2f5 | 131 | if( debugSerial != NULL ) { |
sschocke | 0:56c72c87d2f5 | 132 | debugSerial->printf("Done\r\nStarting Web Server..."); |
sschocke | 0:56c72c87d2f5 | 133 | } |
sschocke | 0:56c72c87d2f5 | 134 | |
sschocke | 0:56c72c87d2f5 | 135 | serial->printf("AT+CIPSERVER=1,80\r\n"); |
sschocke | 0:56c72c87d2f5 | 136 | while( data_waiting() == 0 ) { |
sschocke | 0:56c72c87d2f5 | 137 | wait_ms(10); |
sschocke | 0:56c72c87d2f5 | 138 | } |
sschocke | 0:56c72c87d2f5 | 139 | readBuffer(); |
sschocke | 0:56c72c87d2f5 | 140 | } |
sschocke | 0:56c72c87d2f5 | 141 | |
sschocke | 0:56c72c87d2f5 | 142 | void ESP8266_WebServer::queueRequest(void) { |
sschocke | 0:56c72c87d2f5 | 143 | if( strstr(reqBuffer, "HTTP") != NULL ) { |
sschocke | 0:56c72c87d2f5 | 144 | ESP8266_WebRequest* request = new ESP8266_WebRequest(reqBuffer, debugSerial); |
sschocke | 0:56c72c87d2f5 | 145 | |
sschocke | 0:56c72c87d2f5 | 146 | incoming.push(request); |
sschocke | 0:56c72c87d2f5 | 147 | } |
sschocke | 0:56c72c87d2f5 | 148 | } |
sschocke | 0:56c72c87d2f5 | 149 | |
sschocke | 0:56c72c87d2f5 | 150 | ESP8266_WebRequest* ESP8266_WebServer::GetRequest(void) |
sschocke | 0:56c72c87d2f5 | 151 | { |
sschocke | 0:56c72c87d2f5 | 152 | if( incoming.empty() == false ) { |
sschocke | 0:56c72c87d2f5 | 153 | ESP8266_WebRequest* temp = incoming.front(); |
sschocke | 0:56c72c87d2f5 | 154 | incoming.pop(); |
sschocke | 0:56c72c87d2f5 | 155 | temp->Read(); |
sschocke | 0:56c72c87d2f5 | 156 | |
sschocke | 0:56c72c87d2f5 | 157 | return temp; |
sschocke | 0:56c72c87d2f5 | 158 | } |
sschocke | 0:56c72c87d2f5 | 159 | |
sschocke | 0:56c72c87d2f5 | 160 | return NULL; |
sschocke | 0:56c72c87d2f5 | 161 | } |
sschocke | 0:56c72c87d2f5 | 162 | |
sschocke | 0:56c72c87d2f5 | 163 | void ESP8266_WebServer::sendResponse(int linkID, int numBytes) { |
sschocke | 0:56c72c87d2f5 | 164 | bool sent = false; |
sschocke | 0:56c72c87d2f5 | 165 | |
sschocke | 0:56c72c87d2f5 | 166 | readBuffer(); |
sschocke | 0:56c72c87d2f5 | 167 | if( debugSerial != NULL ) { |
sschocke | 0:56c72c87d2f5 | 168 | debugSerial->printf("HTTP Reply Packet(%d bytes)\r\n", numBytes); |
sschocke | 0:56c72c87d2f5 | 169 | } |
sschocke | 0:56c72c87d2f5 | 170 | while( sent == false ) { |
sschocke | 0:56c72c87d2f5 | 171 | while( reqMode == true ) { wait_ms(1); } |
sschocke | 0:56c72c87d2f5 | 172 | serial->printf("AT+CIPSEND=%d,%d\r\n", linkID, numBytes); |
sschocke | 0:56c72c87d2f5 | 173 | wait_ms(100); |
sschocke | 0:56c72c87d2f5 | 174 | if( (string_waiting(">") == 1) ) { |
sschocke | 0:56c72c87d2f5 | 175 | char* error = strstr(buffer, "ERROR\r\n"); |
sschocke | 0:56c72c87d2f5 | 176 | if( error != NULL ) { continue; } |
sschocke | 0:56c72c87d2f5 | 177 | for( int i=0; i<numBytes; i++ ) { |
sschocke | 0:56c72c87d2f5 | 178 | serial->putc(response[i]); |
sschocke | 0:56c72c87d2f5 | 179 | } |
sschocke | 0:56c72c87d2f5 | 180 | while( string_waiting("\r\nSEND OK\r\n") == 0 ) { |
sschocke | 0:56c72c87d2f5 | 181 | wait_ms(10); |
sschocke | 0:56c72c87d2f5 | 182 | } |
sschocke | 0:56c72c87d2f5 | 183 | error = strstr(buffer, "ERROR\r\n"); |
sschocke | 0:56c72c87d2f5 | 184 | if( error != NULL ) { continue; } |
sschocke | 0:56c72c87d2f5 | 185 | sent = true; |
sschocke | 0:56c72c87d2f5 | 186 | } |
sschocke | 0:56c72c87d2f5 | 187 | } |
sschocke | 0:56c72c87d2f5 | 188 | readBuffer(); |
sschocke | 0:56c72c87d2f5 | 189 | } |
sschocke | 0:56c72c87d2f5 | 190 | |
sschocke | 0:56c72c87d2f5 | 191 | void ESP8266_WebServer::SendError(int linkID, std::string error) { |
sschocke | 0:56c72c87d2f5 | 192 | SendError(linkID, error.c_str()); |
sschocke | 0:56c72c87d2f5 | 193 | } |
sschocke | 0:56c72c87d2f5 | 194 | void ESP8266_WebServer::SendError(int linkID, const char* error) { |
sschocke | 0:56c72c87d2f5 | 195 | sprintf(response, "HTTP/1.1 %s\r\nContent-Type: text/html\r\nContent-Length: %d\r\n\r\n%s", error, strlen(error), error); |
sschocke | 0:56c72c87d2f5 | 196 | sendResponse(linkID, strlen(response)); |
sschocke | 0:56c72c87d2f5 | 197 | } |
sschocke | 0:56c72c87d2f5 | 198 | void ESP8266_WebServer::Send404Error(int linkID) { |
sschocke | 0:56c72c87d2f5 | 199 | SendError(linkID, "404 Not Found"); |
sschocke | 0:56c72c87d2f5 | 200 | } |
sschocke | 0:56c72c87d2f5 | 201 | |
sschocke | 0:56c72c87d2f5 | 202 | void ESP8266_WebServer::SendReply(int linkID, std::string reply, const char* mimeType) { |
sschocke | 3:4ef7db7a95a7 | 203 | SendReply(linkID, reply.c_str(), reply.length(), mimeType, 60); |
sschocke | 0:56c72c87d2f5 | 204 | } |
sschocke | 5:48b7fd921bef | 205 | void ESP8266_WebServer::SendReply(int linkID, std::string reply, const char* mimeType, int maxAge) { |
sschocke | 5:48b7fd921bef | 206 | SendReply(linkID, reply.c_str(), reply.length(), mimeType, maxAge); |
sschocke | 5:48b7fd921bef | 207 | } |
sschocke | 0:56c72c87d2f5 | 208 | |
sschocke | 2:6079554681d6 | 209 | void ESP8266_WebServer::SendReply(int linkID, char const* reply, int replySize, const char* mimeType) { |
sschocke | 3:4ef7db7a95a7 | 210 | SendReply(linkID, reply, replySize, mimeType, 600); |
sschocke | 3:4ef7db7a95a7 | 211 | } |
sschocke | 3:4ef7db7a95a7 | 212 | void ESP8266_WebServer::SendReply(int linkID, char const* reply, const char* mimeType, int maxAge) { |
sschocke | 3:4ef7db7a95a7 | 213 | SendReply(linkID, reply, strlen(reply), mimeType, maxAge); |
sschocke | 3:4ef7db7a95a7 | 214 | } |
sschocke | 3:4ef7db7a95a7 | 215 | void ESP8266_WebServer::SendReply(int linkID, char const* reply, int replySize, const char* mimeType, int maxAge) { |
sschocke | 3:4ef7db7a95a7 | 216 | 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); |
sschocke | 8:5573f6f70a82 | 217 | if( debugSerial != NULL ) { |
sschocke | 8:5573f6f70a82 | 218 | debugSerial->printf("HTTP Reply Header(%d bytes): %s\r\n", strlen(response), response); |
sschocke | 8:5573f6f70a82 | 219 | } |
sschocke | 0:56c72c87d2f5 | 220 | sendResponse(linkID, strlen(response)); |
sschocke | 2:6079554681d6 | 221 | char const* sendPtr = reply; |
sschocke | 2:6079554681d6 | 222 | int bytesSent = 0; |
sschocke | 2:6079554681d6 | 223 | while( bytesSent < replySize ) { |
sschocke | 2:6079554681d6 | 224 | int bytesToSend = replySize - bytesSent; |
sschocke | 2:6079554681d6 | 225 | if( bytesToSend > sizeof(response) ) { |
sschocke | 2:6079554681d6 | 226 | bytesToSend = sizeof(response); |
sschocke | 2:6079554681d6 | 227 | } |
sschocke | 2:6079554681d6 | 228 | |
sschocke | 2:6079554681d6 | 229 | memcpy(response, sendPtr, bytesToSend); |
sschocke | 2:6079554681d6 | 230 | sendResponse(linkID, bytesToSend); |
sschocke | 2:6079554681d6 | 231 | sendPtr += bytesToSend; |
sschocke | 2:6079554681d6 | 232 | bytesSent += bytesToSend; |
sschocke | 2:6079554681d6 | 233 | } |
sschocke | 0:56c72c87d2f5 | 234 | } |
sschocke | 0:56c72c87d2f5 | 235 | |
sschocke | 1:1c4333ce7448 | 236 | void ESP8266_WebServer::SendFile(int linkID, FileHandle* file, const char* mimeType) { |
sschocke | 3:4ef7db7a95a7 | 237 | SendFile(linkID, file, mimeType, 86400); |
sschocke | 3:4ef7db7a95a7 | 238 | } |
sschocke | 3:4ef7db7a95a7 | 239 | void ESP8266_WebServer::SendFile(int linkID, FileHandle* file, const char* mimeType, int maxAge) { |
sschocke | 3:4ef7db7a95a7 | 240 | 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); |
sschocke | 8:5573f6f70a82 | 241 | if( debugSerial != NULL ) { |
sschocke | 8:5573f6f70a82 | 242 | debugSerial->printf("HTTP Reply Header(%d bytes): %s\r\n", strlen(response), response); |
sschocke | 8:5573f6f70a82 | 243 | } |
sschocke | 1:1c4333ce7448 | 244 | sendResponse(linkID, strlen(response)); |
sschocke | 1:1c4333ce7448 | 245 | int numBytes = file->read(response, sizeof(response)); |
sschocke | 1:1c4333ce7448 | 246 | while( numBytes > 0) { |
sschocke | 1:1c4333ce7448 | 247 | sendResponse(linkID, numBytes); |
sschocke | 1:1c4333ce7448 | 248 | numBytes = file->read(response, sizeof(response)); |
sschocke | 1:1c4333ce7448 | 249 | } |
sschocke | 1:1c4333ce7448 | 250 | } |
sschocke | 1:1c4333ce7448 | 251 | |
leet | 4:759de84e790b | 252 | int ESP8266_WebServer::SendStream(int linkID, char const* reply, int StreamSize, int WindowSize, const char* mimeType, int maxAge) { |
leet | 4:759de84e790b | 253 | 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); |
sschocke | 8:5573f6f70a82 | 254 | if( debugSerial != NULL ) { |
sschocke | 8:5573f6f70a82 | 255 | debugSerial->printf("HTTP Reply Header(%d bytes): %s\r\n", strlen(response), response); |
sschocke | 8:5573f6f70a82 | 256 | } |
leet | 4:759de84e790b | 257 | sendResponse(linkID, strlen(response)); |
leet | 4:759de84e790b | 258 | return SendStream(linkID, reply, WindowSize); |
leet | 4:759de84e790b | 259 | } |
leet | 4:759de84e790b | 260 | |
sschocke | 5:48b7fd921bef | 261 | std::string ESP8266_WebServer::GetStationMAC(void) { |
sschocke | 5:48b7fd921bef | 262 | while( reqMode == true ) { wait_ms(1); } |
sschocke | 5:48b7fd921bef | 263 | readBuffer(); |
sschocke | 5:48b7fd921bef | 264 | serial->printf("AT+CIPSTAMAC?\r\n"); |
sschocke | 5:48b7fd921bef | 265 | while( data_waiting() == 0 ) { |
sschocke | 5:48b7fd921bef | 266 | wait_ms(10); |
sschocke | 5:48b7fd921bef | 267 | } |
sschocke | 5:48b7fd921bef | 268 | readBuffer(); |
sschocke | 5:48b7fd921bef | 269 | if( debugSerial != NULL ) { |
sschocke | 5:48b7fd921bef | 270 | debugSerial->printf("Station MAC Reply: %s\r\n", reply); |
sschocke | 5:48b7fd921bef | 271 | } |
sschocke | 5:48b7fd921bef | 272 | |
sschocke | 5:48b7fd921bef | 273 | std::string mac = std::string(reply); |
sschocke | 5:48b7fd921bef | 274 | mac = mac.substr(1, 17); |
sschocke | 5:48b7fd921bef | 275 | |
sschocke | 5:48b7fd921bef | 276 | return mac; |
sschocke | 5:48b7fd921bef | 277 | } |
sschocke | 5:48b7fd921bef | 278 | std::string ESP8266_WebServer::GetAPMAC(void) { |
sschocke | 5:48b7fd921bef | 279 | while( reqMode == true ) { wait_ms(1); } |
sschocke | 5:48b7fd921bef | 280 | readBuffer(); |
sschocke | 5:48b7fd921bef | 281 | serial->printf("AT+CIPAPMAC?\r\n"); |
sschocke | 5:48b7fd921bef | 282 | while( data_waiting() == 0 ) { |
sschocke | 5:48b7fd921bef | 283 | wait_ms(10); |
sschocke | 5:48b7fd921bef | 284 | } |
sschocke | 5:48b7fd921bef | 285 | readBuffer(); |
sschocke | 5:48b7fd921bef | 286 | if( debugSerial != NULL ) { |
sschocke | 5:48b7fd921bef | 287 | debugSerial->printf("SoftAP MAC Reply: %s\r\n", reply); |
sschocke | 5:48b7fd921bef | 288 | } |
sschocke | 5:48b7fd921bef | 289 | |
sschocke | 5:48b7fd921bef | 290 | std::string mac = std::string(reply); |
sschocke | 5:48b7fd921bef | 291 | mac = mac.substr(1, 17); |
sschocke | 5:48b7fd921bef | 292 | |
sschocke | 5:48b7fd921bef | 293 | return mac; |
sschocke | 5:48b7fd921bef | 294 | } |
sschocke | 5:48b7fd921bef | 295 | std::string ESP8266_WebServer::GetStationIP(void) { |
sschocke | 5:48b7fd921bef | 296 | while( reqMode == true ) { wait_ms(1); } |
sschocke | 5:48b7fd921bef | 297 | readBuffer(); |
sschocke | 5:48b7fd921bef | 298 | serial->printf("AT+CIPSTA?\r\n"); |
sschocke | 5:48b7fd921bef | 299 | while( data_waiting() == 0 ) { |
sschocke | 5:48b7fd921bef | 300 | wait_ms(10); |
sschocke | 5:48b7fd921bef | 301 | } |
sschocke | 5:48b7fd921bef | 302 | readBuffer(); |
sschocke | 5:48b7fd921bef | 303 | if( debugSerial != NULL ) { |
sschocke | 5:48b7fd921bef | 304 | debugSerial->printf("Station IP Reply: %s\r\n", reply); |
sschocke | 5:48b7fd921bef | 305 | } |
sschocke | 5:48b7fd921bef | 306 | |
sschocke | 5:48b7fd921bef | 307 | std::string ip = std::string(reply); |
sschocke | 5:48b7fd921bef | 308 | ip = ip.substr(1, ip.find('"', 1) - 1); |
sschocke | 5:48b7fd921bef | 309 | |
sschocke | 5:48b7fd921bef | 310 | return ip; |
sschocke | 5:48b7fd921bef | 311 | } |
sschocke | 5:48b7fd921bef | 312 | std::string ESP8266_WebServer::GetAPIP(void) { |
sschocke | 5:48b7fd921bef | 313 | while( reqMode == true ) { wait_ms(1); } |
sschocke | 5:48b7fd921bef | 314 | readBuffer(); |
sschocke | 5:48b7fd921bef | 315 | serial->printf("AT+CIPAP?\r\n"); |
sschocke | 5:48b7fd921bef | 316 | while( data_waiting() == 0 ) { |
sschocke | 5:48b7fd921bef | 317 | wait_ms(10); |
sschocke | 5:48b7fd921bef | 318 | } |
sschocke | 5:48b7fd921bef | 319 | readBuffer(); |
sschocke | 5:48b7fd921bef | 320 | if( debugSerial != NULL ) { |
sschocke | 5:48b7fd921bef | 321 | debugSerial->printf("SoftAP IP Reply: %s\r\n", reply); |
sschocke | 5:48b7fd921bef | 322 | } |
sschocke | 5:48b7fd921bef | 323 | |
sschocke | 5:48b7fd921bef | 324 | std::string ip = std::string(reply); |
sschocke | 5:48b7fd921bef | 325 | ip = ip.substr(1, ip.find('"', 1) - 1); |
sschocke | 5:48b7fd921bef | 326 | |
sschocke | 5:48b7fd921bef | 327 | return ip; |
sschocke | 5:48b7fd921bef | 328 | } |
sschocke | 5:48b7fd921bef | 329 | int ESP8266_WebServer::GetOperatingMode(void) { |
sschocke | 5:48b7fd921bef | 330 | while( reqMode == true ) { wait_ms(1); } |
sschocke | 5:48b7fd921bef | 331 | readBuffer(); |
sschocke | 5:48b7fd921bef | 332 | serial->printf("AT+CWMODE?\r\n"); |
sschocke | 5:48b7fd921bef | 333 | while( data_waiting() == 0 ) { |
sschocke | 5:48b7fd921bef | 334 | wait_ms(10); |
sschocke | 5:48b7fd921bef | 335 | } |
sschocke | 5:48b7fd921bef | 336 | readBuffer(); |
sschocke | 5:48b7fd921bef | 337 | if( debugSerial != NULL ) { |
sschocke | 5:48b7fd921bef | 338 | debugSerial->printf("Operating Mode Reply: %s\r\n", reply); |
sschocke | 5:48b7fd921bef | 339 | } |
sschocke | 5:48b7fd921bef | 340 | |
sschocke | 5:48b7fd921bef | 341 | return atoi(reply); |
sschocke | 5:48b7fd921bef | 342 | } |
sschocke | 5:48b7fd921bef | 343 | std::string ESP8266_WebServer::GetStationSSID(void) { |
sschocke | 5:48b7fd921bef | 344 | while( reqMode == true ) { wait_ms(1); } |
sschocke | 5:48b7fd921bef | 345 | readBuffer(); |
sschocke | 5:48b7fd921bef | 346 | serial->printf("AT+CWJAP?\r\n"); |
sschocke | 5:48b7fd921bef | 347 | while( data_waiting() == 0 ) { |
sschocke | 5:48b7fd921bef | 348 | wait_ms(10); |
sschocke | 5:48b7fd921bef | 349 | } |
sschocke | 5:48b7fd921bef | 350 | readBuffer(); |
sschocke | 5:48b7fd921bef | 351 | if( debugSerial != NULL ) { |
sschocke | 5:48b7fd921bef | 352 | debugSerial->printf("Station SSID Reply: %s\r\n", reply); |
sschocke | 5:48b7fd921bef | 353 | } |
sschocke | 5:48b7fd921bef | 354 | |
sschocke | 5:48b7fd921bef | 355 | std::string ssid = std::string(reply); |
sschocke | 5:48b7fd921bef | 356 | if( strstr(reply, "No AP\r\n") != NULL ) { return "(None)"; } |
sschocke | 5:48b7fd921bef | 357 | ssid = ssid.substr(1, ssid.find('"', 1) - 1); |
sschocke | 5:48b7fd921bef | 358 | |
sschocke | 5:48b7fd921bef | 359 | return ssid; |
sschocke | 5:48b7fd921bef | 360 | } |
sschocke | 5:48b7fd921bef | 361 | std::list<std::string> ESP8266_WebServer::ListAvailableSSID(void) { |
sschocke | 5:48b7fd921bef | 362 | std::list<std::string> apList; |
sschocke | 5:48b7fd921bef | 363 | |
sschocke | 5:48b7fd921bef | 364 | while( reqMode == true ) { wait_ms(1); } |
sschocke | 5:48b7fd921bef | 365 | readBuffer(); |
sschocke | 5:48b7fd921bef | 366 | serial->printf("AT+CWLAP\r\n"); |
sschocke | 5:48b7fd921bef | 367 | while( data_waiting() == 0 ) { |
sschocke | 5:48b7fd921bef | 368 | wait_ms(10); |
sschocke | 5:48b7fd921bef | 369 | } |
sschocke | 5:48b7fd921bef | 370 | readBuffer(); |
sschocke | 5:48b7fd921bef | 371 | if( debugSerial != NULL ) { |
sschocke | 5:48b7fd921bef | 372 | debugSerial->printf("SSID List Reply: %s\r\n", reply); |
sschocke | 5:48b7fd921bef | 373 | } |
sschocke | 5:48b7fd921bef | 374 | |
sschocke | 5:48b7fd921bef | 375 | char ssid[65]; |
sschocke | 5:48b7fd921bef | 376 | char apmac[20]; |
sschocke | 5:48b7fd921bef | 377 | int ecn; |
sschocke | 5:48b7fd921bef | 378 | int rssi; |
sschocke | 5:48b7fd921bef | 379 | int tokenLength; |
sschocke | 5:48b7fd921bef | 380 | char* token = strstr(reply, "("); |
sschocke | 5:48b7fd921bef | 381 | while( token != NULL ) { |
sschocke | 5:48b7fd921bef | 382 | int numMatched = sscanf(token, "(%d,\"%[^\"]\",%d,\"%[0123456789abcdef:]\",%*d)\r\n%n", &ecn, ssid, &rssi, apmac, &tokenLength); |
sschocke | 5:48b7fd921bef | 383 | if( numMatched < 4 ) { |
sschocke | 5:48b7fd921bef | 384 | if( debugSerial != NULL ) { |
sschocke | 5:48b7fd921bef | 385 | debugSerial->printf("SSID List Token Error: NumMatched=%d, SSID=%s\r\n", numMatched, ssid); |
sschocke | 5:48b7fd921bef | 386 | } |
sschocke | 5:48b7fd921bef | 387 | return apList; |
sschocke | 5:48b7fd921bef | 388 | } |
sschocke | 5:48b7fd921bef | 389 | if( debugSerial != NULL ) { |
sschocke | 5:48b7fd921bef | 390 | debugSerial->printf("SSID List Token : SSID=%s, ECN=%d, RSSI=%d, APMAC=%s, TokenLength=%d\r\n", ssid, ecn, rssi, apmac, tokenLength); |
sschocke | 5:48b7fd921bef | 391 | } |
sschocke | 5:48b7fd921bef | 392 | apList.push_back(std::string(ssid)); |
sschocke | 5:48b7fd921bef | 393 | token += tokenLength; |
sschocke | 5:48b7fd921bef | 394 | token = strstr(token, "("); |
sschocke | 5:48b7fd921bef | 395 | } |
sschocke | 5:48b7fd921bef | 396 | |
sschocke | 5:48b7fd921bef | 397 | return apList; |
sschocke | 5:48b7fd921bef | 398 | } |
sschocke | 5:48b7fd921bef | 399 | std::string ESP8266_WebServer::GetFirmwareVersion(void) { |
sschocke | 5:48b7fd921bef | 400 | while( reqMode == true ) { wait_ms(1); } |
sschocke | 5:48b7fd921bef | 401 | readBuffer(); |
sschocke | 5:48b7fd921bef | 402 | serial->printf("AT+GMR\r\n"); |
sschocke | 5:48b7fd921bef | 403 | while( data_waiting() == 0 ) { |
sschocke | 5:48b7fd921bef | 404 | wait_ms(10); |
sschocke | 5:48b7fd921bef | 405 | } |
sschocke | 5:48b7fd921bef | 406 | readBuffer(); |
sschocke | 5:48b7fd921bef | 407 | if( debugSerial != NULL ) { |
sschocke | 5:48b7fd921bef | 408 | debugSerial->printf("Firmware Version Reply: %s\r\n", reply); |
sschocke | 5:48b7fd921bef | 409 | } |
sschocke | 5:48b7fd921bef | 410 | |
sschocke | 5:48b7fd921bef | 411 | std::string ver = std::string(reply); |
sschocke | 5:48b7fd921bef | 412 | ver = ver.substr(0, ver.find('\r')); |
sschocke | 5:48b7fd921bef | 413 | |
sschocke | 5:48b7fd921bef | 414 | return ver; |
sschocke | 5:48b7fd921bef | 415 | } |
sschocke | 5:48b7fd921bef | 416 | |
leet | 4:759de84e790b | 417 | int ESP8266_WebServer::SendStream(int linkID, char const* reply, int WindowSize) { |
leet | 4:759de84e790b | 418 | char const* sendPtr = reply; |
leet | 4:759de84e790b | 419 | int bytesSent = 0; |
leet | 4:759de84e790b | 420 | while( bytesSent < WindowSize ) { |
leet | 4:759de84e790b | 421 | int bytesToSend = WindowSize - bytesSent; |
leet | 4:759de84e790b | 422 | if( bytesToSend > sizeof(response) ) { |
leet | 4:759de84e790b | 423 | bytesToSend = sizeof(response); |
leet | 4:759de84e790b | 424 | } |
leet | 4:759de84e790b | 425 | |
leet | 4:759de84e790b | 426 | memcpy(response, sendPtr, bytesToSend); |
leet | 4:759de84e790b | 427 | sendResponse(linkID, bytesToSend); |
leet | 4:759de84e790b | 428 | sendPtr += bytesToSend; |
leet | 4:759de84e790b | 429 | bytesSent += bytesToSend; |
leet | 4:759de84e790b | 430 | } |
leet | 4:759de84e790b | 431 | |
leet | 4:759de84e790b | 432 | return bytesSent; |
leet | 4:759de84e790b | 433 | } |
leet | 4:759de84e790b | 434 | |
sschocke | 5:48b7fd921bef | 435 | bool ESP8266_WebServer::SetOperatingMode(int mode) { |
sschocke | 5:48b7fd921bef | 436 | if( debugSerial != NULL ) { |
sschocke | 5:48b7fd921bef | 437 | debugSerial->printf("Set Operating Mode to %s(%d)\r\n", opModes[mode], mode); |
sschocke | 5:48b7fd921bef | 438 | } |
sschocke | 6:34d93ea4d519 | 439 | |
sschocke | 5:48b7fd921bef | 440 | while( reqMode == true ) { wait_ms(1); } |
sschocke | 5:48b7fd921bef | 441 | readBuffer(); |
sschocke | 5:48b7fd921bef | 442 | serial->printf("AT+CWMODE=%d\r\n", mode); |
sschocke | 5:48b7fd921bef | 443 | while( data_waiting() == 0 ) { |
sschocke | 5:48b7fd921bef | 444 | wait_ms(10); |
sschocke | 5:48b7fd921bef | 445 | } |
sschocke | 5:48b7fd921bef | 446 | readBuffer(); |
sschocke | 5:48b7fd921bef | 447 | if( debugSerial != NULL ) { |
sschocke | 5:48b7fd921bef | 448 | debugSerial->printf("Set Operating Mode Reply: %s\r\n", reply); |
sschocke | 5:48b7fd921bef | 449 | } |
sschocke | 5:48b7fd921bef | 450 | if( strstr(reply, "\r\nOK\r\n") != NULL ) { return true; } |
sschocke | 5:48b7fd921bef | 451 | return false; |
sschocke | 5:48b7fd921bef | 452 | } |
sschocke | 5:48b7fd921bef | 453 | |
sschocke | 5:48b7fd921bef | 454 | bool ESP8266_WebServer::SetStationSSID(std::string newAP, std::string password) { |
sschocke | 5:48b7fd921bef | 455 | if( debugSerial != NULL ) { |
sschocke | 5:48b7fd921bef | 456 | debugSerial->printf("Set Station SSID to %s, Password=%s\r\n", newAP.c_str(), password.c_str()); |
sschocke | 5:48b7fd921bef | 457 | } |
sschocke | 5:48b7fd921bef | 458 | while( reqMode == true ) { wait_ms(1); } |
sschocke | 5:48b7fd921bef | 459 | readBuffer(); |
sschocke | 5:48b7fd921bef | 460 | serial->printf("AT+CWJAP=\"%s\",\"%s\"\r\n", newAP.c_str(), password.c_str()); |
sschocke | 5:48b7fd921bef | 461 | while( data_waiting() == 0 ) { |
sschocke | 5:48b7fd921bef | 462 | wait_ms(10); |
sschocke | 5:48b7fd921bef | 463 | } |
sschocke | 5:48b7fd921bef | 464 | readBuffer(); |
sschocke | 5:48b7fd921bef | 465 | if( debugSerial != NULL ) { |
sschocke | 5:48b7fd921bef | 466 | debugSerial->printf("Set Station SSID Reply: %s\r\n", reply); |
sschocke | 5:48b7fd921bef | 467 | } |
sschocke | 5:48b7fd921bef | 468 | if( strstr(reply, "\r\nOK\r\n") != NULL ) { return true; } |
sschocke | 5:48b7fd921bef | 469 | |
sschocke | 5:48b7fd921bef | 470 | return false; |
sschocke | 5:48b7fd921bef | 471 | } |
sschocke | 5:48b7fd921bef | 472 | |
sschocke | 0:56c72c87d2f5 | 473 | ESP8266_WebRequest::ESP8266_WebRequest(const char* packet, Serial* debug) { |
sschocke | 0:56c72c87d2f5 | 474 | int sz = strlen(packet); |
sschocke | 0:56c72c87d2f5 | 475 | data = (char *)malloc(sz+1); |
sschocke | 0:56c72c87d2f5 | 476 | memcpy(data, packet, sz+1); |
sschocke | 0:56c72c87d2f5 | 477 | debugSerial = debug; |
sschocke | 0:56c72c87d2f5 | 478 | } |
sschocke | 0:56c72c87d2f5 | 479 | |
sschocke | 0:56c72c87d2f5 | 480 | void ESP8266_WebRequest::Read(void) { |
sschocke | 0:56c72c87d2f5 | 481 | int bytesRecv, ipdLen, linkID; |
sschocke | 0:56c72c87d2f5 | 482 | int numMatched = sscanf(data,"+IPD,%d,%d:%n", &linkID, &bytesRecv, &ipdLen); |
sschocke | 0:56c72c87d2f5 | 483 | if( numMatched != 2 ) { |
sschocke | 0:56c72c87d2f5 | 484 | if( debugSerial != NULL ) { |
sschocke | 0:56c72c87d2f5 | 485 | debugSerial->printf("IPD ERROR : Matched %d, LinkID=%d, BytesRecv=%d, IPD Header Len=%d\r\n", numMatched, linkID, bytesRecv, ipdLen); |
sschocke | 0:56c72c87d2f5 | 486 | } |
sschocke | 0:56c72c87d2f5 | 487 | return; |
sschocke | 0:56c72c87d2f5 | 488 | } |
sschocke | 0:56c72c87d2f5 | 489 | |
sschocke | 0:56c72c87d2f5 | 490 | if( debugSerial != NULL ) { |
sschocke | 0:56c72c87d2f5 | 491 | debugSerial->printf("IPD Data: LinkID=%d, BytesRecv=%d, IPD Header Len=%d\r\n", linkID, bytesRecv, ipdLen); |
sschocke | 0:56c72c87d2f5 | 492 | } |
sschocke | 0:56c72c87d2f5 | 493 | if( strstr(data, "HTTP") != NULL ) { |
sschocke | 0:56c72c87d2f5 | 494 | if( debugSerial != NULL ) { |
sschocke | 0:56c72c87d2f5 | 495 | debugSerial->printf("Got HTTP Request\r\n"); |
sschocke | 0:56c72c87d2f5 | 496 | } |
sschocke | 0:56c72c87d2f5 | 497 | char* httpPacket = data + ipdLen; |
sschocke | 0:56c72c87d2f5 | 498 | if( debugSerial != NULL ) { |
sschocke | 0:56c72c87d2f5 | 499 | debugSerial->printf("HTTP Packet: %s\r\n", httpPacket); |
sschocke | 0:56c72c87d2f5 | 500 | } |
sschocke | 8:5573f6f70a82 | 501 | char* httpMethod = (char*)malloc(16); |
sschocke | 8:5573f6f70a82 | 502 | char* httpURI = (char*)malloc(256); |
sschocke | 8:5573f6f70a82 | 503 | |
sschocke | 0:56c72c87d2f5 | 504 | int numMatched = sscanf(httpPacket, "%s %s HTTP/%*c.%*c", httpMethod, httpURI); |
sschocke | 0:56c72c87d2f5 | 505 | if( numMatched != 2 ) { |
sschocke | 0:56c72c87d2f5 | 506 | if( debugSerial != NULL ) { |
sschocke | 0:56c72c87d2f5 | 507 | debugSerial->printf("HTTP ERROR : Matched %d, Method=%s, URI=%s\r\n", numMatched, httpMethod, httpURI); |
sschocke | 0:56c72c87d2f5 | 508 | } |
sschocke | 8:5573f6f70a82 | 509 | |
sschocke | 8:5573f6f70a82 | 510 | free(httpMethod); |
sschocke | 8:5573f6f70a82 | 511 | free(httpURI); |
sschocke | 0:56c72c87d2f5 | 512 | return; |
sschocke | 0:56c72c87d2f5 | 513 | } |
sschocke | 0:56c72c87d2f5 | 514 | |
sschocke | 0:56c72c87d2f5 | 515 | LinkID = linkID; |
sschocke | 0:56c72c87d2f5 | 516 | Method = httpMethod; |
sschocke | 0:56c72c87d2f5 | 517 | URI = httpURI; |
sschocke | 0:56c72c87d2f5 | 518 | int pos = URI.find('?'); |
sschocke | 0:56c72c87d2f5 | 519 | if(pos != string::npos ) { |
sschocke | 0:56c72c87d2f5 | 520 | string params = URI.substr(pos+1); |
sschocke | 0:56c72c87d2f5 | 521 | URI = URI.substr(0,pos); |
sschocke | 0:56c72c87d2f5 | 522 | pos = params.find('='); |
sschocke | 0:56c72c87d2f5 | 523 | while( pos != string::npos ) { |
sschocke | 0:56c72c87d2f5 | 524 | string name = params.substr(0,pos); |
sschocke | 0:56c72c87d2f5 | 525 | string value = params.substr(pos+1); |
sschocke | 0:56c72c87d2f5 | 526 | pos = params.find('&'); |
sschocke | 0:56c72c87d2f5 | 527 | if( pos == string::npos ) |
sschocke | 0:56c72c87d2f5 | 528 | { |
sschocke | 0:56c72c87d2f5 | 529 | if( debugSerial != NULL ) { |
sschocke | 0:56c72c87d2f5 | 530 | debugSerial->printf("HTTP GET Parameter %s=%s\r\n", name.c_str(), value.c_str()); |
sschocke | 0:56c72c87d2f5 | 531 | } |
sschocke | 0:56c72c87d2f5 | 532 | Parameters[name] = value; |
sschocke | 0:56c72c87d2f5 | 533 | break; |
sschocke | 0:56c72c87d2f5 | 534 | } |
sschocke | 0:56c72c87d2f5 | 535 | |
sschocke | 0:56c72c87d2f5 | 536 | value = value.substr(0,value.find('&')); |
sschocke | 0:56c72c87d2f5 | 537 | params = params.substr(pos+1); |
sschocke | 0:56c72c87d2f5 | 538 | pos = params.find('='); |
sschocke | 0:56c72c87d2f5 | 539 | if( debugSerial != NULL ) { |
sschocke | 0:56c72c87d2f5 | 540 | debugSerial->printf("HTTP GET Parameter %s=%s\r\n", name.c_str(), value.c_str()); |
sschocke | 0:56c72c87d2f5 | 541 | } |
sschocke | 0:56c72c87d2f5 | 542 | Parameters[name] = value; |
sschocke | 0:56c72c87d2f5 | 543 | } |
sschocke | 0:56c72c87d2f5 | 544 | } |
sschocke | 0:56c72c87d2f5 | 545 | if( debugSerial != NULL ) { |
sschocke | 0:56c72c87d2f5 | 546 | debugSerial->printf("HTTP %s %s\r\n", httpMethod, httpURI); |
sschocke | 0:56c72c87d2f5 | 547 | } |
sschocke | 8:5573f6f70a82 | 548 | |
sschocke | 8:5573f6f70a82 | 549 | free(httpMethod); |
sschocke | 8:5573f6f70a82 | 550 | free(httpURI); |
sschocke | 0:56c72c87d2f5 | 551 | } |
sschocke | 0:56c72c87d2f5 | 552 | } |
sschocke | 0:56c72c87d2f5 | 553 | |
sschocke | 0:56c72c87d2f5 | 554 | ESP8266_WebRequest::~ESP8266_WebRequest() |
sschocke | 0:56c72c87d2f5 | 555 | { |
sschocke | 0:56c72c87d2f5 | 556 | free(data); |
sschocke | 0:56c72c87d2f5 | 557 | } |