get read of delays caused by readUntil from network

pull/191/head
Hansi, dl9rdz 2021-09-22 16:16:15 +02:00
rodzic cb5b3584d0
commit d4de05e29b
1 zmienionych plików z 15 dodań i 6 usunięć

Wyświetl plik

@ -3527,15 +3527,24 @@ void sondehub_reply_handler(WiFiClient *client) {
else {
// any reply here belongs to normal telemetry upload, lets just print it.
// and wait for a valid HTTP response
int cnt = 0;
while(client->available() > 0) {
// data is available from remote server, process it...
int cnt = client->readBytesUntil('\n', rs_msg, MSG_SIZE - 1);
rs_msg[cnt] = 0;
Serial.println(rs_msg);
// If something that looks like a valid HTTP response is received, we are ready to send the next data item
if (shState == SH_CONN_WAITACK && cnt > 11 && strncmp(rs_msg, "HTTP/1", 6) == 0) {
shState = SH_CONN_IDLE;
// readBytesUntil may wait for up to 1 second if enough data is not available...
// int cnt = client->readBytesUntil('\n', rs_msg, MSG_SIZE - 1);
int c = client->read();
if(c<0) break; // should never happen in available() returned >0 right before....
rs_msg[cnt++] = c;
if(c=='\n') {
rs_msg[cnt] = 0;
Serial.println(rs_msg);
// If something that looks like a valid HTTP response is received, we are ready to send the next data item
if (shState == SH_CONN_WAITACK && cnt > 11 && strncmp(rs_msg, "HTTP/1", 6) == 0) {
shState = SH_CONN_IDLE;
}
cnt=0;
}
if(cnt>=MSG_SIZE-1) { cnt=0; }
}
}
// send import requests if needed