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