ESP8266 library to get and send data.
Fork of ESP8266 by
ESP8266.h@5:5cc7894bb8cb, 2016-10-21 (annotated)
- Committer:
- Wosser1sProductions
- Date:
- Fri Oct 21 21:24:11 2016 +0000
- Revision:
- 5:5cc7894bb8cb
- Parent:
- 4:c05f7a1b4e47
Added deepsleep command (cannot wake up by pulling CH_PD down and then back up)
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
quevedo | 0:e58f27687450 | 1 | #ifndef ESP8266_H |
quevedo | 0:e58f27687450 | 2 | #define ESP8266_H |
quevedo | 0:e58f27687450 | 3 | |
quevedo | 0:e58f27687450 | 4 | #include <string> |
quevedo | 0:e58f27687450 | 5 | #include "mbed.h" |
quevedo | 0:e58f27687450 | 6 | |
Wosser1sProductions | 4:c05f7a1b4e47 | 7 | #define CMD_END "\r\n" |
Wosser1sProductions | 4:c05f7a1b4e47 | 8 | |
quevedo | 0:e58f27687450 | 9 | /** |
Wosser1sProductions | 4:c05f7a1b4e47 | 10 | * Info about host to send data. |
Wosser1sProductions | 4:c05f7a1b4e47 | 11 | * Owner: Name of who owns the host |
Wosser1sProductions | 4:c05f7a1b4e47 | 12 | * Host: IP or address |
Wosser1sProductions | 4:c05f7a1b4e47 | 13 | * GETstring: String to fill in sensor ID and data |
Wosser1sProductions | 4:c05f7a1b4e47 | 14 | */ |
Wosser1sProductions | 4:c05f7a1b4e47 | 15 | typedef struct { |
Wosser1sProductions | 4:c05f7a1b4e47 | 16 | char* Owner; |
Wosser1sProductions | 4:c05f7a1b4e47 | 17 | char* Host; |
Wosser1sProductions | 4:c05f7a1b4e47 | 18 | char* GETstring; |
Wosser1sProductions | 4:c05f7a1b4e47 | 19 | } HostInfo; |
quevedo | 0:e58f27687450 | 20 | |
Wosser1sProductions | 4:c05f7a1b4e47 | 21 | /** |
Wosser1sProductions | 4:c05f7a1b4e47 | 22 | * Info about WiFi networks |
Wosser1sProductions | 4:c05f7a1b4e47 | 23 | * Owner: Name of who owns the network |
Wosser1sProductions | 4:c05f7a1b4e47 | 24 | * SSID: Name of the network |
Wosser1sProductions | 4:c05f7a1b4e47 | 25 | * password: Password of the network |
Wosser1sProductions | 4:c05f7a1b4e47 | 26 | */ |
Wosser1sProductions | 4:c05f7a1b4e47 | 27 | typedef struct { |
Wosser1sProductions | 4:c05f7a1b4e47 | 28 | char* Owner; |
Wosser1sProductions | 4:c05f7a1b4e47 | 29 | char* SSID; |
Wosser1sProductions | 4:c05f7a1b4e47 | 30 | char* password; |
Wosser1sProductions | 4:c05f7a1b4e47 | 31 | } WifiInfo; |
Wosser1sProductions | 4:c05f7a1b4e47 | 32 | |
Wosser1sProductions | 4:c05f7a1b4e47 | 33 | typedef enum { STATION = 1, ACCESS_POINT, BOTH} WiFiMode; |
quevedo | 0:e58f27687450 | 34 | |
Wosser1sProductions | 4:c05f7a1b4e47 | 35 | class ESP8266 { |
Wosser1sProductions | 4:c05f7a1b4e47 | 36 | public: |
Wosser1sProductions | 4:c05f7a1b4e47 | 37 | /** |
Wosser1sProductions | 4:c05f7a1b4e47 | 38 | * ESP8266 constructor |
Wosser1sProductions | 4:c05f7a1b4e47 | 39 | * |
Wosser1sProductions | 4:c05f7a1b4e47 | 40 | * @param tx TX pin |
Wosser1sProductions | 4:c05f7a1b4e47 | 41 | * @param rx RX pin |
Wosser1sProductions | 4:c05f7a1b4e47 | 42 | * @param br Baud Rate |
Wosser1sProductions | 4:c05f7a1b4e47 | 43 | */ |
Wosser1sProductions | 4:c05f7a1b4e47 | 44 | ESP8266(PinName tx, PinName rx, int br); |
Wosser1sProductions | 4:c05f7a1b4e47 | 45 | |
Wosser1sProductions | 4:c05f7a1b4e47 | 46 | /** |
Wosser1sProductions | 4:c05f7a1b4e47 | 47 | * ESP8266 destructor |
Wosser1sProductions | 4:c05f7a1b4e47 | 48 | */ |
Wosser1sProductions | 4:c05f7a1b4e47 | 49 | ~ESP8266(); |
quevedo | 0:e58f27687450 | 50 | |
Wosser1sProductions | 4:c05f7a1b4e47 | 51 | void SendCMD(char *s); |
Wosser1sProductions | 4:c05f7a1b4e47 | 52 | void Reset(void); |
Wosser1sProductions | 4:c05f7a1b4e47 | 53 | bool RcvReply(char *r, int to); |
Wosser1sProductions | 4:c05f7a1b4e47 | 54 | bool GetList(char *l); |
Wosser1sProductions | 4:c05f7a1b4e47 | 55 | void Join(char *id, char *pwd); |
Wosser1sProductions | 4:c05f7a1b4e47 | 56 | bool GetIP(char *ip); |
Wosser1sProductions | 4:c05f7a1b4e47 | 57 | void SetMode(WiFiMode mode); |
Wosser1sProductions | 4:c05f7a1b4e47 | 58 | void Quit(void); |
Wosser1sProductions | 4:c05f7a1b4e47 | 59 | void SetSingle(void); |
Wosser1sProductions | 4:c05f7a1b4e47 | 60 | void SetMultiple(void); |
Wosser1sProductions | 4:c05f7a1b4e47 | 61 | bool GetConnStatus(char *st); |
Wosser1sProductions | 4:c05f7a1b4e47 | 62 | void StartServerMode(int port); |
Wosser1sProductions | 4:c05f7a1b4e47 | 63 | void CloseServerMode(void); |
Wosser1sProductions | 4:c05f7a1b4e47 | 64 | void setTransparent(void); |
Wosser1sProductions | 4:c05f7a1b4e47 | 65 | void startTCPConn(char *IP, int port); |
Wosser1sProductions | 4:c05f7a1b4e47 | 66 | void sendURL(char *URL, char *IP, char *command); |
Wosser1sProductions | 5:5cc7894bb8cb | 67 | |
Wosser1sProductions | 5:5cc7894bb8cb | 68 | void deepsleep(size_t ms); |
quevedo | 0:e58f27687450 | 69 | |
Wosser1sProductions | 4:c05f7a1b4e47 | 70 | private: |
Wosser1sProductions | 4:c05f7a1b4e47 | 71 | Serial comm; |
Wosser1sProductions | 4:c05f7a1b4e47 | 72 | void AddEOL(char * s); |
Wosser1sProductions | 4:c05f7a1b4e47 | 73 | void AddChar(char * s, char c); |
quevedo | 0:e58f27687450 | 74 | }; |
quevedo | 0:e58f27687450 | 75 | |
Wosser1sProductions | 4:c05f7a1b4e47 | 76 | #endif //ESP8266_H |
quevedo | 0:e58f27687450 | 77 | /* |
quevedo | 0:e58f27687450 | 78 | COMMAND TABLE |
quevedo | 0:e58f27687450 | 79 | Basic: |
quevedo | 0:e58f27687450 | 80 | AT: Just to generate "OK" reply |
Wosser1sProductions | 4:c05f7a1b4e47 | 81 | |
quevedo | 0:e58f27687450 | 82 | Wifi: |
quevedo | 0:e58f27687450 | 83 | AT+RST: restart the module |
quevedo | 0:e58f27687450 | 84 | AT+CWMODE: define wifi mode; AT+CWMODE=<mode> 1= Sta, 2= AP, 3=both; Inquiry: AT+CWMODE? or AT+CWMODE=? |
quevedo | 0:e58f27687450 | 85 | AT+CWJAP: join the AP wifi; AT+ CWJAP =<ssid>,< pwd > - ssid = ssid, pwd = wifi password, both between quotes; Inquiry: AT+ CWJAP? |
quevedo | 0:e58f27687450 | 86 | AT+CWLAP: list the AP wifi |
quevedo | 0:e58f27687450 | 87 | AT+CWQAP: quit the AP wifi; Inquiry: AT+CWQAP=? |
quevedo | 1:399414d48048 | 88 | * AT+CWSAP: set the parameters of AP; AT+CWSAP= <ssid>,<pwd>,<chl>,<ecn> - ssid, pwd, chl = channel, ecn = encryption; Inquiry: AT+CWJAP? |
Wosser1sProductions | 4:c05f7a1b4e47 | 89 | |
quevedo | 0:e58f27687450 | 90 | TCP/IP: |
quevedo | 2:77388e8f0697 | 91 | AT+CIPSTATUS: get the connection status |
quevedo | 1:399414d48048 | 92 | * 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=? |
quevedo | 1:399414d48048 | 93 | * AT+CIPSEND: send data; 1)single connection(+CIPMUX=0) AT+CIPSEND=<length>; 2) multiple connection (+CIPMUX=1) AT+CIPSEND= <id>,<length>; Inquiry: AT+CIPSEND=? |
quevedo | 1:399414d48048 | 94 | * AT+CIPCLOSE: close TCP or UDP connection; AT+CIPCLOSE=<id> or AT+CIPCLOSE; Inquiry: AT+CIPCLOSE=? |
quevedo | 0:e58f27687450 | 95 | AT+CIFSR: Get IP address; Inquiry: AT+ CIFSR=? |
quevedo | 0:e58f27687450 | 96 | AT+CIPMUX: set mutiple connection; AT+ CIPMUX=<mode> - 0 for single connection 1 for mutiple connection; Inquiry: AT+CIPMUX? |
quevedo | 2:77388e8f0697 | 97 | AT+CIPSERVER: set as server; AT+ CIPSERVER= <mode>[,<port> ] - mode 0 to close server mode, mode 1 to open; port = port; Inquiry: AT+CIFSR=? |
quevedo | 1:399414d48048 | 98 | * +IPD: received data |
quevedo | 0:e58f27687450 | 99 | */ |