pengfei wu
/
ESP8266Program
For test
ESP8266.h@30:46a560b71e61, 2015-02-04 (annotated)
- Committer:
- shennongmin
- Date:
- Wed Feb 04 15:03:52 2015 +0000
- Revision:
- 30:46a560b71e61
- Parent:
- 29:75185b05d6a4
- Child:
- 31:ab3e7ca014c1
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 | 29:75185b05d6a4 | 45 | public: |
shennongmin | 29:75185b05d6a4 | 46 | |
shennongmin | 29:75185b05d6a4 | 47 | /** |
shennongmin | 29:75185b05d6a4 | 48 | * Constructor. |
shennongmin | 29:75185b05d6a4 | 49 | * |
shennongmin | 29:75185b05d6a4 | 50 | * Need an serial port for communication between MCU and ESP8266. |
shennongmin | 29:75185b05d6a4 | 51 | * |
shennongmin | 29:75185b05d6a4 | 52 | * @param tx - the TX of serial port. |
shennongmin | 29:75185b05d6a4 | 53 | * @param rx - the RX of serial port. |
shennongmin | 29:75185b05d6a4 | 54 | * @param baud_rate - the baud rate of communication(default 9600). |
shennongmin | 29:75185b05d6a4 | 55 | */ |
shennongmin | 29:75185b05d6a4 | 56 | ESP8266(PinName tx, PinName rx, int baud_rate = 9600); |
shennongmin | 4:962bf18523f4 | 57 | |
shennongmin | 30:46a560b71e61 | 58 | bool setStationMode(String ssid, String pwd); |
shennongmin | 30:46a560b71e61 | 59 | bool setSoftAPMode(String ssid, String pwd, |
shennongmin | 30:46a560b71e61 | 60 | ESP8266Channel chl = ESP8266_CHANNEL_7, ESP8266Encrypstion ecn = ESP8266_ECN_WAP_WAP2_PSK); |
shennongmin | 30:46a560b71e61 | 61 | |
shennongmin | 30:46a560b71e61 | 62 | bool setStationSoftAPMode(String ssid, String pwd, String sap_ssid, String sap_pwd , |
shennongmin | 30:46a560b71e61 | 63 | ESP8266Channel chl = ESP8266_CHANNEL_7, ESP8266Encrypstion ecn = ESP8266_ECN_WAP_WAP2_PSK); |
shennongmin | 7:a11e381ce969 | 64 | |
shennongmin | 17:c449356787f1 | 65 | bool ipConfig(uint8_t type, String addr, int port, uint8_t mux = 0, uint8_t id = 0); |
shennongmin | 4:962bf18523f4 | 66 | |
shennongmin | 7:a11e381ce969 | 67 | //send data in sigle connection mode |
shennongmin | 23:4cec7b9e3715 | 68 | bool send(String str); |
shennongmin | 7:a11e381ce969 | 69 | |
shennongmin | 7:a11e381ce969 | 70 | //send data int multiple connection mode |
shennongmin | 23:4cec7b9e3715 | 71 | bool send(uint8_t id, String str); |
shennongmin | 4:962bf18523f4 | 72 | |
shennongmin | 23:4cec7b9e3715 | 73 | int recvData(char *buf); |
shennongmin | 4:962bf18523f4 | 74 | |
shennongmin | 7:a11e381ce969 | 75 | //reset the module |
shennongmin | 29:75185b05d6a4 | 76 | bool reset(void); |
shennongmin | 7:a11e381ce969 | 77 | |
shennongmin | 7:a11e381ce969 | 78 | //set the working mode of module |
shennongmin | 17:c449356787f1 | 79 | bool confMode(uint8_t mode); |
shennongmin | 7:a11e381ce969 | 80 | |
shennongmin | 7:a11e381ce969 | 81 | //set the name and password of wifi |
shennongmin | 7:a11e381ce969 | 82 | bool confJAP(String ssid , String pwd); |
shennongmin | 7:a11e381ce969 | 83 | |
shennongmin | 7:a11e381ce969 | 84 | //set the parametter of SSID, password, channel, encryption in AP mode. |
shennongmin | 10:9d4ec0359a5c | 85 | bool confSAP(String ssid , String pwd , uint8_t chl , uint8_t ecn); |
shennongmin | 4:962bf18523f4 | 86 | |
shennongmin | 7:a11e381ce969 | 87 | //inquire the current mode of wifi module |
shennongmin | 7:a11e381ce969 | 88 | String showMode(void); |
shennongmin | 7:a11e381ce969 | 89 | |
shennongmin | 7:a11e381ce969 | 90 | //show the list of wifi hotspot |
shennongmin | 7:a11e381ce969 | 91 | String showAP(void); |
shennongmin | 7:a11e381ce969 | 92 | |
shennongmin | 7:a11e381ce969 | 93 | //show the name of current wifi access port |
shennongmin | 7:a11e381ce969 | 94 | String showJAP(void); |
shennongmin | 7:a11e381ce969 | 95 | |
shennongmin | 7:a11e381ce969 | 96 | //quit the connection of current wifi |
shennongmin | 7:a11e381ce969 | 97 | bool quitAP(void); |
shennongmin | 7:a11e381ce969 | 98 | |
shennongmin | 7:a11e381ce969 | 99 | //show the parameter of ssid, password, channel, encryption in AP mode |
shennongmin | 7:a11e381ce969 | 100 | String showSAP(void); |
shennongmin | 4:962bf18523f4 | 101 | |
shennongmin | 7:a11e381ce969 | 102 | //inquire the connection status |
shennongmin | 7:a11e381ce969 | 103 | String showStatus(void); |
shennongmin | 7:a11e381ce969 | 104 | |
shennongmin | 7:a11e381ce969 | 105 | //show the current connection mode(sigle or multiple) |
shennongmin | 7:a11e381ce969 | 106 | String showMux(void); |
shennongmin | 7:a11e381ce969 | 107 | |
shennongmin | 7:a11e381ce969 | 108 | //set the connection mode(sigle:0 or multiple:1) |
shennongmin | 17:c449356787f1 | 109 | bool confMux(int mux); |
shennongmin | 7:a11e381ce969 | 110 | |
shennongmin | 7:a11e381ce969 | 111 | //create new tcp or udp connection (sigle connection mode) |
shennongmin | 10:9d4ec0359a5c | 112 | bool newMux(uint8_t type, String addr, int port); |
shennongmin | 4:962bf18523f4 | 113 | |
shennongmin | 7:a11e381ce969 | 114 | //create new tcp or udp connection (multiple connection mode)(id:0-4) |
shennongmin | 10:9d4ec0359a5c | 115 | bool newMux(uint8_t id, uint8_t type, String addr, int port); |
shennongmin | 7:a11e381ce969 | 116 | |
shennongmin | 7:a11e381ce969 | 117 | //close tcp or udp (sigle connection mode) |
shennongmin | 7:a11e381ce969 | 118 | void closeMux(void); |
shennongmin | 7:a11e381ce969 | 119 | |
shennongmin | 7:a11e381ce969 | 120 | //close tcp or udp (multiple connection mode) |
shennongmin | 10:9d4ec0359a5c | 121 | void closeMux(uint8_t id); |
shennongmin | 7:a11e381ce969 | 122 | |
shennongmin | 7:a11e381ce969 | 123 | //show the current ip address |
shennongmin | 7:a11e381ce969 | 124 | String showIP(void); |
shennongmin | 7:a11e381ce969 | 125 | |
shennongmin | 7:a11e381ce969 | 126 | //set the parameter of server |
shennongmin | 10:9d4ec0359a5c | 127 | bool confServer(uint8_t mode, int port); |
shennongmin | 4:962bf18523f4 | 128 | |
shennongmin | 29:75185b05d6a4 | 129 | // get m_mux_id |
shennongmin | 29:75185b05d6a4 | 130 | int getMuxID(void); |
shennongmin | 10:9d4ec0359a5c | 131 | |
shennongmin | 10:9d4ec0359a5c | 132 | private: |
shennongmin | 29:75185b05d6a4 | 133 | ArduinoSerial m_uart; |
shennongmin | 29:75185b05d6a4 | 134 | int m_mux_id; |
shennongmin | 4:962bf18523f4 | 135 | }; |
shennongmin | 9:95a0ce98e12b | 136 | |
shennongmin | 10:9d4ec0359a5c | 137 | #endif /* #ifndef __ESP8266_H__ */ |