WiFi WebServer for ESP8266

Fork of ESP8266_WebServer by Sebastian Schocke

Committer:
leet
Date:
Wed Jan 07 20:51:00 2015 +0000
Revision:
9:85554edde164
Parent:
8:5573f6f70a82
Add x-icon for favicon MIME Type

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