Provide an easy-to-use way to manipulate ESP8266.
Fork of WeeESP8266 by
ESP8266.h@23:b888991fd6fd, 2015-03-28 (annotated)
- Committer:
- JojoS
- Date:
- Sat Mar 28 14:49:05 2015 +0000
- Revision:
- 23:b888991fd6fd
- Parent:
- 22:9b876a9b2f80
- added Baudrate to constructor; - removed delay in read status
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
itead | 1:edc634cad906 | 1 | /** |
itead | 2:fb209f93f3f1 | 2 | * @file ESP8266.h |
itead | 2:fb209f93f3f1 | 3 | * @brief The definition of class ESP8266. |
itead | 1:edc634cad906 | 4 | * @author Wu Pengfei<pengfei.wu@itead.cc> |
itead | 1:edc634cad906 | 5 | * @date 2015.02 |
itead | 1:edc634cad906 | 6 | * |
itead | 1:edc634cad906 | 7 | * @par Copyright: |
itead | 1:edc634cad906 | 8 | * Copyright (c) 2015 ITEAD Intelligent Systems Co., Ltd. \n\n |
itead | 1:edc634cad906 | 9 | * This program is free software; you can redistribute it and/or |
itead | 1:edc634cad906 | 10 | * modify it under the terms of the GNU General Public License as |
itead | 1:edc634cad906 | 11 | * published by the Free Software Foundation; either version 2 of |
itead | 1:edc634cad906 | 12 | * the License, or (at your option) any later version. \n\n |
itead | 1:edc634cad906 | 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
itead | 1:edc634cad906 | 14 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
itead | 1:edc634cad906 | 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
itead | 1:edc634cad906 | 16 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
itead | 1:edc634cad906 | 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
itead | 1:edc634cad906 | 18 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
itead | 1:edc634cad906 | 19 | * THE SOFTWARE. |
itead | 1:edc634cad906 | 20 | */ |
itead | 2:fb209f93f3f1 | 21 | #ifndef __ESP8266_H__ |
itead | 2:fb209f93f3f1 | 22 | #define __ESP8266_H__ |
itead | 0:d3b93948c925 | 23 | |
itead | 1:edc634cad906 | 24 | #include "ArduinoAPI.h" |
itead | 0:d3b93948c925 | 25 | |
itead | 1:edc634cad906 | 26 | /** |
itead | 1:edc634cad906 | 27 | * Provide an easy-to-use way to manipulate ESP8266. |
itead | 1:edc634cad906 | 28 | */ |
itead | 2:fb209f93f3f1 | 29 | class ESP8266 { |
itead | 1:edc634cad906 | 30 | public: |
itead | 1:edc634cad906 | 31 | |
itead | 3:9f745022331a | 32 | /** |
itead | 3:9f745022331a | 33 | * Constuctor. |
itead | 3:9f745022331a | 34 | * |
itead | 3:9f745022331a | 35 | * @param uart - an reference of ArduinoSerial object with baud 9600. |
itead | 3:9f745022331a | 36 | */ |
JojoS | 22:9b876a9b2f80 | 37 | ESP8266(ArduinoSerial &uart, int baud_rate=9600); /* baud rate is 9600 */ |
itead | 1:edc634cad906 | 38 | |
itead | 1:edc634cad906 | 39 | /** |
itead | 3:9f745022331a | 40 | * Verify ESP8266 whether live or not. |
itead | 1:edc634cad906 | 41 | * |
itead | 1:edc634cad906 | 42 | * Actually, this method will send command "AT" to ESP8266 and waiting for "OK". |
itead | 1:edc634cad906 | 43 | * |
itead | 1:edc634cad906 | 44 | * @retval true - alive. |
itead | 1:edc634cad906 | 45 | * @retval false - dead. |
itead | 1:edc634cad906 | 46 | */ |
itead | 1:edc634cad906 | 47 | bool kick(void); |
itead | 1:edc634cad906 | 48 | |
itead | 1:edc634cad906 | 49 | /** |
itead | 1:edc634cad906 | 50 | * Restart ESP8266 by "AT+RST". |
itead | 1:edc634cad906 | 51 | * |
itead | 1:edc634cad906 | 52 | * This method will take 3 seconds or more. |
itead | 1:edc634cad906 | 53 | * |
itead | 1:edc634cad906 | 54 | * @retval true - success. |
itead | 1:edc634cad906 | 55 | * @retval false - failure. |
itead | 1:edc634cad906 | 56 | */ |
itead | 1:edc634cad906 | 57 | bool restart(void); |
itead | 1:edc634cad906 | 58 | |
itead | 1:edc634cad906 | 59 | /** |
itead | 1:edc634cad906 | 60 | * Get the version of AT Command Set. |
itead | 1:edc634cad906 | 61 | * |
itead | 1:edc634cad906 | 62 | * @return the string of version. |
itead | 1:edc634cad906 | 63 | */ |
itead | 1:edc634cad906 | 64 | String getVersion(void); |
itead | 1:edc634cad906 | 65 | |
itead | 1:edc634cad906 | 66 | /** |
itead | 1:edc634cad906 | 67 | * Set operation mode to staion. |
itead | 1:edc634cad906 | 68 | * |
itead | 1:edc634cad906 | 69 | * @retval true - success. |
itead | 1:edc634cad906 | 70 | * @retval false - failure. |
itead | 1:edc634cad906 | 71 | */ |
itead | 1:edc634cad906 | 72 | bool setOprToStation(void); |
itead | 1:edc634cad906 | 73 | |
itead | 1:edc634cad906 | 74 | /** |
itead | 1:edc634cad906 | 75 | * Set operation mode to softap. |
itead | 1:edc634cad906 | 76 | * |
itead | 1:edc634cad906 | 77 | * @retval true - success. |
itead | 1:edc634cad906 | 78 | * @retval false - failure. |
itead | 1:edc634cad906 | 79 | */ |
itead | 1:edc634cad906 | 80 | bool setOprToSoftAP(void); |
itead | 1:edc634cad906 | 81 | |
itead | 1:edc634cad906 | 82 | /** |
itead | 1:edc634cad906 | 83 | * Set operation mode to station + softap. |
itead | 1:edc634cad906 | 84 | * |
itead | 1:edc634cad906 | 85 | * @retval true - success. |
itead | 1:edc634cad906 | 86 | * @retval false - failure. |
itead | 1:edc634cad906 | 87 | */ |
itead | 1:edc634cad906 | 88 | bool setOprToStationSoftAP(void); |
itead | 1:edc634cad906 | 89 | |
itead | 1:edc634cad906 | 90 | /** |
itead | 1:edc634cad906 | 91 | * Search available AP list and return it. |
itead | 1:edc634cad906 | 92 | * |
itead | 1:edc634cad906 | 93 | * @return the list of available APs. |
itead | 1:edc634cad906 | 94 | * @note This method will occupy a lot of memeory(hundreds of Bytes to a couple of KBytes). |
itead | 1:edc634cad906 | 95 | * Do not call this method unless you must and ensure that your board has enough memery left. |
itead | 1:edc634cad906 | 96 | */ |
itead | 1:edc634cad906 | 97 | String getAPList(void); |
itead | 1:edc634cad906 | 98 | |
itead | 1:edc634cad906 | 99 | /** |
itead | 1:edc634cad906 | 100 | * Join in AP. |
itead | 1:edc634cad906 | 101 | * |
itead | 1:edc634cad906 | 102 | * @param ssid - SSID of AP to join in. |
itead | 1:edc634cad906 | 103 | * @param pwd - Password of AP to join in. |
itead | 1:edc634cad906 | 104 | * @retval true - success. |
itead | 1:edc634cad906 | 105 | * @retval false - failure. |
itead | 1:edc634cad906 | 106 | * @note This method will take a couple of seconds. |
itead | 1:edc634cad906 | 107 | */ |
itead | 1:edc634cad906 | 108 | bool joinAP(String ssid, String pwd); |
itead | 1:edc634cad906 | 109 | |
itead | 1:edc634cad906 | 110 | /** |
itead | 1:edc634cad906 | 111 | * Leave AP joined before. |
itead | 1:edc634cad906 | 112 | * |
itead | 1:edc634cad906 | 113 | * @retval true - success. |
itead | 1:edc634cad906 | 114 | * @retval false - failure. |
itead | 1:edc634cad906 | 115 | */ |
itead | 1:edc634cad906 | 116 | bool leaveAP(void); |
itead | 1:edc634cad906 | 117 | |
itead | 1:edc634cad906 | 118 | /** |
itead | 1:edc634cad906 | 119 | * Set SoftAP parameters. |
itead | 1:edc634cad906 | 120 | * |
itead | 1:edc634cad906 | 121 | * @param ssid - SSID of SoftAP. |
itead | 1:edc634cad906 | 122 | * @param pwd - PASSWORD of SoftAP. |
itead | 1:edc634cad906 | 123 | * @param chl - the channel (1 - 13, default: 7). |
itead | 1:edc634cad906 | 124 | * @param ecn - the way of encrypstion (0 - OPEN, 1 - WEP, |
itead | 21:d1a7f48ab3ba | 125 | * 2 - WPA_PSK, 3 - WPA2_PSK, 4 - WPA_WPA2_PSK, default: 4). |
itead | 1:edc634cad906 | 126 | * @note This method should not be called when station mode. |
itead | 1:edc634cad906 | 127 | */ |
itead | 6:18eb2d9fb2ac | 128 | bool setSoftAPParam(String ssid, String pwd, uint8_t chl = 7, uint8_t ecn = 4); |
itead | 1:edc634cad906 | 129 | |
itead | 1:edc634cad906 | 130 | /** |
itead | 1:edc634cad906 | 131 | * Get the IP list of devices connected to SoftAP. |
itead | 1:edc634cad906 | 132 | * |
itead | 1:edc634cad906 | 133 | * @return the list of IP. |
itead | 1:edc634cad906 | 134 | * @note This method should not be called when station mode. |
itead | 1:edc634cad906 | 135 | */ |
itead | 3:9f745022331a | 136 | String getJoinedDeviceIP(void); |
itead | 3:9f745022331a | 137 | |
itead | 3:9f745022331a | 138 | /** |
itead | 3:9f745022331a | 139 | * Get the current status of connection(UDP and TCP). |
itead | 3:9f745022331a | 140 | * |
JojoS | 23:b888991fd6fd | 141 | * @param pStatus - pointer to int for Status, decoded from status query |
itead | 3:9f745022331a | 142 | * @return the status. |
itead | 3:9f745022331a | 143 | */ |
JojoS | 23:b888991fd6fd | 144 | String getIPStatus(int *pStatus=NULL); |
itead | 3:9f745022331a | 145 | |
itead | 3:9f745022331a | 146 | /** |
itead | 3:9f745022331a | 147 | * Get the IP address of ESP8266. |
itead | 3:9f745022331a | 148 | * |
itead | 3:9f745022331a | 149 | * @return the IP list. |
itead | 3:9f745022331a | 150 | */ |
itead | 3:9f745022331a | 151 | String getLocalIP(void); |
itead | 3:9f745022331a | 152 | |
itead | 3:9f745022331a | 153 | /** |
itead | 3:9f745022331a | 154 | * Enable IP MUX(multiple connection mode). |
itead | 3:9f745022331a | 155 | * |
itead | 3:9f745022331a | 156 | * In multiple connection mode, a couple of TCP and UDP communication can be builded. |
itead | 3:9f745022331a | 157 | * They can be distinguished by the identifier of TCP or UDP named mux_id. |
itead | 3:9f745022331a | 158 | * |
itead | 3:9f745022331a | 159 | * @retval true - success. |
itead | 3:9f745022331a | 160 | * @retval false - failure. |
itead | 3:9f745022331a | 161 | */ |
itead | 3:9f745022331a | 162 | bool enableMUX(void); |
itead | 3:9f745022331a | 163 | |
itead | 3:9f745022331a | 164 | /** |
itead | 3:9f745022331a | 165 | * Disable IP MUX(single connection mode). |
itead | 3:9f745022331a | 166 | * |
itead | 3:9f745022331a | 167 | * In single connection mode, only one TCP or UDP communication can be builded. |
itead | 3:9f745022331a | 168 | * |
itead | 3:9f745022331a | 169 | * @retval true - success. |
itead | 3:9f745022331a | 170 | * @retval false - failure. |
itead | 3:9f745022331a | 171 | */ |
itead | 3:9f745022331a | 172 | bool disableMUX(void); |
itead | 3:9f745022331a | 173 | |
itead | 3:9f745022331a | 174 | |
itead | 3:9f745022331a | 175 | /** |
itead | 3:9f745022331a | 176 | * Create TCP connection in single mode. |
itead | 3:9f745022331a | 177 | * |
itead | 3:9f745022331a | 178 | * @param addr - the IP or domain name of the target host. |
itead | 3:9f745022331a | 179 | * @param port - the port number of the target host. |
itead | 3:9f745022331a | 180 | * @retval true - success. |
itead | 3:9f745022331a | 181 | * @retval false - failure. |
itead | 3:9f745022331a | 182 | */ |
itead | 3:9f745022331a | 183 | bool createTCP(String addr, uint32_t port); |
itead | 3:9f745022331a | 184 | |
itead | 3:9f745022331a | 185 | /** |
itead | 3:9f745022331a | 186 | * Release TCP connection in single mode. |
itead | 3:9f745022331a | 187 | * |
itead | 3:9f745022331a | 188 | * @retval true - success. |
itead | 3:9f745022331a | 189 | * @retval false - failure. |
itead | 3:9f745022331a | 190 | */ |
itead | 3:9f745022331a | 191 | bool releaseTCP(void); |
itead | 3:9f745022331a | 192 | |
itead | 3:9f745022331a | 193 | /** |
itead | 3:9f745022331a | 194 | * Register UDP port number in single mode. |
itead | 3:9f745022331a | 195 | * |
itead | 3:9f745022331a | 196 | * @param addr - the IP or domain name of the target host. |
itead | 3:9f745022331a | 197 | * @param port - the port number of the target host. |
itead | 3:9f745022331a | 198 | * @retval true - success. |
itead | 3:9f745022331a | 199 | * @retval false - failure. |
itead | 3:9f745022331a | 200 | */ |
itead | 3:9f745022331a | 201 | bool registerUDP(String addr, uint32_t port); |
itead | 3:9f745022331a | 202 | |
itead | 3:9f745022331a | 203 | /** |
itead | 3:9f745022331a | 204 | * Unregister UDP port number in single mode. |
itead | 3:9f745022331a | 205 | * |
itead | 3:9f745022331a | 206 | * @retval true - success. |
itead | 3:9f745022331a | 207 | * @retval false - failure. |
itead | 3:9f745022331a | 208 | */ |
itead | 3:9f745022331a | 209 | bool unregisterUDP(void); |
itead | 4:c8e2381d34d2 | 210 | |
itead | 3:9f745022331a | 211 | /** |
itead | 3:9f745022331a | 212 | * Create TCP connection in multiple mode. |
itead | 3:9f745022331a | 213 | * |
itead | 3:9f745022331a | 214 | * @param mux_id - the identifier of this TCP(available value: 0 - 4). |
itead | 3:9f745022331a | 215 | * @param addr - the IP or domain name of the target host. |
itead | 3:9f745022331a | 216 | * @param port - the port number of the target host. |
itead | 3:9f745022331a | 217 | * @retval true - success. |
itead | 3:9f745022331a | 218 | * @retval false - failure. |
itead | 3:9f745022331a | 219 | */ |
itead | 3:9f745022331a | 220 | bool createTCP(uint8_t mux_id, String addr, uint32_t port); |
itead | 3:9f745022331a | 221 | |
itead | 3:9f745022331a | 222 | /** |
itead | 3:9f745022331a | 223 | * Release TCP connection in multiple mode. |
itead | 3:9f745022331a | 224 | * |
itead | 3:9f745022331a | 225 | * @param mux_id - the identifier of this TCP(available value: 0 - 4). |
itead | 3:9f745022331a | 226 | * @retval true - success. |
itead | 3:9f745022331a | 227 | * @retval false - failure. |
itead | 3:9f745022331a | 228 | */ |
itead | 3:9f745022331a | 229 | bool releaseTCP(uint8_t mux_id); |
itead | 3:9f745022331a | 230 | |
itead | 3:9f745022331a | 231 | /** |
itead | 3:9f745022331a | 232 | * Register UDP port number in multiple mode. |
itead | 3:9f745022331a | 233 | * |
itead | 3:9f745022331a | 234 | * @param mux_id - the identifier of this TCP(available value: 0 - 4). |
itead | 3:9f745022331a | 235 | * @param addr - the IP or domain name of the target host. |
itead | 3:9f745022331a | 236 | * @param port - the port number of the target host. |
itead | 3:9f745022331a | 237 | * @retval true - success. |
itead | 3:9f745022331a | 238 | * @retval false - failure. |
itead | 3:9f745022331a | 239 | */ |
itead | 3:9f745022331a | 240 | bool registerUDP(uint8_t mux_id, String addr, uint32_t port); |
itead | 3:9f745022331a | 241 | |
itead | 3:9f745022331a | 242 | /** |
itead | 3:9f745022331a | 243 | * Unregister UDP port number in multiple mode. |
itead | 3:9f745022331a | 244 | * |
itead | 3:9f745022331a | 245 | * @param mux_id - the identifier of this TCP(available value: 0 - 4). |
itead | 3:9f745022331a | 246 | * @retval true - success. |
itead | 3:9f745022331a | 247 | * @retval false - failure. |
itead | 3:9f745022331a | 248 | */ |
itead | 3:9f745022331a | 249 | bool unregisterUDP(uint8_t mux_id); |
itead | 4:c8e2381d34d2 | 250 | |
itead | 4:c8e2381d34d2 | 251 | |
itead | 4:c8e2381d34d2 | 252 | /** |
itead | 4:c8e2381d34d2 | 253 | * Set the timeout of TCP Server. |
itead | 4:c8e2381d34d2 | 254 | * |
itead | 4:c8e2381d34d2 | 255 | * @param timeout - the duration for timeout by second(0 ~ 28800, default:180). |
itead | 4:c8e2381d34d2 | 256 | * @retval true - success. |
itead | 4:c8e2381d34d2 | 257 | * @retval false - failure. |
itead | 4:c8e2381d34d2 | 258 | */ |
itead | 4:c8e2381d34d2 | 259 | bool setTCPServerTimeout(uint32_t timeout = 180); |
itead | 3:9f745022331a | 260 | |
itead | 3:9f745022331a | 261 | /** |
itead | 4:c8e2381d34d2 | 262 | * Start TCP Server(Only in multiple mode). |
itead | 4:c8e2381d34d2 | 263 | * |
itead | 4:c8e2381d34d2 | 264 | * After started, user should call method: getIPStatus to know the status of TCP connections. |
itead | 4:c8e2381d34d2 | 265 | * The methods of receiving data can be called for user's any purpose. After communication, |
itead | 4:c8e2381d34d2 | 266 | * release the TCP connection is needed by calling method: releaseTCP with mux_id. |
itead | 4:c8e2381d34d2 | 267 | * |
itead | 4:c8e2381d34d2 | 268 | * @param port - the port number to listen(default: 333). |
itead | 4:c8e2381d34d2 | 269 | * @retval true - success. |
itead | 4:c8e2381d34d2 | 270 | * @retval false - failure. |
itead | 4:c8e2381d34d2 | 271 | * |
itead | 4:c8e2381d34d2 | 272 | * @see String getIPStatus(void); |
itead | 4:c8e2381d34d2 | 273 | * @see uint32_t recv(uint8_t *coming_mux_id, uint8_t *buffer, uint32_t len, uint32_t timeout); |
itead | 4:c8e2381d34d2 | 274 | * @see bool releaseTCP(uint8_t mux_id); |
itead | 4:c8e2381d34d2 | 275 | */ |
itead | 4:c8e2381d34d2 | 276 | bool startTCPServer(uint32_t port = 333); |
itead | 4:c8e2381d34d2 | 277 | |
itead | 4:c8e2381d34d2 | 278 | /** |
itead | 4:c8e2381d34d2 | 279 | * Stop TCP Server(Only in multiple mode). |
itead | 4:c8e2381d34d2 | 280 | * |
itead | 4:c8e2381d34d2 | 281 | * @retval true - success. |
itead | 4:c8e2381d34d2 | 282 | * @retval false - failure. |
itead | 4:c8e2381d34d2 | 283 | */ |
itead | 4:c8e2381d34d2 | 284 | bool stopTCPServer(void); |
itead | 4:c8e2381d34d2 | 285 | |
itead | 4:c8e2381d34d2 | 286 | /** |
itead | 4:c8e2381d34d2 | 287 | * Send data based on TCP or UDP builded already in single mode. |
itead | 4:c8e2381d34d2 | 288 | * |
itead | 4:c8e2381d34d2 | 289 | * @param buffer - the buffer of data to send. |
itead | 4:c8e2381d34d2 | 290 | * @param len - the length of data to send. |
itead | 4:c8e2381d34d2 | 291 | * @retval true - success. |
itead | 4:c8e2381d34d2 | 292 | * @retval false - failure. |
itead | 4:c8e2381d34d2 | 293 | */ |
itead | 4:c8e2381d34d2 | 294 | bool send(const uint8_t *buffer, uint32_t len); |
itead | 4:c8e2381d34d2 | 295 | |
itead | 4:c8e2381d34d2 | 296 | /** |
itead | 3:9f745022331a | 297 | * Send data based on one of TCP or UDP builded already in multiple mode. |
itead | 3:9f745022331a | 298 | * |
itead | 3:9f745022331a | 299 | * @param mux_id - the identifier of this TCP(available value: 0 - 4). |
itead | 3:9f745022331a | 300 | * @param buffer - the buffer of data to send. |
itead | 3:9f745022331a | 301 | * @param len - the length of data to send. |
itead | 3:9f745022331a | 302 | * @retval true - success. |
itead | 3:9f745022331a | 303 | * @retval false - failure. |
itead | 3:9f745022331a | 304 | */ |
itead | 9:dec2cf52b744 | 305 | bool send(uint8_t mux_id, const uint8_t *buffer, uint32_t len); |
itead | 3:9f745022331a | 306 | |
itead | 3:9f745022331a | 307 | /** |
itead | 4:c8e2381d34d2 | 308 | * Receive data from TCP or UDP builded already in single mode. |
itead | 4:c8e2381d34d2 | 309 | * |
itead | 4:c8e2381d34d2 | 310 | * @param buffer - the buffer for storing data. |
itead | 9:dec2cf52b744 | 311 | * @param buffer_size - the length of the buffer. |
itead | 4:c8e2381d34d2 | 312 | * @param timeout - the time waiting data. |
itead | 4:c8e2381d34d2 | 313 | * @return the length of data received actually. |
itead | 4:c8e2381d34d2 | 314 | */ |
itead | 9:dec2cf52b744 | 315 | uint32_t recv(uint8_t *buffer, uint32_t buffer_size, uint32_t timeout = 1000); |
itead | 4:c8e2381d34d2 | 316 | |
itead | 4:c8e2381d34d2 | 317 | /** |
itead | 3:9f745022331a | 318 | * Receive data from one of TCP or UDP builded already in multiple mode. |
itead | 3:9f745022331a | 319 | * |
itead | 3:9f745022331a | 320 | * @param mux_id - the identifier of this TCP(available value: 0 - 4). |
itead | 3:9f745022331a | 321 | * @param buffer - the buffer for storing data. |
itead | 9:dec2cf52b744 | 322 | * @param buffer_size - the length of the buffer. |
itead | 3:9f745022331a | 323 | * @param timeout - the time waiting data. |
itead | 3:9f745022331a | 324 | * @return the length of data received actually. |
itead | 3:9f745022331a | 325 | */ |
itead | 9:dec2cf52b744 | 326 | uint32_t recv(uint8_t mux_id, uint8_t *buffer, uint32_t buffer_size, uint32_t timeout = 1000); |
itead | 3:9f745022331a | 327 | |
itead | 3:9f745022331a | 328 | /** |
itead | 3:9f745022331a | 329 | * Receive data from all of TCP or UDP builded already in multiple mode. |
itead | 3:9f745022331a | 330 | * |
itead | 3:9f745022331a | 331 | * After return, coming_mux_id store the id of TCP or UDP from which data coming. |
itead | 3:9f745022331a | 332 | * User should read the value of coming_mux_id and decide what next to do. |
itead | 3:9f745022331a | 333 | * |
itead | 3:9f745022331a | 334 | * @param coming_mux_id - the identifier of TCP or UDP. |
itead | 3:9f745022331a | 335 | * @param buffer - the buffer for storing data. |
itead | 9:dec2cf52b744 | 336 | * @param buffer_size - the length of the buffer. |
itead | 3:9f745022331a | 337 | * @param timeout - the time waiting data. |
itead | 3:9f745022331a | 338 | * @return the length of data received actually. |
itead | 3:9f745022331a | 339 | */ |
itead | 9:dec2cf52b744 | 340 | uint32_t recv(uint8_t *coming_mux_id, uint8_t *buffer, uint32_t buffer_size, uint32_t timeout = 1000); |
itead | 4:c8e2381d34d2 | 341 | |
itead | 1:edc634cad906 | 342 | private: |
itead | 9:dec2cf52b744 | 343 | /* |
itead | 9:dec2cf52b744 | 344 | * Recvive data from uart. Return all received data if target found or timeout. |
itead | 9:dec2cf52b744 | 345 | */ |
itead | 6:18eb2d9fb2ac | 346 | String recvString(String target, uint32_t timeout = 1000); |
itead | 9:dec2cf52b744 | 347 | |
itead | 9:dec2cf52b744 | 348 | /* |
itead | 9:dec2cf52b744 | 349 | * Recvive data from uart. Return all received data if one of target1 and target2 found or timeout. |
itead | 9:dec2cf52b744 | 350 | */ |
itead | 6:18eb2d9fb2ac | 351 | String recvString(String target1, String target2, uint32_t timeout = 1000); |
itead | 9:dec2cf52b744 | 352 | |
itead | 9:dec2cf52b744 | 353 | /* |
itead | 9:dec2cf52b744 | 354 | * Recvive data from uart. Return all received data if one of target1, target2 and target3 found or timeout. |
itead | 9:dec2cf52b744 | 355 | */ |
itead | 6:18eb2d9fb2ac | 356 | String recvString(String target1, String target2, String target3, uint32_t timeout = 1000); |
itead | 9:dec2cf52b744 | 357 | |
itead | 9:dec2cf52b744 | 358 | /* |
itead | 9:dec2cf52b744 | 359 | * Recvive data from uart and search first target. Return true if target found, false for timeout. |
itead | 9:dec2cf52b744 | 360 | */ |
itead | 6:18eb2d9fb2ac | 361 | bool recvFind(String target, uint32_t timeout = 1000); |
itead | 9:dec2cf52b744 | 362 | |
itead | 9:dec2cf52b744 | 363 | /* |
itead | 9:dec2cf52b744 | 364 | * Recvive data from uart and search first target and cut out the substring between begin and end(excluding begin and end self). |
itead | 9:dec2cf52b744 | 365 | * Return true if target found, false for timeout. |
itead | 9:dec2cf52b744 | 366 | */ |
itead | 6:18eb2d9fb2ac | 367 | bool recvFindAndFilter(String target, String begin, String end, String &data, uint32_t timeout = 1000); |
itead | 5:5fa655d7212c | 368 | |
itead | 9:dec2cf52b744 | 369 | /* |
itead | 9:dec2cf52b744 | 370 | * Receive a package from uart. |
itead | 9:dec2cf52b744 | 371 | * |
itead | 9:dec2cf52b744 | 372 | * @param buffer - the buffer storing data. |
itead | 9:dec2cf52b744 | 373 | * @param buffer_size - guess what! |
itead | 9:dec2cf52b744 | 374 | * @param data_len - the length of data actually received(maybe more than buffer_size, the remained data will be abandoned). |
itead | 9:dec2cf52b744 | 375 | * @param timeout - the duration waitting data comming. |
itead | 9:dec2cf52b744 | 376 | * @param coming_mux_id - in single connection mode, should be NULL and not NULL in multiple. |
itead | 9:dec2cf52b744 | 377 | */ |
itead | 15:5c5a85e984a8 | 378 | uint32_t recvPkg(uint8_t *buffer, uint32_t buffer_size, uint32_t *data_len, uint32_t timeout, uint8_t *coming_mux_id); |
itead | 9:dec2cf52b744 | 379 | |
itead | 9:dec2cf52b744 | 380 | |
itead | 5:5fa655d7212c | 381 | bool eAT(void); |
itead | 5:5fa655d7212c | 382 | bool eATRST(void); |
itead | 6:18eb2d9fb2ac | 383 | bool eATGMR(String &version); |
itead | 5:5fa655d7212c | 384 | |
itead | 10:002615561b0b | 385 | bool qATCWMODE(uint8_t *mode); |
itead | 5:5fa655d7212c | 386 | bool sATCWMODE(uint8_t mode); |
itead | 6:18eb2d9fb2ac | 387 | bool sATCWJAP(String ssid, String pwd); |
itead | 6:18eb2d9fb2ac | 388 | bool eATCWLAP(String &list); |
itead | 6:18eb2d9fb2ac | 389 | bool eATCWQAP(void); |
itead | 6:18eb2d9fb2ac | 390 | bool sATCWSAP(String ssid, String pwd, uint8_t chl, uint8_t ecn); |
itead | 6:18eb2d9fb2ac | 391 | bool eATCWLIF(String &list); |
itead | 6:18eb2d9fb2ac | 392 | |
JojoS | 23:b888991fd6fd | 393 | bool eATCIPSTATUS(String &list, int *pStatus=NULL); |
itead | 6:18eb2d9fb2ac | 394 | bool sATCIPSTARTSingle(String type, String addr, uint32_t port); |
itead | 6:18eb2d9fb2ac | 395 | bool sATCIPSTARTMultiple(uint8_t mux_id, String type, String addr, uint32_t port); |
itead | 9:dec2cf52b744 | 396 | bool sATCIPSENDSingle(const uint8_t *buffer, uint32_t len); |
itead | 9:dec2cf52b744 | 397 | bool sATCIPSENDMultiple(uint8_t mux_id, const uint8_t *buffer, uint32_t len); |
itead | 6:18eb2d9fb2ac | 398 | bool sATCIPCLOSEMulitple(uint8_t mux_id); |
itead | 6:18eb2d9fb2ac | 399 | bool eATCIPCLOSESingle(void); |
itead | 6:18eb2d9fb2ac | 400 | bool eATCIFSR(String &list); |
itead | 6:18eb2d9fb2ac | 401 | bool sATCIPMUX(uint8_t mode); |
itead | 9:dec2cf52b744 | 402 | bool sATCIPSERVER(uint8_t mode, uint32_t port = 333); |
itead | 6:18eb2d9fb2ac | 403 | bool sATCIPSTO(uint32_t timeout); |
itead | 6:18eb2d9fb2ac | 404 | |
itead | 6:18eb2d9fb2ac | 405 | /* |
itead | 6:18eb2d9fb2ac | 406 | * +IPD,len:data |
itead | 6:18eb2d9fb2ac | 407 | * +IPD,id,len:data |
itead | 6:18eb2d9fb2ac | 408 | */ |
itead | 6:18eb2d9fb2ac | 409 | |
itead | 6:18eb2d9fb2ac | 410 | |
itead | 3:9f745022331a | 411 | ArduinoSerial *m_puart; /* The UART to communicate with ESP8266 */ |
itead | 1:edc634cad906 | 412 | |
itead | 1:edc634cad906 | 413 | }; |
itead | 0:d3b93948c925 | 414 | |
itead | 2:fb209f93f3f1 | 415 | #endif /* #ifndef __ESP8266_H__ */ |