Clinton Lee Taylor / Mbed 2 deprecated WiFiLamp

Dependencies:   ESP8266_WebServer mbed

Fork of WiFiLamp by Sebastian Schocke

Committer:
sschocke
Date:
Wed Dec 31 15:15:50 2014 +0000
Revision:
20:f5a6527bfda6
Parent:
11:3ab606a42227
Rework of Web Server to handle multiple simultaneous requests

Who changed what in which revision?

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