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

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers ESP8266.cpp Source File

ESP8266.cpp

Go to the documentation of this file.
00001 /**
00002  * @file ESP8266.cpp
00003  * @brief The implementation of class ESP8266.
00004  * @author Wu Pengfei<pengfei.wu@itead.cc>
00005  * @date 2015.02
00006  *
00007  * @par Copyright:
00008  * Copyright (c) 2015 ITEAD Intelligent Systems Co., Ltd. \n\n
00009  * This program is free software; you can redistribute it and/or
00010  * modify it under the terms of the GNU General Public License as
00011  * published by the Free Software Foundation; either version 2 of
00012  * the License, or (at your option) any later version. \n\n
00013  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00014  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00015  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
00016  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00017  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
00018  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
00019  * THE SOFTWARE.
00020  */
00021 #include "ESP8266_Lib.h"
00022 
00023 Timer g_Timer;
00024 
00025 #ifdef ESP8266_USE_SOFTWARE_SERIAL
00026 ESP8266::ESP8266(SoftwareSerial &uart): m_puart(&uart)
00027 {
00028     g_Timer.start();
00029     m_onData = NULL;
00030     m_onDataPtr = NULL;
00031 }
00032 #else
00033 ESP8266::ESP8266(HardwareSerial &uart): m_puart(&uart)
00034 {
00035     g_Timer.start();
00036     m_onData = NULL;
00037     m_onDataPtr = NULL;
00038 }
00039 #endif
00040 
00041 bool ESP8266::kick(void)
00042 {
00043     LOG_ENTER;
00044     return eAT();
00045 }
00046 
00047 bool ESP8266::restart(void)
00048 {
00049     LOG_ENTER;
00050     unsigned long start;
00051     if (eATRST()) {
00052         //delay(2000);
00053         wait_ms(2000);
00054         //start = millis();
00055         start = g_Timer.read_ms();
00056         while (g_Timer.read_ms() - start < 3000) {
00057             if (eAT()) {
00058                 //delay(1500); /* Waiting for stable */
00059                 wait_ms(1500);
00060                 return true;
00061             }
00062             //delay(100);
00063             wait_ms(100);
00064         }
00065     }
00066     return false;
00067 }
00068 
00069 String ESP8266::getVersion(void)
00070 {
00071     LOG_ENTER;
00072     String version;
00073     eATGMR(version);
00074     return version;
00075 }
00076 
00077 bool ESP8266::setEcho(uint8_t mode)
00078 {
00079     LOG_ENTER;
00080     return eATE(mode);
00081 }
00082 
00083 bool ESP8266::restore(void)
00084 {
00085     LOG_ENTER;
00086     return eATRESTORE();
00087 }
00088 
00089 bool ESP8266::setUart(uint32_t baudrate,uint8_t pattern)
00090 {
00091     LOG_ENTER;
00092     return eATSETUART(baudrate,pattern);
00093 }
00094 
00095 bool ESP8266::deepSleep(uint32_t time)
00096 {
00097     LOG_ENTER;
00098     return eATGSLP(time);
00099 }
00100 
00101 bool ESP8266::setOprToStation(uint8_t pattern1,uint8_t pattern2)
00102 {
00103     LOG_ENTER;
00104     uint8_t mode;
00105     if (!qATCWMODE(&mode,pattern1)) {
00106         return false;
00107     }
00108     if (mode == 1) {
00109         return true;
00110     } else {
00111         if (sATCWMODE(1,pattern2)) {
00112             return true;
00113         } else {
00114             return false;
00115         }
00116     }
00117 }
00118 
00119 String ESP8266::getWifiModeList(void)
00120 {
00121     LOG_ENTER;
00122     String list;
00123     eATCWMODE(list);
00124     return list;
00125 }
00126 
00127 bool ESP8266::setOprToSoftAP(uint8_t pattern1,uint8_t pattern2)
00128 {
00129     LOG_ENTER;
00130     uint8_t mode;
00131     if (!qATCWMODE(&mode,pattern1)) {
00132         return false;
00133     }
00134     if (mode == 2) {
00135         return true;
00136     } else {
00137         if (sATCWMODE(2,pattern2) ) {
00138             return true;
00139         } else {
00140             return false;
00141         }
00142     }
00143 }
00144 
00145 bool ESP8266::setOprToStationSoftAP(uint8_t pattern1,uint8_t pattern2)
00146 {
00147     LOG_ENTER;
00148     uint8_t mode;
00149     if (!qATCWMODE(&mode,pattern1)) {
00150         return false;
00151     }
00152     if (mode == 3) {
00153         return true;
00154     } else {
00155         if (sATCWMODE(3,pattern2) ) {
00156             return true;
00157         } else {
00158             return false;
00159         }
00160     }
00161 }
00162 
00163 uint8_t ESP8266::getOprMode(uint8_t pattern1)
00164 {
00165     LOG_ENTER;
00166     uint8_t mode;
00167     if (!qATCWMODE(&mode,pattern1)) {
00168         return 0;
00169     } else {
00170         return mode;
00171     }
00172 }
00173 
00174 String ESP8266::getNowConecAp(uint8_t pattern)
00175 {
00176     LOG_ENTER;
00177     String ssid;
00178     qATCWJAP(ssid,pattern);
00179     return ssid;
00180 }
00181 
00182 String ESP8266::getAPList(void)
00183 {
00184     LOG_ENTER;
00185     String list;
00186     eATCWLAP(list);
00187     return list;
00188 }
00189 
00190 bool ESP8266::joinAP(String ssid, String pwd,uint8_t pattern)
00191 {
00192     LOG_ENTER;
00193     return sATCWJAP(ssid, pwd,pattern);
00194 }
00195 
00196 bool ESP8266::leaveAP(void)
00197 {
00198     LOG_ENTER;
00199     return eATCWQAP();
00200 }
00201 
00202 String ESP8266::getSoftAPParam(uint8_t pattern)
00203 {
00204     LOG_ENTER;
00205     String list;
00206     qATCWSAP(list,pattern);
00207     return list;
00208 }
00209 
00210 bool ESP8266::setSoftAPParam(String ssid, String pwd, uint8_t chl, uint8_t ecn,uint8_t pattern)
00211 {
00212     LOG_ENTER;
00213     return sATCWSAP(ssid, pwd, chl, ecn,pattern);
00214 }
00215 
00216 String ESP8266::getJoinedDeviceIP(void)
00217 {
00218     LOG_ENTER;
00219     String list;
00220     eATCWLIF(list);
00221     return list;
00222 }
00223 
00224 String ESP8266::getDHCP(uint8_t pattern)
00225 {
00226     LOG_ENTER;
00227     String dhcp;
00228     qATCWDHCP(dhcp,pattern);
00229     return dhcp;
00230 }
00231 
00232 bool ESP8266::setDHCP(uint8_t mode, uint8_t en, uint8_t pattern)
00233 {
00234     LOG_ENTER;
00235     return sATCWDHCP(mode, en, pattern);
00236 }
00237 
00238 bool ESP8266::setAutoConnect(uint8_t en)
00239 {
00240     LOG_ENTER;
00241     return eATCWAUTOCONN(en);
00242 }
00243 
00244 String ESP8266::getStationMac(uint8_t pattern)
00245 {
00246     LOG_ENTER;
00247     String mac;
00248     qATCIPSTAMAC(mac,pattern);
00249     return mac;
00250 }
00251 
00252 bool ESP8266::setStationMac(String mac,uint8_t pattern)
00253 {
00254     LOG_ENTER;
00255     return eATCIPSTAMAC(mac,pattern);
00256 }
00257 
00258 String ESP8266::getStationIp(uint8_t pattern)
00259 {
00260     LOG_ENTER;
00261     String ip;
00262     qATCIPSTAIP(ip,pattern);
00263     return ip;
00264 }
00265 
00266 bool ESP8266::setStationIp(String ip,String gateway,String netmask,uint8_t pattern)
00267 {
00268     LOG_ENTER;
00269     return eATCIPSTAIP(ip,gateway,netmask,pattern);
00270 }
00271 
00272 String ESP8266::getAPIp(uint8_t pattern)
00273 {
00274     LOG_ENTER;
00275     String ip;
00276     qATCIPAP(ip,pattern);
00277     return ip;
00278 }
00279 
00280 bool ESP8266::setAPIp(String ip,uint8_t pattern)
00281 {
00282     LOG_ENTER;
00283     return eATCIPAP(ip,pattern);
00284 }
00285 
00286 bool ESP8266::startSmartConfig(uint8_t type)
00287 {
00288     LOG_ENTER;
00289     return eCWSTARTSMART(type);
00290 }
00291 
00292 bool ESP8266::stopSmartConfig(void)
00293 {
00294     LOG_ENTER;
00295     return eCWSTOPSMART();
00296 }
00297 
00298 
00299 String ESP8266::getIPStatus(void)
00300 {
00301     LOG_ENTER;
00302     String list;
00303     eATCIPSTATUS(list);
00304     return list;
00305 }
00306 
00307 String ESP8266::getLocalIP(void)
00308 {
00309     LOG_ENTER;
00310     String list;
00311     eATCIFSR(list);
00312     return list;
00313 }
00314 
00315 bool ESP8266::enableMUX(void)
00316 {
00317     LOG_ENTER;
00318     return sATCIPMUX(1);
00319 }
00320 
00321 bool ESP8266::disableMUX(void)
00322 {
00323     LOG_ENTER;
00324     return sATCIPMUX(0);
00325 }
00326 
00327 bool ESP8266::createTCP(String addr, uint32_t port)
00328 {
00329     LOG_ENTER;
00330     return sATCIPSTARTSingle("TCP", addr, port);
00331 }
00332 
00333 bool ESP8266::releaseTCP(void)
00334 {
00335     LOG_ENTER;
00336     return eATCIPCLOSESingle();
00337 }
00338 
00339 bool ESP8266::registerUDP(String addr, uint32_t port)
00340 {
00341     LOG_ENTER;
00342     return sATCIPSTARTSingle("UDP", addr, port);
00343 }
00344 
00345 bool ESP8266::unregisterUDP(void)
00346 {
00347     LOG_ENTER;
00348     return eATCIPCLOSESingle();
00349 }
00350 
00351 bool ESP8266::createTCP(uint8_t mux_id, String addr, uint32_t port)
00352 {
00353     LOG_ENTER;
00354     return sATCIPSTARTMultiple(mux_id, "TCP", addr, port);
00355 }
00356 
00357 bool ESP8266::releaseTCP(uint8_t mux_id)
00358 {
00359     LOG_ENTER;
00360     return sATCIPCLOSEMulitple(mux_id);
00361 }
00362 
00363 bool ESP8266::registerUDP(uint8_t mux_id, String addr, uint32_t port)
00364 {
00365     LOG_ENTER;
00366     return sATCIPSTARTMultiple(mux_id, "UDP", addr, port);
00367 }
00368 
00369 bool ESP8266::unregisterUDP(uint8_t mux_id)
00370 {
00371     LOG_ENTER;
00372     return sATCIPCLOSEMulitple(mux_id);
00373 }
00374 
00375 bool ESP8266::setTCPServerTimeout(uint32_t timeout)
00376 {
00377     LOG_ENTER;
00378     return sATCIPSTO(timeout);
00379 }
00380 
00381 bool ESP8266::startTCPServer(uint32_t port)
00382 {
00383     LOG_ENTER;
00384     if (sATCIPSERVER(1, port)) {
00385         return true;
00386     }
00387     return false;
00388 }
00389 
00390 bool ESP8266::stopTCPServer(void)
00391 {
00392     LOG_ENTER;
00393     sATCIPSERVER(0);
00394     restart();
00395     return false;
00396 }
00397 
00398 bool ESP8266::setCIPMODE(uint8_t mode)
00399 {
00400     LOG_ENTER;
00401     return sATCIPMODE(mode);
00402 }
00403 
00404 bool ESP8266::saveTransLink (uint8_t mode,String ip,uint32_t port)
00405 {
00406     LOG_ENTER;
00407     return eATSAVETRANSLINK(mode,ip,port);
00408 }
00409 
00410 bool ESP8266::setPing(String ip)
00411 {
00412     LOG_ENTER;
00413     return eATPING(ip);
00414 }
00415 
00416 
00417 bool ESP8266::startServer(uint32_t port)
00418 {
00419     LOG_ENTER;
00420     return startTCPServer(port);
00421 }
00422 
00423 bool ESP8266::stopServer(void)
00424 {
00425     LOG_ENTER;
00426     return stopTCPServer();
00427 }
00428 
00429 bool ESP8266::send(const uint8_t *buffer, uint32_t len)
00430 {
00431     LOG_ENTER;
00432     return sATCIPSENDSingle(buffer, len);
00433 }
00434 
00435 bool ESP8266::sendFromFlash(uint8_t mux_id, const uint8_t *buffer, uint32_t len)
00436 {
00437     LOG_ENTER;
00438     return sATCIPSENDMultipleFromFlash(mux_id, buffer, len);
00439 }
00440 
00441 bool ESP8266::sendFromFlash(const uint8_t *buffer, uint32_t len)
00442 {
00443     LOG_ENTER;
00444     return sATCIPSENDSingleFromFlash(buffer, len);
00445 }
00446 
00447 bool ESP8266::send(uint8_t mux_id, const uint8_t *buffer, uint32_t len)
00448 {
00449     LOG_ENTER;
00450     return sATCIPSENDMultiple(mux_id, buffer, len);
00451 }
00452 
00453 void ESP8266::run()
00454 {
00455     LOG_ENTER;
00456     rx_empty();
00457 }
00458 
00459 /*----------------------------------------------------------------------------*/
00460 /* +IPD,<id>,<len>:<data> */
00461 /* +IPD,<len>:<data> */
00462 
00463 uint32_t ESP8266::checkIPD(String& data)
00464 {
00465     //Serial.print("### check: ");
00466     //Serial.println(data);
00467     LOG_ENTER;
00468     int32_t index_PIPDcomma = -1;
00469     int32_t index_colon = -1; /* : */
00470     int32_t index_comma = -1; /* , */
00471     int32_t len = -1;
00472     int8_t id = -1;
00473     {
00474         // Just for easier diffing
00475         index_PIPDcomma = data.indexOf("+IPD,");
00476         if (index_PIPDcomma != -1) {
00477             index_colon = data.indexOf(':', index_PIPDcomma + 5);
00478             if (index_colon != -1) {
00479                 index_comma = data.indexOf(',', index_PIPDcomma + 5);
00480                 /* +IPD,id,len:data */
00481                 if (index_comma != -1 && index_comma < index_colon) {
00482                     id = data.substring(index_PIPDcomma + 5, index_comma).toInt();
00483                     if (id < 0 || id > 4) {
00484                         return 0;
00485                     }
00486                     len = data.substring(index_comma + 1, index_colon).toInt();
00487                     if (len <= 0) {
00488                         return 0;
00489                     }
00490                 } else { /* +IPD,len:data */
00491                     len = data.substring(index_PIPDcomma + 5, index_colon).toInt();
00492                     if (len <= 0) {
00493                         return 0;
00494                     }
00495                 }
00496                 if (m_onData) {
00497                     m_onData(id, len, m_onDataPtr);
00498                 }
00499                 return len;
00500             }
00501         }
00502     }
00503     return 0;
00504 }
00505 
00506 void ESP8266::rx_empty(void)
00507 {
00508     LOG_ENTER;
00509     String data;
00510     char a;
00511     unsigned long start = g_Timer.read_ms();
00512     while (g_Timer.read_ms() - start < 10) {
00513         if (m_puart->readable()) {
00514             a = m_puart->getc();
00515             if(a == '\0') continue;
00516             data += a;
00517             if (checkIPD(data)) {
00518                 data = "";
00519             }
00520             start = g_Timer.read_ms();
00521         }
00522     }
00523 }
00524 
00525 String ESP8266::recvString(String target, uint32_t timeout)
00526 {
00527     LOG_ENTER;
00528     //pc.printf("Enter recvString,2 param\r\n");
00529     String data;
00530     char a;
00531     unsigned long start = g_Timer.read_ms();
00532     while (g_Timer.read_ms() - start < timeout) {
00533         while(m_puart->readable() > 0) {
00534             a = m_puart->getc();
00535             ESP8266_LOG("a=0x%02X ", a);
00536             if(a == '\0') continue;
00537             data += a;
00538             if (data.indexOf(target) != -1) {
00539                 ESP8266_LOG("\r\ndata = %s\r\n", data.c_str());
00540                 //pc.printf("\r\ndata = %s\r\n", data.c_str());
00541                 return data;
00542             } else if (checkIPD(data)) {
00543                 data = "";
00544             }
00545         }
00546     }
00547     ESP8266_LOG("\r\n");
00548     ESP8266_LOG("data1 = %s\r\n", data.c_str());
00549     //pc.printf("data1 = %s\r\n", data.c_str());
00550     return data;
00551 }
00552 
00553 String ESP8266::recvString(String target1, String target2, uint32_t timeout)
00554 {
00555     LOG_ENTER;
00556     String data;
00557     char a;
00558     unsigned long start = g_Timer.read_ms();
00559     while (g_Timer.read_ms() - start < timeout) {
00560         while(m_puart->readable() > 0) {
00561             a = m_puart->getc();
00562             ESP8266_LOG("a=0x%02x ", a);
00563             if(a == '\0') continue;
00564             data += a;
00565             if (data.indexOf(target1) != -1) {
00566                 ESP8266_LOG("\r\ndata2 = %s\r\n", data.c_str());
00567                 //pc.printf("data2 = %s\r\n", data.c_str());
00568                 return data;
00569             } else if (data.indexOf(target2) != -1) {
00570                 ESP8266_LOG("\r\ndata3 = %s\r\n", data.c_str());
00571                 //pc.printf("data3 = %s\r\n", data.c_str());
00572                 return data;
00573             } else if (checkIPD(data)) {
00574                 data = "";
00575             }
00576         }
00577     }
00578     ESP8266_LOG("\r\ndata4 = %s\r\n", data.c_str());
00579     //pc.printf("data4 = %s\r\n", data.c_str());
00580     return data;
00581 }
00582 
00583 String ESP8266::recvString(String target1, String target2, String target3, uint32_t timeout)
00584 {
00585     LOG_ENTER;
00586     String data;
00587     char a;
00588     unsigned long start = g_Timer.read_ms();
00589     while (g_Timer.read_ms() - start < timeout) {
00590         while(m_puart->readable() > 0) {
00591             a = m_puart->getc();
00592             ESP8266_LOG("a=0x%02x ", a);
00593             if(a == '\0') continue;
00594             data += a;
00595 
00596             if (data.indexOf(target1) != -1) {
00597                 ESP8266_LOG("\r\ndata5 = %s\r\n", data.c_str());
00598                 //pc.printf("data5 = %s\r\n", data.c_str());
00599                 return data;
00600             } else if (data.indexOf(target2) != -1) {
00601                 ESP8266_LOG("\r\ndata6 = %s\r\n", data.c_str());
00602                 //pc.printf("data6 = %s\r\n", data.c_str());
00603                 return data;
00604             } else if (data.indexOf(target3) != -1) {
00605                 ESP8266_LOG("\r\ndata7 = %s\r\n", data.c_str());
00606                 //pc.printf("data7 = %s\r\n", data.c_str());
00607                 return data;
00608             } else if (checkIPD(data)) {
00609                 data = "";
00610             }
00611         }
00612     }
00613     ESP8266_LOG("\r\ndata8 = %s\r\n", data.c_str());
00614     //pc.printf("data8 = %s\r\n", data.c_str());
00615     return data;
00616 }
00617 
00618 bool ESP8266::recvFind(String target, uint32_t timeout)
00619 {
00620     LOG_ENTER;
00621     String data_tmp;
00622     data_tmp = recvString(target, timeout);
00623     if (data_tmp.indexOf(target) != -1) {
00624         return true;
00625     }
00626     return false;
00627 }
00628 
00629 bool ESP8266::recvFindAndFilter(String target, String begin, String end, String &data, uint32_t timeout)
00630 {
00631     LOG_ENTER;
00632     String data_tmp;
00633     data_tmp = recvString(target, timeout);
00634     if (data_tmp.indexOf(target) != -1) {
00635         int32_t index1 = data_tmp.indexOf(begin);
00636         int32_t index2 = data_tmp.indexOf(end);
00637         if (index1 != -1 && index2 != -1) {
00638             index1 += begin.length();
00639             data = data_tmp.substring(index1, index2);
00640             return true;
00641         }
00642     }
00643     data = data_tmp;
00644     return false;
00645 }
00646 
00647 bool ESP8266::eAT(void)
00648 {
00649     LOG_ENTER;
00650     rx_empty();
00651     //m_puart->println(F("AT"));
00652     m_puart->printf("AT\r\n");
00653     return recvFind("OK");
00654 }
00655 
00656 bool ESP8266::eATRST(void)
00657 {
00658     LOG_ENTER;
00659     rx_empty();
00660     //m_puart->println(F("AT+RST"));
00661     m_puart->printf("AT+RST\r\n");
00662     return recvFind("OK");
00663 }
00664 
00665 bool ESP8266::eATGMR(String &version)
00666 {
00667     LOG_ENTER;
00668     rx_empty();
00669     wait_ms(3000);
00670     //m_puart->println(F("AT+GMR"));
00671     m_puart->printf("AT+GMR\r\n");
00672     return recvFindAndFilter("OK", "\r\r\n", "\r\n\r\nOK", version, 10000);
00673 }
00674 
00675 bool ESP8266::eATGSLP(uint32_t time)
00676 {
00677     LOG_ENTER;
00678     rx_empty();
00679     //m_puart->print(F("AT+GSLP="));
00680     //m_puart->println(time);
00681     m_puart->printf("AT+GSLP=%u\r\n", time);
00682     return recvFind("OK");
00683 }
00684 
00685 bool ESP8266::eATE(uint8_t mode)
00686 {
00687     LOG_ENTER;
00688     rx_empty();
00689     //m_puart->print(F("ATE"));
00690     //m_puart->println(mode);
00691     m_puart->printf("ATE%d\r\n", mode);
00692     return recvFind("OK");
00693 }
00694 
00695 bool ESP8266::eATRESTORE(void)
00696 {
00697     LOG_ENTER;
00698     rx_empty();
00699     //m_puart->println(F("AT+RESTORE"));
00700     m_puart->printf("AT+RESTORE\r\n");
00701     return recvFind("OK");
00702 }
00703 
00704 bool ESP8266::eATSETUART(uint32_t baudrate,uint8_t pattern)
00705 {
00706     LOG_ENTER;
00707     rx_empty();
00708     if(pattern>3||pattern<1) {
00709         return false;
00710     }
00711     switch(pattern) {
00712         case 1:
00713             //m_puart->print(F("AT+UART="));
00714             m_puart->printf("AT+UART=");
00715             break;
00716         case 2:
00717             //m_puart->print(F("AT+UART_CUR="));
00718             m_puart->printf("AT+UART_CUR=");
00719             break;
00720         case 3:
00721             //m_puart->print(F("AT+UART_DEF="));
00722             m_puart->printf("AT+UART_DEF=");
00723             break;
00724     }
00725     #if 0
00726     m_puart->print(baudrate);
00727     m_puart->print(F(","));
00728     m_puart->print(8);
00729     m_puart->print(F(","));
00730     m_puart->print(1);
00731     m_puart->print(F(","));
00732     m_puart->print(0);
00733     m_puart->print(F(","));
00734     m_puart->println(0);
00735     #else
00736     m_puart->printf("%u,%d,%d,%d,%d\r\n", baudrate, 8, 1, 0, 0);
00737     #endif
00738     if(recvFind("OK",5000)) {
00739         //m_puart->begin(baudrate);
00740         m_puart->baud(baudrate);
00741         return true;
00742     } else {
00743         return false;
00744     }
00745 }
00746 
00747 bool ESP8266::qATCWMODE(uint8_t *mode,uint8_t pattern)
00748 {
00749     LOG_ENTER;
00750     String str_mode;
00751     bool ret;
00752     if (!mode||!pattern) {
00753         return false;
00754     }
00755     rx_empty();
00756     switch(pattern) {
00757         case 1 :
00758             //m_puart->println(F("AT+CWMODE_DEF?"));
00759             m_puart->printf("AT+CWMODE_DEF?\r\n");
00760             break;
00761         case 2:
00762             //m_puart->println(F("AT+CWMODE_CUR?"));
00763             m_puart->printf("AT+CWMODE_CUR?\r\n");
00764             break;
00765         default:
00766             //m_puart->println(F("AT+CWMODE?"));
00767             m_puart->printf("AT+CWMODE?\r\n");
00768     }
00769     ret = recvFindAndFilter("OK", ":", "\r\n\r\nOK", str_mode);
00770     if (ret) {
00771         *mode = (uint8_t)str_mode.toInt();
00772         return true;
00773     } else {
00774         return false;
00775     }
00776 }
00777 
00778 bool ESP8266::eATCWMODE(String &list)
00779 {
00780     LOG_ENTER;
00781     rx_empty();
00782     //m_puart->println(F("AT+CWMODE=?"));
00783     m_puart->printf("AT+CWMODE=?\r\n");
00784     return recvFindAndFilter("OK", "+CWMODE:(", ")\r\n\r\nOK", list);
00785 }
00786 
00787 bool ESP8266::sATCWMODE(uint8_t mode,uint8_t pattern)
00788 {
00789     LOG_ENTER;
00790     if(!pattern) {
00791         return false;
00792     }
00793     String data;
00794     rx_empty();
00795     switch(pattern) {
00796         case 1 :
00797             //m_puart->print(F("AT+CWMODE_DEF="));
00798             m_puart->printf("AT+CWMODE_DEF=");
00799             break;
00800         case 2:
00801             //m_puart->print(F("AT+CWMODE_CUR="));
00802             m_puart->printf("AT+CWMODE_CUR=");
00803             break;
00804         default:
00805             //m_puart->print(F("AT+CWMODE="));
00806             m_puart->printf("AT+CWMODE=");
00807     }
00808     //m_puart->println(mode);
00809     m_puart->printf("%d\r\n", mode);
00810     data = recvString("OK", "no change");
00811 
00812     if (data.indexOf("OK") != -1 || data.indexOf("no change") != -1) {
00813         return true;
00814     }
00815     return false;
00816 }
00817 
00818 
00819 bool ESP8266::qATCWJAP(String &ssid,uint8_t pattern)
00820 {
00821     LOG_ENTER;
00822     bool ret;
00823     if (!pattern) {
00824         return false;
00825     }
00826     rx_empty();
00827     switch(pattern) {
00828         case 1 :
00829             //m_puart->println(F("AT+CWJAP_DEF?"));
00830             m_puart->printf("AT+CWJAP_DEF?\r\n");
00831             break;
00832         case 2:
00833             //m_puart->println(F("AT+CWJAP_CUR?"));
00834             m_puart->printf("AT+CWJAP_CUR?\r\n");
00835             break;
00836         default:
00837             //m_puart->println(F("AT+CWJAP?"));
00838             m_puart->printf("AT+CWJAP?\r\n");
00839     }
00840     ssid = recvString("OK", "No AP");
00841     if (ssid.indexOf("OK") != -1 || ssid.indexOf("No AP") != -1) {
00842         return true;
00843     }
00844     return false;
00845 
00846 }
00847 
00848 bool ESP8266::sATCWJAP(String ssid, String pwd, uint8_t pattern)
00849 {
00850     LOG_ENTER;
00851     String data;
00852     if (!pattern) {
00853         return false;
00854     }
00855     rx_empty();
00856     switch(pattern) {
00857         case 1 :
00858             //m_puart->print(F("AT+CWJAP_DEF=\""));
00859             m_puart->printf("AT+CWJAP_DEF=\"");
00860             break;
00861         case 2:
00862             //m_puart->print(F("AT+CWJAP_CUR=\""));
00863             m_puart->printf("AT+CWJAP_CUR=\"");
00864             break;
00865         default:
00866             //m_puart->print(F("AT+CWJAP=\""));
00867             m_puart->printf("AT+CWJAP=\"");
00868     }
00869 #if 0
00870     m_puart->print(ssid);
00871     m_puart->print(F("\",\""));
00872     m_puart->print(pwd);
00873     m_puart->println(F("\""));
00874 #else
00875     //TODO:
00876     m_puart->printf("%s\",\"%s\"\r\n", ssid.c_str(), pwd.c_str());
00877 #endif
00878     data = recvString("OK", "FAIL", 20000);
00879     if (data.indexOf("OK") != -1) {
00880         return true;
00881     }
00882     return false;
00883 }
00884 
00885 bool ESP8266::eATCWLAP(String &list)
00886 {
00887     LOG_ENTER;
00888     String data;
00889     rx_empty();
00890     //m_puart->println(F("AT+CWLAP"));
00891     m_puart->printf("AT+CWLAP\r\n");
00892     return recvFindAndFilter("OK", "\r\r\n", "\r\n\r\nOK", list, 15000);
00893 }
00894 
00895 bool ESP8266::eATCWQAP(void)
00896 {
00897     LOG_ENTER;
00898     String data;
00899     rx_empty();
00900     //m_puart->println(F("AT+CWQAP"));
00901     m_puart->printf("AT+CWQAP\r\n");
00902     return recvFind("OK");
00903 }
00904 
00905 bool ESP8266::qATCWSAP(String &List,uint8_t pattern)
00906 {
00907     LOG_ENTER;
00908     if (!pattern) {
00909         return false;
00910     }
00911     rx_empty();
00912     switch(pattern) {
00913         case 1 :
00914             //m_puart->println(F("AT+CWSAP_DEF?"));
00915             m_puart->printf("AT+CWSAP_DEF?\r\n");
00916             break;
00917         case 2:
00918             //m_puart->println(F("AT+CWSAP_CUR?"));
00919             m_puart->printf("AT+CWSAP_CUR?\r\n");
00920             break;
00921         default:
00922             //m_puart->println(F("AT+CWSAP?"));
00923             m_puart->printf("AT+CWSAP?\r\n");
00924     }
00925     return recvFindAndFilter("OK", "\r\r\n", "\r\n\r\nOK", List,10000);
00926 }
00927 
00928 bool ESP8266::sATCWSAP(String ssid, String pwd, uint8_t chl, uint8_t ecn,uint8_t pattern)
00929 {
00930     LOG_ENTER;
00931     String data;
00932     if (!pattern) {
00933         return false;
00934     }
00935     rx_empty();
00936     switch(pattern) {
00937         case 1 :
00938             //m_puart->print(F("AT+CWSAP_DEF=\""));
00939             m_puart->printf("AT+CWSAP_DEF=\"");
00940             break;
00941         case 2:
00942             //m_puart->print(F("AT+CWSAP_CUR=\""));
00943             m_puart->printf("AT+CWSAP_CUR=\"");
00944             break;
00945         default:
00946             //m_puart->print(F("AT+CWSAP=\""));
00947             m_puart->printf("AT+CWSAP=\"");
00948     }
00949     #if 0
00950     m_puart->print(ssid);
00951     m_puart->print(F("\",\""));
00952     m_puart->print(pwd);
00953     m_puart->print(F("\","));
00954     m_puart->print(chl);
00955     m_puart->print(F(","));
00956     m_puart->println(ecn);
00957     #else
00958     m_puart->printf("%s\",\"%s\",%d,%d\r\n", ssid.c_str(), pwd.c_str(), chl, ecn);
00959     #endif
00960     data = recvString("OK", "ERROR", 5000);
00961     if (data.indexOf("OK") != -1) {
00962         return true;
00963     }
00964     return false;
00965 }
00966 
00967 bool ESP8266::eATCWLIF(String &list)
00968 {
00969     LOG_ENTER;
00970     String data;
00971     rx_empty();
00972     //m_puart->println(F("AT+CWLIF"));
00973     m_puart->printf("AT+CWLIF\r\n");
00974     return recvFindAndFilter("OK", "\r\r\n", "\r\n\r\nOK", list);
00975 }
00976 
00977 bool ESP8266::qATCWDHCP(String &List,uint8_t pattern)
00978 {
00979     LOG_ENTER;
00980     if (!pattern) {
00981         return false;
00982     }
00983     rx_empty();
00984     switch(pattern) {
00985         case 1 :
00986             //m_puart->println(F("AT+CWDHCP_DEF?"));
00987             m_puart->printf("AT+CWDHCP_DEF?\r\n");
00988             break;
00989         case 2:
00990             //m_puart->println(F("AT+CWDHCP_CUR?"));
00991             m_puart->printf("AT+CWDHCP_CUR?\r\n");
00992             break;
00993         default:
00994             //m_puart->println(F("AT+CWDHCP?"));
00995             m_puart->printf("AT+CWDHCP?\r\n");
00996     }
00997 
00998     return recvFindAndFilter("OK", "\r\r\n", "\r\nOK", List,10000);
00999 
01000 }
01001 
01002 
01003 bool ESP8266::sATCWDHCP(uint8_t mode, uint8_t en, uint8_t pattern)
01004 {
01005     LOG_ENTER;
01006     String data;
01007     if (!pattern) {
01008         return false;
01009     }
01010     rx_empty();
01011     switch(pattern) {
01012         case 1 :
01013             //m_puart->print(F("AT+CWDHCP_DEF="));
01014             m_puart->printf("AT+CWDHCP_DEF=");
01015             break;
01016         case 2:
01017             //m_puart->print(F("AT+CWDHCP_CUR="));
01018             m_puart->printf("AT+CWDHCP_CUR=");
01019             break;
01020         default:
01021             //m_puart->print(F("AT+CWDHCP="));
01022             m_puart->printf("AT+CWDHCP=");
01023     }
01024     #if 0
01025     m_puart->print(mode);
01026     m_puart->print(F(","));
01027     m_puart->println(en);
01028     #else
01029     m_puart->printf("%d,%d\r\n", mode, en);
01030     #endif
01031     data = recvString("OK", "ERROR", 2000);
01032 
01033     if (data.indexOf("OK") != -1) {
01034         return true;
01035     }
01036     return false;
01037 }
01038 
01039 
01040 bool ESP8266::eATCWAUTOCONN(uint8_t en)
01041 {
01042     LOG_ENTER;
01043     rx_empty();
01044     if(en>1||en<0) {
01045         return false;
01046     }
01047     #if 0
01048     m_puart->print(F("AT+CWAUTOCONN="));
01049     m_puart->println(en);
01050     #else
01051     m_puart->printf("AT+CWAUTOCONN=%d\r\n", en);
01052     #endif
01053     return recvFind("OK");
01054 
01055 }
01056 
01057 bool ESP8266::qATCIPSTAMAC(String &mac,uint8_t pattern)
01058 {
01059     LOG_ENTER;
01060     rx_empty();
01061     if (!pattern) {
01062         return false;
01063     }
01064     switch(pattern) {
01065         case 1 :
01066             //m_puart->println(F("AT+CIPSTAMAC_DEF?"));
01067             m_puart->printf("AT+CIPSTAMAC_DEF?\r\n");
01068             break;
01069         case 2:
01070             //m_puart->println(F("AT+CIPSTAMAC_CUR?"));
01071             m_puart->printf("AT+CIPSTAMAC_CUR?\r\n");
01072             break;
01073         default:
01074             //m_puart->println(F("AT+CIPSTAMAC?"));
01075             m_puart->printf("AT+CIPSTAMAC?\r\n");
01076     }
01077     return recvFindAndFilter("OK", "\r\r\n", "\r\n\r\nOK", mac,2000);
01078 
01079 }
01080 
01081 
01082 
01083 bool ESP8266::eATCIPSTAMAC(String mac,uint8_t pattern)
01084 {
01085     LOG_ENTER;
01086     rx_empty();
01087     if (!pattern) {
01088         return false;
01089     }
01090     switch(pattern) {
01091         case 1 :
01092             //m_puart->print(F("AT+CIPSTAMAC_DEF="));
01093             m_puart->printf("AT+CIPSTAMAC_DEF=");
01094             break;
01095         case 2:
01096             //m_puart->print(F("AT+CIPSTAMAC_CUR="));
01097             m_puart->printf("AT+CIPSTAMAC_CUR=");
01098             break;
01099         default:
01100             //m_puart->print(F("AT+CIPSTAMAC="));
01101             m_puart->printf("AT+CIPSTAMAC=");
01102     }
01103     #if 0
01104     m_puart->print(F("\""));
01105     m_puart->print(mac);
01106     m_puart->println(F("\""));
01107     #else
01108     m_puart->printf("\"%s\"\r\n", mac.c_str());
01109     #endif
01110     return recvFind("OK");
01111 
01112 }
01113 
01114 bool ESP8266::qATCIPSTAIP(String &ip,uint8_t pattern)
01115 {
01116     LOG_ENTER;
01117     rx_empty();
01118     if (!pattern) {
01119         return false;
01120     }
01121     switch(pattern) {
01122         case 1 :
01123             //m_puart->println(F("AT+CIPSTA_DEF?"));
01124             m_puart->printf("AT+CIPSTA_DEF?\r\n");
01125             break;
01126         case 2:
01127             //m_puart->println(F("AT+CIPSTA_CUR?"));
01128             m_puart->printf("AT+CIPSTA_CUR?\r\n");
01129             break;
01130         default:
01131             //m_puart->println(F("AT+CIPSTA?"));
01132             m_puart->printf("AT+CIPSTA?\r\n");
01133     }
01134     return recvFindAndFilter("OK", "\r\r\n", "\r\n\r\nOK", ip,2000);
01135 
01136 }
01137 
01138 bool ESP8266::eATCIPSTAIP(String ip,String gateway,String netmask,uint8_t pattern)
01139 {
01140     LOG_ENTER;
01141     rx_empty();
01142     if (!pattern) {
01143         return false;
01144     }
01145     switch(pattern) {
01146         case 1 :
01147             //m_puart->print(F("AT+CIPSTA_DEF="));
01148             m_puart->printf("AT+CIPSTA_DEF=");
01149             break;
01150         case 2:
01151             //m_puart->print(F("AT+CIPSTA_CUR="));
01152             m_puart->printf("AT+CIPSTA_CUR=");
01153             break;
01154         default:
01155             //m_puart->print(F("AT+CIPSTA="));
01156             m_puart->printf("AT+CIPSTA=");
01157     }
01158     #if 0
01159     m_puart->print(F("\""));
01160     m_puart->print(ip);
01161     m_puart->print(F("\",\""));
01162     m_puart->print(gateway);
01163     m_puart->print(F("\",\""));
01164     m_puart->print(netmask);
01165     m_puart->println(F("\""));
01166     #else
01167     m_puart->printf("\"%s\",\"%s\",\"%s\"\r\n", ip.c_str(), gateway.c_str(), netmask.c_str());
01168     #endif
01169     return recvFind("OK");
01170 
01171 }
01172 
01173 
01174 bool ESP8266::qATCIPAP(String &ip,uint8_t pattern)
01175 {
01176     LOG_ENTER;
01177     rx_empty();
01178     if (!pattern) {
01179         return false;
01180     }
01181     switch(pattern) {
01182         case 1 :
01183             //m_puart->println(F("AT+CIPAP_DEF?"));
01184             m_puart->printf("AT+CIPAP_DEF?\r\n");
01185             break;
01186         case 2:
01187             //m_puart->println(F("AT+CIPAP_CUR?"));
01188             m_puart->printf("AT+CIPAP_CUR?\r\n");
01189             break;
01190         default:
01191             //m_puart->println(F("AT+CIPAP?"));
01192             m_puart->printf("AT+CIPAP?\r\n");
01193     }
01194     return recvFindAndFilter("OK", "\r\r\n", "\r\n\r\nOK", ip,2000);
01195 
01196 }
01197 
01198 
01199 bool ESP8266::eATCIPAP(String ip,uint8_t pattern)
01200 {
01201     LOG_ENTER;
01202     rx_empty();
01203     if (!pattern) {
01204         return false;
01205     }
01206     switch(pattern) {
01207         case 1 :
01208             //m_puart->print(F("AT+CIPAP_DEF="));
01209             m_puart->printf("AT+CIPAP_DEF=");
01210             break;
01211         case 2:
01212             //m_puart->print(F("AT+CIPAP_CUR="));
01213             m_puart->printf("AT+CIPAP_CUR=");
01214             break;
01215         default:
01216             //m_puart->print(F("AT+CIPAP="));
01217             m_puart->printf("AT+CIPAP=");
01218     }
01219     #if 0
01220     m_puart->print(F("\""));
01221     m_puart->print(ip);
01222     m_puart->println(F("\""));
01223     #else
01224     m_puart->printf("\"%s\"\r\n", ip.c_str());
01225     #endif
01226     return recvFind("OK");
01227 
01228 }
01229 
01230 
01231 bool ESP8266::eCWSTARTSMART(uint8_t type)
01232 {
01233     LOG_ENTER;
01234     rx_empty();
01235     #if 0
01236     m_puart->print(F("AT+CWSTARTSMART="));
01237     m_puart->println(type);
01238     #else
01239     m_puart->printf("AT+CWSTARTSMART=%d\r\n", type);
01240     #endif
01241     return recvFind("OK");
01242 }
01243 
01244 bool ESP8266::eCWSTOPSMART(void)
01245 {
01246     LOG_ENTER;
01247     rx_empty();
01248     //m_puart->println(F("AT+CWSTOPSMART"));
01249     m_puart->printf("AT+CWSTOPSMART\r\n");
01250     return recvFind("OK");
01251 }
01252 
01253 bool ESP8266::eATCIPSTATUS(String &list)
01254 {
01255     LOG_ENTER;
01256     String data;
01257     //delay(100);
01258     wait_ms(100);
01259     rx_empty();
01260     //m_puart->println(F("AT+CIPSTATUS"));
01261     m_puart->printf("AT+CIPSTATUS\r\n");
01262     return recvFindAndFilter("OK", "\r\r\n", "\r\n\r\nOK", list);
01263 }
01264 
01265 bool ESP8266::sATCIPSTARTSingle(String type, String addr, uint32_t port)
01266 {
01267     LOG_ENTER;
01268     String data;
01269     rx_empty();
01270     #if 0
01271     m_puart->print(F("AT+CIPSTART=\""));
01272     m_puart->print(type);
01273     m_puart->print(F("\",\""));
01274     m_puart->print(addr);
01275     m_puart->print(F("\","));
01276     m_puart->println(port);
01277     #else
01278     m_puart->printf("AT+CIPSTART=\"%s\",\"%s\",%u\r\n", type.c_str(), addr.c_str(), port);
01279     #endif
01280     data = recvString("OK", "ERROR", "ALREADY CONNECT", 10000);
01281     if (data.indexOf("OK") != -1 || data.indexOf("ALREADY CONNECT") != -1) {
01282         return true;
01283     }
01284     return false;
01285 }
01286 
01287 bool ESP8266::sATCIPSTARTMultiple(uint8_t mux_id, String type, String addr, uint32_t port)
01288 {
01289     LOG_ENTER;
01290     String data;
01291     rx_empty();
01292     #if 0
01293     m_puart->print(F("AT+CIPSTART="));
01294     m_puart->print(mux_id);
01295     m_puart->print(F(",\""));
01296     m_puart->print(type);
01297     m_puart->print(F("\",\""));
01298     m_puart->print(addr);
01299     m_puart->print(F("\","));
01300     m_puart->println(port);
01301     #else
01302     m_puart->printf("AT+CIPSTART=%d,\"%s\",\"%s\",%u\r\n", mux_id, type.c_str(), addr.c_str(), port);
01303     #endif
01304     data = recvString("OK", "ERROR", "ALREADY CONNECT", 10000);
01305     if (data.indexOf("OK") != -1 || data.indexOf("ALREADY CONNECT") != -1) {
01306         return true;
01307     }
01308     return false;
01309 }
01310 
01311 bool ESP8266::sATCIPSENDSingle(const uint8_t *buffer, uint32_t len)
01312 {
01313     LOG_ENTER;
01314     rx_empty();
01315     #if 0
01316     m_puart->print(F("AT+CIPSEND="));
01317     m_puart->println(len);
01318     #else
01319     m_puart->printf("AT+CIPSEND=%u\r\n", len);
01320     #endif
01321     if (recvFind(">", 5000)) {
01322         rx_empty();
01323         for (uint32_t i = 0; i < len; i++) {
01324             //m_puart->write(buffer[i]);
01325             m_puart->putc(buffer[i]);
01326         }
01327         return recvFind("SEND OK", 10000);
01328     }
01329     return false;
01330 }
01331 
01332 bool ESP8266::sATCIPSENDMultiple(uint8_t mux_id, const uint8_t *buffer, uint32_t len)
01333 {
01334     LOG_ENTER;
01335     rx_empty();
01336     #if 0
01337     m_puart->print(F("AT+CIPSEND="));
01338     m_puart->print(mux_id);
01339     m_puart->print(F(","));
01340     m_puart->println(len);
01341     #else
01342     m_puart->printf("AT+CIPSEND=%d,%u\r\n", mux_id, len);
01343     #endif
01344     if (recvFind(">", 5000)) {
01345         rx_empty();
01346         for (uint32_t i = 0; i < len; i++) {
01347             //m_puart->write(buffer[i]);
01348             m_puart->putc(buffer[i]);
01349         }
01350         return recvFind("SEND OK", 10000);
01351     }
01352     return false;
01353 }
01354 
01355 bool ESP8266::sATCIPSENDSingleFromFlash(const uint8_t *buffer, uint32_t len)
01356 {
01357     LOG_ENTER;
01358     rx_empty();
01359     #if 0
01360     m_puart->print(F("AT+CIPSEND="));
01361     m_puart->println(len);
01362     #else
01363     m_puart->printf("AT+CIPSEND=%u\r\n", len);
01364     #endif
01365     if (recvFind(">", 5000)) {
01366         rx_empty();
01367         for (uint32_t i = 0; i < len; i++) {
01368             //m_puart->write((char) pgm_read_byte(&buffer[i]));
01369             m_puart->putc(buffer[i]);
01370         }
01371         return recvFind("SEND OK", 10000);
01372     }
01373     return false;
01374 }
01375 
01376 bool ESP8266::sATCIPSENDMultipleFromFlash(uint8_t mux_id, const uint8_t *buffer, uint32_t len)
01377 {
01378     LOG_ENTER;
01379     rx_empty();
01380     #if 0
01381     m_puart->print(F("AT+CIPSEND="));
01382     m_puart->print(mux_id);
01383     m_puart->print(F(","));
01384     m_puart->println(len);
01385     #else
01386     m_puart->printf("AT+CIPSEND=%d,%u\r\n", mux_id, len);
01387     #endif
01388     if (recvFind(">", 5000)) {
01389         rx_empty();
01390         for (uint32_t i = 0; i < len; i++) {
01391             //m_puart->write((char) pgm_read_byte(&buffer[i]));
01392             m_puart->putc(buffer[i]);
01393         }
01394         return recvFind("SEND OK", 10000);
01395     }
01396     return false;
01397 }
01398 
01399 bool ESP8266::sATCIPCLOSEMulitple(uint8_t mux_id)
01400 {
01401     LOG_ENTER;
01402     String data;
01403     rx_empty();
01404     #if 0
01405     m_puart->print(F("AT+CIPCLOSE="));
01406     m_puart->println(mux_id);
01407     #else
01408     m_puart->printf("AT+CIPCLOSE=%d\r\n", mux_id);
01409     #endif
01410     data = recvString("OK", "link is not", 5000);
01411     if (data.indexOf("OK") != -1 || data.indexOf("link is not") != -1) {
01412         return true;
01413     }
01414     return false;
01415 }
01416 
01417 bool ESP8266::eATCIPCLOSESingle(void)
01418 {
01419     LOG_ENTER;
01420     rx_empty();
01421     //m_puart->println(F("AT+CIPCLOSE"));
01422     m_puart->printf("AT+CIPCLOSE\r\n");
01423     return recvFind("OK", 5000);
01424 }
01425 
01426 bool ESP8266::eATCIFSR(String &list)
01427 {
01428     LOG_ENTER;
01429     rx_empty();
01430     //m_puart->println(F("AT+CIFSR"));
01431     m_puart->printf("AT+CIFSR\r\n");
01432     return recvFindAndFilter("OK", "\r\r\n", "\r\n\r\nOK", list);
01433 }
01434 
01435 bool ESP8266::sATCIPMUX(uint8_t mode)
01436 {
01437     LOG_ENTER;
01438     String data;
01439     rx_empty();
01440     #if 0
01441     m_puart->print(F("AT+CIPMUX="));
01442     m_puart->println(mode);
01443     #else
01444     m_puart->printf("AT+CIPMUX=%d\r\n", mode);
01445     #endif
01446     data = recvString("OK", "Link is builded");
01447     if (data.indexOf("OK") != -1) {
01448         return true;
01449     }
01450     return false;
01451 }
01452 
01453 bool ESP8266::sATCIPSERVER(uint8_t mode, uint32_t port)
01454 {
01455     LOG_ENTER;
01456     String data;
01457     if (mode) {
01458         rx_empty();
01459         #if 0
01460         m_puart->print(F("AT+CIPSERVER=1,"));
01461         m_puart->println(port);
01462         #else
01463         m_puart->printf("AT+CIPSERVER=1,%u\r\n", port);
01464         #endif
01465         data = recvString("OK", "no change");
01466         if (data.indexOf("OK") != -1 || data.indexOf("no change") != -1) {
01467             return true;
01468         }
01469         return false;
01470     } else {
01471         rx_empty();
01472         //m_puart->println(F("AT+CIPSERVER=0"));
01473         m_puart->printf("AT+CIPSERVER=0\r\n");
01474         return recvFind("\r\r\n");
01475     }
01476 }
01477 
01478 bool ESP8266::sATCIPMODE(uint8_t mode)
01479 {
01480     LOG_ENTER;
01481     String data;
01482     if(mode>1||mode<0) {
01483         return false;
01484     }
01485     rx_empty();
01486     #if 0
01487     m_puart->print(F("AT+CIPMODE="));
01488     m_puart->println(mode);
01489     #else
01490     m_puart->printf("AT+CIPMODE=%d\r\n", mode);
01491     #endif
01492     data = recvString("OK", "Link is builded",2000);
01493     if (data.indexOf("OK") != -1 ) {
01494         return true;
01495     }
01496     return false;
01497 }
01498 
01499 bool ESP8266::eATSAVETRANSLINK(uint8_t mode,String ip,uint32_t port)
01500 {
01501     LOG_ENTER;
01502     String data;
01503     rx_empty();
01504     #if 0
01505     m_puart->print(F("AT+SAVETRANSLINK="));
01506     m_puart->print(mode);
01507     m_puart->print(F(",\""));
01508     m_puart->print(ip);
01509     m_puart->print(F("\","));
01510     m_puart->println(port);
01511     #else
01512     m_puart->printf("AT+SAVETRANSLINK=%d,\"%s\",%u\r\n", mode, ip.c_str(), port);
01513     #endif
01514     data = recvString("OK", "ERROR",2000);
01515     if (data.indexOf("OK") != -1 ) {
01516         return true;
01517     }
01518     return false;
01519 }
01520 
01521 bool ESP8266::eATPING(String ip)
01522 {
01523     LOG_ENTER;
01524     rx_empty();
01525     #if 0
01526     m_puart->print(F("AT+PING="));
01527     m_puart->print(F("\""));
01528     m_puart->print(ip);
01529     m_puart->println(F("\""));
01530     #else
01531     m_puart->printf("AT+PING=\"%s\"\r\n", ip.c_str());
01532     #endif
01533     return recvFind("OK",2000);
01534 }
01535 
01536 bool ESP8266::sATCIPSTO(uint32_t timeout)
01537 {
01538     LOG_ENTER;
01539     rx_empty();
01540     #if 0
01541     m_puart->print(F("AT+CIPSTO="));
01542     m_puart->println(timeout);
01543     #else
01544     m_puart->printf("AT+CIPSTO=%u\r\n", timeout);
01545     #endif
01546     return recvFind("OK");
01547 }