For test

Dependencies:   mbed

Committer:
shennongmin
Date:
Wed Feb 04 15:32:20 2015 +0000
Revision:
31:ab3e7ca014c1
Parent:
30:46a560b71e61
Child:
32:91b3f3162c6a
compile okay

Who changed what in which revision?

UserRevisionLine numberNew 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 31:ab3e7ca014c1 58 /**
shennongmin 31:ab3e7ca014c1 59 * Set as station mode and join in ssid with pwd.
shennongmin 31:ab3e7ca014c1 60 *
shennongmin 31:ab3e7ca014c1 61 * @param ssid - SSID of AP to join in.
shennongmin 31:ab3e7ca014c1 62 * @param pwd - PASSWORD of AP to join in.
shennongmin 31:ab3e7ca014c1 63 * @return true if success, false for failure.
shennongmin 31:ab3e7ca014c1 64 */
shennongmin 30:46a560b71e61 65 bool setStationMode(String ssid, String pwd);
shennongmin 31:ab3e7ca014c1 66
shennongmin 31:ab3e7ca014c1 67 /**
shennongmin 31:ab3e7ca014c1 68 * Set as softap mode and start softap.
shennongmin 31:ab3e7ca014c1 69 *
shennongmin 31:ab3e7ca014c1 70 * @param sap_ssid - SSID of its self softap.
shennongmin 31:ab3e7ca014c1 71 * @param sap_pwd - PASSWORD of its self softap.
shennongmin 31:ab3e7ca014c1 72 * @param chl - the channel can be 1, 2, 3, ..., 13.
shennongmin 31:ab3e7ca014c1 73 * @param enc - the method of encrypstion.
shennongmin 31:ab3e7ca014c1 74 * @return true if success, false for failure.
shennongmin 31:ab3e7ca014c1 75 */
shennongmin 31:ab3e7ca014c1 76 bool setSoftAPMode(String sap_ssid, String sap_pwd,
shennongmin 30:46a560b71e61 77 ESP8266Channel chl = ESP8266_CHANNEL_7, ESP8266Encrypstion ecn = ESP8266_ECN_WAP_WAP2_PSK);
shennongmin 30:46a560b71e61 78
shennongmin 31:ab3e7ca014c1 79 /**
shennongmin 31:ab3e7ca014c1 80 * Set as softap + station mode and start softap and join in ssid with pwd.
shennongmin 31:ab3e7ca014c1 81 *
shennongmin 31:ab3e7ca014c1 82 * @param ssid - SSID of AP to join in.
shennongmin 31:ab3e7ca014c1 83 * @param pwd - PASSWORD of AP to join in.
shennongmin 31:ab3e7ca014c1 84 * @param sap_ssid - SSID of its self softap.
shennongmin 31:ab3e7ca014c1 85 * @param sap_pwd - PASSWORD of its self softap.
shennongmin 31:ab3e7ca014c1 86 * @param chl - the channel can be 1, 2, 3, ..., 13.
shennongmin 31:ab3e7ca014c1 87 * @param enc - the method of encrypstion.
shennongmin 31:ab3e7ca014c1 88 * @return true if success, false for failure.
shennongmin 31:ab3e7ca014c1 89 */
shennongmin 30:46a560b71e61 90 bool setStationSoftAPMode(String ssid, String pwd, String sap_ssid, String sap_pwd ,
shennongmin 30:46a560b71e61 91 ESP8266Channel chl = ESP8266_CHANNEL_7, ESP8266Encrypstion ecn = ESP8266_ECN_WAP_WAP2_PSK);
shennongmin 7:a11e381ce969 92
shennongmin 31:ab3e7ca014c1 93
shennongmin 17:c449356787f1 94 bool ipConfig(uint8_t type, String addr, int port, uint8_t mux = 0, uint8_t id = 0);
shennongmin 4:962bf18523f4 95
shennongmin 7:a11e381ce969 96 //send data in sigle connection mode
shennongmin 23:4cec7b9e3715 97 bool send(String str);
shennongmin 7:a11e381ce969 98
shennongmin 7:a11e381ce969 99 //send data int multiple connection mode
shennongmin 23:4cec7b9e3715 100 bool send(uint8_t id, String str);
shennongmin 4:962bf18523f4 101
shennongmin 23:4cec7b9e3715 102 int recvData(char *buf);
shennongmin 4:962bf18523f4 103
shennongmin 7:a11e381ce969 104 //reset the module
shennongmin 29:75185b05d6a4 105 bool reset(void);
shennongmin 7:a11e381ce969 106
shennongmin 7:a11e381ce969 107 //set the working mode of module
shennongmin 17:c449356787f1 108 bool confMode(uint8_t mode);
shennongmin 7:a11e381ce969 109
shennongmin 7:a11e381ce969 110 //set the name and password of wifi
shennongmin 7:a11e381ce969 111 bool confJAP(String ssid , String pwd);
shennongmin 7:a11e381ce969 112
shennongmin 7:a11e381ce969 113 //set the parametter of SSID, password, channel, encryption in AP mode.
shennongmin 10:9d4ec0359a5c 114 bool confSAP(String ssid , String pwd , uint8_t chl , uint8_t ecn);
shennongmin 4:962bf18523f4 115
shennongmin 7:a11e381ce969 116 //inquire the current mode of wifi module
shennongmin 7:a11e381ce969 117 String showMode(void);
shennongmin 7:a11e381ce969 118
shennongmin 7:a11e381ce969 119 //show the list of wifi hotspot
shennongmin 7:a11e381ce969 120 String showAP(void);
shennongmin 7:a11e381ce969 121
shennongmin 7:a11e381ce969 122 //show the name of current wifi access port
shennongmin 7:a11e381ce969 123 String showJAP(void);
shennongmin 7:a11e381ce969 124
shennongmin 7:a11e381ce969 125 //quit the connection of current wifi
shennongmin 7:a11e381ce969 126 bool quitAP(void);
shennongmin 7:a11e381ce969 127
shennongmin 7:a11e381ce969 128 //show the parameter of ssid, password, channel, encryption in AP mode
shennongmin 7:a11e381ce969 129 String showSAP(void);
shennongmin 4:962bf18523f4 130
shennongmin 7:a11e381ce969 131 //inquire the connection status
shennongmin 7:a11e381ce969 132 String showStatus(void);
shennongmin 7:a11e381ce969 133
shennongmin 7:a11e381ce969 134 //show the current connection mode(sigle or multiple)
shennongmin 7:a11e381ce969 135 String showMux(void);
shennongmin 7:a11e381ce969 136
shennongmin 7:a11e381ce969 137 //set the connection mode(sigle:0 or multiple:1)
shennongmin 17:c449356787f1 138 bool confMux(int mux);
shennongmin 7:a11e381ce969 139
shennongmin 7:a11e381ce969 140 //create new tcp or udp connection (sigle connection mode)
shennongmin 10:9d4ec0359a5c 141 bool newMux(uint8_t type, String addr, int port);
shennongmin 4:962bf18523f4 142
shennongmin 7:a11e381ce969 143 //create new tcp or udp connection (multiple connection mode)(id:0-4)
shennongmin 10:9d4ec0359a5c 144 bool newMux(uint8_t id, uint8_t type, String addr, int port);
shennongmin 7:a11e381ce969 145
shennongmin 7:a11e381ce969 146 //close tcp or udp (sigle connection mode)
shennongmin 7:a11e381ce969 147 void closeMux(void);
shennongmin 7:a11e381ce969 148
shennongmin 7:a11e381ce969 149 //close tcp or udp (multiple connection mode)
shennongmin 10:9d4ec0359a5c 150 void closeMux(uint8_t id);
shennongmin 7:a11e381ce969 151
shennongmin 7:a11e381ce969 152 //show the current ip address
shennongmin 7:a11e381ce969 153 String showIP(void);
shennongmin 7:a11e381ce969 154
shennongmin 7:a11e381ce969 155 //set the parameter of server
shennongmin 10:9d4ec0359a5c 156 bool confServer(uint8_t mode, int port);
shennongmin 4:962bf18523f4 157
shennongmin 29:75185b05d6a4 158 // get m_mux_id
shennongmin 29:75185b05d6a4 159 int getMuxID(void);
shennongmin 10:9d4ec0359a5c 160
shennongmin 10:9d4ec0359a5c 161 private:
shennongmin 29:75185b05d6a4 162 ArduinoSerial m_uart;
shennongmin 29:75185b05d6a4 163 int m_mux_id;
shennongmin 4:962bf18523f4 164 };
shennongmin 9:95a0ce98e12b 165
shennongmin 10:9d4ec0359a5c 166 #endif /* #ifndef __ESP8266_H__ */