Proper look for connection.

See discussion here: https://github.com/esp8266/Arduino/issues/5257
This commit is contained in:
TD-er
2018-10-20 00:20:58 +02:00
parent a50a035238
commit 6f226e6d65
3 changed files with 34 additions and 25 deletions
+2 -2
View File
@@ -78,7 +78,7 @@ bool do_process_c003_delay_queue(int controller_number, const C003_queue_element
client.print(" \n");
unsigned long timer = millis() + 200;
while (!client.available() && !timeOutReached(timer))
while (!client_available(client) && !timeOutReached(timer))
delay(1);
timer = millis() + 1000;
@@ -102,7 +102,7 @@ bool do_process_c003_delay_queue(int controller_number, const C003_queue_element
addLog(LOG_LEVEL_DEBUG, log);
client.println(SecuritySettings.ControllerPassword[element.controller_idx]);
delay(100);
while (client.available())
while (client_available(client))
client.read();
strcpy_P(log, PSTR("TELNT: Sending cmd"));
+2 -2
View File
@@ -106,8 +106,8 @@ boolean Blynk_get(const String& command, byte controllerIndex, float *data )
boolean success = !ControllerSettings.MustCheckReply;
if (ControllerSettings.MustCheckReply || data) {
unsigned long timer = millis() + 200;
while (!client.available() && !timeOutReached(timer))
yield();
while (!client_available(client) && !timeOutReached(timer))
delay(1);
char log[80] = {0};
+30 -21
View File
@@ -402,26 +402,30 @@ bool safeReadStringUntil(Stream &input, String &str, char terminator, unsigned i
do {
//read character
c = input.read();
if (c >= 0) {
//found terminator, we're ok
if (c == terminator) {
return(true);
}
//found character, add to string
else{
str += char(c);
//string at max size?
if (str.length() >= maxSize) {
addLog(LOG_LEVEL_ERROR, F("Not enough bufferspace to read all input data!"));
return(false);
}
}
}
// We must run the backgroundtasks every now and then.
if (timeOutReached(backgroundtasks_timer)) {
backgroundtasks_timer += 10;
backgroundtasks();
if (input.available()) {
c = input.read();
if (c >= 0) {
//found terminator, we're ok
if (c == terminator) {
return(true);
}
//found character, add to string
else{
str += char(c);
//string at max size?
if (str.length() >= maxSize) {
addLog(LOG_LEVEL_ERROR, F("Not enough bufferspace to read all input data!"));
return(false);
}
}
}
// We must run the backgroundtasks every now and then.
if (timeOutReached(backgroundtasks_timer)) {
backgroundtasks_timer += 10;
backgroundtasks();
} else {
yield();
}
} else {
yield();
}
@@ -621,6 +625,11 @@ bool try_connect_host(int controller_number, WiFiClient& client, ControllerSetti
// See: https://github.com/esp8266/Arduino/pull/5113
// https://github.com/esp8266/Arduino/pull/1829
bool client_available(WiFiClient& client) {
#ifdef ESP32
yield();
#else
esp_yield(); // Could be called from events
#endif
return client.available() || client.connected();
}
@@ -631,7 +640,7 @@ bool send_via_http(const String& logIdentifier, WiFiClient& client, const String
if (must_check_reply) {
unsigned long timer = millis() + 200;
while (!client.available()) {
while (!client_available(client)) {
if (timeOutReached(timer)) return false;
delay(1);
}