ESP8266 library to get and send data.
Fork of ESP8266 by
Diff: ESP8266.h
- Revision:
- 4:c05f7a1b4e47
- Parent:
- 3:4f24e7e803a1
- Child:
- 5:5cc7894bb8cb
--- a/ESP8266.h Sat Jun 11 14:05:06 2016 +0000 +++ b/ESP8266.h Fri Oct 21 16:33:31 2016 +0000 @@ -4,53 +4,79 @@ #include <string> #include "mbed.h" -class ESP8266 -{ -public: +#define CMD_END "\r\n" + /** - * ESP8266 constructor - * - * @param tx TX pin - * @param rx RX pin - * @param br Baud Rate - */ - ESP8266(PinName tx, PinName rx, int br); + * Info about host to send data. + * Owner: Name of who owns the host + * Host: IP or address + * GETstring: String to fill in sensor ID and data + */ +typedef struct { + char* Owner; + char* Host; + char* GETstring; +} HostInfo; - /** - * ESP8266 destructor - */ - ~ESP8266(); +/** + * Info about WiFi networks + * Owner: Name of who owns the network + * SSID: Name of the network + * password: Password of the network + */ +typedef struct { + char* Owner; + char* SSID; + char* password; +} WifiInfo; + +typedef enum { STATION = 1, ACCESS_POINT, BOTH} WiFiMode; -void SendCMD(char * s); -void Reset(void); -bool RcvReply(char * r, int to); -void GetList(char * l); -void Join(char * id, char * pwd); -void GetIP(char * ip); -void SetMode(char mode); -void Quit(void); -void SetSingle(void); -void SetMultiple(void); -void GetConnStatus(char * st); -void StartServerMode(int port); -void CloseServerMode(void); -void setTransparent(void); -void startTCPConn(char * IP, int port); -void sendURL(char *URL, char *command); +class ESP8266 { + public: + /** + * ESP8266 constructor + * + * @param tx TX pin + * @param rx RX pin + * @param br Baud Rate + */ + ESP8266(PinName tx, PinName rx, int br); + + /** + * ESP8266 destructor + */ + ~ESP8266(); -private: -Serial comm; -void AddEOL(char * s); -void AddChar(char * s, char c); -void itoa(int c, char s[]); + void SendCMD(char *s); + void Reset(void); + bool RcvReply(char *r, int to); + bool GetList(char *l); + void Join(char *id, char *pwd); + bool GetIP(char *ip); + void SetMode(WiFiMode mode); + void Quit(void); + void SetSingle(void); + void SetMultiple(void); + bool GetConnStatus(char *st); + void StartServerMode(int port); + void CloseServerMode(void); + void setTransparent(void); + void startTCPConn(char *IP, int port); + void sendURL(char *URL, char *IP, char *command); + private: + Serial comm; + void AddEOL(char * s); + void AddChar(char * s, char c); }; -#endif +#endif //ESP8266_H /* COMMAND TABLE Basic: AT: Just to generate "OK" reply + Wifi: AT+RST: restart the module AT+CWMODE: define wifi mode; AT+CWMODE=<mode> 1= Sta, 2= AP, 3=both; Inquiry: AT+CWMODE? or AT+CWMODE=? @@ -58,6 +84,7 @@ AT+CWLAP: list the AP wifi AT+CWQAP: quit the AP wifi; Inquiry: AT+CWQAP=? * AT+CWSAP: set the parameters of AP; AT+CWSAP= <ssid>,<pwd>,<chl>,<ecn> - ssid, pwd, chl = channel, ecn = encryption; Inquiry: AT+CWJAP? + TCP/IP: AT+CIPSTATUS: get the connection status * AT+CIPSTART: set up TCP or UDP connection 1)single connection (+CIPMUX=0) AT+CIPSTART= <type>,<addr>,<port>; 2) multiple connection (+CIPMUX=1) AT+CIPSTART= <id><type>,<addr>, <port> - id = 0-4, type = TCP/UDP, addr = IP address, port= port; Inquiry: AT+CIPSTART=?