WiFi WebServer for ESP8266

Fork of ESP8266_WebServer by Sebastian Schocke

Committer:
sschocke
Date:
Thu Jan 01 16:27:58 2015 +0000
Revision:
3:4ef7db7a95a7
Parent:
2:6079554681d6
Child:
4:759de84e790b
Child:
5:48b7fd921bef
Added extra functions allowing Cache Control with replies; Added a few missing mimeTypes

Who changed what in which revision?

UserRevisionLine numberNew contents of line
sschocke 0:56c72c87d2f5 1 #include "mbed.h"
sschocke 0:56c72c87d2f5 2 #include <string>
sschocke 0:56c72c87d2f5 3 #include <map>
sschocke 0:56c72c87d2f5 4 #include <queue>
sschocke 0:56c72c87d2f5 5 #include <list>
sschocke 0:56c72c87d2f5 6
sschocke 0:56c72c87d2f5 7 #ifndef _ESP8266_WEB_SERVER_H
sschocke 0:56c72c87d2f5 8 #define _ESP8266_WEB_SERVER_H
sschocke 0:56c72c87d2f5 9
sschocke 0:56c72c87d2f5 10 const char mimeHTML[] = "text/html";
sschocke 0:56c72c87d2f5 11 const char mimeJavaScript[] = "text/javascript";
sschocke 0:56c72c87d2f5 12 const char mimeCSS[] = "text/css";
sschocke 0:56c72c87d2f5 13 const char mimeJPEG[] = "image/jpeg";
sschocke 0:56c72c87d2f5 14 const char mimePNG[] = "image/png";
sschocke 3:4ef7db7a95a7 15 const char mimeGIF[] = "image/gif";
sschocke 3:4ef7db7a95a7 16 const char mimeText[] = "text/plain";
sschocke 0:56c72c87d2f5 17
sschocke 0:56c72c87d2f5 18 class ESP8266_WebRequest
sschocke 0:56c72c87d2f5 19 {
sschocke 0:56c72c87d2f5 20 char httpMethod[64];
sschocke 0:56c72c87d2f5 21 char httpURI[512];
sschocke 0:56c72c87d2f5 22 char* data;
sschocke 0:56c72c87d2f5 23 Serial *debugSerial;
sschocke 0:56c72c87d2f5 24
sschocke 0:56c72c87d2f5 25 public:
sschocke 0:56c72c87d2f5 26 ESP8266_WebRequest(const char* packet, Serial* debug);
sschocke 0:56c72c87d2f5 27 ~ESP8266_WebRequest();
sschocke 0:56c72c87d2f5 28 int LinkID;
sschocke 0:56c72c87d2f5 29 void Read(void);
sschocke 0:56c72c87d2f5 30 std::string Method;
sschocke 0:56c72c87d2f5 31 std::string URI;
sschocke 0:56c72c87d2f5 32 std::map<std::string, std::string> Parameters;
sschocke 0:56c72c87d2f5 33 };
sschocke 0:56c72c87d2f5 34
sschocke 0:56c72c87d2f5 35 class ESP8266_WebServer
sschocke 0:56c72c87d2f5 36 {
sschocke 0:56c72c87d2f5 37 Serial *serial;
sschocke 0:56c72c87d2f5 38 char buffer[1024];
sschocke 0:56c72c87d2f5 39 char reply[1024];
sschocke 0:56c72c87d2f5 40 char response[2048];
sschocke 0:56c72c87d2f5 41 char reqBuffer[1024];
sschocke 0:56c72c87d2f5 42 volatile char* rxptr;
sschocke 0:56c72c87d2f5 43 volatile char* rxptrStored;
sschocke 0:56c72c87d2f5 44 volatile bool reqMode;
sschocke 0:56c72c87d2f5 45 volatile int ipdLen;
sschocke 0:56c72c87d2f5 46 volatile int reqLen;
sschocke 0:56c72c87d2f5 47 std::queue<ESP8266_WebRequest*, std::list<ESP8266_WebRequest*> > incoming;
sschocke 0:56c72c87d2f5 48
sschocke 0:56c72c87d2f5 49 private:
sschocke 0:56c72c87d2f5 50 short data_waiting(void);
sschocke 0:56c72c87d2f5 51 short string_waiting(const char*);
sschocke 0:56c72c87d2f5 52 void readBuffer(void);
sschocke 0:56c72c87d2f5 53 void sendResponse(int linkID, int numBytes);
sschocke 0:56c72c87d2f5 54 void queueRequest(void);
sschocke 0:56c72c87d2f5 55
sschocke 0:56c72c87d2f5 56 public:
sschocke 0:56c72c87d2f5 57 Serial *debugSerial;
sschocke 0:56c72c87d2f5 58 bool echoMode;
sschocke 0:56c72c87d2f5 59
sschocke 0:56c72c87d2f5 60 ESP8266_WebServer(Serial *espUART);
sschocke 0:56c72c87d2f5 61 void rxint(void);
sschocke 0:56c72c87d2f5 62 void debugBuffers(Serial* target);
sschocke 0:56c72c87d2f5 63 void Initialize(void);
sschocke 0:56c72c87d2f5 64 ESP8266_WebRequest* GetRequest(void);
sschocke 0:56c72c87d2f5 65 void SendError(int linkID, std::string error);
sschocke 0:56c72c87d2f5 66 void SendError(int linkID, const char* error);
sschocke 0:56c72c87d2f5 67 void Send404Error(int linkID);
sschocke 0:56c72c87d2f5 68 void SendReply(int linkID, std::string reply, const char* mimeType);
sschocke 2:6079554681d6 69 void SendReply(int linkID, char const* reply, int replySize, const char* mimeType);
sschocke 3:4ef7db7a95a7 70 void SendReply(int linkID, char const* reply, int replySize, const char* mimeType, int maxAge);
sschocke 3:4ef7db7a95a7 71 void SendReply(int linkID, char const* reply, const char* mimeType, int maxAge);
sschocke 1:1c4333ce7448 72 void SendFile(int linkID, FileHandle* file, const char* mimeType);
sschocke 3:4ef7db7a95a7 73 void SendFile(int linkID, FileHandle* file, const char* mimeType, int maxAge);
sschocke 0:56c72c87d2f5 74 };
sschocke 0:56c72c87d2f5 75
sschocke 0:56c72c87d2f5 76 #endif