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