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