WiFi WebServer for ESP8266

Fork of ESP8266_WebServer by Sebastian Schocke

Committer:
sschocke
Date:
Thu Jan 01 10:11:55 2015 +0000
Revision:
0:56c72c87d2f5
Child:
1:1c4333ce7448
Initial Commit

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 0:56c72c87d2f5 15
sschocke 0:56c72c87d2f5 16 class ESP8266_WebRequest
sschocke 0:56c72c87d2f5 17 {
sschocke 0:56c72c87d2f5 18 char httpMethod[64];
sschocke 0:56c72c87d2f5 19 char httpURI[512];
sschocke 0:56c72c87d2f5 20 char* data;
sschocke 0:56c72c87d2f5 21 Serial *debugSerial;
sschocke 0:56c72c87d2f5 22
sschocke 0:56c72c87d2f5 23 public:
sschocke 0:56c72c87d2f5 24 ESP8266_WebRequest(const char* packet, Serial* debug);
sschocke 0:56c72c87d2f5 25 ~ESP8266_WebRequest();
sschocke 0:56c72c87d2f5 26 int LinkID;
sschocke 0:56c72c87d2f5 27 void Read(void);
sschocke 0:56c72c87d2f5 28 std::string Method;
sschocke 0:56c72c87d2f5 29 std::string URI;
sschocke 0:56c72c87d2f5 30 std::map<std::string, std::string> Parameters;
sschocke 0:56c72c87d2f5 31 };
sschocke 0:56c72c87d2f5 32
sschocke 0:56c72c87d2f5 33 class ESP8266_WebServer
sschocke 0:56c72c87d2f5 34 {
sschocke 0:56c72c87d2f5 35 Serial *serial;
sschocke 0:56c72c87d2f5 36 char buffer[1024];
sschocke 0:56c72c87d2f5 37 char reply[1024];
sschocke 0:56c72c87d2f5 38 char response[2048];
sschocke 0:56c72c87d2f5 39 char reqBuffer[1024];
sschocke 0:56c72c87d2f5 40 volatile char* rxptr;
sschocke 0:56c72c87d2f5 41 volatile char* rxptrStored;
sschocke 0:56c72c87d2f5 42 volatile bool reqMode;
sschocke 0:56c72c87d2f5 43 volatile int ipdLen;
sschocke 0:56c72c87d2f5 44 volatile int reqLen;
sschocke 0:56c72c87d2f5 45 std::queue<ESP8266_WebRequest*, std::list<ESP8266_WebRequest*> > incoming;
sschocke 0:56c72c87d2f5 46
sschocke 0:56c72c87d2f5 47 private:
sschocke 0:56c72c87d2f5 48 short data_waiting(void);
sschocke 0:56c72c87d2f5 49 short string_waiting(const char*);
sschocke 0:56c72c87d2f5 50 void readBuffer(void);
sschocke 0:56c72c87d2f5 51 void sendResponse(int linkID, int numBytes);
sschocke 0:56c72c87d2f5 52 void queueRequest(void);
sschocke 0:56c72c87d2f5 53
sschocke 0:56c72c87d2f5 54 public:
sschocke 0:56c72c87d2f5 55 Serial *debugSerial;
sschocke 0:56c72c87d2f5 56 bool echoMode;
sschocke 0:56c72c87d2f5 57
sschocke 0:56c72c87d2f5 58 ESP8266_WebServer(Serial *espUART);
sschocke 0:56c72c87d2f5 59 void rxint(void);
sschocke 0:56c72c87d2f5 60 void debugBuffers(Serial* target);
sschocke 0:56c72c87d2f5 61 void Initialize(void);
sschocke 0:56c72c87d2f5 62 ESP8266_WebRequest* GetRequest(void);
sschocke 0:56c72c87d2f5 63 void SendError(int linkID, std::string error);
sschocke 0:56c72c87d2f5 64 void SendError(int linkID, const char* error);
sschocke 0:56c72c87d2f5 65 void Send404Error(int linkID);
sschocke 0:56c72c87d2f5 66 void SendReply(int linkID, std::string reply, const char* mimeType);
sschocke 0:56c72c87d2f5 67 void SendReply(int linkID, const char* reply, int replySize, const char* mimeType);
sschocke 0:56c72c87d2f5 68 };
sschocke 0:56c72c87d2f5 69
sschocke 0:56c72c87d2f5 70 #endif