hadif azli
/
TEST123
BLYNK TEST
ESP8266.cpp@5:8a3cf73d7ed3, 2021-01-26 (annotated)
- Committer:
- kenobi
- Date:
- Tue Jan 26 08:23:29 2021 +0000
- Revision:
- 5:8a3cf73d7ed3
- Parent:
- 3:4cd9171ba989
bLYNK
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
lixianyu | 3:4cd9171ba989 | 1 | /** |
lixianyu | 3:4cd9171ba989 | 2 | * @file ESP8266.cpp |
lixianyu | 3:4cd9171ba989 | 3 | * @brief The implementation of class ESP8266. |
lixianyu | 3:4cd9171ba989 | 4 | * @author Wu Pengfei<pengfei.wu@itead.cc> |
lixianyu | 3:4cd9171ba989 | 5 | * @date 2015.02 |
lixianyu | 3:4cd9171ba989 | 6 | * |
lixianyu | 3:4cd9171ba989 | 7 | * @par Copyright: |
lixianyu | 3:4cd9171ba989 | 8 | * Copyright (c) 2015 ITEAD Intelligent Systems Co., Ltd. \n\n |
lixianyu | 3:4cd9171ba989 | 9 | * This program is free software; you can redistribute it and/or |
lixianyu | 3:4cd9171ba989 | 10 | * modify it under the terms of the GNU General Public License as |
lixianyu | 3:4cd9171ba989 | 11 | * published by the Free Software Foundation; either version 2 of |
lixianyu | 3:4cd9171ba989 | 12 | * the License, or (at your option) any later version. \n\n |
lixianyu | 3:4cd9171ba989 | 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
lixianyu | 3:4cd9171ba989 | 14 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
lixianyu | 3:4cd9171ba989 | 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
lixianyu | 3:4cd9171ba989 | 16 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
lixianyu | 3:4cd9171ba989 | 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
lixianyu | 3:4cd9171ba989 | 18 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
lixianyu | 3:4cd9171ba989 | 19 | * THE SOFTWARE. |
lixianyu | 3:4cd9171ba989 | 20 | */ |
lixianyu | 3:4cd9171ba989 | 21 | #include "ESP8266_HardSer.h" |
lixianyu | 3:4cd9171ba989 | 22 | //#include <avr/pgmspace.h> |
lixianyu | 3:4cd9171ba989 | 23 | #ifdef ESP8266_USE_SOFTWARE_SERIAL |
lixianyu | 3:4cd9171ba989 | 24 | ESP8266::ESP8266(SoftwareSerial &uart): m_puart(&uart) |
lixianyu | 3:4cd9171ba989 | 25 | { |
lixianyu | 3:4cd9171ba989 | 26 | m_onData = NULL; |
lixianyu | 3:4cd9171ba989 | 27 | m_onDataPtr = NULL; |
lixianyu | 3:4cd9171ba989 | 28 | } |
lixianyu | 3:4cd9171ba989 | 29 | #else |
lixianyu | 3:4cd9171ba989 | 30 | ESP8266::ESP8266(HardwareSerial &uart): m_puart(&uart) |
lixianyu | 3:4cd9171ba989 | 31 | { |
lixianyu | 3:4cd9171ba989 | 32 | m_onData = NULL; |
lixianyu | 3:4cd9171ba989 | 33 | m_onDataPtr = NULL; |
lixianyu | 3:4cd9171ba989 | 34 | } |
lixianyu | 3:4cd9171ba989 | 35 | #endif |
lixianyu | 3:4cd9171ba989 | 36 | |
lixianyu | 3:4cd9171ba989 | 37 | bool ESP8266::kick(void) |
lixianyu | 3:4cd9171ba989 | 38 | { |
lixianyu | 3:4cd9171ba989 | 39 | LOG_ENTER; |
lixianyu | 3:4cd9171ba989 | 40 | return eAT(); |
lixianyu | 3:4cd9171ba989 | 41 | } |
lixianyu | 3:4cd9171ba989 | 42 | |
lixianyu | 3:4cd9171ba989 | 43 | bool ESP8266::restart(void) |
lixianyu | 3:4cd9171ba989 | 44 | { |
lixianyu | 3:4cd9171ba989 | 45 | LOG_ENTER; |
lixianyu | 3:4cd9171ba989 | 46 | unsigned long start; |
lixianyu | 3:4cd9171ba989 | 47 | if (eATRST()) { |
lixianyu | 3:4cd9171ba989 | 48 | //delay(2000); |
lixianyu | 3:4cd9171ba989 | 49 | wait_ms(2000); |
lixianyu | 3:4cd9171ba989 | 50 | //start = millis(); |
lixianyu | 3:4cd9171ba989 | 51 | start = g_Timer.read_ms(); |
lixianyu | 3:4cd9171ba989 | 52 | while (g_Timer.read_ms() - start < 3000) { |
lixianyu | 3:4cd9171ba989 | 53 | if (eAT()) { |
lixianyu | 3:4cd9171ba989 | 54 | //delay(1500); /* Waiting for stable */ |
lixianyu | 3:4cd9171ba989 | 55 | wait_ms(1500); |
lixianyu | 3:4cd9171ba989 | 56 | return true; |
lixianyu | 3:4cd9171ba989 | 57 | } |
lixianyu | 3:4cd9171ba989 | 58 | //delay(100); |
lixianyu | 3:4cd9171ba989 | 59 | wait_ms(100); |
lixianyu | 3:4cd9171ba989 | 60 | } |
lixianyu | 3:4cd9171ba989 | 61 | } |
lixianyu | 3:4cd9171ba989 | 62 | return false; |
lixianyu | 3:4cd9171ba989 | 63 | } |
lixianyu | 3:4cd9171ba989 | 64 | |
lixianyu | 3:4cd9171ba989 | 65 | String ESP8266::getVersion(void) |
lixianyu | 3:4cd9171ba989 | 66 | { |
lixianyu | 3:4cd9171ba989 | 67 | LOG_ENTER; |
lixianyu | 3:4cd9171ba989 | 68 | String version; |
lixianyu | 3:4cd9171ba989 | 69 | eATGMR(version); |
lixianyu | 3:4cd9171ba989 | 70 | return version; |
lixianyu | 3:4cd9171ba989 | 71 | } |
lixianyu | 3:4cd9171ba989 | 72 | |
lixianyu | 3:4cd9171ba989 | 73 | bool ESP8266::setEcho(uint8_t mode) |
lixianyu | 3:4cd9171ba989 | 74 | { |
lixianyu | 3:4cd9171ba989 | 75 | LOG_ENTER; |
lixianyu | 3:4cd9171ba989 | 76 | return eATE(mode); |
lixianyu | 3:4cd9171ba989 | 77 | } |
lixianyu | 3:4cd9171ba989 | 78 | |
lixianyu | 3:4cd9171ba989 | 79 | bool ESP8266::restore(void) |
lixianyu | 3:4cd9171ba989 | 80 | { |
lixianyu | 3:4cd9171ba989 | 81 | LOG_ENTER; |
lixianyu | 3:4cd9171ba989 | 82 | return eATRESTORE(); |
lixianyu | 3:4cd9171ba989 | 83 | } |
lixianyu | 3:4cd9171ba989 | 84 | |
lixianyu | 3:4cd9171ba989 | 85 | bool ESP8266::setUart(uint32_t baudrate,uint8_t pattern) |
lixianyu | 3:4cd9171ba989 | 86 | { |
lixianyu | 3:4cd9171ba989 | 87 | LOG_ENTER; |
lixianyu | 3:4cd9171ba989 | 88 | return eATSETUART(baudrate,pattern); |
lixianyu | 3:4cd9171ba989 | 89 | } |
lixianyu | 3:4cd9171ba989 | 90 | |
lixianyu | 3:4cd9171ba989 | 91 | bool ESP8266::deepSleep(uint32_t time) |
lixianyu | 3:4cd9171ba989 | 92 | { |
lixianyu | 3:4cd9171ba989 | 93 | LOG_ENTER; |
lixianyu | 3:4cd9171ba989 | 94 | return eATGSLP(time); |
lixianyu | 3:4cd9171ba989 | 95 | } |
lixianyu | 3:4cd9171ba989 | 96 | |
lixianyu | 3:4cd9171ba989 | 97 | bool ESP8266::setOprToStation(uint8_t pattern1,uint8_t pattern2) |
lixianyu | 3:4cd9171ba989 | 98 | { |
lixianyu | 3:4cd9171ba989 | 99 | LOG_ENTER; |
lixianyu | 3:4cd9171ba989 | 100 | uint8_t mode; |
lixianyu | 3:4cd9171ba989 | 101 | if (!qATCWMODE(&mode,pattern1)) { |
lixianyu | 3:4cd9171ba989 | 102 | return false; |
lixianyu | 3:4cd9171ba989 | 103 | } |
lixianyu | 3:4cd9171ba989 | 104 | if (mode == 1) { |
lixianyu | 3:4cd9171ba989 | 105 | return true; |
lixianyu | 3:4cd9171ba989 | 106 | } else { |
lixianyu | 3:4cd9171ba989 | 107 | if (sATCWMODE(1,pattern2)) { |
lixianyu | 3:4cd9171ba989 | 108 | return true; |
lixianyu | 3:4cd9171ba989 | 109 | } else { |
lixianyu | 3:4cd9171ba989 | 110 | return false; |
lixianyu | 3:4cd9171ba989 | 111 | } |
lixianyu | 3:4cd9171ba989 | 112 | } |
lixianyu | 3:4cd9171ba989 | 113 | } |
lixianyu | 3:4cd9171ba989 | 114 | |
lixianyu | 3:4cd9171ba989 | 115 | String ESP8266::getWifiModeList(void) |
lixianyu | 3:4cd9171ba989 | 116 | { |
lixianyu | 3:4cd9171ba989 | 117 | LOG_ENTER; |
lixianyu | 3:4cd9171ba989 | 118 | String list; |
lixianyu | 3:4cd9171ba989 | 119 | eATCWMODE(list); |
lixianyu | 3:4cd9171ba989 | 120 | return list; |
lixianyu | 3:4cd9171ba989 | 121 | } |
lixianyu | 3:4cd9171ba989 | 122 | |
lixianyu | 3:4cd9171ba989 | 123 | bool ESP8266::setOprToSoftAP(uint8_t pattern1,uint8_t pattern2) |
lixianyu | 3:4cd9171ba989 | 124 | { |
lixianyu | 3:4cd9171ba989 | 125 | LOG_ENTER; |
lixianyu | 3:4cd9171ba989 | 126 | uint8_t mode; |
lixianyu | 3:4cd9171ba989 | 127 | if (!qATCWMODE(&mode,pattern1)) { |
lixianyu | 3:4cd9171ba989 | 128 | return false; |
lixianyu | 3:4cd9171ba989 | 129 | } |
lixianyu | 3:4cd9171ba989 | 130 | if (mode == 2) { |
lixianyu | 3:4cd9171ba989 | 131 | return true; |
lixianyu | 3:4cd9171ba989 | 132 | } else { |
lixianyu | 3:4cd9171ba989 | 133 | if (sATCWMODE(2,pattern2) ) { |
lixianyu | 3:4cd9171ba989 | 134 | return true; |
lixianyu | 3:4cd9171ba989 | 135 | } else { |
lixianyu | 3:4cd9171ba989 | 136 | return false; |
lixianyu | 3:4cd9171ba989 | 137 | } |
lixianyu | 3:4cd9171ba989 | 138 | } |
lixianyu | 3:4cd9171ba989 | 139 | } |
lixianyu | 3:4cd9171ba989 | 140 | |
lixianyu | 3:4cd9171ba989 | 141 | bool ESP8266::setOprToStationSoftAP(uint8_t pattern1,uint8_t pattern2) |
lixianyu | 3:4cd9171ba989 | 142 | { |
lixianyu | 3:4cd9171ba989 | 143 | LOG_ENTER; |
lixianyu | 3:4cd9171ba989 | 144 | uint8_t mode; |
lixianyu | 3:4cd9171ba989 | 145 | if (!qATCWMODE(&mode,pattern1)) { |
lixianyu | 3:4cd9171ba989 | 146 | return false; |
lixianyu | 3:4cd9171ba989 | 147 | } |
lixianyu | 3:4cd9171ba989 | 148 | if (mode == 3) { |
lixianyu | 3:4cd9171ba989 | 149 | return true; |
lixianyu | 3:4cd9171ba989 | 150 | } else { |
lixianyu | 3:4cd9171ba989 | 151 | if (sATCWMODE(3,pattern2) ) { |
lixianyu | 3:4cd9171ba989 | 152 | return true; |
lixianyu | 3:4cd9171ba989 | 153 | } else { |
lixianyu | 3:4cd9171ba989 | 154 | return false; |
lixianyu | 3:4cd9171ba989 | 155 | } |
lixianyu | 3:4cd9171ba989 | 156 | } |
lixianyu | 3:4cd9171ba989 | 157 | } |
lixianyu | 3:4cd9171ba989 | 158 | |
lixianyu | 3:4cd9171ba989 | 159 | uint8_t ESP8266::getOprMode(uint8_t pattern1) |
lixianyu | 3:4cd9171ba989 | 160 | { |
lixianyu | 3:4cd9171ba989 | 161 | LOG_ENTER; |
lixianyu | 3:4cd9171ba989 | 162 | uint8_t mode; |
lixianyu | 3:4cd9171ba989 | 163 | if (!qATCWMODE(&mode,pattern1)) { |
lixianyu | 3:4cd9171ba989 | 164 | return 0; |
lixianyu | 3:4cd9171ba989 | 165 | } else { |
lixianyu | 3:4cd9171ba989 | 166 | return mode; |
lixianyu | 3:4cd9171ba989 | 167 | } |
lixianyu | 3:4cd9171ba989 | 168 | } |
lixianyu | 3:4cd9171ba989 | 169 | |
lixianyu | 3:4cd9171ba989 | 170 | String ESP8266::getNowConecAp(uint8_t pattern) |
lixianyu | 3:4cd9171ba989 | 171 | { |
lixianyu | 3:4cd9171ba989 | 172 | LOG_ENTER; |
lixianyu | 3:4cd9171ba989 | 173 | String ssid; |
lixianyu | 3:4cd9171ba989 | 174 | qATCWJAP(ssid,pattern); |
lixianyu | 3:4cd9171ba989 | 175 | return ssid; |
lixianyu | 3:4cd9171ba989 | 176 | } |
lixianyu | 3:4cd9171ba989 | 177 | |
lixianyu | 3:4cd9171ba989 | 178 | String ESP8266::getAPList(void) |
lixianyu | 3:4cd9171ba989 | 179 | { |
lixianyu | 3:4cd9171ba989 | 180 | LOG_ENTER; |
lixianyu | 3:4cd9171ba989 | 181 | String list; |
lixianyu | 3:4cd9171ba989 | 182 | eATCWLAP(list); |
lixianyu | 3:4cd9171ba989 | 183 | return list; |
lixianyu | 3:4cd9171ba989 | 184 | } |
lixianyu | 3:4cd9171ba989 | 185 | |
lixianyu | 3:4cd9171ba989 | 186 | bool ESP8266::joinAP(String ssid, String pwd,uint8_t pattern) |
lixianyu | 3:4cd9171ba989 | 187 | { |
lixianyu | 3:4cd9171ba989 | 188 | LOG_ENTER; |
lixianyu | 3:4cd9171ba989 | 189 | return sATCWJAP(ssid, pwd,pattern); |
lixianyu | 3:4cd9171ba989 | 190 | } |
lixianyu | 3:4cd9171ba989 | 191 | |
lixianyu | 3:4cd9171ba989 | 192 | bool ESP8266::leaveAP(void) |
lixianyu | 3:4cd9171ba989 | 193 | { |
lixianyu | 3:4cd9171ba989 | 194 | LOG_ENTER; |
lixianyu | 3:4cd9171ba989 | 195 | return eATCWQAP(); |
lixianyu | 3:4cd9171ba989 | 196 | } |
lixianyu | 3:4cd9171ba989 | 197 | |
lixianyu | 3:4cd9171ba989 | 198 | String ESP8266::getSoftAPParam(uint8_t pattern) |
lixianyu | 3:4cd9171ba989 | 199 | { |
lixianyu | 3:4cd9171ba989 | 200 | LOG_ENTER; |
lixianyu | 3:4cd9171ba989 | 201 | String list; |
lixianyu | 3:4cd9171ba989 | 202 | qATCWSAP(list,pattern); |
lixianyu | 3:4cd9171ba989 | 203 | return list; |
lixianyu | 3:4cd9171ba989 | 204 | } |
lixianyu | 3:4cd9171ba989 | 205 | |
lixianyu | 3:4cd9171ba989 | 206 | bool ESP8266::setSoftAPParam(String ssid, String pwd, uint8_t chl, uint8_t ecn,uint8_t pattern) |
lixianyu | 3:4cd9171ba989 | 207 | { |
lixianyu | 3:4cd9171ba989 | 208 | LOG_ENTER; |
lixianyu | 3:4cd9171ba989 | 209 | return sATCWSAP(ssid, pwd, chl, ecn,pattern); |
lixianyu | 3:4cd9171ba989 | 210 | } |
lixianyu | 3:4cd9171ba989 | 211 | |
lixianyu | 3:4cd9171ba989 | 212 | String ESP8266::getJoinedDeviceIP(void) |
lixianyu | 3:4cd9171ba989 | 213 | { |
lixianyu | 3:4cd9171ba989 | 214 | LOG_ENTER; |
lixianyu | 3:4cd9171ba989 | 215 | String list; |
lixianyu | 3:4cd9171ba989 | 216 | eATCWLIF(list); |
lixianyu | 3:4cd9171ba989 | 217 | return list; |
lixianyu | 3:4cd9171ba989 | 218 | } |
lixianyu | 3:4cd9171ba989 | 219 | |
lixianyu | 3:4cd9171ba989 | 220 | String ESP8266::getDHCP(uint8_t pattern) |
lixianyu | 3:4cd9171ba989 | 221 | { |
lixianyu | 3:4cd9171ba989 | 222 | LOG_ENTER; |
lixianyu | 3:4cd9171ba989 | 223 | String dhcp; |
lixianyu | 3:4cd9171ba989 | 224 | qATCWDHCP(dhcp,pattern); |
lixianyu | 3:4cd9171ba989 | 225 | return dhcp; |
lixianyu | 3:4cd9171ba989 | 226 | } |
lixianyu | 3:4cd9171ba989 | 227 | |
lixianyu | 3:4cd9171ba989 | 228 | bool ESP8266::setDHCP(uint8_t mode, uint8_t en, uint8_t pattern) |
lixianyu | 3:4cd9171ba989 | 229 | { |
lixianyu | 3:4cd9171ba989 | 230 | LOG_ENTER; |
lixianyu | 3:4cd9171ba989 | 231 | return sATCWDHCP(mode, en, pattern); |
lixianyu | 3:4cd9171ba989 | 232 | } |
lixianyu | 3:4cd9171ba989 | 233 | |
lixianyu | 3:4cd9171ba989 | 234 | bool ESP8266::setAutoConnect(uint8_t en) |
lixianyu | 3:4cd9171ba989 | 235 | { |
lixianyu | 3:4cd9171ba989 | 236 | LOG_ENTER; |
lixianyu | 3:4cd9171ba989 | 237 | return eATCWAUTOCONN(en); |
lixianyu | 3:4cd9171ba989 | 238 | } |
lixianyu | 3:4cd9171ba989 | 239 | |
lixianyu | 3:4cd9171ba989 | 240 | String ESP8266::getStationMac(uint8_t pattern) |
lixianyu | 3:4cd9171ba989 | 241 | { |
lixianyu | 3:4cd9171ba989 | 242 | LOG_ENTER; |
lixianyu | 3:4cd9171ba989 | 243 | String mac; |
lixianyu | 3:4cd9171ba989 | 244 | qATCIPSTAMAC(mac,pattern); |
lixianyu | 3:4cd9171ba989 | 245 | return mac; |
lixianyu | 3:4cd9171ba989 | 246 | } |
lixianyu | 3:4cd9171ba989 | 247 | |
lixianyu | 3:4cd9171ba989 | 248 | bool ESP8266::setStationMac(String mac,uint8_t pattern) |
lixianyu | 3:4cd9171ba989 | 249 | { |
lixianyu | 3:4cd9171ba989 | 250 | LOG_ENTER; |
lixianyu | 3:4cd9171ba989 | 251 | return eATCIPSTAMAC(mac,pattern); |
lixianyu | 3:4cd9171ba989 | 252 | } |
lixianyu | 3:4cd9171ba989 | 253 | |
lixianyu | 3:4cd9171ba989 | 254 | String ESP8266::getStationIp(uint8_t pattern) |
lixianyu | 3:4cd9171ba989 | 255 | { |
lixianyu | 3:4cd9171ba989 | 256 | LOG_ENTER; |
lixianyu | 3:4cd9171ba989 | 257 | String ip; |
lixianyu | 3:4cd9171ba989 | 258 | qATCIPSTAIP(ip,pattern); |
lixianyu | 3:4cd9171ba989 | 259 | return ip; |
lixianyu | 3:4cd9171ba989 | 260 | } |
lixianyu | 3:4cd9171ba989 | 261 | |
lixianyu | 3:4cd9171ba989 | 262 | bool ESP8266::setStationIp(String ip,String gateway,String netmask,uint8_t pattern) |
lixianyu | 3:4cd9171ba989 | 263 | { |
lixianyu | 3:4cd9171ba989 | 264 | LOG_ENTER; |
lixianyu | 3:4cd9171ba989 | 265 | return eATCIPSTAIP(ip,gateway,netmask,pattern); |
lixianyu | 3:4cd9171ba989 | 266 | } |
lixianyu | 3:4cd9171ba989 | 267 | |
lixianyu | 3:4cd9171ba989 | 268 | String ESP8266::getAPIp(uint8_t pattern) |
lixianyu | 3:4cd9171ba989 | 269 | { |
lixianyu | 3:4cd9171ba989 | 270 | LOG_ENTER; |
lixianyu | 3:4cd9171ba989 | 271 | String ip; |
lixianyu | 3:4cd9171ba989 | 272 | qATCIPAP(ip,pattern); |
lixianyu | 3:4cd9171ba989 | 273 | return ip; |
lixianyu | 3:4cd9171ba989 | 274 | } |
lixianyu | 3:4cd9171ba989 | 275 | |
lixianyu | 3:4cd9171ba989 | 276 | bool ESP8266::setAPIp(String ip,uint8_t pattern) |
lixianyu | 3:4cd9171ba989 | 277 | { |
lixianyu | 3:4cd9171ba989 | 278 | LOG_ENTER; |
lixianyu | 3:4cd9171ba989 | 279 | return eATCIPAP(ip,pattern); |
lixianyu | 3:4cd9171ba989 | 280 | } |
lixianyu | 3:4cd9171ba989 | 281 | |
lixianyu | 3:4cd9171ba989 | 282 | bool ESP8266::startSmartConfig(uint8_t type) |
lixianyu | 3:4cd9171ba989 | 283 | { |
lixianyu | 3:4cd9171ba989 | 284 | LOG_ENTER; |
lixianyu | 3:4cd9171ba989 | 285 | return eCWSTARTSMART(type); |
lixianyu | 3:4cd9171ba989 | 286 | } |
lixianyu | 3:4cd9171ba989 | 287 | |
lixianyu | 3:4cd9171ba989 | 288 | bool ESP8266::stopSmartConfig(void) |
lixianyu | 3:4cd9171ba989 | 289 | { |
lixianyu | 3:4cd9171ba989 | 290 | LOG_ENTER; |
lixianyu | 3:4cd9171ba989 | 291 | return eCWSTOPSMART(); |
lixianyu | 3:4cd9171ba989 | 292 | } |
lixianyu | 3:4cd9171ba989 | 293 | |
lixianyu | 3:4cd9171ba989 | 294 | |
lixianyu | 3:4cd9171ba989 | 295 | String ESP8266::getIPStatus(void) |
lixianyu | 3:4cd9171ba989 | 296 | { |
lixianyu | 3:4cd9171ba989 | 297 | LOG_ENTER; |
lixianyu | 3:4cd9171ba989 | 298 | String list; |
lixianyu | 3:4cd9171ba989 | 299 | eATCIPSTATUS(list); |
lixianyu | 3:4cd9171ba989 | 300 | return list; |
lixianyu | 3:4cd9171ba989 | 301 | } |
lixianyu | 3:4cd9171ba989 | 302 | |
lixianyu | 3:4cd9171ba989 | 303 | String ESP8266::getLocalIP(void) |
lixianyu | 3:4cd9171ba989 | 304 | { |
lixianyu | 3:4cd9171ba989 | 305 | LOG_ENTER; |
lixianyu | 3:4cd9171ba989 | 306 | String list; |
lixianyu | 3:4cd9171ba989 | 307 | eATCIFSR(list); |
lixianyu | 3:4cd9171ba989 | 308 | return list; |
lixianyu | 3:4cd9171ba989 | 309 | } |
lixianyu | 3:4cd9171ba989 | 310 | |
lixianyu | 3:4cd9171ba989 | 311 | bool ESP8266::enableMUX(void) |
lixianyu | 3:4cd9171ba989 | 312 | { |
lixianyu | 3:4cd9171ba989 | 313 | LOG_ENTER; |
lixianyu | 3:4cd9171ba989 | 314 | return sATCIPMUX(1); |
lixianyu | 3:4cd9171ba989 | 315 | } |
lixianyu | 3:4cd9171ba989 | 316 | |
lixianyu | 3:4cd9171ba989 | 317 | bool ESP8266::disableMUX(void) |
lixianyu | 3:4cd9171ba989 | 318 | { |
lixianyu | 3:4cd9171ba989 | 319 | LOG_ENTER; |
lixianyu | 3:4cd9171ba989 | 320 | return sATCIPMUX(0); |
lixianyu | 3:4cd9171ba989 | 321 | } |
lixianyu | 3:4cd9171ba989 | 322 | |
lixianyu | 3:4cd9171ba989 | 323 | bool ESP8266::createTCP(String addr, uint32_t port) |
lixianyu | 3:4cd9171ba989 | 324 | { |
lixianyu | 3:4cd9171ba989 | 325 | LOG_ENTER; |
lixianyu | 3:4cd9171ba989 | 326 | return sATCIPSTARTSingle("TCP", addr, port); |
lixianyu | 3:4cd9171ba989 | 327 | } |
lixianyu | 3:4cd9171ba989 | 328 | |
lixianyu | 3:4cd9171ba989 | 329 | bool ESP8266::releaseTCP(void) |
lixianyu | 3:4cd9171ba989 | 330 | { |
lixianyu | 3:4cd9171ba989 | 331 | LOG_ENTER; |
lixianyu | 3:4cd9171ba989 | 332 | return eATCIPCLOSESingle(); |
lixianyu | 3:4cd9171ba989 | 333 | } |
lixianyu | 3:4cd9171ba989 | 334 | |
lixianyu | 3:4cd9171ba989 | 335 | bool ESP8266::registerUDP(String addr, uint32_t port) |
lixianyu | 3:4cd9171ba989 | 336 | { |
lixianyu | 3:4cd9171ba989 | 337 | LOG_ENTER; |
lixianyu | 3:4cd9171ba989 | 338 | return sATCIPSTARTSingle("UDP", addr, port); |
lixianyu | 3:4cd9171ba989 | 339 | } |
lixianyu | 3:4cd9171ba989 | 340 | |
lixianyu | 3:4cd9171ba989 | 341 | bool ESP8266::unregisterUDP(void) |
lixianyu | 3:4cd9171ba989 | 342 | { |
lixianyu | 3:4cd9171ba989 | 343 | LOG_ENTER; |
lixianyu | 3:4cd9171ba989 | 344 | return eATCIPCLOSESingle(); |
lixianyu | 3:4cd9171ba989 | 345 | } |
lixianyu | 3:4cd9171ba989 | 346 | |
lixianyu | 3:4cd9171ba989 | 347 | bool ESP8266::createTCP(uint8_t mux_id, String addr, uint32_t port) |
lixianyu | 3:4cd9171ba989 | 348 | { |
lixianyu | 3:4cd9171ba989 | 349 | LOG_ENTER; |
lixianyu | 3:4cd9171ba989 | 350 | return sATCIPSTARTMultiple(mux_id, "TCP", addr, port); |
lixianyu | 3:4cd9171ba989 | 351 | } |
lixianyu | 3:4cd9171ba989 | 352 | |
lixianyu | 3:4cd9171ba989 | 353 | bool ESP8266::releaseTCP(uint8_t mux_id) |
lixianyu | 3:4cd9171ba989 | 354 | { |
lixianyu | 3:4cd9171ba989 | 355 | LOG_ENTER; |
lixianyu | 3:4cd9171ba989 | 356 | return sATCIPCLOSEMulitple(mux_id); |
lixianyu | 3:4cd9171ba989 | 357 | } |
lixianyu | 3:4cd9171ba989 | 358 | |
lixianyu | 3:4cd9171ba989 | 359 | bool ESP8266::registerUDP(uint8_t mux_id, String addr, uint32_t port) |
lixianyu | 3:4cd9171ba989 | 360 | { |
lixianyu | 3:4cd9171ba989 | 361 | LOG_ENTER; |
lixianyu | 3:4cd9171ba989 | 362 | return sATCIPSTARTMultiple(mux_id, "UDP", addr, port); |
lixianyu | 3:4cd9171ba989 | 363 | } |
lixianyu | 3:4cd9171ba989 | 364 | |
lixianyu | 3:4cd9171ba989 | 365 | bool ESP8266::unregisterUDP(uint8_t mux_id) |
lixianyu | 3:4cd9171ba989 | 366 | { |
lixianyu | 3:4cd9171ba989 | 367 | LOG_ENTER; |
lixianyu | 3:4cd9171ba989 | 368 | return sATCIPCLOSEMulitple(mux_id); |
lixianyu | 3:4cd9171ba989 | 369 | } |
lixianyu | 3:4cd9171ba989 | 370 | |
lixianyu | 3:4cd9171ba989 | 371 | bool ESP8266::setTCPServerTimeout(uint32_t timeout) |
lixianyu | 3:4cd9171ba989 | 372 | { |
lixianyu | 3:4cd9171ba989 | 373 | LOG_ENTER; |
lixianyu | 3:4cd9171ba989 | 374 | return sATCIPSTO(timeout); |
lixianyu | 3:4cd9171ba989 | 375 | } |
lixianyu | 3:4cd9171ba989 | 376 | |
lixianyu | 3:4cd9171ba989 | 377 | bool ESP8266::startTCPServer(uint32_t port) |
lixianyu | 3:4cd9171ba989 | 378 | { |
lixianyu | 3:4cd9171ba989 | 379 | LOG_ENTER; |
lixianyu | 3:4cd9171ba989 | 380 | if (sATCIPSERVER(1, port)) { |
lixianyu | 3:4cd9171ba989 | 381 | return true; |
lixianyu | 3:4cd9171ba989 | 382 | } |
lixianyu | 3:4cd9171ba989 | 383 | return false; |
lixianyu | 3:4cd9171ba989 | 384 | } |
lixianyu | 3:4cd9171ba989 | 385 | |
lixianyu | 3:4cd9171ba989 | 386 | bool ESP8266::stopTCPServer(void) |
lixianyu | 3:4cd9171ba989 | 387 | { |
lixianyu | 3:4cd9171ba989 | 388 | LOG_ENTER; |
lixianyu | 3:4cd9171ba989 | 389 | sATCIPSERVER(0); |
lixianyu | 3:4cd9171ba989 | 390 | restart(); |
lixianyu | 3:4cd9171ba989 | 391 | return false; |
lixianyu | 3:4cd9171ba989 | 392 | } |
lixianyu | 3:4cd9171ba989 | 393 | |
lixianyu | 3:4cd9171ba989 | 394 | bool ESP8266::setCIPMODE(uint8_t mode) |
lixianyu | 3:4cd9171ba989 | 395 | { |
lixianyu | 3:4cd9171ba989 | 396 | LOG_ENTER; |
lixianyu | 3:4cd9171ba989 | 397 | return sATCIPMODE(mode); |
lixianyu | 3:4cd9171ba989 | 398 | } |
lixianyu | 3:4cd9171ba989 | 399 | |
lixianyu | 3:4cd9171ba989 | 400 | bool ESP8266::saveTransLink (uint8_t mode,String ip,uint32_t port) |
lixianyu | 3:4cd9171ba989 | 401 | { |
lixianyu | 3:4cd9171ba989 | 402 | LOG_ENTER; |
lixianyu | 3:4cd9171ba989 | 403 | return eATSAVETRANSLINK(mode,ip,port); |
lixianyu | 3:4cd9171ba989 | 404 | } |
lixianyu | 3:4cd9171ba989 | 405 | |
lixianyu | 3:4cd9171ba989 | 406 | bool ESP8266::setPing(String ip) |
lixianyu | 3:4cd9171ba989 | 407 | { |
lixianyu | 3:4cd9171ba989 | 408 | LOG_ENTER; |
lixianyu | 3:4cd9171ba989 | 409 | return eATPING(ip); |
lixianyu | 3:4cd9171ba989 | 410 | } |
lixianyu | 3:4cd9171ba989 | 411 | |
lixianyu | 3:4cd9171ba989 | 412 | |
lixianyu | 3:4cd9171ba989 | 413 | bool ESP8266::startServer(uint32_t port) |
lixianyu | 3:4cd9171ba989 | 414 | { |
lixianyu | 3:4cd9171ba989 | 415 | LOG_ENTER; |
lixianyu | 3:4cd9171ba989 | 416 | return startTCPServer(port); |
lixianyu | 3:4cd9171ba989 | 417 | } |
lixianyu | 3:4cd9171ba989 | 418 | |
lixianyu | 3:4cd9171ba989 | 419 | bool ESP8266::stopServer(void) |
lixianyu | 3:4cd9171ba989 | 420 | { |
lixianyu | 3:4cd9171ba989 | 421 | LOG_ENTER; |
lixianyu | 3:4cd9171ba989 | 422 | return stopTCPServer(); |
lixianyu | 3:4cd9171ba989 | 423 | } |
lixianyu | 3:4cd9171ba989 | 424 | |
lixianyu | 3:4cd9171ba989 | 425 | bool ESP8266::send(const uint8_t *buffer, uint32_t len) |
lixianyu | 3:4cd9171ba989 | 426 | { |
lixianyu | 3:4cd9171ba989 | 427 | LOG_ENTER; |
lixianyu | 3:4cd9171ba989 | 428 | return sATCIPSENDSingle(buffer, len); |
lixianyu | 3:4cd9171ba989 | 429 | } |
lixianyu | 3:4cd9171ba989 | 430 | |
lixianyu | 3:4cd9171ba989 | 431 | bool ESP8266::sendFromFlash(uint8_t mux_id, const uint8_t *buffer, uint32_t len) |
lixianyu | 3:4cd9171ba989 | 432 | { |
lixianyu | 3:4cd9171ba989 | 433 | LOG_ENTER; |
lixianyu | 3:4cd9171ba989 | 434 | return sATCIPSENDMultipleFromFlash(mux_id, buffer, len); |
lixianyu | 3:4cd9171ba989 | 435 | } |
lixianyu | 3:4cd9171ba989 | 436 | |
lixianyu | 3:4cd9171ba989 | 437 | bool ESP8266::sendFromFlash(const uint8_t *buffer, uint32_t len) |
lixianyu | 3:4cd9171ba989 | 438 | { |
lixianyu | 3:4cd9171ba989 | 439 | LOG_ENTER; |
lixianyu | 3:4cd9171ba989 | 440 | return sATCIPSENDSingleFromFlash(buffer, len); |
lixianyu | 3:4cd9171ba989 | 441 | } |
lixianyu | 3:4cd9171ba989 | 442 | |
lixianyu | 3:4cd9171ba989 | 443 | bool ESP8266::send(uint8_t mux_id, const uint8_t *buffer, uint32_t len) |
lixianyu | 3:4cd9171ba989 | 444 | { |
lixianyu | 3:4cd9171ba989 | 445 | LOG_ENTER; |
lixianyu | 3:4cd9171ba989 | 446 | return sATCIPSENDMultiple(mux_id, buffer, len); |
lixianyu | 3:4cd9171ba989 | 447 | } |
lixianyu | 3:4cd9171ba989 | 448 | |
lixianyu | 3:4cd9171ba989 | 449 | void ESP8266::run() |
lixianyu | 3:4cd9171ba989 | 450 | { |
lixianyu | 3:4cd9171ba989 | 451 | LOG_ENTER; |
lixianyu | 3:4cd9171ba989 | 452 | rx_empty(); |
lixianyu | 3:4cd9171ba989 | 453 | } |
lixianyu | 3:4cd9171ba989 | 454 | |
lixianyu | 3:4cd9171ba989 | 455 | /*----------------------------------------------------------------------------*/ |
lixianyu | 3:4cd9171ba989 | 456 | /* +IPD,<id>,<len>:<data> */ |
lixianyu | 3:4cd9171ba989 | 457 | /* +IPD,<len>:<data> */ |
lixianyu | 3:4cd9171ba989 | 458 | |
lixianyu | 3:4cd9171ba989 | 459 | uint32_t ESP8266::checkIPD(String& data) |
lixianyu | 3:4cd9171ba989 | 460 | { |
lixianyu | 3:4cd9171ba989 | 461 | //Serial.print("### check: "); |
lixianyu | 3:4cd9171ba989 | 462 | //Serial.println(data); |
lixianyu | 3:4cd9171ba989 | 463 | LOG_ENTER; |
lixianyu | 3:4cd9171ba989 | 464 | int32_t index_PIPDcomma = -1; |
lixianyu | 3:4cd9171ba989 | 465 | int32_t index_colon = -1; /* : */ |
lixianyu | 3:4cd9171ba989 | 466 | int32_t index_comma = -1; /* , */ |
lixianyu | 3:4cd9171ba989 | 467 | int32_t len = -1; |
lixianyu | 3:4cd9171ba989 | 468 | int8_t id = -1; |
lixianyu | 3:4cd9171ba989 | 469 | { |
lixianyu | 3:4cd9171ba989 | 470 | // Just for easier diffing |
lixianyu | 3:4cd9171ba989 | 471 | index_PIPDcomma = data.indexOf("+IPD,"); |
lixianyu | 3:4cd9171ba989 | 472 | if (index_PIPDcomma != -1) { |
lixianyu | 3:4cd9171ba989 | 473 | index_colon = data.indexOf(':', index_PIPDcomma + 5); |
lixianyu | 3:4cd9171ba989 | 474 | if (index_colon != -1) { |
lixianyu | 3:4cd9171ba989 | 475 | index_comma = data.indexOf(',', index_PIPDcomma + 5); |
lixianyu | 3:4cd9171ba989 | 476 | /* +IPD,id,len:data */ |
lixianyu | 3:4cd9171ba989 | 477 | if (index_comma != -1 && index_comma < index_colon) { |
lixianyu | 3:4cd9171ba989 | 478 | id = data.substring(index_PIPDcomma + 5, index_comma).toInt(); |
lixianyu | 3:4cd9171ba989 | 479 | if (id < 0 || id > 4) { |
lixianyu | 3:4cd9171ba989 | 480 | return 0; |
lixianyu | 3:4cd9171ba989 | 481 | } |
lixianyu | 3:4cd9171ba989 | 482 | len = data.substring(index_comma + 1, index_colon).toInt(); |
lixianyu | 3:4cd9171ba989 | 483 | if (len <= 0) { |
lixianyu | 3:4cd9171ba989 | 484 | return 0; |
lixianyu | 3:4cd9171ba989 | 485 | } |
lixianyu | 3:4cd9171ba989 | 486 | } else { /* +IPD,len:data */ |
lixianyu | 3:4cd9171ba989 | 487 | len = data.substring(index_PIPDcomma + 5, index_colon).toInt(); |
lixianyu | 3:4cd9171ba989 | 488 | if (len <= 0) { |
lixianyu | 3:4cd9171ba989 | 489 | return 0; |
lixianyu | 3:4cd9171ba989 | 490 | } |
lixianyu | 3:4cd9171ba989 | 491 | } |
lixianyu | 3:4cd9171ba989 | 492 | if (m_onData) { |
lixianyu | 3:4cd9171ba989 | 493 | m_onData(id, len, m_onDataPtr); |
lixianyu | 3:4cd9171ba989 | 494 | } |
lixianyu | 3:4cd9171ba989 | 495 | return len; |
lixianyu | 3:4cd9171ba989 | 496 | } |
lixianyu | 3:4cd9171ba989 | 497 | } |
lixianyu | 3:4cd9171ba989 | 498 | } |
lixianyu | 3:4cd9171ba989 | 499 | return 0; |
lixianyu | 3:4cd9171ba989 | 500 | } |
lixianyu | 3:4cd9171ba989 | 501 | |
lixianyu | 3:4cd9171ba989 | 502 | void ESP8266::rx_empty(void) |
lixianyu | 3:4cd9171ba989 | 503 | { |
lixianyu | 3:4cd9171ba989 | 504 | LOG_ENTER; |
lixianyu | 3:4cd9171ba989 | 505 | String data; |
lixianyu | 3:4cd9171ba989 | 506 | char a; |
lixianyu | 3:4cd9171ba989 | 507 | unsigned long start = g_Timer.read_ms(); |
lixianyu | 3:4cd9171ba989 | 508 | while (g_Timer.read_ms() - start < 10) { |
lixianyu | 3:4cd9171ba989 | 509 | if (m_puart->readable()) { |
lixianyu | 3:4cd9171ba989 | 510 | a = m_puart->getc(); |
lixianyu | 3:4cd9171ba989 | 511 | if(a == '\0') continue; |
lixianyu | 3:4cd9171ba989 | 512 | data += a; |
lixianyu | 3:4cd9171ba989 | 513 | if (checkIPD(data)) { |
lixianyu | 3:4cd9171ba989 | 514 | data = ""; |
lixianyu | 3:4cd9171ba989 | 515 | } |
lixianyu | 3:4cd9171ba989 | 516 | start = g_Timer.read_ms(); |
lixianyu | 3:4cd9171ba989 | 517 | } |
lixianyu | 3:4cd9171ba989 | 518 | } |
lixianyu | 3:4cd9171ba989 | 519 | } |
lixianyu | 3:4cd9171ba989 | 520 | |
lixianyu | 3:4cd9171ba989 | 521 | String ESP8266::recvString(String target, uint32_t timeout) |
lixianyu | 3:4cd9171ba989 | 522 | { |
lixianyu | 3:4cd9171ba989 | 523 | LOG_ENTER; |
lixianyu | 3:4cd9171ba989 | 524 | String data; |
lixianyu | 3:4cd9171ba989 | 525 | char a; |
lixianyu | 3:4cd9171ba989 | 526 | unsigned long start = g_Timer.read_ms(); |
lixianyu | 3:4cd9171ba989 | 527 | while (g_Timer.read_ms() - start < timeout) { |
lixianyu | 3:4cd9171ba989 | 528 | while(m_puart->readable() > 0) { |
lixianyu | 3:4cd9171ba989 | 529 | a = m_puart->getc(); |
lixianyu | 3:4cd9171ba989 | 530 | ESP8266_LOG("a=0x%02X ", a); |
lixianyu | 3:4cd9171ba989 | 531 | if(a == '\0') continue; |
lixianyu | 3:4cd9171ba989 | 532 | data += a; |
lixianyu | 3:4cd9171ba989 | 533 | if (data.indexOf(target) != -1) { |
lixianyu | 3:4cd9171ba989 | 534 | ESP8266_LOG("\r\ndata = %s\r\n", data.c_str()); |
lixianyu | 3:4cd9171ba989 | 535 | return data; |
lixianyu | 3:4cd9171ba989 | 536 | } else if (checkIPD(data)) { |
lixianyu | 3:4cd9171ba989 | 537 | data = ""; |
lixianyu | 3:4cd9171ba989 | 538 | } |
lixianyu | 3:4cd9171ba989 | 539 | } |
lixianyu | 3:4cd9171ba989 | 540 | } |
lixianyu | 3:4cd9171ba989 | 541 | ESP8266_LOG("\r\n"); |
lixianyu | 3:4cd9171ba989 | 542 | ESP8266_LOG("data1 = %s\r\n", data.c_str()); |
lixianyu | 3:4cd9171ba989 | 543 | return data; |
lixianyu | 3:4cd9171ba989 | 544 | } |
lixianyu | 3:4cd9171ba989 | 545 | |
lixianyu | 3:4cd9171ba989 | 546 | String ESP8266::recvString(String target1, String target2, uint32_t timeout) |
lixianyu | 3:4cd9171ba989 | 547 | { |
lixianyu | 3:4cd9171ba989 | 548 | LOG_ENTER; |
lixianyu | 3:4cd9171ba989 | 549 | String data; |
lixianyu | 3:4cd9171ba989 | 550 | char a; |
lixianyu | 3:4cd9171ba989 | 551 | unsigned long start = g_Timer.read_ms(); |
lixianyu | 3:4cd9171ba989 | 552 | while (g_Timer.read_ms() - start < timeout) { |
lixianyu | 3:4cd9171ba989 | 553 | while(m_puart->readable() > 0) { |
lixianyu | 3:4cd9171ba989 | 554 | a = m_puart->getc(); |
lixianyu | 3:4cd9171ba989 | 555 | ESP8266_LOG("a=0x%02x ", a); |
lixianyu | 3:4cd9171ba989 | 556 | if(a == '\0') continue; |
lixianyu | 3:4cd9171ba989 | 557 | data += a; |
lixianyu | 3:4cd9171ba989 | 558 | if (data.indexOf(target1) != -1) { |
lixianyu | 3:4cd9171ba989 | 559 | ESP8266_LOG("\r\ndata2 = %s\r\n", data.c_str()); |
lixianyu | 3:4cd9171ba989 | 560 | return data; |
lixianyu | 3:4cd9171ba989 | 561 | } else if (data.indexOf(target2) != -1) { |
lixianyu | 3:4cd9171ba989 | 562 | ESP8266_LOG("\r\ndata3 = %s\r\n", data.c_str()); |
lixianyu | 3:4cd9171ba989 | 563 | return data; |
lixianyu | 3:4cd9171ba989 | 564 | } else if (checkIPD(data)) { |
lixianyu | 3:4cd9171ba989 | 565 | data = ""; |
lixianyu | 3:4cd9171ba989 | 566 | } |
lixianyu | 3:4cd9171ba989 | 567 | } |
lixianyu | 3:4cd9171ba989 | 568 | } |
lixianyu | 3:4cd9171ba989 | 569 | ESP8266_LOG("\r\ndata4 = %s\r\n", data.c_str()); |
lixianyu | 3:4cd9171ba989 | 570 | return data; |
lixianyu | 3:4cd9171ba989 | 571 | } |
lixianyu | 3:4cd9171ba989 | 572 | |
lixianyu | 3:4cd9171ba989 | 573 | String ESP8266::recvString(String target1, String target2, String target3, uint32_t timeout) |
lixianyu | 3:4cd9171ba989 | 574 | { |
lixianyu | 3:4cd9171ba989 | 575 | LOG_ENTER; |
lixianyu | 3:4cd9171ba989 | 576 | String data; |
lixianyu | 3:4cd9171ba989 | 577 | char a; |
lixianyu | 3:4cd9171ba989 | 578 | unsigned long start = g_Timer.read_ms(); |
lixianyu | 3:4cd9171ba989 | 579 | while (g_Timer.read_ms() - start < timeout) { |
lixianyu | 3:4cd9171ba989 | 580 | while(m_puart->readable() > 0) { |
lixianyu | 3:4cd9171ba989 | 581 | a = m_puart->getc(); |
lixianyu | 3:4cd9171ba989 | 582 | ESP8266_LOG("a=0x%02x ", a); |
lixianyu | 3:4cd9171ba989 | 583 | if(a == '\0') continue; |
lixianyu | 3:4cd9171ba989 | 584 | data += a; |
lixianyu | 3:4cd9171ba989 | 585 | |
lixianyu | 3:4cd9171ba989 | 586 | if (data.indexOf(target1) != -1) { |
lixianyu | 3:4cd9171ba989 | 587 | ESP8266_LOG("\r\ndata5 = %s\r\n", data.c_str()); |
lixianyu | 3:4cd9171ba989 | 588 | return data; |
lixianyu | 3:4cd9171ba989 | 589 | } else if (data.indexOf(target2) != -1) { |
lixianyu | 3:4cd9171ba989 | 590 | ESP8266_LOG("\r\ndata6 = %s\r\n", data.c_str()); |
lixianyu | 3:4cd9171ba989 | 591 | return data; |
lixianyu | 3:4cd9171ba989 | 592 | } else if (data.indexOf(target3) != -1) { |
lixianyu | 3:4cd9171ba989 | 593 | ESP8266_LOG("\r\ndata7 = %s\r\n", data.c_str()); |
lixianyu | 3:4cd9171ba989 | 594 | return data; |
lixianyu | 3:4cd9171ba989 | 595 | } else if (checkIPD(data)) { |
lixianyu | 3:4cd9171ba989 | 596 | data = ""; |
lixianyu | 3:4cd9171ba989 | 597 | } |
lixianyu | 3:4cd9171ba989 | 598 | } |
lixianyu | 3:4cd9171ba989 | 599 | } |
lixianyu | 3:4cd9171ba989 | 600 | ESP8266_LOG("\r\ndata8 = %s\r\n", data.c_str()); |
lixianyu | 3:4cd9171ba989 | 601 | return data; |
lixianyu | 3:4cd9171ba989 | 602 | } |
lixianyu | 3:4cd9171ba989 | 603 | |
lixianyu | 3:4cd9171ba989 | 604 | bool ESP8266::recvFind(String target, uint32_t timeout) |
lixianyu | 3:4cd9171ba989 | 605 | { |
lixianyu | 3:4cd9171ba989 | 606 | LOG_ENTER; |
lixianyu | 3:4cd9171ba989 | 607 | String data_tmp; |
lixianyu | 3:4cd9171ba989 | 608 | data_tmp = recvString(target, timeout); |
lixianyu | 3:4cd9171ba989 | 609 | if (data_tmp.indexOf(target) != -1) { |
lixianyu | 3:4cd9171ba989 | 610 | return true; |
lixianyu | 3:4cd9171ba989 | 611 | } |
lixianyu | 3:4cd9171ba989 | 612 | return false; |
lixianyu | 3:4cd9171ba989 | 613 | } |
lixianyu | 3:4cd9171ba989 | 614 | |
lixianyu | 3:4cd9171ba989 | 615 | bool ESP8266::recvFindAndFilter(String target, String begin, String end, String &data, uint32_t timeout) |
lixianyu | 3:4cd9171ba989 | 616 | { |
lixianyu | 3:4cd9171ba989 | 617 | LOG_ENTER; |
lixianyu | 3:4cd9171ba989 | 618 | String data_tmp; |
lixianyu | 3:4cd9171ba989 | 619 | data_tmp = recvString(target, timeout); |
lixianyu | 3:4cd9171ba989 | 620 | if (data_tmp.indexOf(target) != -1) { |
lixianyu | 3:4cd9171ba989 | 621 | int32_t index1 = data_tmp.indexOf(begin); |
lixianyu | 3:4cd9171ba989 | 622 | int32_t index2 = data_tmp.indexOf(end); |
lixianyu | 3:4cd9171ba989 | 623 | if (index1 != -1 && index2 != -1) { |
lixianyu | 3:4cd9171ba989 | 624 | index1 += begin.length(); |
lixianyu | 3:4cd9171ba989 | 625 | data = data_tmp.substring(index1, index2); |
lixianyu | 3:4cd9171ba989 | 626 | return true; |
lixianyu | 3:4cd9171ba989 | 627 | } |
lixianyu | 3:4cd9171ba989 | 628 | } |
lixianyu | 3:4cd9171ba989 | 629 | data = data_tmp; |
lixianyu | 3:4cd9171ba989 | 630 | return false; |
lixianyu | 3:4cd9171ba989 | 631 | } |
lixianyu | 3:4cd9171ba989 | 632 | |
lixianyu | 3:4cd9171ba989 | 633 | bool ESP8266::eAT(void) |
lixianyu | 3:4cd9171ba989 | 634 | { |
lixianyu | 3:4cd9171ba989 | 635 | LOG_ENTER; |
lixianyu | 3:4cd9171ba989 | 636 | rx_empty(); |
lixianyu | 3:4cd9171ba989 | 637 | //m_puart->println(F("AT")); |
lixianyu | 3:4cd9171ba989 | 638 | m_puart->printf("AT\r\n"); |
lixianyu | 3:4cd9171ba989 | 639 | return recvFind("OK"); |
lixianyu | 3:4cd9171ba989 | 640 | } |
lixianyu | 3:4cd9171ba989 | 641 | |
lixianyu | 3:4cd9171ba989 | 642 | bool ESP8266::eATRST(void) |
lixianyu | 3:4cd9171ba989 | 643 | { |
lixianyu | 3:4cd9171ba989 | 644 | LOG_ENTER; |
lixianyu | 3:4cd9171ba989 | 645 | rx_empty(); |
lixianyu | 3:4cd9171ba989 | 646 | //m_puart->println(F("AT+RST")); |
lixianyu | 3:4cd9171ba989 | 647 | m_puart->printf("AT+RST\r\n"); |
lixianyu | 3:4cd9171ba989 | 648 | return recvFind("OK"); |
lixianyu | 3:4cd9171ba989 | 649 | } |
lixianyu | 3:4cd9171ba989 | 650 | |
lixianyu | 3:4cd9171ba989 | 651 | bool ESP8266::eATGMR(String &version) |
lixianyu | 3:4cd9171ba989 | 652 | { |
lixianyu | 3:4cd9171ba989 | 653 | LOG_ENTER; |
lixianyu | 3:4cd9171ba989 | 654 | rx_empty(); |
lixianyu | 3:4cd9171ba989 | 655 | wait_ms(3000); |
lixianyu | 3:4cd9171ba989 | 656 | //m_puart->println(F("AT+GMR")); |
lixianyu | 3:4cd9171ba989 | 657 | m_puart->printf("AT+GMR\r\n"); |
lixianyu | 3:4cd9171ba989 | 658 | return recvFindAndFilter("OK", "\r\r\n", "\r\n\r\nOK", version, 10000); |
lixianyu | 3:4cd9171ba989 | 659 | } |
lixianyu | 3:4cd9171ba989 | 660 | |
lixianyu | 3:4cd9171ba989 | 661 | bool ESP8266::eATGSLP(uint32_t time) |
lixianyu | 3:4cd9171ba989 | 662 | { |
lixianyu | 3:4cd9171ba989 | 663 | LOG_ENTER; |
lixianyu | 3:4cd9171ba989 | 664 | rx_empty(); |
lixianyu | 3:4cd9171ba989 | 665 | //m_puart->print(F("AT+GSLP=")); |
lixianyu | 3:4cd9171ba989 | 666 | //m_puart->println(time); |
lixianyu | 3:4cd9171ba989 | 667 | m_puart->printf("AT+GSLP=%u\r\n", time); |
lixianyu | 3:4cd9171ba989 | 668 | return recvFind("OK"); |
lixianyu | 3:4cd9171ba989 | 669 | } |
lixianyu | 3:4cd9171ba989 | 670 | |
lixianyu | 3:4cd9171ba989 | 671 | bool ESP8266::eATE(uint8_t mode) |
lixianyu | 3:4cd9171ba989 | 672 | { |
lixianyu | 3:4cd9171ba989 | 673 | LOG_ENTER; |
lixianyu | 3:4cd9171ba989 | 674 | rx_empty(); |
lixianyu | 3:4cd9171ba989 | 675 | //m_puart->print(F("ATE")); |
lixianyu | 3:4cd9171ba989 | 676 | //m_puart->println(mode); |
lixianyu | 3:4cd9171ba989 | 677 | m_puart->printf("ATE%d\r\n", mode); |
lixianyu | 3:4cd9171ba989 | 678 | return recvFind("OK"); |
lixianyu | 3:4cd9171ba989 | 679 | } |
lixianyu | 3:4cd9171ba989 | 680 | |
lixianyu | 3:4cd9171ba989 | 681 | bool ESP8266::eATRESTORE(void) |
lixianyu | 3:4cd9171ba989 | 682 | { |
lixianyu | 3:4cd9171ba989 | 683 | LOG_ENTER; |
lixianyu | 3:4cd9171ba989 | 684 | rx_empty(); |
lixianyu | 3:4cd9171ba989 | 685 | //m_puart->println(F("AT+RESTORE")); |
lixianyu | 3:4cd9171ba989 | 686 | m_puart->printf("AT+RESTORE\r\n"); |
lixianyu | 3:4cd9171ba989 | 687 | return recvFind("OK"); |
lixianyu | 3:4cd9171ba989 | 688 | } |
lixianyu | 3:4cd9171ba989 | 689 | |
lixianyu | 3:4cd9171ba989 | 690 | bool ESP8266::eATSETUART(uint32_t baudrate,uint8_t pattern) |
lixianyu | 3:4cd9171ba989 | 691 | { |
lixianyu | 3:4cd9171ba989 | 692 | LOG_ENTER; |
lixianyu | 3:4cd9171ba989 | 693 | rx_empty(); |
lixianyu | 3:4cd9171ba989 | 694 | if(pattern>3||pattern<1) { |
lixianyu | 3:4cd9171ba989 | 695 | return false; |
lixianyu | 3:4cd9171ba989 | 696 | } |
lixianyu | 3:4cd9171ba989 | 697 | switch(pattern) { |
lixianyu | 3:4cd9171ba989 | 698 | case 1: |
lixianyu | 3:4cd9171ba989 | 699 | //m_puart->print(F("AT+UART=")); |
lixianyu | 3:4cd9171ba989 | 700 | m_puart->printf("AT+UART="); |
lixianyu | 3:4cd9171ba989 | 701 | break; |
lixianyu | 3:4cd9171ba989 | 702 | case 2: |
lixianyu | 3:4cd9171ba989 | 703 | //m_puart->print(F("AT+UART_CUR=")); |
lixianyu | 3:4cd9171ba989 | 704 | m_puart->printf("AT+UART_CUR="); |
lixianyu | 3:4cd9171ba989 | 705 | break; |
lixianyu | 3:4cd9171ba989 | 706 | case 3: |
lixianyu | 3:4cd9171ba989 | 707 | //m_puart->print(F("AT+UART_DEF=")); |
lixianyu | 3:4cd9171ba989 | 708 | m_puart->printf("AT+UART_DEF="); |
lixianyu | 3:4cd9171ba989 | 709 | break; |
lixianyu | 3:4cd9171ba989 | 710 | } |
lixianyu | 3:4cd9171ba989 | 711 | #if 0 |
lixianyu | 3:4cd9171ba989 | 712 | m_puart->print(baudrate); |
lixianyu | 3:4cd9171ba989 | 713 | m_puart->print(F(",")); |
lixianyu | 3:4cd9171ba989 | 714 | m_puart->print(8); |
lixianyu | 3:4cd9171ba989 | 715 | m_puart->print(F(",")); |
lixianyu | 3:4cd9171ba989 | 716 | m_puart->print(1); |
lixianyu | 3:4cd9171ba989 | 717 | m_puart->print(F(",")); |
lixianyu | 3:4cd9171ba989 | 718 | m_puart->print(0); |
lixianyu | 3:4cd9171ba989 | 719 | m_puart->print(F(",")); |
lixianyu | 3:4cd9171ba989 | 720 | m_puart->println(0); |
lixianyu | 3:4cd9171ba989 | 721 | #else |
lixianyu | 3:4cd9171ba989 | 722 | m_puart->printf("%u,%d,%d,%d,%d\r\n", baudrate, 8, 1, 0, 0); |
lixianyu | 3:4cd9171ba989 | 723 | #endif |
lixianyu | 3:4cd9171ba989 | 724 | if(recvFind("OK",5000)) { |
lixianyu | 3:4cd9171ba989 | 725 | //m_puart->begin(baudrate); |
lixianyu | 3:4cd9171ba989 | 726 | m_puart->baud(baudrate); |
lixianyu | 3:4cd9171ba989 | 727 | return true; |
lixianyu | 3:4cd9171ba989 | 728 | } else { |
lixianyu | 3:4cd9171ba989 | 729 | return false; |
lixianyu | 3:4cd9171ba989 | 730 | } |
lixianyu | 3:4cd9171ba989 | 731 | } |
lixianyu | 3:4cd9171ba989 | 732 | |
lixianyu | 3:4cd9171ba989 | 733 | bool ESP8266::qATCWMODE(uint8_t *mode,uint8_t pattern) |
lixianyu | 3:4cd9171ba989 | 734 | { |
lixianyu | 3:4cd9171ba989 | 735 | LOG_ENTER; |
lixianyu | 3:4cd9171ba989 | 736 | String str_mode; |
lixianyu | 3:4cd9171ba989 | 737 | bool ret; |
lixianyu | 3:4cd9171ba989 | 738 | if (!mode||!pattern) { |
lixianyu | 3:4cd9171ba989 | 739 | return false; |
lixianyu | 3:4cd9171ba989 | 740 | } |
lixianyu | 3:4cd9171ba989 | 741 | rx_empty(); |
lixianyu | 3:4cd9171ba989 | 742 | switch(pattern) { |
lixianyu | 3:4cd9171ba989 | 743 | case 1 : |
lixianyu | 3:4cd9171ba989 | 744 | //m_puart->println(F("AT+CWMODE_DEF?")); |
lixianyu | 3:4cd9171ba989 | 745 | m_puart->printf("AT+CWMODE_DEF?\r\n"); |
lixianyu | 3:4cd9171ba989 | 746 | break; |
lixianyu | 3:4cd9171ba989 | 747 | case 2: |
lixianyu | 3:4cd9171ba989 | 748 | //m_puart->println(F("AT+CWMODE_CUR?")); |
lixianyu | 3:4cd9171ba989 | 749 | m_puart->printf("AT+CWMODE_CUR?\r\n"); |
lixianyu | 3:4cd9171ba989 | 750 | break; |
lixianyu | 3:4cd9171ba989 | 751 | default: |
lixianyu | 3:4cd9171ba989 | 752 | //m_puart->println(F("AT+CWMODE?")); |
lixianyu | 3:4cd9171ba989 | 753 | m_puart->printf("AT+CWMODE?\r\n"); |
lixianyu | 3:4cd9171ba989 | 754 | } |
lixianyu | 3:4cd9171ba989 | 755 | ret = recvFindAndFilter("OK", ":", "\r\n\r\nOK", str_mode); |
lixianyu | 3:4cd9171ba989 | 756 | if (ret) { |
lixianyu | 3:4cd9171ba989 | 757 | *mode = (uint8_t)str_mode.toInt(); |
lixianyu | 3:4cd9171ba989 | 758 | return true; |
lixianyu | 3:4cd9171ba989 | 759 | } else { |
lixianyu | 3:4cd9171ba989 | 760 | return false; |
lixianyu | 3:4cd9171ba989 | 761 | } |
lixianyu | 3:4cd9171ba989 | 762 | } |
lixianyu | 3:4cd9171ba989 | 763 | |
lixianyu | 3:4cd9171ba989 | 764 | bool ESP8266::eATCWMODE(String &list) |
lixianyu | 3:4cd9171ba989 | 765 | { |
lixianyu | 3:4cd9171ba989 | 766 | LOG_ENTER; |
lixianyu | 3:4cd9171ba989 | 767 | rx_empty(); |
lixianyu | 3:4cd9171ba989 | 768 | //m_puart->println(F("AT+CWMODE=?")); |
lixianyu | 3:4cd9171ba989 | 769 | m_puart->printf("AT+CWMODE=?\r\n"); |
lixianyu | 3:4cd9171ba989 | 770 | return recvFindAndFilter("OK", "+CWMODE:(", ")\r\n\r\nOK", list); |
lixianyu | 3:4cd9171ba989 | 771 | } |
lixianyu | 3:4cd9171ba989 | 772 | |
lixianyu | 3:4cd9171ba989 | 773 | bool ESP8266::sATCWMODE(uint8_t mode,uint8_t pattern) |
lixianyu | 3:4cd9171ba989 | 774 | { |
lixianyu | 3:4cd9171ba989 | 775 | LOG_ENTER; |
lixianyu | 3:4cd9171ba989 | 776 | if(!pattern) { |
lixianyu | 3:4cd9171ba989 | 777 | return false; |
lixianyu | 3:4cd9171ba989 | 778 | } |
lixianyu | 3:4cd9171ba989 | 779 | String data; |
lixianyu | 3:4cd9171ba989 | 780 | rx_empty(); |
lixianyu | 3:4cd9171ba989 | 781 | switch(pattern) { |
lixianyu | 3:4cd9171ba989 | 782 | case 1 : |
lixianyu | 3:4cd9171ba989 | 783 | //m_puart->print(F("AT+CWMODE_DEF=")); |
lixianyu | 3:4cd9171ba989 | 784 | m_puart->printf("AT+CWMODE_DEF="); |
lixianyu | 3:4cd9171ba989 | 785 | break; |
lixianyu | 3:4cd9171ba989 | 786 | case 2: |
lixianyu | 3:4cd9171ba989 | 787 | //m_puart->print(F("AT+CWMODE_CUR=")); |
lixianyu | 3:4cd9171ba989 | 788 | m_puart->printf("AT+CWMODE_CUR="); |
lixianyu | 3:4cd9171ba989 | 789 | break; |
lixianyu | 3:4cd9171ba989 | 790 | default: |
lixianyu | 3:4cd9171ba989 | 791 | //m_puart->print(F("AT+CWMODE=")); |
lixianyu | 3:4cd9171ba989 | 792 | m_puart->printf("AT+CWMODE="); |
lixianyu | 3:4cd9171ba989 | 793 | } |
lixianyu | 3:4cd9171ba989 | 794 | //m_puart->println(mode); |
lixianyu | 3:4cd9171ba989 | 795 | m_puart->printf("%d\r\n", mode); |
lixianyu | 3:4cd9171ba989 | 796 | data = recvString("OK", "no change"); |
lixianyu | 3:4cd9171ba989 | 797 | |
lixianyu | 3:4cd9171ba989 | 798 | if (data.indexOf("OK") != -1 || data.indexOf("no change") != -1) { |
lixianyu | 3:4cd9171ba989 | 799 | return true; |
lixianyu | 3:4cd9171ba989 | 800 | } |
lixianyu | 3:4cd9171ba989 | 801 | return false; |
lixianyu | 3:4cd9171ba989 | 802 | } |
lixianyu | 3:4cd9171ba989 | 803 | |
lixianyu | 3:4cd9171ba989 | 804 | |
lixianyu | 3:4cd9171ba989 | 805 | bool ESP8266::qATCWJAP(String &ssid,uint8_t pattern) |
lixianyu | 3:4cd9171ba989 | 806 | { |
lixianyu | 3:4cd9171ba989 | 807 | LOG_ENTER; |
lixianyu | 3:4cd9171ba989 | 808 | bool ret; |
lixianyu | 3:4cd9171ba989 | 809 | if (!pattern) { |
lixianyu | 3:4cd9171ba989 | 810 | return false; |
lixianyu | 3:4cd9171ba989 | 811 | } |
lixianyu | 3:4cd9171ba989 | 812 | rx_empty(); |
lixianyu | 3:4cd9171ba989 | 813 | switch(pattern) { |
lixianyu | 3:4cd9171ba989 | 814 | case 1 : |
lixianyu | 3:4cd9171ba989 | 815 | //m_puart->println(F("AT+CWJAP_DEF?")); |
lixianyu | 3:4cd9171ba989 | 816 | m_puart->printf("AT+CWJAP_DEF?\r\n"); |
lixianyu | 3:4cd9171ba989 | 817 | break; |
lixianyu | 3:4cd9171ba989 | 818 | case 2: |
lixianyu | 3:4cd9171ba989 | 819 | //m_puart->println(F("AT+CWJAP_CUR?")); |
lixianyu | 3:4cd9171ba989 | 820 | m_puart->printf("AT+CWJAP_CUR?\r\n"); |
lixianyu | 3:4cd9171ba989 | 821 | break; |
lixianyu | 3:4cd9171ba989 | 822 | default: |
lixianyu | 3:4cd9171ba989 | 823 | //m_puart->println(F("AT+CWJAP?")); |
lixianyu | 3:4cd9171ba989 | 824 | m_puart->printf("AT+CWJAP?\r\n"); |
lixianyu | 3:4cd9171ba989 | 825 | } |
lixianyu | 3:4cd9171ba989 | 826 | ssid = recvString("OK", "No AP"); |
lixianyu | 3:4cd9171ba989 | 827 | if (ssid.indexOf("OK") != -1 || ssid.indexOf("No AP") != -1) { |
lixianyu | 3:4cd9171ba989 | 828 | return true; |
lixianyu | 3:4cd9171ba989 | 829 | } |
lixianyu | 3:4cd9171ba989 | 830 | return false; |
lixianyu | 3:4cd9171ba989 | 831 | |
lixianyu | 3:4cd9171ba989 | 832 | } |
lixianyu | 3:4cd9171ba989 | 833 | |
lixianyu | 3:4cd9171ba989 | 834 | bool ESP8266::sATCWJAP(String ssid, String pwd, uint8_t pattern) |
lixianyu | 3:4cd9171ba989 | 835 | { |
lixianyu | 3:4cd9171ba989 | 836 | LOG_ENTER; |
lixianyu | 3:4cd9171ba989 | 837 | String data; |
lixianyu | 3:4cd9171ba989 | 838 | if (!pattern) { |
lixianyu | 3:4cd9171ba989 | 839 | return false; |
lixianyu | 3:4cd9171ba989 | 840 | } |
lixianyu | 3:4cd9171ba989 | 841 | rx_empty(); |
lixianyu | 3:4cd9171ba989 | 842 | switch(pattern) { |
lixianyu | 3:4cd9171ba989 | 843 | case 1 : |
lixianyu | 3:4cd9171ba989 | 844 | //m_puart->print(F("AT+CWJAP_DEF=\"")); |
lixianyu | 3:4cd9171ba989 | 845 | m_puart->printf("AT+CWJAP_DEF=\""); |
lixianyu | 3:4cd9171ba989 | 846 | break; |
lixianyu | 3:4cd9171ba989 | 847 | case 2: |
lixianyu | 3:4cd9171ba989 | 848 | //m_puart->print(F("AT+CWJAP_CUR=\"")); |
lixianyu | 3:4cd9171ba989 | 849 | m_puart->printf("AT+CWJAP_CUR=\""); |
lixianyu | 3:4cd9171ba989 | 850 | break; |
lixianyu | 3:4cd9171ba989 | 851 | default: |
lixianyu | 3:4cd9171ba989 | 852 | //m_puart->print(F("AT+CWJAP=\"")); |
lixianyu | 3:4cd9171ba989 | 853 | m_puart->printf("AT+CWJAP=\""); |
lixianyu | 3:4cd9171ba989 | 854 | } |
lixianyu | 3:4cd9171ba989 | 855 | #if 0 |
lixianyu | 3:4cd9171ba989 | 856 | m_puart->print(ssid); |
lixianyu | 3:4cd9171ba989 | 857 | m_puart->print(F("\",\"")); |
lixianyu | 3:4cd9171ba989 | 858 | m_puart->print(pwd); |
lixianyu | 3:4cd9171ba989 | 859 | m_puart->println(F("\"")); |
lixianyu | 3:4cd9171ba989 | 860 | #else |
lixianyu | 3:4cd9171ba989 | 861 | //TODO: |
lixianyu | 3:4cd9171ba989 | 862 | m_puart->printf("%s\",\"%s\"\r\n", ssid.c_str(), pwd.c_str()); |
lixianyu | 3:4cd9171ba989 | 863 | #endif |
lixianyu | 3:4cd9171ba989 | 864 | data = recvString("OK", "FAIL", 20000); |
lixianyu | 3:4cd9171ba989 | 865 | if (data.indexOf("OK") != -1) { |
lixianyu | 3:4cd9171ba989 | 866 | return true; |
lixianyu | 3:4cd9171ba989 | 867 | } |
lixianyu | 3:4cd9171ba989 | 868 | return false; |
lixianyu | 3:4cd9171ba989 | 869 | } |
lixianyu | 3:4cd9171ba989 | 870 | |
lixianyu | 3:4cd9171ba989 | 871 | bool ESP8266::eATCWLAP(String &list) |
lixianyu | 3:4cd9171ba989 | 872 | { |
lixianyu | 3:4cd9171ba989 | 873 | LOG_ENTER; |
lixianyu | 3:4cd9171ba989 | 874 | String data; |
lixianyu | 3:4cd9171ba989 | 875 | rx_empty(); |
lixianyu | 3:4cd9171ba989 | 876 | //m_puart->println(F("AT+CWLAP")); |
lixianyu | 3:4cd9171ba989 | 877 | m_puart->printf("AT+CWLAP\r\n"); |
lixianyu | 3:4cd9171ba989 | 878 | return recvFindAndFilter("OK", "\r\r\n", "\r\n\r\nOK", list, 15000); |
lixianyu | 3:4cd9171ba989 | 879 | } |
lixianyu | 3:4cd9171ba989 | 880 | |
lixianyu | 3:4cd9171ba989 | 881 | bool ESP8266::eATCWQAP(void) |
lixianyu | 3:4cd9171ba989 | 882 | { |
lixianyu | 3:4cd9171ba989 | 883 | LOG_ENTER; |
lixianyu | 3:4cd9171ba989 | 884 | String data; |
lixianyu | 3:4cd9171ba989 | 885 | rx_empty(); |
lixianyu | 3:4cd9171ba989 | 886 | //m_puart->println(F("AT+CWQAP")); |
lixianyu | 3:4cd9171ba989 | 887 | m_puart->printf("AT+CWQAP\r\n"); |
lixianyu | 3:4cd9171ba989 | 888 | return recvFind("OK"); |
lixianyu | 3:4cd9171ba989 | 889 | } |
lixianyu | 3:4cd9171ba989 | 890 | |
lixianyu | 3:4cd9171ba989 | 891 | bool ESP8266::qATCWSAP(String &List,uint8_t pattern) |
lixianyu | 3:4cd9171ba989 | 892 | { |
lixianyu | 3:4cd9171ba989 | 893 | LOG_ENTER; |
lixianyu | 3:4cd9171ba989 | 894 | if (!pattern) { |
lixianyu | 3:4cd9171ba989 | 895 | return false; |
lixianyu | 3:4cd9171ba989 | 896 | } |
lixianyu | 3:4cd9171ba989 | 897 | rx_empty(); |
lixianyu | 3:4cd9171ba989 | 898 | switch(pattern) { |
lixianyu | 3:4cd9171ba989 | 899 | case 1 : |
lixianyu | 3:4cd9171ba989 | 900 | //m_puart->println(F("AT+CWSAP_DEF?")); |
lixianyu | 3:4cd9171ba989 | 901 | m_puart->printf("AT+CWSAP_DEF?\r\n"); |
lixianyu | 3:4cd9171ba989 | 902 | break; |
lixianyu | 3:4cd9171ba989 | 903 | case 2: |
lixianyu | 3:4cd9171ba989 | 904 | //m_puart->println(F("AT+CWSAP_CUR?")); |
lixianyu | 3:4cd9171ba989 | 905 | m_puart->printf("AT+CWSAP_CUR?\r\n"); |
lixianyu | 3:4cd9171ba989 | 906 | break; |
lixianyu | 3:4cd9171ba989 | 907 | default: |
lixianyu | 3:4cd9171ba989 | 908 | //m_puart->println(F("AT+CWSAP?")); |
lixianyu | 3:4cd9171ba989 | 909 | m_puart->printf("AT+CWSAP?\r\n"); |
lixianyu | 3:4cd9171ba989 | 910 | } |
lixianyu | 3:4cd9171ba989 | 911 | return recvFindAndFilter("OK", "\r\r\n", "\r\n\r\nOK", List,10000); |
lixianyu | 3:4cd9171ba989 | 912 | } |
lixianyu | 3:4cd9171ba989 | 913 | |
lixianyu | 3:4cd9171ba989 | 914 | bool ESP8266::sATCWSAP(String ssid, String pwd, uint8_t chl, uint8_t ecn,uint8_t pattern) |
lixianyu | 3:4cd9171ba989 | 915 | { |
lixianyu | 3:4cd9171ba989 | 916 | LOG_ENTER; |
lixianyu | 3:4cd9171ba989 | 917 | String data; |
lixianyu | 3:4cd9171ba989 | 918 | if (!pattern) { |
lixianyu | 3:4cd9171ba989 | 919 | return false; |
lixianyu | 3:4cd9171ba989 | 920 | } |
lixianyu | 3:4cd9171ba989 | 921 | rx_empty(); |
lixianyu | 3:4cd9171ba989 | 922 | switch(pattern) { |
lixianyu | 3:4cd9171ba989 | 923 | case 1 : |
lixianyu | 3:4cd9171ba989 | 924 | //m_puart->print(F("AT+CWSAP_DEF=\"")); |
lixianyu | 3:4cd9171ba989 | 925 | m_puart->printf("AT+CWSAP_DEF=\""); |
lixianyu | 3:4cd9171ba989 | 926 | break; |
lixianyu | 3:4cd9171ba989 | 927 | case 2: |
lixianyu | 3:4cd9171ba989 | 928 | //m_puart->print(F("AT+CWSAP_CUR=\"")); |
lixianyu | 3:4cd9171ba989 | 929 | m_puart->printf("AT+CWSAP_CUR=\""); |
lixianyu | 3:4cd9171ba989 | 930 | break; |
lixianyu | 3:4cd9171ba989 | 931 | default: |
lixianyu | 3:4cd9171ba989 | 932 | //m_puart->print(F("AT+CWSAP=\"")); |
lixianyu | 3:4cd9171ba989 | 933 | m_puart->printf("AT+CWSAP=\""); |
lixianyu | 3:4cd9171ba989 | 934 | } |
lixianyu | 3:4cd9171ba989 | 935 | #if 0 |
lixianyu | 3:4cd9171ba989 | 936 | m_puart->print(ssid); |
lixianyu | 3:4cd9171ba989 | 937 | m_puart->print(F("\",\"")); |
lixianyu | 3:4cd9171ba989 | 938 | m_puart->print(pwd); |
lixianyu | 3:4cd9171ba989 | 939 | m_puart->print(F("\",")); |
lixianyu | 3:4cd9171ba989 | 940 | m_puart->print(chl); |
lixianyu | 3:4cd9171ba989 | 941 | m_puart->print(F(",")); |
lixianyu | 3:4cd9171ba989 | 942 | m_puart->println(ecn); |
lixianyu | 3:4cd9171ba989 | 943 | #else |
lixianyu | 3:4cd9171ba989 | 944 | m_puart->printf("%s\",\"%s\",%d,%d\r\n", ssid.c_str(), pwd.c_str(), chl, ecn); |
lixianyu | 3:4cd9171ba989 | 945 | #endif |
lixianyu | 3:4cd9171ba989 | 946 | data = recvString("OK", "ERROR", 5000); |
lixianyu | 3:4cd9171ba989 | 947 | if (data.indexOf("OK") != -1) { |
lixianyu | 3:4cd9171ba989 | 948 | return true; |
lixianyu | 3:4cd9171ba989 | 949 | } |
lixianyu | 3:4cd9171ba989 | 950 | return false; |
lixianyu | 3:4cd9171ba989 | 951 | } |
lixianyu | 3:4cd9171ba989 | 952 | |
lixianyu | 3:4cd9171ba989 | 953 | bool ESP8266::eATCWLIF(String &list) |
lixianyu | 3:4cd9171ba989 | 954 | { |
lixianyu | 3:4cd9171ba989 | 955 | LOG_ENTER; |
lixianyu | 3:4cd9171ba989 | 956 | String data; |
lixianyu | 3:4cd9171ba989 | 957 | rx_empty(); |
lixianyu | 3:4cd9171ba989 | 958 | //m_puart->println(F("AT+CWLIF")); |
lixianyu | 3:4cd9171ba989 | 959 | m_puart->printf("AT+CWLIF\r\n"); |
lixianyu | 3:4cd9171ba989 | 960 | return recvFindAndFilter("OK", "\r\r\n", "\r\n\r\nOK", list); |
lixianyu | 3:4cd9171ba989 | 961 | } |
lixianyu | 3:4cd9171ba989 | 962 | |
lixianyu | 3:4cd9171ba989 | 963 | bool ESP8266::qATCWDHCP(String &List,uint8_t pattern) |
lixianyu | 3:4cd9171ba989 | 964 | { |
lixianyu | 3:4cd9171ba989 | 965 | LOG_ENTER; |
lixianyu | 3:4cd9171ba989 | 966 | if (!pattern) { |
lixianyu | 3:4cd9171ba989 | 967 | return false; |
lixianyu | 3:4cd9171ba989 | 968 | } |
lixianyu | 3:4cd9171ba989 | 969 | rx_empty(); |
lixianyu | 3:4cd9171ba989 | 970 | switch(pattern) { |
lixianyu | 3:4cd9171ba989 | 971 | case 1 : |
lixianyu | 3:4cd9171ba989 | 972 | //m_puart->println(F("AT+CWDHCP_DEF?")); |
lixianyu | 3:4cd9171ba989 | 973 | m_puart->printf("AT+CWDHCP_DEF?\r\n"); |
lixianyu | 3:4cd9171ba989 | 974 | break; |
lixianyu | 3:4cd9171ba989 | 975 | case 2: |
lixianyu | 3:4cd9171ba989 | 976 | //m_puart->println(F("AT+CWDHCP_CUR?")); |
lixianyu | 3:4cd9171ba989 | 977 | m_puart->printf("AT+CWDHCP_CUR?\r\n"); |
lixianyu | 3:4cd9171ba989 | 978 | break; |
lixianyu | 3:4cd9171ba989 | 979 | default: |
lixianyu | 3:4cd9171ba989 | 980 | //m_puart->println(F("AT+CWDHCP?")); |
lixianyu | 3:4cd9171ba989 | 981 | m_puart->printf("AT+CWDHCP?\r\n"); |
lixianyu | 3:4cd9171ba989 | 982 | } |
lixianyu | 3:4cd9171ba989 | 983 | |
lixianyu | 3:4cd9171ba989 | 984 | return recvFindAndFilter("OK", "\r\r\n", "\r\nOK", List,10000); |
lixianyu | 3:4cd9171ba989 | 985 | |
lixianyu | 3:4cd9171ba989 | 986 | } |
lixianyu | 3:4cd9171ba989 | 987 | |
lixianyu | 3:4cd9171ba989 | 988 | |
lixianyu | 3:4cd9171ba989 | 989 | bool ESP8266::sATCWDHCP(uint8_t mode, uint8_t en, uint8_t pattern) |
lixianyu | 3:4cd9171ba989 | 990 | { |
lixianyu | 3:4cd9171ba989 | 991 | LOG_ENTER; |
lixianyu | 3:4cd9171ba989 | 992 | String data; |
lixianyu | 3:4cd9171ba989 | 993 | if (!pattern) { |
lixianyu | 3:4cd9171ba989 | 994 | return false; |
lixianyu | 3:4cd9171ba989 | 995 | } |
lixianyu | 3:4cd9171ba989 | 996 | rx_empty(); |
lixianyu | 3:4cd9171ba989 | 997 | switch(pattern) { |
lixianyu | 3:4cd9171ba989 | 998 | case 1 : |
lixianyu | 3:4cd9171ba989 | 999 | //m_puart->print(F("AT+CWDHCP_DEF=")); |
lixianyu | 3:4cd9171ba989 | 1000 | m_puart->printf("AT+CWDHCP_DEF="); |
lixianyu | 3:4cd9171ba989 | 1001 | break; |
lixianyu | 3:4cd9171ba989 | 1002 | case 2: |
lixianyu | 3:4cd9171ba989 | 1003 | //m_puart->print(F("AT+CWDHCP_CUR=")); |
lixianyu | 3:4cd9171ba989 | 1004 | m_puart->printf("AT+CWDHCP_CUR="); |
lixianyu | 3:4cd9171ba989 | 1005 | break; |
lixianyu | 3:4cd9171ba989 | 1006 | default: |
lixianyu | 3:4cd9171ba989 | 1007 | //m_puart->print(F("AT+CWDHCP=")); |
lixianyu | 3:4cd9171ba989 | 1008 | m_puart->printf("AT+CWDHCP="); |
lixianyu | 3:4cd9171ba989 | 1009 | } |
lixianyu | 3:4cd9171ba989 | 1010 | #if 0 |
lixianyu | 3:4cd9171ba989 | 1011 | m_puart->print(mode); |
lixianyu | 3:4cd9171ba989 | 1012 | m_puart->print(F(",")); |
lixianyu | 3:4cd9171ba989 | 1013 | m_puart->println(en); |
lixianyu | 3:4cd9171ba989 | 1014 | #else |
lixianyu | 3:4cd9171ba989 | 1015 | m_puart->printf("%d,%d\r\n", mode, en); |
lixianyu | 3:4cd9171ba989 | 1016 | #endif |
lixianyu | 3:4cd9171ba989 | 1017 | data = recvString("OK", "ERROR", 2000); |
lixianyu | 3:4cd9171ba989 | 1018 | |
lixianyu | 3:4cd9171ba989 | 1019 | if (data.indexOf("OK") != -1) { |
lixianyu | 3:4cd9171ba989 | 1020 | return true; |
lixianyu | 3:4cd9171ba989 | 1021 | } |
lixianyu | 3:4cd9171ba989 | 1022 | return false; |
lixianyu | 3:4cd9171ba989 | 1023 | } |
lixianyu | 3:4cd9171ba989 | 1024 | |
lixianyu | 3:4cd9171ba989 | 1025 | |
lixianyu | 3:4cd9171ba989 | 1026 | bool ESP8266::eATCWAUTOCONN(uint8_t en) |
lixianyu | 3:4cd9171ba989 | 1027 | { |
lixianyu | 3:4cd9171ba989 | 1028 | LOG_ENTER; |
lixianyu | 3:4cd9171ba989 | 1029 | rx_empty(); |
lixianyu | 3:4cd9171ba989 | 1030 | if(en>1||en<0) { |
lixianyu | 3:4cd9171ba989 | 1031 | return false; |
lixianyu | 3:4cd9171ba989 | 1032 | } |
lixianyu | 3:4cd9171ba989 | 1033 | #if 0 |
lixianyu | 3:4cd9171ba989 | 1034 | m_puart->print(F("AT+CWAUTOCONN=")); |
lixianyu | 3:4cd9171ba989 | 1035 | m_puart->println(en); |
lixianyu | 3:4cd9171ba989 | 1036 | #else |
lixianyu | 3:4cd9171ba989 | 1037 | m_puart->printf("AT+CWAUTOCONN=%d\r\n", en); |
lixianyu | 3:4cd9171ba989 | 1038 | #endif |
lixianyu | 3:4cd9171ba989 | 1039 | return recvFind("OK"); |
lixianyu | 3:4cd9171ba989 | 1040 | |
lixianyu | 3:4cd9171ba989 | 1041 | } |
lixianyu | 3:4cd9171ba989 | 1042 | |
lixianyu | 3:4cd9171ba989 | 1043 | bool ESP8266::qATCIPSTAMAC(String &mac,uint8_t pattern) |
lixianyu | 3:4cd9171ba989 | 1044 | { |
lixianyu | 3:4cd9171ba989 | 1045 | LOG_ENTER; |
lixianyu | 3:4cd9171ba989 | 1046 | rx_empty(); |
lixianyu | 3:4cd9171ba989 | 1047 | if (!pattern) { |
lixianyu | 3:4cd9171ba989 | 1048 | return false; |
lixianyu | 3:4cd9171ba989 | 1049 | } |
lixianyu | 3:4cd9171ba989 | 1050 | switch(pattern) { |
lixianyu | 3:4cd9171ba989 | 1051 | case 1 : |
lixianyu | 3:4cd9171ba989 | 1052 | //m_puart->println(F("AT+CIPSTAMAC_DEF?")); |
lixianyu | 3:4cd9171ba989 | 1053 | m_puart->printf("AT+CIPSTAMAC_DEF?\r\n"); |
lixianyu | 3:4cd9171ba989 | 1054 | break; |
lixianyu | 3:4cd9171ba989 | 1055 | case 2: |
lixianyu | 3:4cd9171ba989 | 1056 | //m_puart->println(F("AT+CIPSTAMAC_CUR?")); |
lixianyu | 3:4cd9171ba989 | 1057 | m_puart->printf("AT+CIPSTAMAC_CUR?\r\n"); |
lixianyu | 3:4cd9171ba989 | 1058 | break; |
lixianyu | 3:4cd9171ba989 | 1059 | default: |
lixianyu | 3:4cd9171ba989 | 1060 | //m_puart->println(F("AT+CIPSTAMAC?")); |
lixianyu | 3:4cd9171ba989 | 1061 | m_puart->printf("AT+CIPSTAMAC?\r\n"); |
lixianyu | 3:4cd9171ba989 | 1062 | } |
lixianyu | 3:4cd9171ba989 | 1063 | return recvFindAndFilter("OK", "\r\r\n", "\r\n\r\nOK", mac,2000); |
lixianyu | 3:4cd9171ba989 | 1064 | |
lixianyu | 3:4cd9171ba989 | 1065 | } |
lixianyu | 3:4cd9171ba989 | 1066 | |
lixianyu | 3:4cd9171ba989 | 1067 | |
lixianyu | 3:4cd9171ba989 | 1068 | |
lixianyu | 3:4cd9171ba989 | 1069 | bool ESP8266::eATCIPSTAMAC(String mac,uint8_t pattern) |
lixianyu | 3:4cd9171ba989 | 1070 | { |
lixianyu | 3:4cd9171ba989 | 1071 | LOG_ENTER; |
lixianyu | 3:4cd9171ba989 | 1072 | rx_empty(); |
lixianyu | 3:4cd9171ba989 | 1073 | if (!pattern) { |
lixianyu | 3:4cd9171ba989 | 1074 | return false; |
lixianyu | 3:4cd9171ba989 | 1075 | } |
lixianyu | 3:4cd9171ba989 | 1076 | switch(pattern) { |
lixianyu | 3:4cd9171ba989 | 1077 | case 1 : |
lixianyu | 3:4cd9171ba989 | 1078 | //m_puart->print(F("AT+CIPSTAMAC_DEF=")); |
lixianyu | 3:4cd9171ba989 | 1079 | m_puart->printf("AT+CIPSTAMAC_DEF="); |
lixianyu | 3:4cd9171ba989 | 1080 | break; |
lixianyu | 3:4cd9171ba989 | 1081 | case 2: |
lixianyu | 3:4cd9171ba989 | 1082 | //m_puart->print(F("AT+CIPSTAMAC_CUR=")); |
lixianyu | 3:4cd9171ba989 | 1083 | m_puart->printf("AT+CIPSTAMAC_CUR="); |
lixianyu | 3:4cd9171ba989 | 1084 | break; |
lixianyu | 3:4cd9171ba989 | 1085 | default: |
lixianyu | 3:4cd9171ba989 | 1086 | //m_puart->print(F("AT+CIPSTAMAC=")); |
lixianyu | 3:4cd9171ba989 | 1087 | m_puart->printf("AT+CIPSTAMAC="); |
lixianyu | 3:4cd9171ba989 | 1088 | } |
lixianyu | 3:4cd9171ba989 | 1089 | #if 0 |
lixianyu | 3:4cd9171ba989 | 1090 | m_puart->print(F("\"")); |
lixianyu | 3:4cd9171ba989 | 1091 | m_puart->print(mac); |
lixianyu | 3:4cd9171ba989 | 1092 | m_puart->println(F("\"")); |
lixianyu | 3:4cd9171ba989 | 1093 | #else |
lixianyu | 3:4cd9171ba989 | 1094 | m_puart->printf("\"%s\"\r\n", mac.c_str()); |
lixianyu | 3:4cd9171ba989 | 1095 | #endif |
lixianyu | 3:4cd9171ba989 | 1096 | return recvFind("OK"); |
lixianyu | 3:4cd9171ba989 | 1097 | |
lixianyu | 3:4cd9171ba989 | 1098 | } |
lixianyu | 3:4cd9171ba989 | 1099 | |
lixianyu | 3:4cd9171ba989 | 1100 | bool ESP8266::qATCIPSTAIP(String &ip,uint8_t pattern) |
lixianyu | 3:4cd9171ba989 | 1101 | { |
lixianyu | 3:4cd9171ba989 | 1102 | LOG_ENTER; |
lixianyu | 3:4cd9171ba989 | 1103 | rx_empty(); |
lixianyu | 3:4cd9171ba989 | 1104 | if (!pattern) { |
lixianyu | 3:4cd9171ba989 | 1105 | return false; |
lixianyu | 3:4cd9171ba989 | 1106 | } |
lixianyu | 3:4cd9171ba989 | 1107 | switch(pattern) { |
lixianyu | 3:4cd9171ba989 | 1108 | case 1 : |
lixianyu | 3:4cd9171ba989 | 1109 | //m_puart->println(F("AT+CIPSTA_DEF?")); |
lixianyu | 3:4cd9171ba989 | 1110 | m_puart->printf("AT+CIPSTA_DEF?\r\n"); |
lixianyu | 3:4cd9171ba989 | 1111 | break; |
lixianyu | 3:4cd9171ba989 | 1112 | case 2: |
lixianyu | 3:4cd9171ba989 | 1113 | //m_puart->println(F("AT+CIPSTA_CUR?")); |
lixianyu | 3:4cd9171ba989 | 1114 | m_puart->printf("AT+CIPSTA_CUR?\r\n"); |
lixianyu | 3:4cd9171ba989 | 1115 | break; |
lixianyu | 3:4cd9171ba989 | 1116 | default: |
lixianyu | 3:4cd9171ba989 | 1117 | //m_puart->println(F("AT+CIPSTA?")); |
lixianyu | 3:4cd9171ba989 | 1118 | m_puart->printf("AT+CIPSTA?\r\n"); |
lixianyu | 3:4cd9171ba989 | 1119 | } |
lixianyu | 3:4cd9171ba989 | 1120 | return recvFindAndFilter("OK", "\r\r\n", "\r\n\r\nOK", ip,2000); |
lixianyu | 3:4cd9171ba989 | 1121 | |
lixianyu | 3:4cd9171ba989 | 1122 | } |
lixianyu | 3:4cd9171ba989 | 1123 | |
lixianyu | 3:4cd9171ba989 | 1124 | bool ESP8266::eATCIPSTAIP(String ip,String gateway,String netmask,uint8_t pattern) |
lixianyu | 3:4cd9171ba989 | 1125 | { |
lixianyu | 3:4cd9171ba989 | 1126 | LOG_ENTER; |
lixianyu | 3:4cd9171ba989 | 1127 | rx_empty(); |
lixianyu | 3:4cd9171ba989 | 1128 | if (!pattern) { |
lixianyu | 3:4cd9171ba989 | 1129 | return false; |
lixianyu | 3:4cd9171ba989 | 1130 | } |
lixianyu | 3:4cd9171ba989 | 1131 | switch(pattern) { |
lixianyu | 3:4cd9171ba989 | 1132 | case 1 : |
lixianyu | 3:4cd9171ba989 | 1133 | //m_puart->print(F("AT+CIPSTA_DEF=")); |
lixianyu | 3:4cd9171ba989 | 1134 | m_puart->printf("AT+CIPSTA_DEF="); |
lixianyu | 3:4cd9171ba989 | 1135 | break; |
lixianyu | 3:4cd9171ba989 | 1136 | case 2: |
lixianyu | 3:4cd9171ba989 | 1137 | //m_puart->print(F("AT+CIPSTA_CUR=")); |
lixianyu | 3:4cd9171ba989 | 1138 | m_puart->printf("AT+CIPSTA_CUR="); |
lixianyu | 3:4cd9171ba989 | 1139 | break; |
lixianyu | 3:4cd9171ba989 | 1140 | default: |
lixianyu | 3:4cd9171ba989 | 1141 | //m_puart->print(F("AT+CIPSTA=")); |
lixianyu | 3:4cd9171ba989 | 1142 | m_puart->printf("AT+CIPSTA="); |
lixianyu | 3:4cd9171ba989 | 1143 | } |
lixianyu | 3:4cd9171ba989 | 1144 | #if 0 |
lixianyu | 3:4cd9171ba989 | 1145 | m_puart->print(F("\"")); |
lixianyu | 3:4cd9171ba989 | 1146 | m_puart->print(ip); |
lixianyu | 3:4cd9171ba989 | 1147 | m_puart->print(F("\",\"")); |
lixianyu | 3:4cd9171ba989 | 1148 | m_puart->print(gateway); |
lixianyu | 3:4cd9171ba989 | 1149 | m_puart->print(F("\",\"")); |
lixianyu | 3:4cd9171ba989 | 1150 | m_puart->print(netmask); |
lixianyu | 3:4cd9171ba989 | 1151 | m_puart->println(F("\"")); |
lixianyu | 3:4cd9171ba989 | 1152 | #else |
lixianyu | 3:4cd9171ba989 | 1153 | m_puart->printf("\"%s\",\"%s\",\"%s\"\r\n", ip.c_str(), gateway.c_str(), netmask.c_str()); |
lixianyu | 3:4cd9171ba989 | 1154 | #endif |
lixianyu | 3:4cd9171ba989 | 1155 | return recvFind("OK"); |
lixianyu | 3:4cd9171ba989 | 1156 | |
lixianyu | 3:4cd9171ba989 | 1157 | } |
lixianyu | 3:4cd9171ba989 | 1158 | |
lixianyu | 3:4cd9171ba989 | 1159 | |
lixianyu | 3:4cd9171ba989 | 1160 | bool ESP8266::qATCIPAP(String &ip,uint8_t pattern) |
lixianyu | 3:4cd9171ba989 | 1161 | { |
lixianyu | 3:4cd9171ba989 | 1162 | LOG_ENTER; |
lixianyu | 3:4cd9171ba989 | 1163 | rx_empty(); |
lixianyu | 3:4cd9171ba989 | 1164 | if (!pattern) { |
lixianyu | 3:4cd9171ba989 | 1165 | return false; |
lixianyu | 3:4cd9171ba989 | 1166 | } |
lixianyu | 3:4cd9171ba989 | 1167 | switch(pattern) { |
lixianyu | 3:4cd9171ba989 | 1168 | case 1 : |
lixianyu | 3:4cd9171ba989 | 1169 | //m_puart->println(F("AT+CIPAP_DEF?")); |
lixianyu | 3:4cd9171ba989 | 1170 | m_puart->printf("AT+CIPAP_DEF?\r\n"); |
lixianyu | 3:4cd9171ba989 | 1171 | break; |
lixianyu | 3:4cd9171ba989 | 1172 | case 2: |
lixianyu | 3:4cd9171ba989 | 1173 | //m_puart->println(F("AT+CIPAP_CUR?")); |
lixianyu | 3:4cd9171ba989 | 1174 | m_puart->printf("AT+CIPAP_CUR?\r\n"); |
lixianyu | 3:4cd9171ba989 | 1175 | break; |
lixianyu | 3:4cd9171ba989 | 1176 | default: |
lixianyu | 3:4cd9171ba989 | 1177 | //m_puart->println(F("AT+CIPAP?")); |
lixianyu | 3:4cd9171ba989 | 1178 | m_puart->printf("AT+CIPAP?\r\n"); |
lixianyu | 3:4cd9171ba989 | 1179 | } |
lixianyu | 3:4cd9171ba989 | 1180 | return recvFindAndFilter("OK", "\r\r\n", "\r\n\r\nOK", ip,2000); |
lixianyu | 3:4cd9171ba989 | 1181 | |
lixianyu | 3:4cd9171ba989 | 1182 | } |
lixianyu | 3:4cd9171ba989 | 1183 | |
lixianyu | 3:4cd9171ba989 | 1184 | |
lixianyu | 3:4cd9171ba989 | 1185 | bool ESP8266::eATCIPAP(String ip,uint8_t pattern) |
lixianyu | 3:4cd9171ba989 | 1186 | { |
lixianyu | 3:4cd9171ba989 | 1187 | LOG_ENTER; |
lixianyu | 3:4cd9171ba989 | 1188 | rx_empty(); |
lixianyu | 3:4cd9171ba989 | 1189 | if (!pattern) { |
lixianyu | 3:4cd9171ba989 | 1190 | return false; |
lixianyu | 3:4cd9171ba989 | 1191 | } |
lixianyu | 3:4cd9171ba989 | 1192 | switch(pattern) { |
lixianyu | 3:4cd9171ba989 | 1193 | case 1 : |
lixianyu | 3:4cd9171ba989 | 1194 | //m_puart->print(F("AT+CIPAP_DEF=")); |
lixianyu | 3:4cd9171ba989 | 1195 | m_puart->printf("AT+CIPAP_DEF="); |
lixianyu | 3:4cd9171ba989 | 1196 | break; |
lixianyu | 3:4cd9171ba989 | 1197 | case 2: |
lixianyu | 3:4cd9171ba989 | 1198 | //m_puart->print(F("AT+CIPAP_CUR=")); |
lixianyu | 3:4cd9171ba989 | 1199 | m_puart->printf("AT+CIPAP_CUR="); |
lixianyu | 3:4cd9171ba989 | 1200 | break; |
lixianyu | 3:4cd9171ba989 | 1201 | default: |
lixianyu | 3:4cd9171ba989 | 1202 | //m_puart->print(F("AT+CIPAP=")); |
lixianyu | 3:4cd9171ba989 | 1203 | m_puart->printf("AT+CIPAP="); |
lixianyu | 3:4cd9171ba989 | 1204 | } |
lixianyu | 3:4cd9171ba989 | 1205 | #if 0 |
lixianyu | 3:4cd9171ba989 | 1206 | m_puart->print(F("\"")); |
lixianyu | 3:4cd9171ba989 | 1207 | m_puart->print(ip); |
lixianyu | 3:4cd9171ba989 | 1208 | m_puart->println(F("\"")); |
lixianyu | 3:4cd9171ba989 | 1209 | #else |
lixianyu | 3:4cd9171ba989 | 1210 | m_puart->printf("\"%s\"\r\n", ip.c_str()); |
lixianyu | 3:4cd9171ba989 | 1211 | #endif |
lixianyu | 3:4cd9171ba989 | 1212 | return recvFind("OK"); |
lixianyu | 3:4cd9171ba989 | 1213 | |
lixianyu | 3:4cd9171ba989 | 1214 | } |
lixianyu | 3:4cd9171ba989 | 1215 | |
lixianyu | 3:4cd9171ba989 | 1216 | |
lixianyu | 3:4cd9171ba989 | 1217 | bool ESP8266::eCWSTARTSMART(uint8_t type) |
lixianyu | 3:4cd9171ba989 | 1218 | { |
lixianyu | 3:4cd9171ba989 | 1219 | LOG_ENTER; |
lixianyu | 3:4cd9171ba989 | 1220 | rx_empty(); |
lixianyu | 3:4cd9171ba989 | 1221 | #if 0 |
lixianyu | 3:4cd9171ba989 | 1222 | m_puart->print(F("AT+CWSTARTSMART=")); |
lixianyu | 3:4cd9171ba989 | 1223 | m_puart->println(type); |
lixianyu | 3:4cd9171ba989 | 1224 | #else |
lixianyu | 3:4cd9171ba989 | 1225 | m_puart->printf("AT+CWSTARTSMART=%d\r\n", type); |
lixianyu | 3:4cd9171ba989 | 1226 | #endif |
lixianyu | 3:4cd9171ba989 | 1227 | return recvFind("OK"); |
lixianyu | 3:4cd9171ba989 | 1228 | } |
lixianyu | 3:4cd9171ba989 | 1229 | |
lixianyu | 3:4cd9171ba989 | 1230 | bool ESP8266::eCWSTOPSMART(void) |
lixianyu | 3:4cd9171ba989 | 1231 | { |
lixianyu | 3:4cd9171ba989 | 1232 | LOG_ENTER; |
lixianyu | 3:4cd9171ba989 | 1233 | rx_empty(); |
lixianyu | 3:4cd9171ba989 | 1234 | //m_puart->println(F("AT+CWSTOPSMART")); |
lixianyu | 3:4cd9171ba989 | 1235 | m_puart->printf("AT+CWSTOPSMART\r\n"); |
lixianyu | 3:4cd9171ba989 | 1236 | return recvFind("OK"); |
lixianyu | 3:4cd9171ba989 | 1237 | } |
lixianyu | 3:4cd9171ba989 | 1238 | |
lixianyu | 3:4cd9171ba989 | 1239 | bool ESP8266::eATCIPSTATUS(String &list) |
lixianyu | 3:4cd9171ba989 | 1240 | { |
lixianyu | 3:4cd9171ba989 | 1241 | LOG_ENTER; |
lixianyu | 3:4cd9171ba989 | 1242 | String data; |
lixianyu | 3:4cd9171ba989 | 1243 | //delay(100); |
lixianyu | 3:4cd9171ba989 | 1244 | wait_ms(100); |
lixianyu | 3:4cd9171ba989 | 1245 | rx_empty(); |
lixianyu | 3:4cd9171ba989 | 1246 | //m_puart->println(F("AT+CIPSTATUS")); |
lixianyu | 3:4cd9171ba989 | 1247 | m_puart->printf("AT+CIPSTATUS\r\n"); |
lixianyu | 3:4cd9171ba989 | 1248 | return recvFindAndFilter("OK", "\r\r\n", "\r\n\r\nOK", list); |
lixianyu | 3:4cd9171ba989 | 1249 | } |
lixianyu | 3:4cd9171ba989 | 1250 | |
lixianyu | 3:4cd9171ba989 | 1251 | bool ESP8266::sATCIPSTARTSingle(String type, String addr, uint32_t port) |
lixianyu | 3:4cd9171ba989 | 1252 | { |
lixianyu | 3:4cd9171ba989 | 1253 | LOG_ENTER; |
lixianyu | 3:4cd9171ba989 | 1254 | String data; |
lixianyu | 3:4cd9171ba989 | 1255 | rx_empty(); |
lixianyu | 3:4cd9171ba989 | 1256 | #if 0 |
lixianyu | 3:4cd9171ba989 | 1257 | m_puart->print(F("AT+CIPSTART=\"")); |
lixianyu | 3:4cd9171ba989 | 1258 | m_puart->print(type); |
lixianyu | 3:4cd9171ba989 | 1259 | m_puart->print(F("\",\"")); |
lixianyu | 3:4cd9171ba989 | 1260 | m_puart->print(addr); |
lixianyu | 3:4cd9171ba989 | 1261 | m_puart->print(F("\",")); |
lixianyu | 3:4cd9171ba989 | 1262 | m_puart->println(port); |
lixianyu | 3:4cd9171ba989 | 1263 | #else |
lixianyu | 3:4cd9171ba989 | 1264 | m_puart->printf("AT+CIPSTART=\"%s\",\"%s\",%u\r\n", type.c_str(), addr.c_str(), port); |
lixianyu | 3:4cd9171ba989 | 1265 | #endif |
lixianyu | 3:4cd9171ba989 | 1266 | data = recvString("OK", "ERROR", "ALREADY CONNECT", 10000); |
lixianyu | 3:4cd9171ba989 | 1267 | if (data.indexOf("OK") != -1 || data.indexOf("ALREADY CONNECT") != -1) { |
lixianyu | 3:4cd9171ba989 | 1268 | return true; |
lixianyu | 3:4cd9171ba989 | 1269 | } |
lixianyu | 3:4cd9171ba989 | 1270 | return false; |
lixianyu | 3:4cd9171ba989 | 1271 | } |
lixianyu | 3:4cd9171ba989 | 1272 | |
lixianyu | 3:4cd9171ba989 | 1273 | bool ESP8266::sATCIPSTARTMultiple(uint8_t mux_id, String type, String addr, uint32_t port) |
lixianyu | 3:4cd9171ba989 | 1274 | { |
lixianyu | 3:4cd9171ba989 | 1275 | LOG_ENTER; |
lixianyu | 3:4cd9171ba989 | 1276 | String data; |
lixianyu | 3:4cd9171ba989 | 1277 | rx_empty(); |
lixianyu | 3:4cd9171ba989 | 1278 | #if 0 |
lixianyu | 3:4cd9171ba989 | 1279 | m_puart->print(F("AT+CIPSTART=")); |
lixianyu | 3:4cd9171ba989 | 1280 | m_puart->print(mux_id); |
lixianyu | 3:4cd9171ba989 | 1281 | m_puart->print(F(",\"")); |
lixianyu | 3:4cd9171ba989 | 1282 | m_puart->print(type); |
lixianyu | 3:4cd9171ba989 | 1283 | m_puart->print(F("\",\"")); |
lixianyu | 3:4cd9171ba989 | 1284 | m_puart->print(addr); |
lixianyu | 3:4cd9171ba989 | 1285 | m_puart->print(F("\",")); |
lixianyu | 3:4cd9171ba989 | 1286 | m_puart->println(port); |
lixianyu | 3:4cd9171ba989 | 1287 | #else |
lixianyu | 3:4cd9171ba989 | 1288 | m_puart->printf("AT+CIPSTART=%d,\"%s\",\"%s\",%u\r\n", mux_id, type.c_str(), addr.c_str(), port); |
lixianyu | 3:4cd9171ba989 | 1289 | #endif |
lixianyu | 3:4cd9171ba989 | 1290 | data = recvString("OK", "ERROR", "ALREADY CONNECT", 10000); |
lixianyu | 3:4cd9171ba989 | 1291 | if (data.indexOf("OK") != -1 || data.indexOf("ALREADY CONNECT") != -1) { |
lixianyu | 3:4cd9171ba989 | 1292 | return true; |
lixianyu | 3:4cd9171ba989 | 1293 | } |
lixianyu | 3:4cd9171ba989 | 1294 | return false; |
lixianyu | 3:4cd9171ba989 | 1295 | } |
lixianyu | 3:4cd9171ba989 | 1296 | |
lixianyu | 3:4cd9171ba989 | 1297 | bool ESP8266::sATCIPSENDSingle(const uint8_t *buffer, uint32_t len) |
lixianyu | 3:4cd9171ba989 | 1298 | { |
lixianyu | 3:4cd9171ba989 | 1299 | LOG_ENTER; |
lixianyu | 3:4cd9171ba989 | 1300 | rx_empty(); |
lixianyu | 3:4cd9171ba989 | 1301 | #if 0 |
lixianyu | 3:4cd9171ba989 | 1302 | m_puart->print(F("AT+CIPSEND=")); |
lixianyu | 3:4cd9171ba989 | 1303 | m_puart->println(len); |
lixianyu | 3:4cd9171ba989 | 1304 | #else |
lixianyu | 3:4cd9171ba989 | 1305 | m_puart->printf("AT+CIPSEND=%u\r\n", len); |
lixianyu | 3:4cd9171ba989 | 1306 | #endif |
lixianyu | 3:4cd9171ba989 | 1307 | if (recvFind(">", 5000)) { |
lixianyu | 3:4cd9171ba989 | 1308 | rx_empty(); |
lixianyu | 3:4cd9171ba989 | 1309 | for (uint32_t i = 0; i < len; i++) { |
lixianyu | 3:4cd9171ba989 | 1310 | //m_puart->write(buffer[i]); |
lixianyu | 3:4cd9171ba989 | 1311 | m_puart->putc(buffer[i]); |
lixianyu | 3:4cd9171ba989 | 1312 | } |
lixianyu | 3:4cd9171ba989 | 1313 | return recvFind("SEND OK", 10000); |
lixianyu | 3:4cd9171ba989 | 1314 | } |
lixianyu | 3:4cd9171ba989 | 1315 | return false; |
lixianyu | 3:4cd9171ba989 | 1316 | } |
lixianyu | 3:4cd9171ba989 | 1317 | |
lixianyu | 3:4cd9171ba989 | 1318 | bool ESP8266::sATCIPSENDMultiple(uint8_t mux_id, const uint8_t *buffer, uint32_t len) |
lixianyu | 3:4cd9171ba989 | 1319 | { |
lixianyu | 3:4cd9171ba989 | 1320 | LOG_ENTER; |
lixianyu | 3:4cd9171ba989 | 1321 | rx_empty(); |
lixianyu | 3:4cd9171ba989 | 1322 | #if 0 |
lixianyu | 3:4cd9171ba989 | 1323 | m_puart->print(F("AT+CIPSEND=")); |
lixianyu | 3:4cd9171ba989 | 1324 | m_puart->print(mux_id); |
lixianyu | 3:4cd9171ba989 | 1325 | m_puart->print(F(",")); |
lixianyu | 3:4cd9171ba989 | 1326 | m_puart->println(len); |
lixianyu | 3:4cd9171ba989 | 1327 | #else |
lixianyu | 3:4cd9171ba989 | 1328 | m_puart->printf("AT+CIPSEND=%d,%u\r\n", mux_id, len); |
lixianyu | 3:4cd9171ba989 | 1329 | #endif |
lixianyu | 3:4cd9171ba989 | 1330 | if (recvFind(">", 5000)) { |
lixianyu | 3:4cd9171ba989 | 1331 | rx_empty(); |
lixianyu | 3:4cd9171ba989 | 1332 | for (uint32_t i = 0; i < len; i++) { |
lixianyu | 3:4cd9171ba989 | 1333 | //m_puart->write(buffer[i]); |
lixianyu | 3:4cd9171ba989 | 1334 | m_puart->putc(buffer[i]); |
lixianyu | 3:4cd9171ba989 | 1335 | } |
lixianyu | 3:4cd9171ba989 | 1336 | return recvFind("SEND OK", 10000); |
lixianyu | 3:4cd9171ba989 | 1337 | } |
lixianyu | 3:4cd9171ba989 | 1338 | return false; |
lixianyu | 3:4cd9171ba989 | 1339 | } |
lixianyu | 3:4cd9171ba989 | 1340 | |
lixianyu | 3:4cd9171ba989 | 1341 | bool ESP8266::sATCIPSENDSingleFromFlash(const uint8_t *buffer, uint32_t len) |
lixianyu | 3:4cd9171ba989 | 1342 | { |
lixianyu | 3:4cd9171ba989 | 1343 | LOG_ENTER; |
lixianyu | 3:4cd9171ba989 | 1344 | rx_empty(); |
lixianyu | 3:4cd9171ba989 | 1345 | #if 0 |
lixianyu | 3:4cd9171ba989 | 1346 | m_puart->print(F("AT+CIPSEND=")); |
lixianyu | 3:4cd9171ba989 | 1347 | m_puart->println(len); |
lixianyu | 3:4cd9171ba989 | 1348 | #else |
lixianyu | 3:4cd9171ba989 | 1349 | m_puart->printf("AT+CIPSEND=%u\r\n", len); |
lixianyu | 3:4cd9171ba989 | 1350 | #endif |
lixianyu | 3:4cd9171ba989 | 1351 | if (recvFind(">", 5000)) { |
lixianyu | 3:4cd9171ba989 | 1352 | rx_empty(); |
lixianyu | 3:4cd9171ba989 | 1353 | for (uint32_t i = 0; i < len; i++) { |
lixianyu | 3:4cd9171ba989 | 1354 | //m_puart->write((char) pgm_read_byte(&buffer[i])); |
lixianyu | 3:4cd9171ba989 | 1355 | m_puart->putc(buffer[i]); |
lixianyu | 3:4cd9171ba989 | 1356 | } |
lixianyu | 3:4cd9171ba989 | 1357 | return recvFind("SEND OK", 10000); |
lixianyu | 3:4cd9171ba989 | 1358 | } |
lixianyu | 3:4cd9171ba989 | 1359 | return false; |
lixianyu | 3:4cd9171ba989 | 1360 | } |
lixianyu | 3:4cd9171ba989 | 1361 | |
lixianyu | 3:4cd9171ba989 | 1362 | bool ESP8266::sATCIPSENDMultipleFromFlash(uint8_t mux_id, const uint8_t *buffer, uint32_t len) |
lixianyu | 3:4cd9171ba989 | 1363 | { |
lixianyu | 3:4cd9171ba989 | 1364 | LOG_ENTER; |
lixianyu | 3:4cd9171ba989 | 1365 | rx_empty(); |
lixianyu | 3:4cd9171ba989 | 1366 | #if 0 |
lixianyu | 3:4cd9171ba989 | 1367 | m_puart->print(F("AT+CIPSEND=")); |
lixianyu | 3:4cd9171ba989 | 1368 | m_puart->print(mux_id); |
lixianyu | 3:4cd9171ba989 | 1369 | m_puart->print(F(",")); |
lixianyu | 3:4cd9171ba989 | 1370 | m_puart->println(len); |
lixianyu | 3:4cd9171ba989 | 1371 | #else |
lixianyu | 3:4cd9171ba989 | 1372 | m_puart->printf("AT+CIPSEND=%d,%u\r\n", mux_id, len); |
lixianyu | 3:4cd9171ba989 | 1373 | #endif |
lixianyu | 3:4cd9171ba989 | 1374 | if (recvFind(">", 5000)) { |
lixianyu | 3:4cd9171ba989 | 1375 | rx_empty(); |
lixianyu | 3:4cd9171ba989 | 1376 | for (uint32_t i = 0; i < len; i++) { |
lixianyu | 3:4cd9171ba989 | 1377 | //m_puart->write((char) pgm_read_byte(&buffer[i])); |
lixianyu | 3:4cd9171ba989 | 1378 | m_puart->putc(buffer[i]); |
lixianyu | 3:4cd9171ba989 | 1379 | } |
lixianyu | 3:4cd9171ba989 | 1380 | return recvFind("SEND OK", 10000); |
lixianyu | 3:4cd9171ba989 | 1381 | } |
lixianyu | 3:4cd9171ba989 | 1382 | return false; |
lixianyu | 3:4cd9171ba989 | 1383 | } |
lixianyu | 3:4cd9171ba989 | 1384 | |
lixianyu | 3:4cd9171ba989 | 1385 | bool ESP8266::sATCIPCLOSEMulitple(uint8_t mux_id) |
lixianyu | 3:4cd9171ba989 | 1386 | { |
lixianyu | 3:4cd9171ba989 | 1387 | LOG_ENTER; |
lixianyu | 3:4cd9171ba989 | 1388 | String data; |
lixianyu | 3:4cd9171ba989 | 1389 | rx_empty(); |
lixianyu | 3:4cd9171ba989 | 1390 | #if 0 |
lixianyu | 3:4cd9171ba989 | 1391 | m_puart->print(F("AT+CIPCLOSE=")); |
lixianyu | 3:4cd9171ba989 | 1392 | m_puart->println(mux_id); |
lixianyu | 3:4cd9171ba989 | 1393 | #else |
lixianyu | 3:4cd9171ba989 | 1394 | m_puart->printf("AT+CIPCLOSE=%d\r\n", mux_id); |
lixianyu | 3:4cd9171ba989 | 1395 | #endif |
lixianyu | 3:4cd9171ba989 | 1396 | data = recvString("OK", "link is not", 5000); |
lixianyu | 3:4cd9171ba989 | 1397 | if (data.indexOf("OK") != -1 || data.indexOf("link is not") != -1) { |
lixianyu | 3:4cd9171ba989 | 1398 | return true; |
lixianyu | 3:4cd9171ba989 | 1399 | } |
lixianyu | 3:4cd9171ba989 | 1400 | return false; |
lixianyu | 3:4cd9171ba989 | 1401 | } |
lixianyu | 3:4cd9171ba989 | 1402 | |
lixianyu | 3:4cd9171ba989 | 1403 | bool ESP8266::eATCIPCLOSESingle(void) |
lixianyu | 3:4cd9171ba989 | 1404 | { |
lixianyu | 3:4cd9171ba989 | 1405 | LOG_ENTER; |
lixianyu | 3:4cd9171ba989 | 1406 | rx_empty(); |
lixianyu | 3:4cd9171ba989 | 1407 | //m_puart->println(F("AT+CIPCLOSE")); |
lixianyu | 3:4cd9171ba989 | 1408 | m_puart->printf("AT+CIPCLOSE\r\n"); |
lixianyu | 3:4cd9171ba989 | 1409 | return recvFind("OK", 5000); |
lixianyu | 3:4cd9171ba989 | 1410 | } |
lixianyu | 3:4cd9171ba989 | 1411 | |
lixianyu | 3:4cd9171ba989 | 1412 | bool ESP8266::eATCIFSR(String &list) |
lixianyu | 3:4cd9171ba989 | 1413 | { |
lixianyu | 3:4cd9171ba989 | 1414 | LOG_ENTER; |
lixianyu | 3:4cd9171ba989 | 1415 | rx_empty(); |
lixianyu | 3:4cd9171ba989 | 1416 | //m_puart->println(F("AT+CIFSR")); |
lixianyu | 3:4cd9171ba989 | 1417 | m_puart->printf("AT+CIFSR\r\n"); |
lixianyu | 3:4cd9171ba989 | 1418 | return recvFindAndFilter("OK", "\r\r\n", "\r\n\r\nOK", list); |
lixianyu | 3:4cd9171ba989 | 1419 | } |
lixianyu | 3:4cd9171ba989 | 1420 | |
lixianyu | 3:4cd9171ba989 | 1421 | bool ESP8266::sATCIPMUX(uint8_t mode) |
lixianyu | 3:4cd9171ba989 | 1422 | { |
lixianyu | 3:4cd9171ba989 | 1423 | LOG_ENTER; |
lixianyu | 3:4cd9171ba989 | 1424 | String data; |
lixianyu | 3:4cd9171ba989 | 1425 | rx_empty(); |
lixianyu | 3:4cd9171ba989 | 1426 | #if 0 |
lixianyu | 3:4cd9171ba989 | 1427 | m_puart->print(F("AT+CIPMUX=")); |
lixianyu | 3:4cd9171ba989 | 1428 | m_puart->println(mode); |
lixianyu | 3:4cd9171ba989 | 1429 | #else |
lixianyu | 3:4cd9171ba989 | 1430 | m_puart->printf("AT+CIPMUX=%d\r\n", mode); |
lixianyu | 3:4cd9171ba989 | 1431 | #endif |
lixianyu | 3:4cd9171ba989 | 1432 | data = recvString("OK", "Link is builded"); |
lixianyu | 3:4cd9171ba989 | 1433 | if (data.indexOf("OK") != -1) { |
lixianyu | 3:4cd9171ba989 | 1434 | return true; |
lixianyu | 3:4cd9171ba989 | 1435 | } |
lixianyu | 3:4cd9171ba989 | 1436 | return false; |
lixianyu | 3:4cd9171ba989 | 1437 | } |
lixianyu | 3:4cd9171ba989 | 1438 | |
lixianyu | 3:4cd9171ba989 | 1439 | bool ESP8266::sATCIPSERVER(uint8_t mode, uint32_t port) |
lixianyu | 3:4cd9171ba989 | 1440 | { |
lixianyu | 3:4cd9171ba989 | 1441 | LOG_ENTER; |
lixianyu | 3:4cd9171ba989 | 1442 | String data; |
lixianyu | 3:4cd9171ba989 | 1443 | if (mode) { |
lixianyu | 3:4cd9171ba989 | 1444 | rx_empty(); |
lixianyu | 3:4cd9171ba989 | 1445 | #if 0 |
lixianyu | 3:4cd9171ba989 | 1446 | m_puart->print(F("AT+CIPSERVER=1,")); |
lixianyu | 3:4cd9171ba989 | 1447 | m_puart->println(port); |
lixianyu | 3:4cd9171ba989 | 1448 | #else |
lixianyu | 3:4cd9171ba989 | 1449 | m_puart->printf("AT+CIPSERVER=1,%u\r\n", port); |
lixianyu | 3:4cd9171ba989 | 1450 | #endif |
lixianyu | 3:4cd9171ba989 | 1451 | data = recvString("OK", "no change"); |
lixianyu | 3:4cd9171ba989 | 1452 | if (data.indexOf("OK") != -1 || data.indexOf("no change") != -1) { |
lixianyu | 3:4cd9171ba989 | 1453 | return true; |
lixianyu | 3:4cd9171ba989 | 1454 | } |
lixianyu | 3:4cd9171ba989 | 1455 | return false; |
lixianyu | 3:4cd9171ba989 | 1456 | } else { |
lixianyu | 3:4cd9171ba989 | 1457 | rx_empty(); |
lixianyu | 3:4cd9171ba989 | 1458 | //m_puart->println(F("AT+CIPSERVER=0")); |
lixianyu | 3:4cd9171ba989 | 1459 | m_puart->printf("AT+CIPSERVER=0\r\n"); |
lixianyu | 3:4cd9171ba989 | 1460 | return recvFind("\r\r\n"); |
lixianyu | 3:4cd9171ba989 | 1461 | } |
lixianyu | 3:4cd9171ba989 | 1462 | } |
lixianyu | 3:4cd9171ba989 | 1463 | |
lixianyu | 3:4cd9171ba989 | 1464 | bool ESP8266::sATCIPMODE(uint8_t mode) |
lixianyu | 3:4cd9171ba989 | 1465 | { |
lixianyu | 3:4cd9171ba989 | 1466 | LOG_ENTER; |
lixianyu | 3:4cd9171ba989 | 1467 | String data; |
lixianyu | 3:4cd9171ba989 | 1468 | if(mode>1||mode<0) { |
lixianyu | 3:4cd9171ba989 | 1469 | return false; |
lixianyu | 3:4cd9171ba989 | 1470 | } |
lixianyu | 3:4cd9171ba989 | 1471 | rx_empty(); |
lixianyu | 3:4cd9171ba989 | 1472 | #if 0 |
lixianyu | 3:4cd9171ba989 | 1473 | m_puart->print(F("AT+CIPMODE=")); |
lixianyu | 3:4cd9171ba989 | 1474 | m_puart->println(mode); |
lixianyu | 3:4cd9171ba989 | 1475 | #else |
lixianyu | 3:4cd9171ba989 | 1476 | m_puart->printf("AT+CIPMODE=%d\r\n", mode); |
lixianyu | 3:4cd9171ba989 | 1477 | #endif |
lixianyu | 3:4cd9171ba989 | 1478 | data = recvString("OK", "Link is builded",2000); |
lixianyu | 3:4cd9171ba989 | 1479 | if (data.indexOf("OK") != -1 ) { |
lixianyu | 3:4cd9171ba989 | 1480 | return true; |
lixianyu | 3:4cd9171ba989 | 1481 | } |
lixianyu | 3:4cd9171ba989 | 1482 | return false; |
lixianyu | 3:4cd9171ba989 | 1483 | } |
lixianyu | 3:4cd9171ba989 | 1484 | |
lixianyu | 3:4cd9171ba989 | 1485 | bool ESP8266::eATSAVETRANSLINK(uint8_t mode,String ip,uint32_t port) |
lixianyu | 3:4cd9171ba989 | 1486 | { |
lixianyu | 3:4cd9171ba989 | 1487 | LOG_ENTER; |
lixianyu | 3:4cd9171ba989 | 1488 | String data; |
lixianyu | 3:4cd9171ba989 | 1489 | rx_empty(); |
lixianyu | 3:4cd9171ba989 | 1490 | #if 0 |
lixianyu | 3:4cd9171ba989 | 1491 | m_puart->print(F("AT+SAVETRANSLINK=")); |
lixianyu | 3:4cd9171ba989 | 1492 | m_puart->print(mode); |
lixianyu | 3:4cd9171ba989 | 1493 | m_puart->print(F(",\"")); |
lixianyu | 3:4cd9171ba989 | 1494 | m_puart->print(ip); |
lixianyu | 3:4cd9171ba989 | 1495 | m_puart->print(F("\",")); |
lixianyu | 3:4cd9171ba989 | 1496 | m_puart->println(port); |
lixianyu | 3:4cd9171ba989 | 1497 | #else |
lixianyu | 3:4cd9171ba989 | 1498 | m_puart->printf("AT+SAVETRANSLINK=%d,\"%s\",%u\r\n", mode, ip.c_str(), port); |
lixianyu | 3:4cd9171ba989 | 1499 | #endif |
lixianyu | 3:4cd9171ba989 | 1500 | data = recvString("OK", "ERROR",2000); |
lixianyu | 3:4cd9171ba989 | 1501 | if (data.indexOf("OK") != -1 ) { |
lixianyu | 3:4cd9171ba989 | 1502 | return true; |
lixianyu | 3:4cd9171ba989 | 1503 | } |
lixianyu | 3:4cd9171ba989 | 1504 | return false; |
lixianyu | 3:4cd9171ba989 | 1505 | } |
lixianyu | 3:4cd9171ba989 | 1506 | |
lixianyu | 3:4cd9171ba989 | 1507 | bool ESP8266::eATPING(String ip) |
lixianyu | 3:4cd9171ba989 | 1508 | { |
lixianyu | 3:4cd9171ba989 | 1509 | LOG_ENTER; |
lixianyu | 3:4cd9171ba989 | 1510 | rx_empty(); |
lixianyu | 3:4cd9171ba989 | 1511 | #if 0 |
lixianyu | 3:4cd9171ba989 | 1512 | m_puart->print(F("AT+PING=")); |
lixianyu | 3:4cd9171ba989 | 1513 | m_puart->print(F("\"")); |
lixianyu | 3:4cd9171ba989 | 1514 | m_puart->print(ip); |
lixianyu | 3:4cd9171ba989 | 1515 | m_puart->println(F("\"")); |
lixianyu | 3:4cd9171ba989 | 1516 | #else |
lixianyu | 3:4cd9171ba989 | 1517 | m_puart->printf("AT+PING=\"%s\"\r\n", ip.c_str()); |
lixianyu | 3:4cd9171ba989 | 1518 | #endif |
lixianyu | 3:4cd9171ba989 | 1519 | return recvFind("OK",2000); |
lixianyu | 3:4cd9171ba989 | 1520 | } |
lixianyu | 3:4cd9171ba989 | 1521 | |
lixianyu | 3:4cd9171ba989 | 1522 | bool ESP8266::sATCIPSTO(uint32_t timeout) |
lixianyu | 3:4cd9171ba989 | 1523 | { |
lixianyu | 3:4cd9171ba989 | 1524 | LOG_ENTER; |
lixianyu | 3:4cd9171ba989 | 1525 | rx_empty(); |
lixianyu | 3:4cd9171ba989 | 1526 | #if 0 |
lixianyu | 3:4cd9171ba989 | 1527 | m_puart->print(F("AT+CIPSTO=")); |
lixianyu | 3:4cd9171ba989 | 1528 | m_puart->println(timeout); |
lixianyu | 3:4cd9171ba989 | 1529 | #else |
lixianyu | 3:4cd9171ba989 | 1530 | m_puart->printf("AT+CIPSTO=%u\r\n", timeout); |
lixianyu | 3:4cd9171ba989 | 1531 | #endif |
lixianyu | 3:4cd9171ba989 | 1532 | return recvFind("OK"); |
lixianyu | 3:4cd9171ba989 | 1533 | } |