WiFi WebServer for ESP8266

Fork of ESP8266_WebServer by Sebastian Schocke

Committer:
sschocke
Date:
Tue Jan 06 18:44:07 2015 +0000
Revision:
8:5573f6f70a82
Parent:
7:f6172ba3e807
Child:
9:85554edde164
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?

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 5:48b7fd921bef 17 const char mimeJSON[] = "application/json";
sschocke 5:48b7fd921bef 18
sschocke 5:48b7fd921bef 19 #define OPMODE_STATION 1
sschocke 5:48b7fd921bef 20 #define OPMODE_SOFTAP 2
sschocke 5:48b7fd921bef 21 #define OPMODE_ALL 3
sschocke 5:48b7fd921bef 22
sschocke 5:48b7fd921bef 23 extern const char* opModes[];
sschocke 0:56c72c87d2f5 24
sschocke 0:56c72c87d2f5 25 class ESP8266_WebRequest
sschocke 0:56c72c87d2f5 26 {
sschocke 0:56c72c87d2f5 27 char* data;
sschocke 0:56c72c87d2f5 28 Serial *debugSerial;
sschocke 0:56c72c87d2f5 29
sschocke 0:56c72c87d2f5 30 public:
sschocke 0:56c72c87d2f5 31 ESP8266_WebRequest(const char* packet, Serial* debug);
sschocke 0:56c72c87d2f5 32 ~ESP8266_WebRequest();
sschocke 0:56c72c87d2f5 33 int LinkID;
sschocke 0:56c72c87d2f5 34 void Read(void);
sschocke 0:56c72c87d2f5 35 std::string Method;
sschocke 0:56c72c87d2f5 36 std::string URI;
sschocke 0:56c72c87d2f5 37 std::map<std::string, std::string> Parameters;
sschocke 0:56c72c87d2f5 38 };
sschocke 0:56c72c87d2f5 39
sschocke 0:56c72c87d2f5 40 class ESP8266_WebServer
sschocke 0:56c72c87d2f5 41 {
sschocke 0:56c72c87d2f5 42 Serial *serial;
sschocke 8:5573f6f70a82 43 char buffer[128];
sschocke 8:5573f6f70a82 44 char reply[128];
sschocke 0:56c72c87d2f5 45 char response[2048];
sschocke 0:56c72c87d2f5 46 char reqBuffer[1024];
sschocke 0:56c72c87d2f5 47 volatile char* rxptr;
sschocke 0:56c72c87d2f5 48 volatile char* rxptrStored;
sschocke 0:56c72c87d2f5 49 volatile bool reqMode;
sschocke 0:56c72c87d2f5 50 volatile int ipdLen;
sschocke 0:56c72c87d2f5 51 volatile int reqLen;
sschocke 0:56c72c87d2f5 52 std::queue<ESP8266_WebRequest*, std::list<ESP8266_WebRequest*> > incoming;
sschocke 0:56c72c87d2f5 53
sschocke 0:56c72c87d2f5 54 private:
sschocke 0:56c72c87d2f5 55 short data_waiting(void);
sschocke 0:56c72c87d2f5 56 short string_waiting(const char*);
sschocke 0:56c72c87d2f5 57 void readBuffer(void);
sschocke 0:56c72c87d2f5 58 void sendResponse(int linkID, int numBytes);
sschocke 0:56c72c87d2f5 59 void queueRequest(void);
sschocke 0:56c72c87d2f5 60
sschocke 0:56c72c87d2f5 61 public:
sschocke 0:56c72c87d2f5 62 Serial *debugSerial;
sschocke 0:56c72c87d2f5 63 bool echoMode;
sschocke 0:56c72c87d2f5 64
sschocke 0:56c72c87d2f5 65 ESP8266_WebServer(Serial *espUART);
sschocke 0:56c72c87d2f5 66 void rxint(void);
sschocke 0:56c72c87d2f5 67 void debugBuffers(Serial* target);
sschocke 7:f6172ba3e807 68 void ResetModule(void);
sschocke 0:56c72c87d2f5 69 void Initialize(void);
sschocke 0:56c72c87d2f5 70 ESP8266_WebRequest* GetRequest(void);
sschocke 0:56c72c87d2f5 71 void SendError(int linkID, std::string error);
sschocke 0:56c72c87d2f5 72 void SendError(int linkID, const char* error);
sschocke 0:56c72c87d2f5 73 void Send404Error(int linkID);
sschocke 0:56c72c87d2f5 74 void SendReply(int linkID, std::string reply, const char* mimeType);
sschocke 5:48b7fd921bef 75 void SendReply(int linkID, std::string reply, const char* mimeType, int maxAge);
sschocke 2:6079554681d6 76 void SendReply(int linkID, char const* reply, int replySize, const char* mimeType);
sschocke 3:4ef7db7a95a7 77 void SendReply(int linkID, char const* reply, int replySize, const char* mimeType, int maxAge);
sschocke 3:4ef7db7a95a7 78 void SendReply(int linkID, char const* reply, const char* mimeType, int maxAge);
sschocke 1:1c4333ce7448 79 void SendFile(int linkID, FileHandle* file, const char* mimeType);
sschocke 3:4ef7db7a95a7 80 void SendFile(int linkID, FileHandle* file, const char* mimeType, int maxAge);
leet 4:759de84e790b 81 int SendStream(int linkID, char const* reply, int StreamSize, int WindowSize, const char* mimeType, int maxAge);
leet 4:759de84e790b 82 int SendStream(int linkID, char const* reply, int WindowSize);
sschocke 5:48b7fd921bef 83
sschocke 5:48b7fd921bef 84 std::string GetStationMAC(void);
sschocke 5:48b7fd921bef 85 std::string GetAPMAC(void);
sschocke 5:48b7fd921bef 86 std::string GetStationIP(void);
sschocke 5:48b7fd921bef 87 std::string GetAPIP(void);
sschocke 5:48b7fd921bef 88 int GetOperatingMode(void);
sschocke 5:48b7fd921bef 89 std::string GetStationSSID(void);
sschocke 5:48b7fd921bef 90 std::list<std::string> ListAvailableSSID(void);
sschocke 5:48b7fd921bef 91 std::string GetFirmwareVersion(void);
sschocke 5:48b7fd921bef 92
sschocke 5:48b7fd921bef 93 bool SetOperatingMode(int mode);
sschocke 5:48b7fd921bef 94 bool SetStationSSID(std::string newAP, std::string password);
sschocke 0:56c72c87d2f5 95 };
sschocke 0:56c72c87d2f5 96
sschocke 0:56c72c87d2f5 97 #endif