From 7fa5af15db5cb0ae55aacc2a1e9aee81cb6d1ab6 Mon Sep 17 00:00:00 2001 From: Martino Facchin Date: Tue, 7 Jan 2025 12:09:34 +0100 Subject: [PATCH] WiFiS3: fix peek() avoiding AT call Fixes https://github.com/arduino/ArduinoCore-renesas/issues/419 --- libraries/WiFiS3/src/WiFiClient.cpp | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/libraries/WiFiS3/src/WiFiClient.cpp b/libraries/WiFiS3/src/WiFiClient.cpp index 9e6d0926..e0a37aa9 100644 --- a/libraries/WiFiS3/src/WiFiClient.cpp +++ b/libraries/WiFiS3/src/WiFiClient.cpp @@ -185,15 +185,11 @@ int WiFiClient::read(uint8_t *buf, size_t size) { /* -------------------------------------------------------------------------- */ int WiFiClient::peek() { /* -------------------------------------------------------------------------- */ - int rv = -1; - if(_sock >= 0) { - string res = ""; - modem.begin(); - if(modem.write(string(PROMPT(_PEEK)),res, "%s%d\r\n" , CMD_WRITE(_PEEK), _sock)) { - rv = atoi(res.c_str()); - } + read_if_needed(1); + if(_sock >= 0 && rx_buffer != nullptr) { + return rx_buffer->peek(); } - return rv; + return -1; }