pengfei wu
/
ESP8266Program
For test
ESP8266.h@23:4cec7b9e3715, 2015-02-04 (annotated)
- Committer:
- shennongmin
- Date:
- Wed Feb 04 10:06:39 2015 +0000
- Revision:
- 23:4cec7b9e3715
- Parent:
- 22:f5d148878815
- Child:
- 28:c25aff31dcc5
Class ESP8266 okay
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
shennongmin | 10:9d4ec0359a5c | 1 | #ifndef __ESP8266_H__ |
shennongmin | 10:9d4ec0359a5c | 2 | #define __ESP8266_H__ |
shennongmin | 4:962bf18523f4 | 3 | |
shennongmin | 7:a11e381ce969 | 4 | #include "mbed.h" |
shennongmin | 10:9d4ec0359a5c | 5 | #include "time.h" |
shennongmin | 10:9d4ec0359a5c | 6 | #include "ArduinoSerial.h" |
shennongmin | 7:a11e381ce969 | 7 | |
shennongmin | 4:962bf18523f4 | 8 | |
shennongmin | 22:f5d148878815 | 9 | typedef enum { |
shennongmin | 22:f5d148878815 | 10 | ESP8266_ECN_OPEN = 0, |
shennongmin | 22:f5d148878815 | 11 | ESP8266_ECN_WEP = 1, |
shennongmin | 22:f5d148878815 | 12 | ESP8266_ECN_WAP_PSK = 2, |
shennongmin | 22:f5d148878815 | 13 | ESP8266_ECN_WAP2_PSK = 3, |
shennongmin | 22:f5d148878815 | 14 | ESP8266_ECN_WAP_WAP2_PSK = 4, |
shennongmin | 22:f5d148878815 | 15 | } ESP8266Encrypstion; |
shennongmin | 4:962bf18523f4 | 16 | |
shennongmin | 22:f5d148878815 | 17 | typedef enum { |
shennongmin | 22:f5d148878815 | 18 | ESP8266_COMM_UDP = 0, |
shennongmin | 22:f5d148878815 | 19 | ESP8266_COMM_TCP = 1, |
shennongmin | 22:f5d148878815 | 20 | } ESP8266CommMode; |
shennongmin | 4:962bf18523f4 | 21 | |
shennongmin | 22:f5d148878815 | 22 | typedef enum { |
shennongmin | 22:f5d148878815 | 23 | ESP8266_MODE_STA = 1, |
shennongmin | 22:f5d148878815 | 24 | ESP8266_MODE_SAP = 2, |
shennongmin | 22:f5d148878815 | 25 | ESP8266_MODE_STA_SAP = 3, |
shennongmin | 22:f5d148878815 | 26 | } ESP8266WorkMode; |
shennongmin | 4:962bf18523f4 | 27 | |
shennongmin | 4:962bf18523f4 | 28 | |
shennongmin | 9:95a0ce98e12b | 29 | class ESP8266 |
shennongmin | 4:962bf18523f4 | 30 | { |
shennongmin | 4:962bf18523f4 | 31 | public: |
shennongmin | 10:9d4ec0359a5c | 32 | ESP8266(PinName tx, PinName rx); |
shennongmin | 10:9d4ec0359a5c | 33 | |
shennongmin | 18:37254b357abd | 34 | bool begin(void); |
shennongmin | 4:962bf18523f4 | 35 | |
shennongmin | 23:4cec7b9e3715 | 36 | //init port |
shennongmin | 23:4cec7b9e3715 | 37 | bool init(uint8_t mode, String ssid, String pwd, uint8_t chl = 7, uint8_t ecn = ESP8266_ECN_WAP_WAP2_PSK); |
shennongmin | 7:a11e381ce969 | 38 | |
shennongmin | 17:c449356787f1 | 39 | bool ipConfig(uint8_t type, String addr, int port, uint8_t mux = 0, uint8_t id = 0); |
shennongmin | 4:962bf18523f4 | 40 | |
shennongmin | 7:a11e381ce969 | 41 | //send data in sigle connection mode |
shennongmin | 23:4cec7b9e3715 | 42 | bool send(String str); |
shennongmin | 7:a11e381ce969 | 43 | |
shennongmin | 7:a11e381ce969 | 44 | //send data int multiple connection mode |
shennongmin | 23:4cec7b9e3715 | 45 | bool send(uint8_t id, String str); |
shennongmin | 4:962bf18523f4 | 46 | |
shennongmin | 23:4cec7b9e3715 | 47 | int recvData(char *buf); |
shennongmin | 4:962bf18523f4 | 48 | |
shennongmin | 7:a11e381ce969 | 49 | //reset the module |
shennongmin | 23:4cec7b9e3715 | 50 | void reset(void); |
shennongmin | 7:a11e381ce969 | 51 | |
shennongmin | 7:a11e381ce969 | 52 | //set the working mode of module |
shennongmin | 17:c449356787f1 | 53 | bool confMode(uint8_t mode); |
shennongmin | 7:a11e381ce969 | 54 | |
shennongmin | 7:a11e381ce969 | 55 | //set the name and password of wifi |
shennongmin | 7:a11e381ce969 | 56 | bool confJAP(String ssid , String pwd); |
shennongmin | 7:a11e381ce969 | 57 | |
shennongmin | 7:a11e381ce969 | 58 | //set the parametter of SSID, password, channel, encryption in AP mode. |
shennongmin | 10:9d4ec0359a5c | 59 | bool confSAP(String ssid , String pwd , uint8_t chl , uint8_t ecn); |
shennongmin | 4:962bf18523f4 | 60 | |
shennongmin | 7:a11e381ce969 | 61 | //inquire the current mode of wifi module |
shennongmin | 7:a11e381ce969 | 62 | String showMode(void); |
shennongmin | 7:a11e381ce969 | 63 | |
shennongmin | 7:a11e381ce969 | 64 | //show the list of wifi hotspot |
shennongmin | 7:a11e381ce969 | 65 | String showAP(void); |
shennongmin | 7:a11e381ce969 | 66 | |
shennongmin | 7:a11e381ce969 | 67 | //show the name of current wifi access port |
shennongmin | 7:a11e381ce969 | 68 | String showJAP(void); |
shennongmin | 7:a11e381ce969 | 69 | |
shennongmin | 7:a11e381ce969 | 70 | //quit the connection of current wifi |
shennongmin | 7:a11e381ce969 | 71 | bool quitAP(void); |
shennongmin | 7:a11e381ce969 | 72 | |
shennongmin | 7:a11e381ce969 | 73 | //show the parameter of ssid, password, channel, encryption in AP mode |
shennongmin | 7:a11e381ce969 | 74 | String showSAP(void); |
shennongmin | 4:962bf18523f4 | 75 | |
shennongmin | 7:a11e381ce969 | 76 | //inquire the connection status |
shennongmin | 7:a11e381ce969 | 77 | String showStatus(void); |
shennongmin | 7:a11e381ce969 | 78 | |
shennongmin | 7:a11e381ce969 | 79 | //show the current connection mode(sigle or multiple) |
shennongmin | 7:a11e381ce969 | 80 | String showMux(void); |
shennongmin | 7:a11e381ce969 | 81 | |
shennongmin | 7:a11e381ce969 | 82 | //set the connection mode(sigle:0 or multiple:1) |
shennongmin | 17:c449356787f1 | 83 | bool confMux(int mux); |
shennongmin | 7:a11e381ce969 | 84 | |
shennongmin | 7:a11e381ce969 | 85 | //create new tcp or udp connection (sigle connection mode) |
shennongmin | 10:9d4ec0359a5c | 86 | bool newMux(uint8_t type, String addr, int port); |
shennongmin | 4:962bf18523f4 | 87 | |
shennongmin | 7:a11e381ce969 | 88 | //create new tcp or udp connection (multiple connection mode)(id:0-4) |
shennongmin | 10:9d4ec0359a5c | 89 | bool newMux(uint8_t id, uint8_t type, String addr, int port); |
shennongmin | 7:a11e381ce969 | 90 | |
shennongmin | 7:a11e381ce969 | 91 | //close tcp or udp (sigle connection mode) |
shennongmin | 7:a11e381ce969 | 92 | void closeMux(void); |
shennongmin | 7:a11e381ce969 | 93 | |
shennongmin | 7:a11e381ce969 | 94 | //close tcp or udp (multiple connection mode) |
shennongmin | 10:9d4ec0359a5c | 95 | void closeMux(uint8_t id); |
shennongmin | 7:a11e381ce969 | 96 | |
shennongmin | 7:a11e381ce969 | 97 | //show the current ip address |
shennongmin | 7:a11e381ce969 | 98 | String showIP(void); |
shennongmin | 7:a11e381ce969 | 99 | |
shennongmin | 7:a11e381ce969 | 100 | //set the parameter of server |
shennongmin | 10:9d4ec0359a5c | 101 | bool confServer(uint8_t mode, int port); |
shennongmin | 4:962bf18523f4 | 102 | |
shennongmin | 23:4cec7b9e3715 | 103 | // get m_chl_id |
shennongmin | 23:4cec7b9e3715 | 104 | int getChannelID(void); |
shennongmin | 10:9d4ec0359a5c | 105 | |
shennongmin | 10:9d4ec0359a5c | 106 | private: |
shennongmin | 23:4cec7b9e3715 | 107 | ArduinoSerial m_esp_uart; |
shennongmin | 23:4cec7b9e3715 | 108 | int m_chl_id; |
shennongmin | 4:962bf18523f4 | 109 | }; |
shennongmin | 9:95a0ce98e12b | 110 | |
shennongmin | 10:9d4ec0359a5c | 111 | #endif /* #ifndef __ESP8266_H__ */ |