Connect Wi-Fi

Dependencies:   mbed

Committer:
chanagan2540
Date:
Sun Dec 10 08:08:41 2017 +0000
Revision:
3:e1042768703b
Parent:
2:6738db3eb2ed
????;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
chanagan2540 1:c0fbff97b740 1 #ifndef ESP8266_H
chanagan2540 1:c0fbff97b740 2 #define ESP8266_H
chanagan2540 1:c0fbff97b740 3
chanagan2540 1:c0fbff97b740 4 #include <string>
chanagan2540 1:c0fbff97b740 5 #include "mbed.h"
chanagan2540 1:c0fbff97b740 6
chanagan2540 1:c0fbff97b740 7 class ESP8266
chanagan2540 1:c0fbff97b740 8 {
chanagan2540 1:c0fbff97b740 9 public:
chanagan2540 1:c0fbff97b740 10 /**
chanagan2540 1:c0fbff97b740 11 * ESP8266 constructor
chanagan2540 1:c0fbff97b740 12 *
chanagan2540 1:c0fbff97b740 13 * @param tx TX pin
chanagan2540 1:c0fbff97b740 14 * @param rx RX pin
chanagan2540 1:c0fbff97b740 15 * @param br Baud Rate
chanagan2540 1:c0fbff97b740 16 */
chanagan2540 1:c0fbff97b740 17 ESP8266(PinName tx, PinName rx, int br);
chanagan2540 1:c0fbff97b740 18
chanagan2540 1:c0fbff97b740 19 /**
chanagan2540 1:c0fbff97b740 20 * ESP8266 destructor
chanagan2540 1:c0fbff97b740 21 */
chanagan2540 1:c0fbff97b740 22 ~ESP8266();
chanagan2540 1:c0fbff97b740 23
chanagan2540 3:e1042768703b 24 void check(void);
chanagan2540 3:e1042768703b 25 void look(void);
chanagan2540 3:e1042768703b 26 void SetWiFi(char * name, char * ad);
chanagan2540 1:c0fbff97b740 27 void SendCMD(char * s);
chanagan2540 1:c0fbff97b740 28 void Reset(void);
chanagan2540 1:c0fbff97b740 29 void RcvReply(char * r, int to);
chanagan2540 1:c0fbff97b740 30 void GetList(char * l);
chanagan2540 1:c0fbff97b740 31 void Join(char * id, char * pwd);
chanagan2540 1:c0fbff97b740 32 void GetIP(char * ip);
chanagan2540 1:c0fbff97b740 33 void SetMode(char mode);
chanagan2540 1:c0fbff97b740 34 void Quit(void);
chanagan2540 1:c0fbff97b740 35 void SetSingle(void);
chanagan2540 1:c0fbff97b740 36 void SetMultiple(void);
chanagan2540 1:c0fbff97b740 37 void GetConnStatus(char * st);
chanagan2540 1:c0fbff97b740 38 void StartServerMode(int port);
chanagan2540 1:c0fbff97b740 39 void CloseServerMode(void);
chanagan2540 1:c0fbff97b740 40
chanagan2540 1:c0fbff97b740 41 private:
chanagan2540 1:c0fbff97b740 42 Serial comm;
chanagan2540 1:c0fbff97b740 43 void AddEOL(char * s);
chanagan2540 1:c0fbff97b740 44 void AddChar(char * s, char c);
chanagan2540 1:c0fbff97b740 45 void itoa(int c, char s[]);
chanagan2540 1:c0fbff97b740 46
chanagan2540 1:c0fbff97b740 47 };
chanagan2540 1:c0fbff97b740 48
chanagan2540 1:c0fbff97b740 49 #endif
chanagan2540 1:c0fbff97b740 50 /*
chanagan2540 1:c0fbff97b740 51 COMMAND TABLE
chanagan2540 1:c0fbff97b740 52 Basic:
chanagan2540 1:c0fbff97b740 53 AT: Just to generate "OK" reply
chanagan2540 1:c0fbff97b740 54 Wifi:
chanagan2540 1:c0fbff97b740 55 AT+RST: restart the module
chanagan2540 1:c0fbff97b740 56 AT+CWMODE: define wifi mode; AT+CWMODE=<mode> 1= Sta, 2= AP, 3=both; Inquiry: AT+CWMODE? or AT+CWMODE=?
chanagan2540 1:c0fbff97b740 57 AT+CWJAP: join the AP wifi; AT+ CWJAP =<ssid>,< pwd > - ssid = ssid, pwd = wifi password, both between quotes; Inquiry: AT+ CWJAP?
chanagan2540 1:c0fbff97b740 58 AT+CWLAP: list the AP wifi
chanagan2540 1:c0fbff97b740 59 AT+CWQAP: quit the AP wifi; Inquiry: AT+CWQAP=?
chanagan2540 1:c0fbff97b740 60 * AT+CWSAP: set the parameters of AP; AT+CWSAP= <ssid>,<pwd>,<chl>,<ecn> - ssid, pwd, chl = channel, ecn = encryption; Inquiry: AT+CWJAP?
chanagan2540 1:c0fbff97b740 61 TCP/IP:
chanagan2540 1:c0fbff97b740 62 AT+CIPSTATUS: get the connection status
chanagan2540 1:c0fbff97b740 63 * 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=?
chanagan2540 1:c0fbff97b740 64 * AT+CIPSEND: send data; 1)single connection(+CIPMUX=0) AT+CIPSEND=<length>; 2) multiple connection (+CIPMUX=1) AT+CIPSEND= <id>,<length>; Inquiry: AT+CIPSEND=?
chanagan2540 1:c0fbff97b740 65 * AT+CIPCLOSE: close TCP or UDP connection; AT+CIPCLOSE=<id> or AT+CIPCLOSE; Inquiry: AT+CIPCLOSE=?
chanagan2540 1:c0fbff97b740 66 AT+CIFSR: Get IP address; Inquiry: AT+ CIFSR=?
chanagan2540 1:c0fbff97b740 67 AT+CIPMUX: set mutiple connection; AT+ CIPMUX=<mode> - 0 for single connection 1 for mutiple connection; Inquiry: AT+CIPMUX?
chanagan2540 1:c0fbff97b740 68 AT+CIPSERVER: set as server; AT+ CIPSERVER= <mode>[,<port> ] - mode 0 to close server mode, mode 1 to open; port = port; Inquiry: AT+CIFSR=?
chanagan2540 1:c0fbff97b740 69 * +IPD: received data
chanagan2540 1:c0fbff97b740 70 */