WiFi WebServer for ESP8266
Fork of ESP8266_WebServer by
ESP8266_WebServer.h@5:48b7fd921bef, 2015-01-04 (annotated)
- Committer:
- sschocke
- Date:
- Sun Jan 04 11:48:11 2015 +0000
- Revision:
- 5:48b7fd921bef
- Parent:
- 3:4ef7db7a95a7
- Child:
- 6:34d93ea4d519
Added functions for querying and setting WiFi related parameters
Who changed what in which revision?
User | Revision | Line number | New 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 httpMethod[64]; |
sschocke | 0:56c72c87d2f5 | 28 | char httpURI[512]; |
sschocke | 0:56c72c87d2f5 | 29 | char* data; |
sschocke | 0:56c72c87d2f5 | 30 | Serial *debugSerial; |
sschocke | 0:56c72c87d2f5 | 31 | |
sschocke | 0:56c72c87d2f5 | 32 | public: |
sschocke | 0:56c72c87d2f5 | 33 | ESP8266_WebRequest(const char* packet, Serial* debug); |
sschocke | 0:56c72c87d2f5 | 34 | ~ESP8266_WebRequest(); |
sschocke | 0:56c72c87d2f5 | 35 | int LinkID; |
sschocke | 0:56c72c87d2f5 | 36 | void Read(void); |
sschocke | 0:56c72c87d2f5 | 37 | std::string Method; |
sschocke | 0:56c72c87d2f5 | 38 | std::string URI; |
sschocke | 0:56c72c87d2f5 | 39 | std::map<std::string, std::string> Parameters; |
sschocke | 0:56c72c87d2f5 | 40 | }; |
sschocke | 0:56c72c87d2f5 | 41 | |
sschocke | 0:56c72c87d2f5 | 42 | class ESP8266_WebServer |
sschocke | 0:56c72c87d2f5 | 43 | { |
sschocke | 0:56c72c87d2f5 | 44 | Serial *serial; |
sschocke | 0:56c72c87d2f5 | 45 | char buffer[1024]; |
sschocke | 0:56c72c87d2f5 | 46 | char reply[1024]; |
sschocke | 0:56c72c87d2f5 | 47 | char response[2048]; |
sschocke | 0:56c72c87d2f5 | 48 | char reqBuffer[1024]; |
sschocke | 0:56c72c87d2f5 | 49 | volatile char* rxptr; |
sschocke | 0:56c72c87d2f5 | 50 | volatile char* rxptrStored; |
sschocke | 0:56c72c87d2f5 | 51 | volatile bool reqMode; |
sschocke | 0:56c72c87d2f5 | 52 | volatile int ipdLen; |
sschocke | 0:56c72c87d2f5 | 53 | volatile int reqLen; |
sschocke | 0:56c72c87d2f5 | 54 | std::queue<ESP8266_WebRequest*, std::list<ESP8266_WebRequest*> > incoming; |
sschocke | 0:56c72c87d2f5 | 55 | |
sschocke | 0:56c72c87d2f5 | 56 | private: |
sschocke | 0:56c72c87d2f5 | 57 | short data_waiting(void); |
sschocke | 0:56c72c87d2f5 | 58 | short string_waiting(const char*); |
sschocke | 0:56c72c87d2f5 | 59 | void readBuffer(void); |
sschocke | 0:56c72c87d2f5 | 60 | void sendResponse(int linkID, int numBytes); |
sschocke | 0:56c72c87d2f5 | 61 | void queueRequest(void); |
sschocke | 0:56c72c87d2f5 | 62 | |
sschocke | 0:56c72c87d2f5 | 63 | public: |
sschocke | 0:56c72c87d2f5 | 64 | Serial *debugSerial; |
sschocke | 0:56c72c87d2f5 | 65 | bool echoMode; |
sschocke | 0:56c72c87d2f5 | 66 | |
sschocke | 0:56c72c87d2f5 | 67 | ESP8266_WebServer(Serial *espUART); |
sschocke | 0:56c72c87d2f5 | 68 | void rxint(void); |
sschocke | 0:56c72c87d2f5 | 69 | void debugBuffers(Serial* target); |
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); |
sschocke | 5:48b7fd921bef | 82 | |
sschocke | 5:48b7fd921bef | 83 | std::string GetStationMAC(void); |
sschocke | 5:48b7fd921bef | 84 | std::string GetAPMAC(void); |
sschocke | 5:48b7fd921bef | 85 | std::string GetStationIP(void); |
sschocke | 5:48b7fd921bef | 86 | std::string GetAPIP(void); |
sschocke | 5:48b7fd921bef | 87 | int GetOperatingMode(void); |
sschocke | 5:48b7fd921bef | 88 | std::string GetStationSSID(void); |
sschocke | 5:48b7fd921bef | 89 | std::list<std::string> ListAvailableSSID(void); |
sschocke | 5:48b7fd921bef | 90 | std::string GetFirmwareVersion(void); |
sschocke | 5:48b7fd921bef | 91 | |
sschocke | 5:48b7fd921bef | 92 | bool SetOperatingMode(int mode); |
sschocke | 5:48b7fd921bef | 93 | bool SetStationSSID(std::string newAP, std::string password); |
sschocke | 0:56c72c87d2f5 | 94 | }; |
sschocke | 0:56c72c87d2f5 | 95 | |
sschocke | 0:56c72c87d2f5 | 96 | #endif |