From ce05b071566a06df52eb7c9393f9676fe5738ce4 Mon Sep 17 00:00:00 2001 From: TEONE2003 <121766894+TEONE2003@users.noreply.github.com> Date: Fri, 8 Mar 2024 12:42:44 +0100 Subject: [PATCH 1/6] the timeout didn't work and some changes not updated on github but already present on the Arduino library manager --- src/WiFiEspClient.cpp | 22 ++++++++-------------- src/WiFiEspClient.h | 1 + src/utility/EspDrv.cpp | 21 +++++++++++---------- src/utility/EspDrv.h | 2 +- 4 files changed, 21 insertions(+), 25 deletions(-) diff --git a/src/WiFiEspClient.cpp b/src/WiFiEspClient.cpp index 5a242a1..49849fc 100644 --- a/src/WiFiEspClient.cpp +++ b/src/WiFiEspClient.cpp @@ -26,13 +26,9 @@ along with The Arduino WiFiEsp library. If not, see #include "utility/debug.h" -WiFiEspClient::WiFiEspClient() : _sock(255) -{ -} +WiFiEspClient::WiFiEspClient() : _sock(255){STMillis=0;} -WiFiEspClient::WiFiEspClient(uint8_t sock) : _sock(sock) -{ -} +WiFiEspClient::WiFiEspClient(uint8_t sock) : _sock(sock){STMillis=0;} //////////////////////////////////////////////////////////////////////////////// @@ -137,15 +133,13 @@ size_t WiFiEspClient::write(const uint8_t *buf, size_t size) int WiFiEspClient::available() { - if (_sock != 255) - { + STMillis=millis(); + while(millis()-STMillis < getTimeout()){ + if (_sock != 255){ int bytes = EspDrv::availData(_sock); - if (bytes>0) - { - return bytes; - } - } - + if(bytes>0){return bytes;} + } + } return 0; } diff --git a/src/WiFiEspClient.h b/src/WiFiEspClient.h index 1e3823c..61db8c8 100644 --- a/src/WiFiEspClient.h +++ b/src/WiFiEspClient.h @@ -29,6 +29,7 @@ along with The Arduino WiFiEsp library. If not, see class WiFiEspClient : public Client { +protected: unsigned long STMillis; //variable used to do the subtraction and see how much time has passed, for the timeout public: WiFiEspClient(); WiFiEspClient(uint8_t sock); diff --git a/src/utility/EspDrv.cpp b/src/utility/EspDrv.cpp index cb577fe..76b1a61 100644 --- a/src/utility/EspDrv.cpp +++ b/src/utility/EspDrv.cpp @@ -359,7 +359,6 @@ void EspDrv::getIpAddress(IPAddress& ip) LOGDEBUG(F("> getIpAddress")); char buf[20]; - memset(buf, '\0', sizeof(buf)); if (sendCmdGet(F("AT+CIFSR"), F(":STAIP,\""), F("\""), buf, sizeof(buf))) { char* token; @@ -382,7 +381,6 @@ void EspDrv::getIpAddressAP(IPAddress& ip) LOGDEBUG(F("> getIpAddressAP")); char buf[20]; - memset(buf, '\0', sizeof(buf)); if (sendCmdGet(F("AT+CIPAP?"), F("+CIPAP:ip:\""), F("\""), buf, sizeof(buf))) { char* token; @@ -459,7 +457,9 @@ int32_t EspDrv::getCurrentRSSI() uint8_t EspDrv::getScanNetworks() { uint8_t ssidListNum = 0; - int idx; + int idx; + bool ret = false; + espEmptyBuf(); @@ -467,6 +467,8 @@ uint8_t EspDrv::getScanNetworks() LOGDEBUG(F(">> AT+CWLAP")); espSerial->println(F("AT+CWLAP")); + + char buf[100]; idx = readUntil(10000, "+CWLAP:("); @@ -607,8 +609,7 @@ bool EspDrv::startClient(const char* host, uint16_t port, uint8_t sock, uint8_t // for UDP we set a dummy remote port and UDP mode to 2 // this allows to specify the target host/port in CIPSEND - - int ret = -1; + int ret; if (protMode==TCP_MODE) ret = sendCmd(F("AT+CIPSTART=%d,\"TCP\",\"%s\",%u"), 5000, sock, host, port); else if (protMode==SSL_MODE) @@ -629,7 +630,7 @@ void EspDrv::stopClient(uint8_t sock) { LOGDEBUG1(F("> stopClient"), sock); - sendCmd(F("AT+CIPCLOSE=%d"), 4000, sock); + int ret = sendCmd(F("AT+CIPCLOSE=%d"), 4000, sock); } @@ -778,7 +779,7 @@ int EspDrv::getDataBuf(uint8_t connId, uint8_t *buf, uint16_t bufSize) if(_bufPoswrite(data, len); PGM_P p = reinterpret_cast(data); - for (uint16_t i=0; iwrite(c); @@ -1040,7 +1041,7 @@ int EspDrv::sendCmd(const __FlashStringHelper* cmd, int timeout, ...) // Returns: // the index of the tag found in the ESPTAGS array // -1 if no tag was found (timeout) -int EspDrv::readUntil(unsigned int timeout, const char* tag, bool findTags) +int EspDrv::readUntil(int timeout, const char* tag, bool findTags) { ringBuf.reset(); @@ -1109,7 +1110,7 @@ void EspDrv::espEmptyBuf(bool warn) // copied from Serial::timedRead int EspDrv::timedRead() { - unsigned int _timeout = 1000; + int _timeout = 1000; int c; long _startMillis = millis(); do diff --git a/src/utility/EspDrv.h b/src/utility/EspDrv.h index f55ec2d..5c782d9 100644 --- a/src/utility/EspDrv.h +++ b/src/utility/EspDrv.h @@ -322,7 +322,7 @@ class EspDrv static bool sendCmdGet(const __FlashStringHelper* cmd, const char* startTag, const char* endTag, char* outStr, int outStrLen); static bool sendCmdGet(const __FlashStringHelper* cmd, const __FlashStringHelper* startTag, const __FlashStringHelper* endTag, char* outStr, int outStrLen); - static int readUntil(unsigned int timeout, const char* tag=NULL, bool findTags=true); + static int readUntil(int timeout, const char* tag=NULL, bool findTags=true); static void espEmptyBuf(bool warn=true); From cd13f6053ff1f563c39fd8b0eb7dd154d5011e59 Mon Sep 17 00:00:00 2001 From: TEONE2003 <121766894+TEONE2003@users.noreply.github.com> Date: Sat, 9 Mar 2024 09:08:12 +0100 Subject: [PATCH 2/6] Create .gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e43b0f9 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.DS_Store From 37cd1c8b1462559f618bdb9c481f714603cefc6f Mon Sep 17 00:00:00 2001 From: TEONE2003 <121766894+TEONE2003@users.noreply.github.com> Date: Sat, 9 Mar 2024 09:08:34 +0100 Subject: [PATCH 3/6] Update WebClient.ino --- examples/WebClient/WebClient.ino | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/WebClient/WebClient.ino b/examples/WebClient/WebClient.ino index 7e8c802..07be74f 100644 --- a/examples/WebClient/WebClient.ino +++ b/examples/WebClient/WebClient.ino @@ -19,7 +19,7 @@ char ssid[] = "Twim"; // your network SSID (name) char pass[] = "12345678"; // your network password int status = WL_IDLE_STATUS; // the Wifi radio's status -char server[] = "arduino.cc"; +char server[] = "arduino.tips"; // Initialize the Ethernet client object WiFiEspClient client; @@ -60,7 +60,7 @@ void setup() Serial.println("Connected to server"); // Make a HTTP request client.println("GET /asciilogo.txt HTTP/1.1"); - client.println("Host: arduino.cc"); + client.println("Host: "+String(server)); client.println("Connection: close"); client.println(); } From 2b91530f49d1368c53a02a6009b56dfb0a19089a Mon Sep 17 00:00:00 2001 From: TEONE2003 <121766894+TEONE2003@users.noreply.github.com> Date: Wed, 13 Mar 2024 14:56:01 +0100 Subject: [PATCH 4/6] Default debug level at 4,default debug level at 4, 3 says too little about the error --- src/utility/debug.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utility/debug.h b/src/utility/debug.h index 37c266f..cae5ad0 100644 --- a/src/utility/debug.h +++ b/src/utility/debug.h @@ -29,7 +29,7 @@ along with The Arduino WiFiEsp library. If not, see // 4: DEBUG: errors, warnings, informational and debug #ifndef _ESPLOGLEVEL_ -#define _ESPLOGLEVEL_ 3 +#define _ESPLOGLEVEL_ 4 #endif From 6629c71c97d6065475fe28ca56d57105759e80ff Mon Sep 17 00:00:00 2001 From: TEONE2003 <121766894+TEONE2003@users.noreply.github.com> Date: Wed, 13 Mar 2024 15:01:08 +0100 Subject: [PATCH 5/6] initial ok speeded up,fixed bigug that says it doesn't support FW version 3, increased timeout,fixed passing of unsigned long values initial ok speeded up,fixed bigug that says it doesn't support FW version 3, increased timeout,fixed passing of unsigned long values --- src/utility/EspDrv.cpp | 69 ++++++++++++++++++++---------------------- src/utility/EspDrv.h | 2 +- 2 files changed, 34 insertions(+), 37 deletions(-) diff --git a/src/utility/EspDrv.cpp b/src/utility/EspDrv.cpp index 76b1a61..cd59c17 100644 --- a/src/utility/EspDrv.cpp +++ b/src/utility/EspDrv.cpp @@ -75,14 +75,14 @@ void EspDrv::wifiDriverInit(Stream *espSerial) bool initOK = false; - for(int i=0; i<5; i++) + for(int i=0; i<10; i++) { if (sendCmd(F("AT")) == TAG_OK) { initOK=true; break; } - delay(1000); + delay(500); } if (!initOK) @@ -97,17 +97,15 @@ void EspDrv::wifiDriverInit(Stream *espSerial) // check firmware version getFwVersion(); - // prints a warning message if the firmware is not 1.X or 2.X - if ((fwVersion[0] != '1' and fwVersion[0] != '2') or - fwVersion[1] != '.') - { + // prints a warning message if the firmware is not 1.X or 2.X or 3.X + if ((fwVersion[0] == '1' or fwVersion[0] == '2' or fwVersion[0] == '3')){ + LOGINFO1(F("Initilization successful -"), fwVersion); + } + else{ LOGWARN1(F("Warning: Unsupported firmware"), fwVersion); delay(4000); } - else - { - LOGINFO1(F("Initilization successful -"), fwVersion); - } + } @@ -359,6 +357,7 @@ void EspDrv::getIpAddress(IPAddress& ip) LOGDEBUG(F("> getIpAddress")); char buf[20]; + memset(buf, '\0', sizeof(buf)); if (sendCmdGet(F("AT+CIFSR"), F(":STAIP,\""), F("\""), buf, sizeof(buf))) { char* token; @@ -381,6 +380,7 @@ void EspDrv::getIpAddressAP(IPAddress& ip) LOGDEBUG(F("> getIpAddressAP")); char buf[20]; + memset(buf, '\0', sizeof(buf)); if (sendCmdGet(F("AT+CIPAP?"), F("+CIPAP:ip:\""), F("\""), buf, sizeof(buf))) { char* token; @@ -457,9 +457,7 @@ int32_t EspDrv::getCurrentRSSI() uint8_t EspDrv::getScanNetworks() { uint8_t ssidListNum = 0; - int idx; - bool ret = false; - + int idx; espEmptyBuf(); @@ -467,19 +465,17 @@ uint8_t EspDrv::getScanNetworks() LOGDEBUG(F(">> AT+CWLAP")); espSerial->println(F("AT+CWLAP")); - - char buf[100]; - idx = readUntil(10000, "+CWLAP:("); + idx = readUntil(30000, "+CWLAP:("); while (idx == NUMESPTAGS) { _networkEncr[ssidListNum] = espSerial->parseInt(); // discard , and " characters - readUntil(1000, "\""); + readUntil(3000, "\""); - idx = readUntil(1000, "\"", false); + idx = readUntil(3000, "\"", false); if(idx==NUMESPTAGS) { memset(_networkSsid[ssidListNum], 0, WL_SSID_MAX_LENGTH ); @@ -487,11 +483,11 @@ uint8_t EspDrv::getScanNetworks() } // discard , character - readUntil(1000, ","); + readUntil(3000, ","); _networkRssi[ssidListNum] = espSerial->parseInt(); - idx = readUntil(1000, "+CWLAP:("); + idx = readUntil(3000, "+CWLAP:("); if(ssidListNum==WL_NETWORKS_LIST_MAXNUM-1) break; @@ -609,7 +605,8 @@ bool EspDrv::startClient(const char* host, uint16_t port, uint8_t sock, uint8_t // for UDP we set a dummy remote port and UDP mode to 2 // this allows to specify the target host/port in CIPSEND - int ret; + + int ret = -1; if (protMode==TCP_MODE) ret = sendCmd(F("AT+CIPSTART=%d,\"TCP\",\"%s\",%u"), 5000, sock, host, port); else if (protMode==SSL_MODE) @@ -630,7 +627,7 @@ void EspDrv::stopClient(uint8_t sock) { LOGDEBUG1(F("> stopClient"), sock); - int ret = sendCmd(F("AT+CIPCLOSE=%d"), 4000, sock); + sendCmd(F("AT+CIPCLOSE=%d"), 4000, sock); } @@ -738,7 +735,7 @@ bool EspDrv::getData(uint8_t connId, uint8_t *data, bool peek, bool* connClose) // 48 = '0' if (espSerial->peek()==48+connId) { - int idx = readUntil(500, ",CLOSED\r\n", false); + int idx = readUntil(3000, ",CLOSED\r\n", false); if(idx!=NUMESPTAGS) { LOGERROR(F("Tag CLOSED not found")); @@ -779,7 +776,7 @@ int EspDrv::getDataBuf(uint8_t connId, uint8_t *buf, uint16_t bufSize) if(_bufPosprintln(cmdBuf); - int idx = readUntil(1000, (char *)">", false); + int idx = readUntil(3000, (char *)">", false); if(idx!=NUMESPTAGS) { LOGERROR(F("Data packet send error (1)")); @@ -811,7 +808,7 @@ bool EspDrv::sendData(uint8_t sock, const uint8_t *data, uint16_t len) espSerial->write(data, len); - idx = readUntil(2000); + idx = readUntil(3000); if(idx!=TAG_SENDOK) { LOGERROR(F("Data packet send error (2)")); @@ -831,7 +828,7 @@ bool EspDrv::sendData(uint8_t sock, const __FlashStringHelper *data, uint16_t le sprintf_P(cmdBuf, PSTR("AT+CIPSEND=%d,%u"), sock, len2); espSerial->println(cmdBuf); - int idx = readUntil(1000, (char *)">", false); + int idx = readUntil(3000, (char *)">", false); if(idx!=NUMESPTAGS) { LOGERROR(F("Data packet send error (1)")); @@ -840,7 +837,7 @@ bool EspDrv::sendData(uint8_t sock, const __FlashStringHelper *data, uint16_t le //espSerial->write(data, len); PGM_P p = reinterpret_cast(data); - for (int i=0; iwrite(c); @@ -851,7 +848,7 @@ bool EspDrv::sendData(uint8_t sock, const __FlashStringHelper *data, uint16_t le espSerial->write('\n'); } - idx = readUntil(2000); + idx = readUntil(3000); if(idx!=TAG_SENDOK) { LOGERROR(F("Data packet send error (2)")); @@ -871,7 +868,7 @@ bool EspDrv::sendDataUdp(uint8_t sock, const char* host, uint16_t port, const ui //LOGDEBUG1(F("> sendDataUdp:"), cmdBuf); espSerial->println(cmdBuf); - int idx = readUntil(1000, (char *)">", false); + int idx = readUntil(3000, (char *)">", false); if(idx!=NUMESPTAGS) { LOGERROR(F("Data packet send error (1)")); @@ -880,7 +877,7 @@ bool EspDrv::sendDataUdp(uint8_t sock, const char* host, uint16_t port, const ui espSerial->write(data, len); - idx = readUntil(2000); + idx = readUntil(3000); if(idx!=TAG_SENDOK) { LOGERROR(F("Data packet send error (2)")); @@ -930,7 +927,7 @@ bool EspDrv::sendCmdGet(const __FlashStringHelper* cmd, const char* startTag, co espSerial->println(cmd); // read result until the startTag is found - idx = readUntil(1000, startTag); + idx = readUntil(3000, startTag); if(idx==NUMESPTAGS) { @@ -938,7 +935,7 @@ bool EspDrv::sendCmdGet(const __FlashStringHelper* cmd, const char* startTag, co ringBuf.init(); // start tag found, search the endTag - idx = readUntil(500, endTag); + idx = readUntil(3000, endTag); if(idx==NUMESPTAGS) { @@ -947,7 +944,7 @@ bool EspDrv::sendCmdGet(const __FlashStringHelper* cmd, const char* startTag, co ringBuf.getStrN(outStr, strlen(endTag), outStrLen-1); // read the remaining part of the response - readUntil(2000); + readUntil(3000); ret = true; } @@ -1041,7 +1038,7 @@ int EspDrv::sendCmd(const __FlashStringHelper* cmd, int timeout, ...) // Returns: // the index of the tag found in the ESPTAGS array // -1 if no tag was found (timeout) -int EspDrv::readUntil(int timeout, const char* tag, bool findTags) +int EspDrv::readUntil(unsigned int timeout, const char* tag, bool findTags) { ringBuf.reset(); @@ -1110,7 +1107,7 @@ void EspDrv::espEmptyBuf(bool warn) // copied from Serial::timedRead int EspDrv::timedRead() { - int _timeout = 1000; + unsigned int _timeout = 1000; int c; long _startMillis = millis(); do diff --git a/src/utility/EspDrv.h b/src/utility/EspDrv.h index 5c782d9..f55ec2d 100644 --- a/src/utility/EspDrv.h +++ b/src/utility/EspDrv.h @@ -322,7 +322,7 @@ class EspDrv static bool sendCmdGet(const __FlashStringHelper* cmd, const char* startTag, const char* endTag, char* outStr, int outStrLen); static bool sendCmdGet(const __FlashStringHelper* cmd, const __FlashStringHelper* startTag, const __FlashStringHelper* endTag, char* outStr, int outStrLen); - static int readUntil(int timeout, const char* tag=NULL, bool findTags=true); + static int readUntil(unsigned int timeout, const char* tag=NULL, bool findTags=true); static void espEmptyBuf(bool warn=true); From e1b5a52e069d7951d6d60276ca3bf38d675bbf07 Mon Sep 17 00:00:00 2001 From: TEONE2003 <121766894+TEONE2003@users.noreply.github.com> Date: Tue, 26 Mar 2024 19:08:40 +0100 Subject: [PATCH 6/6] Update EspDrv.cpp --- src/utility/EspDrv.cpp | 42 ++++++++++++++++++++++-------------------- 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/src/utility/EspDrv.cpp b/src/utility/EspDrv.cpp index cd59c17..9ded72b 100644 --- a/src/utility/EspDrv.cpp +++ b/src/utility/EspDrv.cpp @@ -230,7 +230,7 @@ void EspDrv::config(IPAddress ip) char buf[16]; sprintf_P(buf, PSTR("%d.%d.%d.%d"), ip[0], ip[1], ip[2], ip[3]); - int ret = sendCmd(F("AT+CIPSTA_CUR=\"%s\""), 2000, buf); + int ret = sendCmd(F("AT+CIPSTA_CUR=\"%s\""), 5000, buf); delay(500); if (ret==TAG_OK) @@ -254,7 +254,7 @@ void EspDrv::configAP(IPAddress ip) char buf[16]; sprintf_P(buf, PSTR("%d.%d.%d.%d"), ip[0], ip[1], ip[2], ip[3]); - int ret = sendCmd(F("AT+CIPAP_CUR=\"%s\""), 2000, buf); + int ret = sendCmd(F("AT+CIPAP_CUR=\"%s\""), 5000, buf); delay(500); if (ret==TAG_OK) @@ -473,9 +473,9 @@ uint8_t EspDrv::getScanNetworks() _networkEncr[ssidListNum] = espSerial->parseInt(); // discard , and " characters - readUntil(3000, "\""); + readUntil(5000, "\""); - idx = readUntil(3000, "\"", false); + idx = readUntil(5000, "\"", false); if(idx==NUMESPTAGS) { memset(_networkSsid[ssidListNum], 0, WL_SSID_MAX_LENGTH ); @@ -483,11 +483,11 @@ uint8_t EspDrv::getScanNetworks() } // discard , character - readUntil(3000, ","); + readUntil(5000, ","); _networkRssi[ssidListNum] = espSerial->parseInt(); - idx = readUntil(3000, "+CWLAP:("); + idx = readUntil(5000, "+CWLAP:("); if(ssidListNum==WL_NETWORKS_LIST_MAXNUM-1) break; @@ -586,7 +586,7 @@ bool EspDrv::startServer(uint16_t port, uint8_t sock) { LOGDEBUG1(F("> startServer"), port); - int ret = sendCmd(F("AT+CIPSERVER=%d,%d"), 1000, sock, port); + int ret = sendCmd(F("AT+CIPSERVER=%d,%d"), 5000, sock, port); return ret==TAG_OK; } @@ -627,7 +627,7 @@ void EspDrv::stopClient(uint8_t sock) { LOGDEBUG1(F("> stopClient"), sock); - sendCmd(F("AT+CIPCLOSE=%d"), 4000, sock); + sendCmd(F("AT+CIPCLOSE=%d"), 5000, sock); } @@ -659,7 +659,7 @@ uint16_t EspDrv::availData(uint8_t connId) int bytes = espSerial->available(); - + if (bytes) { //LOGDEBUG1(F("Bytes in the serial buffer: "), bytes); @@ -735,7 +735,7 @@ bool EspDrv::getData(uint8_t connId, uint8_t *data, bool peek, bool* connClose) // 48 = '0' if (espSerial->peek()==48+connId) { - int idx = readUntil(3000, ",CLOSED\r\n", false); + int idx = readUntil(5000, ",CLOSED\r\n", false); if(idx!=NUMESPTAGS) { LOGERROR(F("Tag CLOSED not found")); @@ -799,7 +799,7 @@ bool EspDrv::sendData(uint8_t sock, const uint8_t *data, uint16_t len) sprintf_P(cmdBuf, PSTR("AT+CIPSEND=%d,%u"), sock, len); espSerial->println(cmdBuf); - int idx = readUntil(3000, (char *)">", false); + int idx = readUntil(5000, (char *)">", false); if(idx!=NUMESPTAGS) { LOGERROR(F("Data packet send error (1)")); @@ -808,7 +808,7 @@ bool EspDrv::sendData(uint8_t sock, const uint8_t *data, uint16_t len) espSerial->write(data, len); - idx = readUntil(3000); + idx = readUntil(5000); if(idx!=TAG_SENDOK) { LOGERROR(F("Data packet send error (2)")); @@ -828,7 +828,7 @@ bool EspDrv::sendData(uint8_t sock, const __FlashStringHelper *data, uint16_t le sprintf_P(cmdBuf, PSTR("AT+CIPSEND=%d,%u"), sock, len2); espSerial->println(cmdBuf); - int idx = readUntil(3000, (char *)">", false); + int idx = readUntil(5000, (char *)">", false); if(idx!=NUMESPTAGS) { LOGERROR(F("Data packet send error (1)")); @@ -848,7 +848,7 @@ bool EspDrv::sendData(uint8_t sock, const __FlashStringHelper *data, uint16_t le espSerial->write('\n'); } - idx = readUntil(3000); + idx = readUntil(5000); if(idx!=TAG_SENDOK) { LOGERROR(F("Data packet send error (2)")); @@ -868,7 +868,7 @@ bool EspDrv::sendDataUdp(uint8_t sock, const char* host, uint16_t port, const ui //LOGDEBUG1(F("> sendDataUdp:"), cmdBuf); espSerial->println(cmdBuf); - int idx = readUntil(3000, (char *)">", false); + int idx = readUntil(5000, (char *)">", false); if(idx!=NUMESPTAGS) { LOGERROR(F("Data packet send error (1)")); @@ -877,7 +877,7 @@ bool EspDrv::sendDataUdp(uint8_t sock, const char* host, uint16_t port, const ui espSerial->write(data, len); - idx = readUntil(3000); + idx = readUntil(5000); if(idx!=TAG_SENDOK) { LOGERROR(F("Data packet send error (2)")); @@ -927,7 +927,7 @@ bool EspDrv::sendCmdGet(const __FlashStringHelper* cmd, const char* startTag, co espSerial->println(cmd); // read result until the startTag is found - idx = readUntil(3000, startTag); + idx = readUntil(5000, startTag); if(idx==NUMESPTAGS) { @@ -935,7 +935,7 @@ bool EspDrv::sendCmdGet(const __FlashStringHelper* cmd, const char* startTag, co ringBuf.init(); // start tag found, search the endTag - idx = readUntil(3000, endTag); + idx = readUntil(5000, endTag); if(idx==NUMESPTAGS) { @@ -944,7 +944,7 @@ bool EspDrv::sendCmdGet(const __FlashStringHelper* cmd, const char* startTag, co ringBuf.getStrN(outStr, strlen(endTag), outStrLen-1); // read the remaining part of the response - readUntil(3000); + readUntil(5000); ret = true; } @@ -1050,6 +1050,7 @@ int EspDrv::readUntil(unsigned int timeout, const char* tag, bool findTags) { if(espSerial->available()) { + c = (char)espSerial->read(); LOGDEBUG0(c); ringBuf.push(c); @@ -1075,6 +1076,7 @@ int EspDrv::readUntil(unsigned int timeout, const char* tag, bool findTags) } } } + if (millis() - start >= timeout) { @@ -1107,7 +1109,7 @@ void EspDrv::espEmptyBuf(bool warn) // copied from Serial::timedRead int EspDrv::timedRead() { - unsigned int _timeout = 1000; + unsigned int _timeout = 5000; int c; long _startMillis = millis(); do