* AM2321的取温度间隔得大于2s,否则,i2c会不工作了 * SimpleTimer有个bug,会导致两次快速的读温度,现在读温度函数里加了保护 * Blynk有个bug,会导致无法把数据传到服务器 * 现在可以正常工作了

Dependencies:   mbed

Committer:
lixianyu
Date:
Fri Jun 24 02:06:43 2016 +0000
Revision:
1:e34100dd6532
Parent:
0:740c1eb2df13
?Arduino??????????0~255??????LPC824????????????????

Who changed what in which revision?

UserRevisionLine numberNew contents of line
lixianyu 0:740c1eb2df13 1 /**
lixianyu 0:740c1eb2df13 2 * @file ESP8266.h
lixianyu 0:740c1eb2df13 3 * @brief The definition of class ESP8266.
lixianyu 0:740c1eb2df13 4 * @author Wu Pengfei<pengfei.wu@itead.cc>
lixianyu 0:740c1eb2df13 5 * @date 2015.02
lixianyu 0:740c1eb2df13 6 *
lixianyu 0:740c1eb2df13 7 * @par Copyright:
lixianyu 0:740c1eb2df13 8 * Copyright (c) 2015 ITEAD Intelligent Systems Co., Ltd. \n\n
lixianyu 0:740c1eb2df13 9 * This program is free software; you can redistribute it and/or
lixianyu 0:740c1eb2df13 10 * modify it under the terms of the GNU General Public License as
lixianyu 0:740c1eb2df13 11 * published by the Free Software Foundation; either version 2 of
lixianyu 0:740c1eb2df13 12 * the License, or (at your option) any later version. \n\n
lixianyu 0:740c1eb2df13 13 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
lixianyu 0:740c1eb2df13 14 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
lixianyu 0:740c1eb2df13 15 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
lixianyu 0:740c1eb2df13 16 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
lixianyu 0:740c1eb2df13 17 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
lixianyu 0:740c1eb2df13 18 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
lixianyu 0:740c1eb2df13 19 * THE SOFTWARE.
lixianyu 0:740c1eb2df13 20 */
lixianyu 0:740c1eb2df13 21 #ifndef __ESP8266_LIB_H__
lixianyu 0:740c1eb2df13 22 #define __ESP8266_LIB_H__
lixianyu 0:740c1eb2df13 23
lixianyu 0:740c1eb2df13 24 //#include "Arduino.h"
lixianyu 0:740c1eb2df13 25 #include "mbed.h"
lixianyu 0:740c1eb2df13 26 #include "WString.h"
lixianyu 0:740c1eb2df13 27
lixianyu 0:740c1eb2df13 28 extern Serial pc;
lixianyu 0:740c1eb2df13 29 //#define LOG_ESP8266
lixianyu 0:740c1eb2df13 30 #ifdef LOG_ESP8266
lixianyu 0:740c1eb2df13 31 #define ESP8266_LOG pc.printf
lixianyu 0:740c1eb2df13 32 #define LOG_ENTER ESP8266_LOG("Enter %s\r\n", __func__);
lixianyu 0:740c1eb2df13 33 #else
lixianyu 0:740c1eb2df13 34 #define ESP8266_LOG(...)
lixianyu 0:740c1eb2df13 35 #define LOG_ENTER
lixianyu 0:740c1eb2df13 36 #endif
lixianyu 0:740c1eb2df13 37
lixianyu 0:740c1eb2df13 38 //#define ESP8266_USE_SOFTWARE_SERIAL
lixianyu 0:740c1eb2df13 39
lixianyu 0:740c1eb2df13 40 #ifdef ESP8266_USE_SOFTWARE_SERIAL
lixianyu 0:740c1eb2df13 41 //#include "SoftwareSerial.h"
lixianyu 0:740c1eb2df13 42 #define SoftwareSerial Serial
lixianyu 0:740c1eb2df13 43 #else
lixianyu 0:740c1eb2df13 44 #define HardwareSerial Serial
lixianyu 0:740c1eb2df13 45 #endif
lixianyu 0:740c1eb2df13 46
lixianyu 0:740c1eb2df13 47 #define VERSION_18 0X18
lixianyu 0:740c1eb2df13 48 #define VERSION_22 0X22
lixianyu 0:740c1eb2df13 49 #define DEFAULT_PATTERN 3
lixianyu 0:740c1eb2df13 50
lixianyu 0:740c1eb2df13 51 /**
lixianyu 0:740c1eb2df13 52 * You can modify the macro to choose a different version
lixianyu 0:740c1eb2df13 53 */
lixianyu 0:740c1eb2df13 54
lixianyu 0:740c1eb2df13 55 #define USER_SEL_VERSION VERSION_22
lixianyu 0:740c1eb2df13 56
lixianyu 0:740c1eb2df13 57 /**
lixianyu 0:740c1eb2df13 58 * Provide an easy-to-use way to manipulate ESP8266.
lixianyu 0:740c1eb2df13 59 */
lixianyu 0:740c1eb2df13 60 class ESP8266 {
lixianyu 0:740c1eb2df13 61 public:
lixianyu 0:740c1eb2df13 62
lixianyu 0:740c1eb2df13 63 typedef void (*onData)(uint8_t mux_id, uint32_t len, void* ptr);
lixianyu 0:740c1eb2df13 64
lixianyu 0:740c1eb2df13 65 #ifdef ESP8266_USE_SOFTWARE_SERIAL
lixianyu 0:740c1eb2df13 66 /*
lixianyu 0:740c1eb2df13 67 * Constuctor.
lixianyu 0:740c1eb2df13 68 *
lixianyu 0:740c1eb2df13 69 * @param uart - an reference of SoftwareSerial object.
lixianyu 0:740c1eb2df13 70 * @warning parameter baud depends on the AT firmware. 9600 is an common value.
lixianyu 0:740c1eb2df13 71 */
lixianyu 0:740c1eb2df13 72
lixianyu 0:740c1eb2df13 73 ESP8266(SoftwareSerial &uart);
lixianyu 0:740c1eb2df13 74
lixianyu 0:740c1eb2df13 75 SoftwareSerial* getUart() { return m_puart; }
lixianyu 0:740c1eb2df13 76
lixianyu 0:740c1eb2df13 77 #else /* HardwareSerial */
lixianyu 0:740c1eb2df13 78 /*
lixianyu 0:740c1eb2df13 79 * Constuctor.
lixianyu 0:740c1eb2df13 80 *
lixianyu 0:740c1eb2df13 81 * @param uart - an reference of HardwareSerial object.
lixianyu 0:740c1eb2df13 82 * @warning parameter baud depends on the AT firmware. 9600 is an common value.
lixianyu 0:740c1eb2df13 83 */
lixianyu 0:740c1eb2df13 84
lixianyu 0:740c1eb2df13 85 ESP8266(HardwareSerial &uart);
lixianyu 0:740c1eb2df13 86
lixianyu 0:740c1eb2df13 87 HardwareSerial* getUart() { return m_puart; }
lixianyu 0:740c1eb2df13 88
lixianyu 0:740c1eb2df13 89 #endif /* #ifdef ESP8266_USE_SOFTWARE_SERIAL */
lixianyu 0:740c1eb2df13 90
lixianyu 0:740c1eb2df13 91 void setOnData(onData cbk, void* ptr) {
lixianyu 0:740c1eb2df13 92 m_onData = cbk;
lixianyu 0:740c1eb2df13 93 m_onDataPtr = ptr;
lixianyu 0:740c1eb2df13 94 }
lixianyu 0:740c1eb2df13 95
lixianyu 0:740c1eb2df13 96 void run();
lixianyu 0:740c1eb2df13 97
lixianyu 0:740c1eb2df13 98 /**
lixianyu 0:740c1eb2df13 99 * Verify ESP8266 whether live or not.
lixianyu 0:740c1eb2df13 100 *
lixianyu 0:740c1eb2df13 101 * Actually, this method will send command "AT" to ESP8266 and waiting for "OK".
lixianyu 0:740c1eb2df13 102 *
lixianyu 0:740c1eb2df13 103 * @retval true - alive.
lixianyu 0:740c1eb2df13 104 * @retval false - dead.
lixianyu 0:740c1eb2df13 105 */
lixianyu 0:740c1eb2df13 106 bool kick(void);
lixianyu 0:740c1eb2df13 107
lixianyu 0:740c1eb2df13 108 /**
lixianyu 0:740c1eb2df13 109 * Restart ESP8266 by "AT+RST".
lixianyu 0:740c1eb2df13 110 *
lixianyu 0:740c1eb2df13 111 * This method will take 3 seconds or more.
lixianyu 0:740c1eb2df13 112 *
lixianyu 0:740c1eb2df13 113 * @retval true - success.
lixianyu 0:740c1eb2df13 114 * @retval false - failure.
lixianyu 0:740c1eb2df13 115 */
lixianyu 0:740c1eb2df13 116 bool restart(void);
lixianyu 0:740c1eb2df13 117
lixianyu 0:740c1eb2df13 118 /**
lixianyu 0:740c1eb2df13 119 * Get the version of AT Command Set.
lixianyu 0:740c1eb2df13 120 *
lixianyu 0:740c1eb2df13 121 * @return the string of version.
lixianyu 0:740c1eb2df13 122 */
lixianyu 0:740c1eb2df13 123 String getVersion(void);
lixianyu 0:740c1eb2df13 124
lixianyu 0:740c1eb2df13 125 /**
lixianyu 0:740c1eb2df13 126 * Start function of deep sleep.
lixianyu 0:740c1eb2df13 127 *
lixianyu 0:740c1eb2df13 128 * @param time - the sleep time.
lixianyu 0:740c1eb2df13 129 * @retval true - success.
lixianyu 0:740c1eb2df13 130 * @retval false - failure.
lixianyu 0:740c1eb2df13 131 * @note the feature requires hardware support.
lixianyu 0:740c1eb2df13 132 */
lixianyu 0:740c1eb2df13 133 bool deepSleep(uint32_t time);
lixianyu 0:740c1eb2df13 134
lixianyu 0:740c1eb2df13 135 /**
lixianyu 0:740c1eb2df13 136 * Switch the echo function.
lixianyu 0:740c1eb2df13 137 *
lixianyu 0:740c1eb2df13 138 * @param mode - 1 start echo -0 stop echo
lixianyu 0:740c1eb2df13 139 * @retval true - success.
lixianyu 0:740c1eb2df13 140 * @retval false - failure.
lixianyu 0:740c1eb2df13 141 *
lixianyu 0:740c1eb2df13 142 */
lixianyu 0:740c1eb2df13 143 bool setEcho(uint8_t mode);
lixianyu 0:740c1eb2df13 144
lixianyu 0:740c1eb2df13 145 /**
lixianyu 0:740c1eb2df13 146 * Restore factory.
lixianyu 0:740c1eb2df13 147 * @retval true - success.
lixianyu 0:740c1eb2df13 148 * @retval false - failure.
lixianyu 0:740c1eb2df13 149 * @note The operation can lead to restart the machine.
lixianyu 0:740c1eb2df13 150 */
lixianyu 0:740c1eb2df13 151 bool restore(void);
lixianyu 0:740c1eb2df13 152
lixianyu 0:740c1eb2df13 153 /**
lixianyu 0:740c1eb2df13 154 * Set up a serial port configuration.
lixianyu 0:740c1eb2df13 155 *
lixianyu 0:740c1eb2df13 156 * @param pattern -1 send "AT+UART=", -2 send "AT+UART_CUR=", -3 send "AT+UART_DEF=".
lixianyu 0:740c1eb2df13 157 * @param baudrate - the uart baudrate.
lixianyu 0:740c1eb2df13 158 * @retval true - success.
lixianyu 0:740c1eb2df13 159 * @retval false - failure.
lixianyu 0:740c1eb2df13 160 * @note Only allows baud rate design, for the other parameters:databits- 8,stopbits -1,parity -0,flow control -0 .
lixianyu 0:740c1eb2df13 161 */
lixianyu 0:740c1eb2df13 162 bool setUart(uint32_t baudrate,uint8_t pattern);
lixianyu 0:740c1eb2df13 163
lixianyu 0:740c1eb2df13 164 /**
lixianyu 0:740c1eb2df13 165 * Set operation mode to station.
lixianyu 0:740c1eb2df13 166 *
lixianyu 0:740c1eb2df13 167 * @param pattern1 -1, send "AT+CWMODE_DEF?",-2,send "AT+CWMODE_CUR?",-3,send "AT+CWMODE?".
lixianyu 0:740c1eb2df13 168 * @param pattern2 -1, send "AT+CWMODE_DEF=",-2,send "AT+CWMODE_CUR=",-3,send "AT+CWMODE=".
lixianyu 0:740c1eb2df13 169 * @retval true - success.
lixianyu 0:740c1eb2df13 170 * @retval false - failure.
lixianyu 0:740c1eb2df13 171 *
lixianyu 0:740c1eb2df13 172 */
lixianyu 0:740c1eb2df13 173 bool setOprToStation(uint8_t pattern1=DEFAULT_PATTERN,uint8_t pattern2=DEFAULT_PATTERN);
lixianyu 0:740c1eb2df13 174
lixianyu 0:740c1eb2df13 175 /**
lixianyu 0:740c1eb2df13 176 * Get the model values list.
lixianyu 0:740c1eb2df13 177 *
lixianyu 0:740c1eb2df13 178 * @return the list of model.
lixianyu 0:740c1eb2df13 179 */
lixianyu 0:740c1eb2df13 180 String getWifiModeList(void);
lixianyu 0:740c1eb2df13 181
lixianyu 0:740c1eb2df13 182 /**
lixianyu 0:740c1eb2df13 183 * Set operation mode to softap.
lixianyu 0:740c1eb2df13 184 * @param pattern1 -1, send "AT+CWMODE_DEF?",-2,send "AT+CWMODE_CUR?",-3,send "AT+CWMODE?".
lixianyu 0:740c1eb2df13 185 * @param pattern2 -1, send "AT+CWMODE_DEF=",-2,send "AT+CWMODE_CUR=",-3,send "AT+CWMODE=".
lixianyu 0:740c1eb2df13 186 *
lixianyu 0:740c1eb2df13 187 * @retval true - success.
lixianyu 0:740c1eb2df13 188 * @retval false - failure.
lixianyu 0:740c1eb2df13 189 */
lixianyu 0:740c1eb2df13 190 bool setOprToSoftAP(uint8_t pattern1=DEFAULT_PATTERN,uint8_t pattern2=DEFAULT_PATTERN);
lixianyu 0:740c1eb2df13 191
lixianyu 0:740c1eb2df13 192 /**
lixianyu 0:740c1eb2df13 193 * Set operation mode to station + softap.
lixianyu 0:740c1eb2df13 194 * @param pattern1 -1, send "AT+CWMODE_DEF?",-2,send "AT+CWMODE_CUR?",-3,send "AT+CWMODE?".
lixianyu 0:740c1eb2df13 195 * @param pattern2 -1, send "AT+CWMODE_DEF=",-2,send "AT+CWMODE_CUR=",-3,send "AT+CWMODE=".
lixianyu 0:740c1eb2df13 196 *
lixianyu 0:740c1eb2df13 197 * @retval true - success.
lixianyu 0:740c1eb2df13 198 * @retval false - failure.
lixianyu 0:740c1eb2df13 199 */
lixianyu 0:740c1eb2df13 200 bool setOprToStationSoftAP(uint8_t pattern1=DEFAULT_PATTERN,uint8_t pattern2=DEFAULT_PATTERN);
lixianyu 0:740c1eb2df13 201
lixianyu 0:740c1eb2df13 202 /**
lixianyu 0:740c1eb2df13 203 * Get the operation mode.
lixianyu 0:740c1eb2df13 204 * @param pattern1 -1, send "AT+CWMODE_DEF?",-2,send "AT+CWMODE_CUR?",-3,send "AT+CWMODE?".
lixianyu 0:740c1eb2df13 205 *
lixianyu 0:740c1eb2df13 206 * @retval 0 - failure.
lixianyu 0:740c1eb2df13 207 * @retval 1 - mode Station.
lixianyu 0:740c1eb2df13 208 * @retval 2 - mode AP.
lixianyu 0:740c1eb2df13 209 * @retval 3 - mode AP + station.
lixianyu 0:740c1eb2df13 210 */
lixianyu 0:740c1eb2df13 211 uint8_t getOprMode(uint8_t pattern1=DEFAULT_PATTERN);
lixianyu 0:740c1eb2df13 212
lixianyu 0:740c1eb2df13 213 /**
lixianyu 0:740c1eb2df13 214 * Search available AP list and return it.
lixianyu 0:740c1eb2df13 215 *
lixianyu 0:740c1eb2df13 216 * @return the list of available APs.
lixianyu 0:740c1eb2df13 217 * @note This method will occupy a lot of memeory(hundreds of Bytes to a couple of KBytes).
lixianyu 0:740c1eb2df13 218 * Do not call this method unless you must and ensure that your board has enough memery left.
lixianyu 0:740c1eb2df13 219 */
lixianyu 0:740c1eb2df13 220 String getAPList(void);
lixianyu 0:740c1eb2df13 221
lixianyu 0:740c1eb2df13 222 /**
lixianyu 0:740c1eb2df13 223 * Search and returns the current connect AP.
lixianyu 0:740c1eb2df13 224 *
lixianyu 0:740c1eb2df13 225 * @param pattern -1, send "AT+CWJAP_DEF?",-2,send "AT+CWJAP_CUR?",-3,send "AT+CWJAP?".
lixianyu 0:740c1eb2df13 226 * @return the ssid of AP connected now.
lixianyu 0:740c1eb2df13 227 */
lixianyu 0:740c1eb2df13 228 String getNowConecAp(uint8_t pattern=DEFAULT_PATTERN);
lixianyu 0:740c1eb2df13 229
lixianyu 0:740c1eb2df13 230 /**
lixianyu 0:740c1eb2df13 231 * Join in AP.
lixianyu 0:740c1eb2df13 232 *
lixianyu 0:740c1eb2df13 233 * @param pattern -1 send "AT+CWJAP_DEF=" -2 send "AT+CWJAP_CUR=" -3 send "AT+CWJAP=".
lixianyu 0:740c1eb2df13 234 * @param ssid - SSID of AP to join in.
lixianyu 0:740c1eb2df13 235 * @param pwd - Password of AP to join in.
lixianyu 0:740c1eb2df13 236 * @retval true - success.
lixianyu 0:740c1eb2df13 237 * @retval false - failure.
lixianyu 0:740c1eb2df13 238 * @note This method will take a couple of seconds.
lixianyu 0:740c1eb2df13 239 */
lixianyu 0:740c1eb2df13 240 bool joinAP(String ssid, String pwd,uint8_t pattern=DEFAULT_PATTERN);
lixianyu 0:740c1eb2df13 241
lixianyu 0:740c1eb2df13 242 /**
lixianyu 0:740c1eb2df13 243 * Leave AP joined before.
lixianyu 0:740c1eb2df13 244 *
lixianyu 0:740c1eb2df13 245 * @retval true - success.
lixianyu 0:740c1eb2df13 246 * @retval false - failure.
lixianyu 0:740c1eb2df13 247 */
lixianyu 0:740c1eb2df13 248 bool leaveAP(void);
lixianyu 0:740c1eb2df13 249
lixianyu 0:740c1eb2df13 250 /**
lixianyu 0:740c1eb2df13 251 * Set SoftAP parameters.
lixianyu 0:740c1eb2df13 252 *
lixianyu 0:740c1eb2df13 253 * @param pattern -1 send "AT+CWSAP_DEF=" -2 send "AT+CWSAP_CUR=" -3 send "AT+CWSAP=".
lixianyu 0:740c1eb2df13 254 * @param ssid - SSID of SoftAP.
lixianyu 0:740c1eb2df13 255 * @param pwd - PASSWORD of SoftAP.
lixianyu 0:740c1eb2df13 256 * @param chl - the channel (1 - 13, default: 7).
lixianyu 0:740c1eb2df13 257 * @param ecn - the way of encrypstion (0 - OPEN, 1 - WEP,
lixianyu 0:740c1eb2df13 258 * 2 - WPA_PSK, 3 - WPA2_PSK, 4 - WPA_WPA2_PSK, default: 4).
lixianyu 0:740c1eb2df13 259 * @retval true - success.
lixianyu 0:740c1eb2df13 260 * @retval false - failure.
lixianyu 0:740c1eb2df13 261 * @note This method should not be called when station mode.
lixianyu 0:740c1eb2df13 262 */
lixianyu 0:740c1eb2df13 263 bool setSoftAPParam(String ssid, String pwd, uint8_t chl = 7, uint8_t ecn = 4,uint8_t pattern=DEFAULT_PATTERN);
lixianyu 0:740c1eb2df13 264
lixianyu 0:740c1eb2df13 265 /**
lixianyu 0:740c1eb2df13 266 * get SoftAP parameters.
lixianyu 0:740c1eb2df13 267 *
lixianyu 0:740c1eb2df13 268 * @param pattern -1 send "AT+CWSAP_DEF?" -2 send "AT+CWSAP_CUR?" -3 send "AT+CWSAP?".
lixianyu 0:740c1eb2df13 269 * @note This method should not be called when station mode.
lixianyu 0:740c1eb2df13 270 */
lixianyu 0:740c1eb2df13 271 String getSoftAPParam(uint8_t pattern=DEFAULT_PATTERN);
lixianyu 0:740c1eb2df13 272
lixianyu 0:740c1eb2df13 273 /**
lixianyu 0:740c1eb2df13 274 * Get the IP list of devices connected to SoftAP.
lixianyu 0:740c1eb2df13 275 *
lixianyu 0:740c1eb2df13 276 * @return the list of IP.
lixianyu 0:740c1eb2df13 277 * @note This method should not be called when station mode.
lixianyu 0:740c1eb2df13 278 */
lixianyu 0:740c1eb2df13 279 String getJoinedDeviceIP(void);
lixianyu 0:740c1eb2df13 280
lixianyu 0:740c1eb2df13 281 /**
lixianyu 0:740c1eb2df13 282 * Get the current state of DHCP.
lixianyu 0:740c1eb2df13 283 *
lixianyu 0:740c1eb2df13 284 * @param pattern -1 send "AT+CWDHCP_DEF?" -2 send "AT+CWDHCP_CUR?" -3 send "AT+CWDHCP?".
lixianyu 0:740c1eb2df13 285 * @return the state of DHCP.
lixianyu 0:740c1eb2df13 286 *
lixianyu 0:740c1eb2df13 287 */
lixianyu 0:740c1eb2df13 288 String getDHCP(uint8_t pattern=DEFAULT_PATTERN);
lixianyu 0:740c1eb2df13 289
lixianyu 0:740c1eb2df13 290 /**
lixianyu 0:740c1eb2df13 291 * Set the state of DHCP.
lixianyu 0:740c1eb2df13 292 * @param pattern -1 send "AT+CWDHCP_DEF=" -2 send "AT+CWDHCP_CUR=" -3 send "AT+CWDHCP=".
lixianyu 0:740c1eb2df13 293 * @param mode - set ap or set station or set ap + station.
lixianyu 0:740c1eb2df13 294 * @param en - 0 disable DHCP - 1 enable DHCP.
lixianyu 0:740c1eb2df13 295 * @retval true - success.
lixianyu 0:740c1eb2df13 296 * @retval false - failure.
lixianyu 0:740c1eb2df13 297 */
lixianyu 0:740c1eb2df13 298 bool setDHCP(uint8_t mode, uint8_t en, uint8_t pattern=DEFAULT_PATTERN);
lixianyu 0:740c1eb2df13 299
lixianyu 0:740c1eb2df13 300 /**
lixianyu 0:740c1eb2df13 301 * make boot automatically connected.
lixianyu 0:740c1eb2df13 302 * @param en -1 enable -0 disable.
lixianyu 0:740c1eb2df13 303 * @retval true - success.
lixianyu 0:740c1eb2df13 304 * @retval false - failure.
lixianyu 0:740c1eb2df13 305 */
lixianyu 0:740c1eb2df13 306 bool setAutoConnect(uint8_t en);
lixianyu 0:740c1eb2df13 307
lixianyu 0:740c1eb2df13 308 /**
lixianyu 0:740c1eb2df13 309 * Get the station's MAC address.
lixianyu 0:740c1eb2df13 310 * @param pattern -1 send "AT+CIPSTAMAC_DEF?=" -2 send "AT+CIPSTAMAC_CUR?" -3 send "AT+CIPSTAMAC?".
lixianyu 0:740c1eb2df13 311 * @return mac address.
lixianyu 0:740c1eb2df13 312 * @note This method should not be called when ap mode.
lixianyu 0:740c1eb2df13 313 */
lixianyu 0:740c1eb2df13 314 String getStationMac(uint8_t pattern=DEFAULT_PATTERN);
lixianyu 0:740c1eb2df13 315
lixianyu 0:740c1eb2df13 316 /**
lixianyu 0:740c1eb2df13 317 * Set the station's MAC address.
lixianyu 0:740c1eb2df13 318 * @param pattern -1 send "AT+CIPSTAMAC_DEF=" -2 send "AT+CIPSTAMAC_CUR=" -3 send "AT+CIPSTAMAC=".
lixianyu 0:740c1eb2df13 319 * @param mac - the mac address of station.
lixianyu 0:740c1eb2df13 320 * @retval true - success.
lixianyu 0:740c1eb2df13 321 * @retval false - failure.
lixianyu 0:740c1eb2df13 322 */
lixianyu 0:740c1eb2df13 323 bool setStationMac(String mac,uint8_t pattern=DEFAULT_PATTERN);
lixianyu 0:740c1eb2df13 324
lixianyu 0:740c1eb2df13 325 /**
lixianyu 0:740c1eb2df13 326 * Get the station's IP.
lixianyu 0:740c1eb2df13 327 * @param pattern -1 send "AT+CIPSTA_DEF?" -2 send "AT+CIPSTA_CUR?" -3 send "AT+CIPSTA?".
lixianyu 0:740c1eb2df13 328 * @return the station's IP.
lixianyu 0:740c1eb2df13 329 * @note This method should not be called when ap mode.
lixianyu 0:740c1eb2df13 330 */
lixianyu 0:740c1eb2df13 331 String getStationIp(uint8_t pattern=DEFAULT_PATTERN);
lixianyu 0:740c1eb2df13 332
lixianyu 0:740c1eb2df13 333 /**
lixianyu 0:740c1eb2df13 334 * Set the station's IP.
lixianyu 0:740c1eb2df13 335 * @param pattern -1 send "AT+CIPSTA_DEF=" -2 send "AT+CIPSTA_CUR=" -3 send "AT+CIPSTA=".
lixianyu 0:740c1eb2df13 336 * @param ip - the ip of station.
lixianyu 0:740c1eb2df13 337 * @param gateway -the gateway of station.
lixianyu 0:740c1eb2df13 338 * @param netmask -the netmask of station.
lixianyu 0:740c1eb2df13 339 * @retval true - success.
lixianyu 0:740c1eb2df13 340 * @retval false - failure.
lixianyu 0:740c1eb2df13 341 * @note This method should not be called when ap mode.
lixianyu 0:740c1eb2df13 342 */
lixianyu 0:740c1eb2df13 343 bool setStationIp(String ip,String gateway,String netmask,uint8_t pattern=DEFAULT_PATTERN);
lixianyu 0:740c1eb2df13 344
lixianyu 0:740c1eb2df13 345 /**
lixianyu 0:740c1eb2df13 346 * Get the AP's IP.
lixianyu 0:740c1eb2df13 347 * @param pattern -1 send "AT+CIPAP_DEF?" -2 send "AT+CIPAP_CUR?" -3 send "AT+CIPAP?".
lixianyu 0:740c1eb2df13 348 * @return ap's ip.
lixianyu 0:740c1eb2df13 349 * @note This method should not be called when station mode.
lixianyu 0:740c1eb2df13 350 *
lixianyu 0:740c1eb2df13 351 */
lixianyu 0:740c1eb2df13 352 String getAPIp(uint8_t pattern=DEFAULT_PATTERN);
lixianyu 0:740c1eb2df13 353
lixianyu 0:740c1eb2df13 354 /**
lixianyu 0:740c1eb2df13 355 * Set the AP IP.
lixianyu 0:740c1eb2df13 356 * @param pattern -1 send "AT+CIPAP_DEF=" -2 send "AT+CIPAP_CUR=" -3 send "AT+CIPAP=".
lixianyu 0:740c1eb2df13 357 * @param ip - the ip of AP.
lixianyu 0:740c1eb2df13 358 * @retval true - success.
lixianyu 0:740c1eb2df13 359 * @retval false - failure.
lixianyu 0:740c1eb2df13 360 * @note This method should not be called when station mode.
lixianyu 0:740c1eb2df13 361 */
lixianyu 0:740c1eb2df13 362 bool setAPIp(String ip,uint8_t pattern=DEFAULT_PATTERN);
lixianyu 0:740c1eb2df13 363
lixianyu 0:740c1eb2df13 364 /**
lixianyu 0:740c1eb2df13 365 * start smartconfig.
lixianyu 0:740c1eb2df13 366 * @param type -1:ESP_TOUCH -2:AirKiss.
lixianyu 0:740c1eb2df13 367 * @retval true - success.
lixianyu 0:740c1eb2df13 368 * @retval false - failure.
lixianyu 0:740c1eb2df13 369 */
lixianyu 0:740c1eb2df13 370 bool startSmartConfig(uint8_t type);
lixianyu 0:740c1eb2df13 371
lixianyu 0:740c1eb2df13 372 /**
lixianyu 0:740c1eb2df13 373 * stop smartconfig.
lixianyu 0:740c1eb2df13 374 *
lixianyu 0:740c1eb2df13 375 * @retval true - success.
lixianyu 0:740c1eb2df13 376 * @retval false - failure.
lixianyu 0:740c1eb2df13 377 */
lixianyu 0:740c1eb2df13 378 bool stopSmartConfig(void);
lixianyu 0:740c1eb2df13 379
lixianyu 0:740c1eb2df13 380 /**
lixianyu 0:740c1eb2df13 381 * Get the current status of connection(UDP and TCP).
lixianyu 0:740c1eb2df13 382 *
lixianyu 0:740c1eb2df13 383 * @return the status.
lixianyu 0:740c1eb2df13 384 */
lixianyu 0:740c1eb2df13 385 String getIPStatus(void);
lixianyu 0:740c1eb2df13 386
lixianyu 0:740c1eb2df13 387 /**
lixianyu 0:740c1eb2df13 388 * Get the IP address of ESP8266.
lixianyu 0:740c1eb2df13 389 *
lixianyu 0:740c1eb2df13 390 * @return the IP list.
lixianyu 0:740c1eb2df13 391 */
lixianyu 0:740c1eb2df13 392 String getLocalIP(void);
lixianyu 0:740c1eb2df13 393
lixianyu 0:740c1eb2df13 394 /**
lixianyu 0:740c1eb2df13 395 * Enable IP MUX(multiple connection mode).
lixianyu 0:740c1eb2df13 396 *
lixianyu 0:740c1eb2df13 397 * In multiple connection mode, a couple of TCP and UDP communication can be builded.
lixianyu 0:740c1eb2df13 398 * They can be distinguished by the identifier of TCP or UDP named mux_id.
lixianyu 0:740c1eb2df13 399 *
lixianyu 0:740c1eb2df13 400 * @retval true - success.
lixianyu 0:740c1eb2df13 401 * @retval false - failure.
lixianyu 0:740c1eb2df13 402 */
lixianyu 0:740c1eb2df13 403 bool enableMUX(void);
lixianyu 0:740c1eb2df13 404
lixianyu 0:740c1eb2df13 405 /**
lixianyu 0:740c1eb2df13 406 * Disable IP MUX(single connection mode).
lixianyu 0:740c1eb2df13 407 *
lixianyu 0:740c1eb2df13 408 * In single connection mode, only one TCP or UDP communication can be builded.
lixianyu 0:740c1eb2df13 409 *
lixianyu 0:740c1eb2df13 410 * @retval true - success.
lixianyu 0:740c1eb2df13 411 * @retval false - failure.
lixianyu 0:740c1eb2df13 412 */
lixianyu 0:740c1eb2df13 413 bool disableMUX(void);
lixianyu 0:740c1eb2df13 414
lixianyu 0:740c1eb2df13 415 /**
lixianyu 0:740c1eb2df13 416 * Create TCP connection in single mode.
lixianyu 0:740c1eb2df13 417 *
lixianyu 0:740c1eb2df13 418 * @param addr - the IP or domain name of the target host.
lixianyu 0:740c1eb2df13 419 * @param port - the port number of the target host.
lixianyu 0:740c1eb2df13 420 * @retval true - success.
lixianyu 0:740c1eb2df13 421 * @retval false - failure.
lixianyu 0:740c1eb2df13 422 */
lixianyu 0:740c1eb2df13 423 bool createTCP(String addr, uint32_t port);
lixianyu 0:740c1eb2df13 424
lixianyu 0:740c1eb2df13 425 /**
lixianyu 0:740c1eb2df13 426 * Release TCP connection in single mode.
lixianyu 0:740c1eb2df13 427 *
lixianyu 0:740c1eb2df13 428 * @retval true - success.
lixianyu 0:740c1eb2df13 429 * @retval false - failure.
lixianyu 0:740c1eb2df13 430 */
lixianyu 0:740c1eb2df13 431 bool releaseTCP(void);
lixianyu 0:740c1eb2df13 432
lixianyu 0:740c1eb2df13 433 /**
lixianyu 0:740c1eb2df13 434 * Register UDP port number in single mode.
lixianyu 0:740c1eb2df13 435 *
lixianyu 0:740c1eb2df13 436 * @param addr - the IP or domain name of the target host.
lixianyu 0:740c1eb2df13 437 * @param port - the port number of the target host.
lixianyu 0:740c1eb2df13 438 * @retval true - success.
lixianyu 0:740c1eb2df13 439 * @retval false - failure.
lixianyu 0:740c1eb2df13 440 */
lixianyu 0:740c1eb2df13 441 bool registerUDP(String addr, uint32_t port);
lixianyu 0:740c1eb2df13 442
lixianyu 0:740c1eb2df13 443 /**
lixianyu 0:740c1eb2df13 444 * Unregister UDP port number in single mode.
lixianyu 0:740c1eb2df13 445 *
lixianyu 0:740c1eb2df13 446 * @retval true - success.
lixianyu 0:740c1eb2df13 447 * @retval false - failure.
lixianyu 0:740c1eb2df13 448 */
lixianyu 0:740c1eb2df13 449 bool unregisterUDP(void);
lixianyu 0:740c1eb2df13 450
lixianyu 0:740c1eb2df13 451 /**
lixianyu 0:740c1eb2df13 452 * Create TCP connection in multiple mode.
lixianyu 0:740c1eb2df13 453 *
lixianyu 0:740c1eb2df13 454 * @param mux_id - the identifier of this TCP(available value: 0 - 4).
lixianyu 0:740c1eb2df13 455 * @param addr - the IP or domain name of the target host.
lixianyu 0:740c1eb2df13 456 * @param port - the port number of the target host.
lixianyu 0:740c1eb2df13 457 * @retval true - success.
lixianyu 0:740c1eb2df13 458 * @retval false - failure.
lixianyu 0:740c1eb2df13 459 */
lixianyu 0:740c1eb2df13 460 bool createTCP(uint8_t mux_id, String addr, uint32_t port);
lixianyu 0:740c1eb2df13 461
lixianyu 0:740c1eb2df13 462 /**
lixianyu 0:740c1eb2df13 463 * Release TCP connection in multiple mode.
lixianyu 0:740c1eb2df13 464 *
lixianyu 0:740c1eb2df13 465 * @param mux_id - the identifier of this TCP(available value: 0 - 4).
lixianyu 0:740c1eb2df13 466 * @retval true - success.
lixianyu 0:740c1eb2df13 467 * @retval false - failure.
lixianyu 0:740c1eb2df13 468 */
lixianyu 0:740c1eb2df13 469 bool releaseTCP(uint8_t mux_id);
lixianyu 0:740c1eb2df13 470
lixianyu 0:740c1eb2df13 471 /**
lixianyu 0:740c1eb2df13 472 * Register UDP port number in multiple mode.
lixianyu 0:740c1eb2df13 473 *
lixianyu 0:740c1eb2df13 474 * @param mux_id - the identifier of this TCP(available value: 0 - 4).
lixianyu 0:740c1eb2df13 475 * @param addr - the IP or domain name of the target host.
lixianyu 0:740c1eb2df13 476 * @param port - the port number of the target host.
lixianyu 0:740c1eb2df13 477 * @retval true - success.
lixianyu 0:740c1eb2df13 478 * @retval false - failure.
lixianyu 0:740c1eb2df13 479 */
lixianyu 0:740c1eb2df13 480 bool registerUDP(uint8_t mux_id, String addr, uint32_t port);
lixianyu 0:740c1eb2df13 481
lixianyu 0:740c1eb2df13 482 /**
lixianyu 0:740c1eb2df13 483 * Unregister UDP port number in multiple mode.
lixianyu 0:740c1eb2df13 484 *
lixianyu 0:740c1eb2df13 485 * @param mux_id - the identifier of this TCP(available value: 0 - 4).
lixianyu 0:740c1eb2df13 486 * @retval true - success.
lixianyu 0:740c1eb2df13 487 * @retval false - failure.
lixianyu 0:740c1eb2df13 488 */
lixianyu 0:740c1eb2df13 489 bool unregisterUDP(uint8_t mux_id);
lixianyu 0:740c1eb2df13 490
lixianyu 0:740c1eb2df13 491 /**
lixianyu 0:740c1eb2df13 492 * Set the timeout of TCP Server.
lixianyu 0:740c1eb2df13 493 *
lixianyu 0:740c1eb2df13 494 * @param timeout - the duration for timeout by second(0 ~ 28800, default:180).
lixianyu 0:740c1eb2df13 495 * @retval true - success.
lixianyu 0:740c1eb2df13 496 * @retval false - failure.
lixianyu 0:740c1eb2df13 497 */
lixianyu 0:740c1eb2df13 498 bool setTCPServerTimeout(uint32_t timeout = 180);
lixianyu 0:740c1eb2df13 499
lixianyu 0:740c1eb2df13 500 /**
lixianyu 0:740c1eb2df13 501 * Start TCP Server(Only in multiple mode).
lixianyu 0:740c1eb2df13 502 *
lixianyu 0:740c1eb2df13 503 * After started, user should call method: getIPStatus to know the status of TCP connections.
lixianyu 0:740c1eb2df13 504 * The methods of receiving data can be called for user's any purpose. After communication,
lixianyu 0:740c1eb2df13 505 * release the TCP connection is needed by calling method: releaseTCP with mux_id.
lixianyu 0:740c1eb2df13 506 *
lixianyu 0:740c1eb2df13 507 * @param port - the port number to listen(default: 333).
lixianyu 0:740c1eb2df13 508 * @retval true - success.
lixianyu 0:740c1eb2df13 509 * @retval false - failure.
lixianyu 0:740c1eb2df13 510 *
lixianyu 0:740c1eb2df13 511 * @see String getIPStatus(void);
lixianyu 0:740c1eb2df13 512 * @see uint32_t recv(uint8_t *coming_mux_id, uint8_t *buffer, uint32_t len, uint32_t timeout);
lixianyu 0:740c1eb2df13 513 * @see bool releaseTCP(uint8_t mux_id);
lixianyu 0:740c1eb2df13 514 */
lixianyu 0:740c1eb2df13 515 bool startTCPServer(uint32_t port = 333);
lixianyu 0:740c1eb2df13 516
lixianyu 0:740c1eb2df13 517 /**
lixianyu 0:740c1eb2df13 518 * Stop TCP Server(Only in multiple mode).
lixianyu 0:740c1eb2df13 519 *
lixianyu 0:740c1eb2df13 520 * @retval true - success.
lixianyu 0:740c1eb2df13 521 * @retval false - failure.
lixianyu 0:740c1eb2df13 522 */
lixianyu 0:740c1eb2df13 523 bool stopTCPServer(void);
lixianyu 0:740c1eb2df13 524
lixianyu 0:740c1eb2df13 525 /**
lixianyu 0:740c1eb2df13 526 *Set the module transfer mode
lixianyu 0:740c1eb2df13 527 *
lixianyu 0:740c1eb2df13 528 * @retval true - success.
lixianyu 0:740c1eb2df13 529 * @retval false - failure.
lixianyu 0:740c1eb2df13 530 */
lixianyu 0:740c1eb2df13 531 bool setCIPMODE(uint8_t mode);
lixianyu 0:740c1eb2df13 532
lixianyu 0:740c1eb2df13 533 /**
lixianyu 0:740c1eb2df13 534 * Start Server(Only in multiple mode).
lixianyu 0:740c1eb2df13 535 *
lixianyu 0:740c1eb2df13 536 * @param port - the port number to listen(default: 333).
lixianyu 0:740c1eb2df13 537 * @retval true - success.
lixianyu 0:740c1eb2df13 538 * @retval false - failure.
lixianyu 0:740c1eb2df13 539 *
lixianyu 0:740c1eb2df13 540 * @see String getIPStatus(void);
lixianyu 0:740c1eb2df13 541 * @see uint32_t recv(uint8_t *coming_mux_id, uint8_t *buffer, uint32_t len, uint32_t timeout);
lixianyu 0:740c1eb2df13 542 */
lixianyu 0:740c1eb2df13 543 bool startServer(uint32_t port = 333);
lixianyu 0:740c1eb2df13 544
lixianyu 0:740c1eb2df13 545 /**
lixianyu 0:740c1eb2df13 546 * Stop Server(Only in multiple mode).
lixianyu 0:740c1eb2df13 547 *
lixianyu 0:740c1eb2df13 548 * @retval true - success.
lixianyu 0:740c1eb2df13 549 * @retval false - failure.
lixianyu 0:740c1eb2df13 550 */
lixianyu 0:740c1eb2df13 551 bool stopServer(void);
lixianyu 0:740c1eb2df13 552 /**
lixianyu 0:740c1eb2df13 553 * Save the passthrough links
lixianyu 0:740c1eb2df13 554 *
lixianyu 0:740c1eb2df13 555 * @retval true - success.
lixianyu 0:740c1eb2df13 556 * @retval false - failure.
lixianyu 0:740c1eb2df13 557 */
lixianyu 0:740c1eb2df13 558 bool saveTransLink (uint8_t mode,String ip,uint32_t port);
lixianyu 0:740c1eb2df13 559
lixianyu 0:740c1eb2df13 560 /**
lixianyu 0:740c1eb2df13 561 * PING COMMAND.
lixianyu 0:740c1eb2df13 562 *
lixianyu 0:740c1eb2df13 563 * @retval true - success.
lixianyu 0:740c1eb2df13 564 * @retval false - failure.
lixianyu 0:740c1eb2df13 565 */
lixianyu 0:740c1eb2df13 566 bool setPing(String ip);
lixianyu 0:740c1eb2df13 567
lixianyu 0:740c1eb2df13 568 /**
lixianyu 0:740c1eb2df13 569 * Send data based on TCP or UDP builded already in single mode.
lixianyu 0:740c1eb2df13 570 *
lixianyu 0:740c1eb2df13 571 * @param buffer - the buffer of data to send.
lixianyu 0:740c1eb2df13 572 * @param len - the length of data to send.
lixianyu 0:740c1eb2df13 573 * @retval true - success.
lixianyu 0:740c1eb2df13 574 * @retval false - failure.
lixianyu 0:740c1eb2df13 575 */
lixianyu 0:740c1eb2df13 576 bool send(const uint8_t *buffer, uint32_t len);
lixianyu 0:740c1eb2df13 577
lixianyu 0:740c1eb2df13 578 /**
lixianyu 0:740c1eb2df13 579 * Send data based on one of TCP or UDP builded already in multiple mode.
lixianyu 0:740c1eb2df13 580 *
lixianyu 0:740c1eb2df13 581 * @param mux_id - the identifier of this TCP(available value: 0 - 4).
lixianyu 0:740c1eb2df13 582 * @param buffer - the buffer of data to send.
lixianyu 0:740c1eb2df13 583 * @param len - the length of data to send.
lixianyu 0:740c1eb2df13 584 * @retval true - success.
lixianyu 0:740c1eb2df13 585 * @retval false - failure.
lixianyu 0:740c1eb2df13 586 */
lixianyu 0:740c1eb2df13 587 bool send(uint8_t mux_id, const uint8_t *buffer, uint32_t len);
lixianyu 0:740c1eb2df13 588
lixianyu 0:740c1eb2df13 589 /**
lixianyu 0:740c1eb2df13 590 * Send data based on TCP or UDP builded already in single mode.
lixianyu 0:740c1eb2df13 591 *
lixianyu 0:740c1eb2df13 592 * @param buffer - the buffer of data to send from flash memeory.
lixianyu 0:740c1eb2df13 593 * @param len - the length of data to send.
lixianyu 0:740c1eb2df13 594 * @retval true - success.
lixianyu 0:740c1eb2df13 595 * @retval false - failure.
lixianyu 0:740c1eb2df13 596 */
lixianyu 0:740c1eb2df13 597 bool sendFromFlash(const uint8_t *buffer, uint32_t len);
lixianyu 0:740c1eb2df13 598
lixianyu 0:740c1eb2df13 599 /**
lixianyu 0:740c1eb2df13 600 * Send data based on one of TCP or UDP builded already in multiple mode.
lixianyu 0:740c1eb2df13 601 *
lixianyu 0:740c1eb2df13 602 * @param mux_id - the identifier of this TCP(available value: 0 - 4).
lixianyu 0:740c1eb2df13 603 * @param buffer - the buffer of data to send from flash memeory.
lixianyu 0:740c1eb2df13 604 * @param len - the length of data to send.
lixianyu 0:740c1eb2df13 605 * @retval true - success.
lixianyu 0:740c1eb2df13 606 * @retval false - failure.
lixianyu 0:740c1eb2df13 607 */
lixianyu 0:740c1eb2df13 608 bool sendFromFlash(uint8_t mux_id, const uint8_t *buffer, uint32_t len);
lixianyu 0:740c1eb2df13 609
lixianyu 0:740c1eb2df13 610 private:
lixianyu 0:740c1eb2df13 611
lixianyu 0:740c1eb2df13 612 /*
lixianyu 0:740c1eb2df13 613 * Empty the buffer or UART RX.
lixianyu 0:740c1eb2df13 614 */
lixianyu 0:740c1eb2df13 615 void rx_empty(void);
lixianyu 0:740c1eb2df13 616
lixianyu 0:740c1eb2df13 617 /*
lixianyu 0:740c1eb2df13 618 * Recvive data from uart. Return all received data if target found or timeout.
lixianyu 0:740c1eb2df13 619 */
lixianyu 0:740c1eb2df13 620 String recvString(String target, uint32_t timeout = 1000);
lixianyu 0:740c1eb2df13 621
lixianyu 0:740c1eb2df13 622 /*
lixianyu 0:740c1eb2df13 623 * Recvive data from uart. Return all received data if one of target1 and target2 found or timeout.
lixianyu 0:740c1eb2df13 624 */
lixianyu 0:740c1eb2df13 625 String recvString(String target1, String target2, uint32_t timeout = 1000);
lixianyu 0:740c1eb2df13 626
lixianyu 0:740c1eb2df13 627 /*
lixianyu 0:740c1eb2df13 628 * Recvive data from uart. Return all received data if one of target1, target2 and target3 found or timeout.
lixianyu 0:740c1eb2df13 629 */
lixianyu 0:740c1eb2df13 630 String recvString(String target1, String target2, String target3, uint32_t timeout = 1000);
lixianyu 0:740c1eb2df13 631
lixianyu 0:740c1eb2df13 632 /*
lixianyu 0:740c1eb2df13 633 * Recvive data from uart and search first target. Return true if target found, false for timeout.
lixianyu 0:740c1eb2df13 634 */
lixianyu 0:740c1eb2df13 635 bool recvFind(String target, uint32_t timeout = 1000);
lixianyu 0:740c1eb2df13 636
lixianyu 0:740c1eb2df13 637 /*
lixianyu 0:740c1eb2df13 638 * Recvive data from uart and search first target and cut out the substring between begin and end(excluding begin and end self).
lixianyu 0:740c1eb2df13 639 * Return true if target found, false for timeout.
lixianyu 0:740c1eb2df13 640 */
lixianyu 0:740c1eb2df13 641 bool recvFindAndFilter(String target, String begin, String end, String &data, uint32_t timeout = 1000);
lixianyu 0:740c1eb2df13 642
lixianyu 0:740c1eb2df13 643 /*
lixianyu 0:740c1eb2df13 644 * Receive a package from uart.
lixianyu 0:740c1eb2df13 645 *
lixianyu 0:740c1eb2df13 646 * @param buffer - the buffer storing data.
lixianyu 0:740c1eb2df13 647 * @param buffer_size - guess what!
lixianyu 0:740c1eb2df13 648 * @param data_len - the length of data actually received(maybe more than buffer_size, the remained data will be abandoned).
lixianyu 0:740c1eb2df13 649 * @param timeout - the duration waitting data comming.
lixianyu 0:740c1eb2df13 650 * @param coming_mux_id - in single connection mode, should be NULL and not NULL in multiple.
lixianyu 0:740c1eb2df13 651 */
lixianyu 0:740c1eb2df13 652 uint32_t checkIPD(String& data);
lixianyu 0:740c1eb2df13 653
lixianyu 0:740c1eb2df13 654
lixianyu 0:740c1eb2df13 655 bool eAT(void);
lixianyu 0:740c1eb2df13 656 bool eATRST(void);
lixianyu 0:740c1eb2df13 657 bool eATGMR(String &version);
lixianyu 0:740c1eb2df13 658 bool eATGSLP(uint32_t time);
lixianyu 0:740c1eb2df13 659 bool eATE(uint8_t mode);
lixianyu 0:740c1eb2df13 660 bool eATRESTORE(void);
lixianyu 0:740c1eb2df13 661 bool eATSETUART(uint32_t baudrate,uint8_t pattern);
lixianyu 0:740c1eb2df13 662
lixianyu 0:740c1eb2df13 663 bool qATCWMODE(uint8_t *mode,uint8_t pattern=3);
lixianyu 0:740c1eb2df13 664 bool eATCWMODE(String &list) ;
lixianyu 0:740c1eb2df13 665 bool sATCWMODE(uint8_t mode,uint8_t pattern=3);
lixianyu 0:740c1eb2df13 666 bool qATCWJAP(String &ssid,uint8_t pattern=3) ;
lixianyu 0:740c1eb2df13 667 bool sATCWJAP(String ssid, String pwd,uint8_t pattern=3);
lixianyu 0:740c1eb2df13 668 bool eATCWLAP(String &list);
lixianyu 0:740c1eb2df13 669 bool eATCWQAP(void);
lixianyu 0:740c1eb2df13 670 bool qATCWSAP(String &List,uint8_t pattern=3);
lixianyu 0:740c1eb2df13 671 bool sATCWSAP(String ssid, String pwd, uint8_t chl, uint8_t ecn,uint8_t pattern=3);
lixianyu 0:740c1eb2df13 672 bool eATCWLIF(String &list);
lixianyu 0:740c1eb2df13 673 bool qATCWDHCP(String &List,uint8_t pattern=3);
lixianyu 0:740c1eb2df13 674 bool sATCWDHCP(uint8_t mode, uint8_t en, uint8_t pattern=3);
lixianyu 0:740c1eb2df13 675 bool eATCWAUTOCONN(uint8_t en);
lixianyu 0:740c1eb2df13 676 bool qATCIPSTAMAC(String &mac,uint8_t pattern=3);
lixianyu 0:740c1eb2df13 677 bool eATCIPSTAMAC(String mac,uint8_t pattern=3);
lixianyu 0:740c1eb2df13 678 bool qATCIPSTAIP(String &ip,uint8_t pattern=3);
lixianyu 0:740c1eb2df13 679 bool eATCIPSTAIP(String ip,String gateway,String netmask,uint8_t pattern=3);
lixianyu 0:740c1eb2df13 680 bool qATCIPAP(String &ip,uint8_t pattern=3);
lixianyu 0:740c1eb2df13 681 bool eATCIPAP(String ip,uint8_t pattern=3);
lixianyu 0:740c1eb2df13 682 bool eCWSTARTSMART(uint8_t type);
lixianyu 0:740c1eb2df13 683 bool eCWSTOPSMART(void);
lixianyu 0:740c1eb2df13 684
lixianyu 0:740c1eb2df13 685
lixianyu 0:740c1eb2df13 686 bool eATCIPSTATUS(String &list);
lixianyu 0:740c1eb2df13 687 bool sATCIPSTARTSingle(String type, String addr, uint32_t port);
lixianyu 0:740c1eb2df13 688 bool sATCIPSTARTMultiple(uint8_t mux_id, String type, String addr, uint32_t port);
lixianyu 0:740c1eb2df13 689 bool sATCIPSENDSingle(const uint8_t *buffer, uint32_t len);
lixianyu 0:740c1eb2df13 690 bool sATCIPSENDMultiple(uint8_t mux_id, const uint8_t *buffer, uint32_t len);
lixianyu 0:740c1eb2df13 691 bool sATCIPSENDSingleFromFlash(const uint8_t *buffer, uint32_t len);
lixianyu 0:740c1eb2df13 692 bool sATCIPSENDMultipleFromFlash(uint8_t mux_id, const uint8_t *buffer, uint32_t len);
lixianyu 0:740c1eb2df13 693 bool sATCIPCLOSEMulitple(uint8_t mux_id);
lixianyu 0:740c1eb2df13 694 bool eATCIPCLOSESingle(void);
lixianyu 0:740c1eb2df13 695 bool eATCIFSR(String &list);
lixianyu 0:740c1eb2df13 696 bool sATCIPMUX(uint8_t mode);
lixianyu 0:740c1eb2df13 697 bool sATCIPSERVER(uint8_t mode, uint32_t port = 333);
lixianyu 0:740c1eb2df13 698 bool sATCIPMODE(uint8_t mode);
lixianyu 0:740c1eb2df13 699 bool eATSAVETRANSLINK(uint8_t mode,String ip,uint32_t port);
lixianyu 0:740c1eb2df13 700 bool eATPING(String ip);
lixianyu 0:740c1eb2df13 701 bool sATCIPSTO(uint32_t timeout);
lixianyu 0:740c1eb2df13 702
lixianyu 0:740c1eb2df13 703 /*
lixianyu 0:740c1eb2df13 704 * +IPD,len:data
lixianyu 0:740c1eb2df13 705 * +IPD,id,len:data
lixianyu 0:740c1eb2df13 706 */
lixianyu 0:740c1eb2df13 707
lixianyu 0:740c1eb2df13 708 #ifdef ESP8266_USE_SOFTWARE_SERIAL
lixianyu 0:740c1eb2df13 709 SoftwareSerial *m_puart; /* The UART to communicate with ESP8266 */
lixianyu 0:740c1eb2df13 710 #else
lixianyu 0:740c1eb2df13 711 HardwareSerial *m_puart; /* The UART to communicate with ESP8266 */
lixianyu 0:740c1eb2df13 712 #endif
lixianyu 0:740c1eb2df13 713 onData m_onData;
lixianyu 0:740c1eb2df13 714 void* m_onDataPtr;
lixianyu 0:740c1eb2df13 715 };
lixianyu 0:740c1eb2df13 716
lixianyu 0:740c1eb2df13 717 #endif /* #ifndef __ESP8266_H__ */
lixianyu 0:740c1eb2df13 718
lixianyu 0:740c1eb2df13 719