Skip to content

Commit 6f226e6

Browse files
committed
Proper look for connection.
See discussion here: esp8266/Arduino#5257
1 parent a50a035 commit 6f226e6

File tree

3 files changed

+34
-25
lines changed

3 files changed

+34
-25
lines changed

src/_C003.ino

+2-2
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ bool do_process_c003_delay_queue(int controller_number, const C003_queue_element
7878
client.print(" \n");
7979

8080
unsigned long timer = millis() + 200;
81-
while (!client.available() && !timeOutReached(timer))
81+
while (!client_available(client) && !timeOutReached(timer))
8282
delay(1);
8383

8484
timer = millis() + 1000;
@@ -102,7 +102,7 @@ bool do_process_c003_delay_queue(int controller_number, const C003_queue_element
102102
addLog(LOG_LEVEL_DEBUG, log);
103103
client.println(SecuritySettings.ControllerPassword[element.controller_idx]);
104104
delay(100);
105-
while (client.available())
105+
while (client_available(client))
106106
client.read();
107107

108108
strcpy_P(log, PSTR("TELNT: Sending cmd"));

src/_C012.ino

+2-2
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,8 @@ boolean Blynk_get(const String& command, byte controllerIndex, float *data )
106106
boolean success = !ControllerSettings.MustCheckReply;
107107
if (ControllerSettings.MustCheckReply || data) {
108108
unsigned long timer = millis() + 200;
109-
while (!client.available() && !timeOutReached(timer))
110-
yield();
109+
while (!client_available(client) && !timeOutReached(timer))
110+
delay(1);
111111

112112
char log[80] = {0};
113113

src/_CPlugin_Helper.h

+30-21
Original file line numberDiff line numberDiff line change
@@ -402,26 +402,30 @@ bool safeReadStringUntil(Stream &input, String &str, char terminator, unsigned i
402402

403403
do {
404404
//read character
405-
c = input.read();
406-
if (c >= 0) {
407-
//found terminator, we're ok
408-
if (c == terminator) {
409-
return(true);
410-
}
411-
//found character, add to string
412-
else{
413-
str += char(c);
414-
//string at max size?
415-
if (str.length() >= maxSize) {
416-
addLog(LOG_LEVEL_ERROR, F("Not enough bufferspace to read all input data!"));
417-
return(false);
418-
}
419-
}
420-
}
421-
// We must run the backgroundtasks every now and then.
422-
if (timeOutReached(backgroundtasks_timer)) {
423-
backgroundtasks_timer += 10;
424-
backgroundtasks();
405+
if (input.available()) {
406+
c = input.read();
407+
if (c >= 0) {
408+
//found terminator, we're ok
409+
if (c == terminator) {
410+
return(true);
411+
}
412+
//found character, add to string
413+
else{
414+
str += char(c);
415+
//string at max size?
416+
if (str.length() >= maxSize) {
417+
addLog(LOG_LEVEL_ERROR, F("Not enough bufferspace to read all input data!"));
418+
return(false);
419+
}
420+
}
421+
}
422+
// We must run the backgroundtasks every now and then.
423+
if (timeOutReached(backgroundtasks_timer)) {
424+
backgroundtasks_timer += 10;
425+
backgroundtasks();
426+
} else {
427+
yield();
428+
}
425429
} else {
426430
yield();
427431
}
@@ -621,6 +625,11 @@ bool try_connect_host(int controller_number, WiFiClient& client, ControllerSetti
621625
// See: https://github.com/esp8266/Arduino/pull/5113
622626
// https://github.com/esp8266/Arduino/pull/1829
623627
bool client_available(WiFiClient& client) {
628+
#ifdef ESP32
629+
yield();
630+
#else
631+
esp_yield(); // Could be called from events
632+
#endif
624633
return client.available() || client.connected();
625634
}
626635

@@ -631,7 +640,7 @@ bool send_via_http(const String& logIdentifier, WiFiClient& client, const String
631640

632641
if (must_check_reply) {
633642
unsigned long timer = millis() + 200;
634-
while (!client.available()) {
643+
while (!client_available(client)) {
635644
if (timeOutReached(timer)) return false;
636645
delay(1);
637646
}

0 commit comments

Comments
 (0)