pengfei wu
/
ESP8266Program
For test
ESP8266.h
- Committer:
- shennongmin
- Date:
- 2015-02-04
- Revision:
- 32:91b3f3162c6a
- Parent:
- 31:ab3e7ca014c1
- Child:
- 34:65cd9c6eedb8
File content as of revision 32:91b3f3162c6a:
/** * @file ESP8266.h */ #ifndef __ESP8266_H__ #define __ESP8266_H__ #include "mbed.h" #include "time.h" #include "ArduinoSerial.h" typedef enum { ESP8266_ECN_OPEN = 0, ESP8266_ECN_WEP = 1, ESP8266_ECN_WAP_PSK = 2, ESP8266_ECN_WAP2_PSK = 3, ESP8266_ECN_WAP_WAP2_PSK = 4, } ESP8266Encrypstion; typedef enum { ESP8266_COMM_UDP = 0, ESP8266_COMM_TCP = 1, } ESP8266CommMode; typedef enum { ESP8266_MODE_STA = 1, ESP8266_MODE_SAP = 2, ESP8266_MODE_STA_SAP = 3, } ESP8266WorkMode; typedef enum { ESP8266_CHANNEL_1 = 1, ESP8266_CHANNEL_2, ESP8266_CHANNEL_3, ESP8266_CHANNEL_4, ESP8266_CHANNEL_5, ESP8266_CHANNEL_6, ESP8266_CHANNEL_7, ESP8266_CHANNEL_8, ESP8266_CHANNEL_9, ESP8266_CHANNEL_10, ESP8266_CHANNEL_11, ESP8266_CHANNEL_12, ESP8266_CHANNEL_13, } ESP8266Channel; /** * Provide methods to manipulate ESP8266 via WiFi. */ class ESP8266 { public: /** * Constructor. * * Need an serial port for communication between MCU and ESP8266. * * @param tx - the TX of serial port. * @param rx - the RX of serial port. * @param baud_rate - the baud rate of communication(default 9600). */ ESP8266(PinName tx, PinName rx, int baud_rate = 9600); /** * Set as station mode and join in ssid with pwd. * * @param ssid - SSID of AP to join in. * @param pwd - PASSWORD of AP to join in. * @return true if success, false for failure. */ bool setStationMode(String ssid, String pwd); /** * Set as softap mode and start softap. * * @param sap_ssid - SSID of its self softap. * @param sap_pwd - PASSWORD of its self softap. * @param chl - the channel can be 1, 2, 3, ..., 13. * @param enc - the method of encrypstion. * @return true if success, false for failure. */ bool setSoftAPMode(String sap_ssid, String sap_pwd, ESP8266Channel chl = ESP8266_CHANNEL_7, ESP8266Encrypstion ecn = ESP8266_ECN_WAP_WAP2_PSK); /** * Set as softap + station mode and start softap and join in ssid with pwd. * * @param ssid - SSID of AP to join in. * @param pwd - PASSWORD of AP to join in. * @param sap_ssid - SSID of its self softap. * @param sap_pwd - PASSWORD of its self softap. * @param chl - the channel can be 1, 2, 3, ..., 13. * @param enc - the method of encrypstion. * @return true if success, false for failure. */ bool setStationSoftAPMode(String ssid, String pwd, String sap_ssid, String sap_pwd , ESP8266Channel chl = ESP8266_CHANNEL_7, ESP8266Encrypstion ecn = ESP8266_ECN_WAP_WAP2_PSK); bool ipConfig(uint8_t type, String addr, int port, uint8_t mux = 0, uint8_t id = 0); //send data in sigle connection mode bool send(String str); //send data int multiple connection mode bool send(uint8_t id, String str); int recvData(char *buf); //reset the module bool reset(void); //set the working mode of module bool confMode(uint8_t mode); //set the name and password of wifi bool confJAP(String ssid , String pwd); //set the parametter of SSID, password, channel, encryption in AP mode. bool confSAP(String ssid , String pwd , uint8_t chl , uint8_t ecn); //inquire the current mode of wifi module String showMode(void); //show the list of wifi hotspot String showAP(void); //show the name of current wifi access port String showJAP(void); //quit the connection of current wifi bool quitAP(void); //show the parameter of ssid, password, channel, encryption in AP mode String showSAP(void); //inquire the connection status String showStatus(void); //show the current connection mode(sigle or multiple) String showMux(void); //set the connection mode(sigle:0 or multiple:1) bool confMux(int mux); //create new tcp or udp connection (sigle connection mode) bool newMux(uint8_t type, String addr, int port); //create new tcp or udp connection (multiple connection mode)(id:0-4) bool newMux(uint8_t id, uint8_t type, String addr, int port); //close tcp or udp (sigle connection mode) void closeMux(void); //close tcp or udp (multiple connection mode) void closeMux(uint8_t id); //show the current ip address String showIP(void); //set the parameter of server bool confServer(uint8_t mode, int port); // get m_mux_id int getMuxID(void); private: ArduinoSerial m_uart; int m_mux_id; }; #endif /* #ifndef __ESP8266_H__ */