For test

Dependencies:   mbed

Committer:
shennongmin
Date:
Wed Feb 04 15:40:07 2015 +0000
Revision:
32:91b3f3162c6a
Parent:
31:ab3e7ca014c1
Child:
34:65cd9c6eedb8
Update docs

Who changed what in which revision?

UserRevisionLine numberNew contents of line
shennongmin 32:91b3f3162c6a 1 /**
shennongmin 32:91b3f3162c6a 2 * @file ESP8266.h
shennongmin 32:91b3f3162c6a 3 */
shennongmin 10:9d4ec0359a5c 4 #ifndef __ESP8266_H__
shennongmin 10:9d4ec0359a5c 5 #define __ESP8266_H__
shennongmin 4:962bf18523f4 6
shennongmin 7:a11e381ce969 7 #include "mbed.h"
shennongmin 10:9d4ec0359a5c 8 #include "time.h"
shennongmin 10:9d4ec0359a5c 9 #include "ArduinoSerial.h"
shennongmin 7:a11e381ce969 10
shennongmin 22:f5d148878815 11 typedef enum {
shennongmin 22:f5d148878815 12 ESP8266_ECN_OPEN = 0,
shennongmin 22:f5d148878815 13 ESP8266_ECN_WEP = 1,
shennongmin 22:f5d148878815 14 ESP8266_ECN_WAP_PSK = 2,
shennongmin 22:f5d148878815 15 ESP8266_ECN_WAP2_PSK = 3,
shennongmin 22:f5d148878815 16 ESP8266_ECN_WAP_WAP2_PSK = 4,
shennongmin 22:f5d148878815 17 } ESP8266Encrypstion;
shennongmin 4:962bf18523f4 18
shennongmin 22:f5d148878815 19 typedef enum {
shennongmin 22:f5d148878815 20 ESP8266_COMM_UDP = 0,
shennongmin 22:f5d148878815 21 ESP8266_COMM_TCP = 1,
shennongmin 22:f5d148878815 22 } ESP8266CommMode;
shennongmin 4:962bf18523f4 23
shennongmin 22:f5d148878815 24 typedef enum {
shennongmin 22:f5d148878815 25 ESP8266_MODE_STA = 1,
shennongmin 22:f5d148878815 26 ESP8266_MODE_SAP = 2,
shennongmin 22:f5d148878815 27 ESP8266_MODE_STA_SAP = 3,
shennongmin 22:f5d148878815 28 } ESP8266WorkMode;
shennongmin 4:962bf18523f4 29
shennongmin 28:c25aff31dcc5 30 typedef enum {
shennongmin 28:c25aff31dcc5 31 ESP8266_CHANNEL_1 = 1,
shennongmin 28:c25aff31dcc5 32 ESP8266_CHANNEL_2,
shennongmin 28:c25aff31dcc5 33 ESP8266_CHANNEL_3,
shennongmin 28:c25aff31dcc5 34 ESP8266_CHANNEL_4,
shennongmin 28:c25aff31dcc5 35 ESP8266_CHANNEL_5,
shennongmin 28:c25aff31dcc5 36 ESP8266_CHANNEL_6,
shennongmin 28:c25aff31dcc5 37 ESP8266_CHANNEL_7,
shennongmin 28:c25aff31dcc5 38 ESP8266_CHANNEL_8,
shennongmin 28:c25aff31dcc5 39 ESP8266_CHANNEL_9,
shennongmin 28:c25aff31dcc5 40 ESP8266_CHANNEL_10,
shennongmin 28:c25aff31dcc5 41 ESP8266_CHANNEL_11,
shennongmin 28:c25aff31dcc5 42 ESP8266_CHANNEL_12,
shennongmin 28:c25aff31dcc5 43 ESP8266_CHANNEL_13,
shennongmin 28:c25aff31dcc5 44 } ESP8266Channel;
shennongmin 4:962bf18523f4 45
shennongmin 32:91b3f3162c6a 46 /**
shennongmin 32:91b3f3162c6a 47 * Provide methods to manipulate ESP8266 via WiFi.
shennongmin 32:91b3f3162c6a 48 */
shennongmin 9:95a0ce98e12b 49 class ESP8266
shennongmin 4:962bf18523f4 50 {
shennongmin 29:75185b05d6a4 51 public:
shennongmin 29:75185b05d6a4 52
shennongmin 29:75185b05d6a4 53 /**
shennongmin 29:75185b05d6a4 54 * Constructor.
shennongmin 29:75185b05d6a4 55 *
shennongmin 29:75185b05d6a4 56 * Need an serial port for communication between MCU and ESP8266.
shennongmin 29:75185b05d6a4 57 *
shennongmin 29:75185b05d6a4 58 * @param tx - the TX of serial port.
shennongmin 29:75185b05d6a4 59 * @param rx - the RX of serial port.
shennongmin 29:75185b05d6a4 60 * @param baud_rate - the baud rate of communication(default 9600).
shennongmin 29:75185b05d6a4 61 */
shennongmin 29:75185b05d6a4 62 ESP8266(PinName tx, PinName rx, int baud_rate = 9600);
shennongmin 4:962bf18523f4 63
shennongmin 31:ab3e7ca014c1 64 /**
shennongmin 31:ab3e7ca014c1 65 * Set as station mode and join in ssid with pwd.
shennongmin 31:ab3e7ca014c1 66 *
shennongmin 31:ab3e7ca014c1 67 * @param ssid - SSID of AP to join in.
shennongmin 31:ab3e7ca014c1 68 * @param pwd - PASSWORD of AP to join in.
shennongmin 31:ab3e7ca014c1 69 * @return true if success, false for failure.
shennongmin 31:ab3e7ca014c1 70 */
shennongmin 30:46a560b71e61 71 bool setStationMode(String ssid, String pwd);
shennongmin 31:ab3e7ca014c1 72
shennongmin 31:ab3e7ca014c1 73 /**
shennongmin 31:ab3e7ca014c1 74 * Set as softap mode and start softap.
shennongmin 31:ab3e7ca014c1 75 *
shennongmin 31:ab3e7ca014c1 76 * @param sap_ssid - SSID of its self softap.
shennongmin 31:ab3e7ca014c1 77 * @param sap_pwd - PASSWORD of its self softap.
shennongmin 31:ab3e7ca014c1 78 * @param chl - the channel can be 1, 2, 3, ..., 13.
shennongmin 31:ab3e7ca014c1 79 * @param enc - the method of encrypstion.
shennongmin 31:ab3e7ca014c1 80 * @return true if success, false for failure.
shennongmin 31:ab3e7ca014c1 81 */
shennongmin 31:ab3e7ca014c1 82 bool setSoftAPMode(String sap_ssid, String sap_pwd,
shennongmin 30:46a560b71e61 83 ESP8266Channel chl = ESP8266_CHANNEL_7, ESP8266Encrypstion ecn = ESP8266_ECN_WAP_WAP2_PSK);
shennongmin 30:46a560b71e61 84
shennongmin 31:ab3e7ca014c1 85 /**
shennongmin 31:ab3e7ca014c1 86 * Set as softap + station mode and start softap and join in ssid with pwd.
shennongmin 31:ab3e7ca014c1 87 *
shennongmin 31:ab3e7ca014c1 88 * @param ssid - SSID of AP to join in.
shennongmin 31:ab3e7ca014c1 89 * @param pwd - PASSWORD of AP to join in.
shennongmin 31:ab3e7ca014c1 90 * @param sap_ssid - SSID of its self softap.
shennongmin 31:ab3e7ca014c1 91 * @param sap_pwd - PASSWORD of its self softap.
shennongmin 31:ab3e7ca014c1 92 * @param chl - the channel can be 1, 2, 3, ..., 13.
shennongmin 31:ab3e7ca014c1 93 * @param enc - the method of encrypstion.
shennongmin 31:ab3e7ca014c1 94 * @return true if success, false for failure.
shennongmin 31:ab3e7ca014c1 95 */
shennongmin 30:46a560b71e61 96 bool setStationSoftAPMode(String ssid, String pwd, String sap_ssid, String sap_pwd ,
shennongmin 30:46a560b71e61 97 ESP8266Channel chl = ESP8266_CHANNEL_7, ESP8266Encrypstion ecn = ESP8266_ECN_WAP_WAP2_PSK);
shennongmin 7:a11e381ce969 98
shennongmin 31:ab3e7ca014c1 99
shennongmin 17:c449356787f1 100 bool ipConfig(uint8_t type, String addr, int port, uint8_t mux = 0, uint8_t id = 0);
shennongmin 4:962bf18523f4 101
shennongmin 7:a11e381ce969 102 //send data in sigle connection mode
shennongmin 23:4cec7b9e3715 103 bool send(String str);
shennongmin 7:a11e381ce969 104
shennongmin 7:a11e381ce969 105 //send data int multiple connection mode
shennongmin 23:4cec7b9e3715 106 bool send(uint8_t id, String str);
shennongmin 4:962bf18523f4 107
shennongmin 23:4cec7b9e3715 108 int recvData(char *buf);
shennongmin 4:962bf18523f4 109
shennongmin 7:a11e381ce969 110 //reset the module
shennongmin 29:75185b05d6a4 111 bool reset(void);
shennongmin 7:a11e381ce969 112
shennongmin 7:a11e381ce969 113 //set the working mode of module
shennongmin 17:c449356787f1 114 bool confMode(uint8_t mode);
shennongmin 7:a11e381ce969 115
shennongmin 7:a11e381ce969 116 //set the name and password of wifi
shennongmin 7:a11e381ce969 117 bool confJAP(String ssid , String pwd);
shennongmin 7:a11e381ce969 118
shennongmin 7:a11e381ce969 119 //set the parametter of SSID, password, channel, encryption in AP mode.
shennongmin 10:9d4ec0359a5c 120 bool confSAP(String ssid , String pwd , uint8_t chl , uint8_t ecn);
shennongmin 4:962bf18523f4 121
shennongmin 7:a11e381ce969 122 //inquire the current mode of wifi module
shennongmin 7:a11e381ce969 123 String showMode(void);
shennongmin 7:a11e381ce969 124
shennongmin 7:a11e381ce969 125 //show the list of wifi hotspot
shennongmin 7:a11e381ce969 126 String showAP(void);
shennongmin 7:a11e381ce969 127
shennongmin 7:a11e381ce969 128 //show the name of current wifi access port
shennongmin 7:a11e381ce969 129 String showJAP(void);
shennongmin 7:a11e381ce969 130
shennongmin 7:a11e381ce969 131 //quit the connection of current wifi
shennongmin 7:a11e381ce969 132 bool quitAP(void);
shennongmin 7:a11e381ce969 133
shennongmin 7:a11e381ce969 134 //show the parameter of ssid, password, channel, encryption in AP mode
shennongmin 7:a11e381ce969 135 String showSAP(void);
shennongmin 4:962bf18523f4 136
shennongmin 7:a11e381ce969 137 //inquire the connection status
shennongmin 7:a11e381ce969 138 String showStatus(void);
shennongmin 7:a11e381ce969 139
shennongmin 7:a11e381ce969 140 //show the current connection mode(sigle or multiple)
shennongmin 7:a11e381ce969 141 String showMux(void);
shennongmin 7:a11e381ce969 142
shennongmin 7:a11e381ce969 143 //set the connection mode(sigle:0 or multiple:1)
shennongmin 17:c449356787f1 144 bool confMux(int mux);
shennongmin 7:a11e381ce969 145
shennongmin 7:a11e381ce969 146 //create new tcp or udp connection (sigle connection mode)
shennongmin 10:9d4ec0359a5c 147 bool newMux(uint8_t type, String addr, int port);
shennongmin 4:962bf18523f4 148
shennongmin 7:a11e381ce969 149 //create new tcp or udp connection (multiple connection mode)(id:0-4)
shennongmin 10:9d4ec0359a5c 150 bool newMux(uint8_t id, uint8_t type, String addr, int port);
shennongmin 7:a11e381ce969 151
shennongmin 7:a11e381ce969 152 //close tcp or udp (sigle connection mode)
shennongmin 7:a11e381ce969 153 void closeMux(void);
shennongmin 7:a11e381ce969 154
shennongmin 7:a11e381ce969 155 //close tcp or udp (multiple connection mode)
shennongmin 10:9d4ec0359a5c 156 void closeMux(uint8_t id);
shennongmin 7:a11e381ce969 157
shennongmin 7:a11e381ce969 158 //show the current ip address
shennongmin 7:a11e381ce969 159 String showIP(void);
shennongmin 7:a11e381ce969 160
shennongmin 7:a11e381ce969 161 //set the parameter of server
shennongmin 10:9d4ec0359a5c 162 bool confServer(uint8_t mode, int port);
shennongmin 4:962bf18523f4 163
shennongmin 29:75185b05d6a4 164 // get m_mux_id
shennongmin 29:75185b05d6a4 165 int getMuxID(void);
shennongmin 10:9d4ec0359a5c 166
shennongmin 10:9d4ec0359a5c 167 private:
shennongmin 29:75185b05d6a4 168 ArduinoSerial m_uart;
shennongmin 29:75185b05d6a4 169 int m_mux_id;
shennongmin 4:962bf18523f4 170 };
shennongmin 9:95a0ce98e12b 171
shennongmin 10:9d4ec0359a5c 172 #endif /* #ifndef __ESP8266_H__ */