Libreria basica para el manejo del ESP01
Dependents: Gateway_Cotosys Gateway_Cotosys_os5
ESP01.h@9:21290fc75c17, 2020-01-06 (annotated)
- Committer:
- Thrillex13
- Date:
- Mon Jan 06 04:39:26 2020 +0000
- Revision:
- 9:21290fc75c17
- Parent:
- 7:8c6f56470ba7
Se arreglo la funcion ReceiveSingleReply para evitar que se quede atascado en un loop.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Thrillex13 | 6:54b89962c798 | 1 | #ifndef ESP01_H |
Thrillex13 | 6:54b89962c798 | 2 | #define ESP01_H |
Thrillex13 | 6:54b89962c798 | 3 | |
Thrillex13 | 6:54b89962c798 | 4 | #include <string> |
Thrillex13 | 6:54b89962c798 | 5 | #include "mbed.h" |
Thrillex13 | 6:54b89962c798 | 6 | |
Thrillex13 | 6:54b89962c798 | 7 | #define CMD_END "\r\n" |
Thrillex13 | 6:54b89962c798 | 8 | |
Thrillex13 | 6:54b89962c798 | 9 | /** |
Thrillex13 | 6:54b89962c798 | 10 | * Info about host to send data. |
Thrillex13 | 6:54b89962c798 | 11 | * Owner: Name of who owns the host |
Thrillex13 | 6:54b89962c798 | 12 | * Host: IP or address |
Thrillex13 | 6:54b89962c798 | 13 | * GETstring: String to fill in sensor ID and data |
Thrillex13 | 6:54b89962c798 | 14 | */ |
Thrillex13 | 6:54b89962c798 | 15 | typedef struct { |
Thrillex13 | 6:54b89962c798 | 16 | char* Owner; |
Thrillex13 | 6:54b89962c798 | 17 | char* Host; |
Thrillex13 | 6:54b89962c798 | 18 | char* GETstring; |
Thrillex13 | 6:54b89962c798 | 19 | } HostInfo; |
Thrillex13 | 6:54b89962c798 | 20 | |
Thrillex13 | 6:54b89962c798 | 21 | /** |
Thrillex13 | 6:54b89962c798 | 22 | * Info about WiFi networks |
Thrillex13 | 6:54b89962c798 | 23 | * Owner: Name of who owns the network |
Thrillex13 | 6:54b89962c798 | 24 | * SSID: Name of the network |
Thrillex13 | 6:54b89962c798 | 25 | * password: Password of the network |
Thrillex13 | 6:54b89962c798 | 26 | */ |
Thrillex13 | 6:54b89962c798 | 27 | typedef struct { |
Thrillex13 | 6:54b89962c798 | 28 | char* Owner; |
Thrillex13 | 6:54b89962c798 | 29 | char* SSID; |
Thrillex13 | 6:54b89962c798 | 30 | char* password; |
Thrillex13 | 6:54b89962c798 | 31 | } WifiInfo; |
Thrillex13 | 6:54b89962c798 | 32 | |
Thrillex13 | 6:54b89962c798 | 33 | typedef enum { STATION = 1, ACCESS_POINT, BOTH} WiFiMode; |
Thrillex13 | 6:54b89962c798 | 34 | |
Thrillex13 | 6:54b89962c798 | 35 | class ESP01 { |
Thrillex13 | 6:54b89962c798 | 36 | public: |
Thrillex13 | 6:54b89962c798 | 37 | /** |
Thrillex13 | 6:54b89962c798 | 38 | * ESP01 constructor |
Thrillex13 | 6:54b89962c798 | 39 | * |
Thrillex13 | 6:54b89962c798 | 40 | * @param tx TX pin |
Thrillex13 | 6:54b89962c798 | 41 | * @param rx RX pin |
Thrillex13 | 6:54b89962c798 | 42 | * @param br Baud Rate |
Thrillex13 | 6:54b89962c798 | 43 | */ |
Thrillex13 | 6:54b89962c798 | 44 | ESP01(PinName tx, PinName rx, int br); |
Thrillex13 | 6:54b89962c798 | 45 | |
Thrillex13 | 6:54b89962c798 | 46 | /** |
Thrillex13 | 6:54b89962c798 | 47 | * ESP01 destructor |
Thrillex13 | 6:54b89962c798 | 48 | */ |
Thrillex13 | 6:54b89962c798 | 49 | ~ESP01(); |
Thrillex13 | 6:54b89962c798 | 50 | |
Thrillex13 | 6:54b89962c798 | 51 | void SendCMD(char *s); |
Thrillex13 | 6:54b89962c798 | 52 | void Reset(void); |
Thrillex13 | 6:54b89962c798 | 53 | bool RcvReply(char *r, int to); |
Thrillex13 | 6:54b89962c798 | 54 | bool GetList(char *l); |
Thrillex13 | 6:54b89962c798 | 55 | void Join(char *id, char *pwd); |
Thrillex13 | 6:54b89962c798 | 56 | bool GetIP(char *ip); |
Thrillex13 | 6:54b89962c798 | 57 | void SetMode(WiFiMode mode); |
Thrillex13 | 6:54b89962c798 | 58 | void Quit(void); |
Thrillex13 | 6:54b89962c798 | 59 | void SetSingle(void); |
Thrillex13 | 6:54b89962c798 | 60 | void SetMultiple(void); |
Thrillex13 | 6:54b89962c798 | 61 | bool GetConnStatus(char *st); |
Thrillex13 | 6:54b89962c798 | 62 | void StartServerMode(int port); |
Thrillex13 | 6:54b89962c798 | 63 | void CloseServerMode(void); |
Thrillex13 | 6:54b89962c798 | 64 | void setTransparent(void); |
Thrillex13 | 6:54b89962c798 | 65 | void startTCPConn(char *IP, int port); |
Thrillex13 | 6:54b89962c798 | 66 | void sendURL(char *URL, char *IP, char *command); |
Thrillex13 | 6:54b89962c798 | 67 | void deepsleep(size_t ms); |
Thrillex13 | 6:54b89962c798 | 68 | |
Thrillex13 | 6:54b89962c798 | 69 | //Funciones que yo he agregado |
Thrillex13 | 6:54b89962c798 | 70 | void StartSmartConfig(void); |
Thrillex13 | 6:54b89962c798 | 71 | void DisableEcho(void); |
Thrillex13 | 6:54b89962c798 | 72 | void EnableDHCP(void); |
Thrillex13 | 6:54b89962c798 | 73 | void RcvSingleReply(char * r); |
Thrillex13 | 6:54b89962c798 | 74 | void GetConnStatusCode(char * st); |
Thrillex13 | 7:8c6f56470ba7 | 75 | void SetMaxTCPConn(int maxconn); |
Thrillex13 | 7:8c6f56470ba7 | 76 | bool TCPDataAvailable(char *data); |
Thrillex13 | 7:8c6f56470ba7 | 77 | void SendTCPData(int socket,int len, char *data); |
Thrillex13 | 6:54b89962c798 | 78 | |
Thrillex13 | 6:54b89962c798 | 79 | private: |
Thrillex13 | 6:54b89962c798 | 80 | Serial comm; |
Thrillex13 | 6:54b89962c798 | 81 | void AddEOL(char * s); |
Thrillex13 | 6:54b89962c798 | 82 | void AddChar(char * s, char c); |
Thrillex13 | 6:54b89962c798 | 83 | }; |
Thrillex13 | 6:54b89962c798 | 84 | |
Thrillex13 | 6:54b89962c798 | 85 | #endif //ESP01_H |
Thrillex13 | 6:54b89962c798 | 86 | /* |
Thrillex13 | 6:54b89962c798 | 87 | COMMAND TABLE |
Thrillex13 | 6:54b89962c798 | 88 | Basic: |
Thrillex13 | 6:54b89962c798 | 89 | AT: Just to generate "OK" reply |
Thrillex13 | 6:54b89962c798 | 90 | |
Thrillex13 | 6:54b89962c798 | 91 | Wifi: |
Thrillex13 | 6:54b89962c798 | 92 | AT+RST: restart the module |
Thrillex13 | 6:54b89962c798 | 93 | AT+CWMODE: define wifi mode; AT+CWMODE=<mode> 1= Sta, 2= AP, 3=both; Inquiry: AT+CWMODE? or AT+CWMODE=? |
Thrillex13 | 6:54b89962c798 | 94 | AT+CWJAP: join the AP wifi; AT+ CWJAP =<ssid>,< pwd > - ssid = ssid, pwd = wifi password, both between quotes; Inquiry: AT+ CWJAP? |
Thrillex13 | 6:54b89962c798 | 95 | AT+CWLAP: list the AP wifi |
Thrillex13 | 6:54b89962c798 | 96 | AT+CWQAP: quit the AP wifi; Inquiry: AT+CWQAP=? |
Thrillex13 | 6:54b89962c798 | 97 | * AT+CWSAP: set the parameters of AP; AT+CWSAP= <ssid>,<pwd>,<chl>,<ecn> - ssid, pwd, chl = channel, ecn = encryption; Inquiry: AT+CWJAP? |
Thrillex13 | 6:54b89962c798 | 98 | |
Thrillex13 | 6:54b89962c798 | 99 | TCP/IP: |
Thrillex13 | 6:54b89962c798 | 100 | AT+CIPSTATUS: get the connection status |
Thrillex13 | 6:54b89962c798 | 101 | * 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=? |
Thrillex13 | 6:54b89962c798 | 102 | * AT+CIPSEND: send data; 1)single connection(+CIPMUX=0) AT+CIPSEND=<length>; 2) multiple connection (+CIPMUX=1) AT+CIPSEND= <id>,<length>; Inquiry: AT+CIPSEND=? |
Thrillex13 | 6:54b89962c798 | 103 | * AT+CIPCLOSE: close TCP or UDP connection; AT+CIPCLOSE=<id> or AT+CIPCLOSE; Inquiry: AT+CIPCLOSE=? |
Thrillex13 | 6:54b89962c798 | 104 | AT+CIFSR: Get IP address; Inquiry: AT+ CIFSR=? |
Thrillex13 | 6:54b89962c798 | 105 | AT+CIPMUX: set mutiple connection; AT+ CIPMUX=<mode> - 0 for single connection 1 for mutiple connection; Inquiry: AT+CIPMUX? |
Thrillex13 | 6:54b89962c798 | 106 | AT+CIPSERVER: set as server; AT+ CIPSERVER= <mode>[,<port> ] - mode 0 to close server mode, mode 1 to open; port = port; Inquiry: AT+CIFSR=? |
Thrillex13 | 6:54b89962c798 | 107 | * +IPD: received data |
Thrillex13 | 6:54b89962c798 | 108 | */ |