Skip to content

Commit 9159e5f

Browse files
committed
feat(wifi): add WiFiUDP::setReplyTimeout()
1 parent 7730c3f commit 9159e5f

2 files changed

Lines changed: 21 additions & 2 deletions

File tree

‎src/system/wifi/esp32SpiAtUdp.cpp‎

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ bool WiFiUDP::write(uint8_t *_packet, uint16_t _len)
205205
_availableData = 0;
206206
_currentPosition = _rxBuffer;
207207
if (_rxBuffer != NULL)
208-
WiFi.getSimpleAtResponse(_rxBuffer, INKPLATE_ESP32_AT_CMD_BUFFER_SIZE, 20000ULL, &_availableData);
208+
WiFi.getSimpleAtResponse(_rxBuffer, INKPLATE_ESP32_AT_CMD_BUFFER_SIZE, _replyTimeoutValue, &_availableData);
209209

210210
return _availableData != 0;
211211
}
@@ -314,4 +314,19 @@ bool WiFiUDP::end()
314314
void WiFiUDP::setConnectionTimeout(uint16_t _connectionTimeout)
315315
{
316316
_connectionTimeoutValue = _connectionTimeout;
317-
}
317+
}
318+
319+
/**
320+
* @brief Sets how long write() waits for the reply packet, in milliseconds (default 20000).
321+
*
322+
* @param uint32_t _replyTimeout
323+
* Reply timeout in milliseconds.
324+
*
325+
* @note UDP can lose packets. With a lost reply, write() blocks until this timeout or until any other
326+
* inbound packet arrives, which is then returned as the reply. Keep it close to the expected
327+
* round-trip time and check the payload of what read() returns.
328+
*/
329+
void WiFiUDP::setReplyTimeout(uint32_t _replyTimeout)
330+
{
331+
_replyTimeoutValue = _replyTimeout;
332+
}

‎src/system/wifi/esp32SpiAtUdp.h‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,15 @@ class WiFiUDP
5858
// Sets connection timeout in milliseconds.
5959
void setConnectionTimeout(uint16_t _connectionTimeout);
6060

61+
// Sets how long write() waits for the reply packet in milliseconds.
62+
void setReplyTimeout(uint32_t _replyTimeout);
63+
6164
private:
6265
uint16_t _localUdpPort = 0;
6366
uint16_t _availableData = 0;
6467
char *_currentPosition = 0;
6568
uint16_t _connectionTimeoutValue = 20000ULL;
69+
uint32_t _replyTimeoutValue = 20000ULL;
6670
char *_dataBuffer = NULL;
6771

6872
// Private RX buffer. Received data must not live in WiFi's shared AT buffer, otherwise any

0 commit comments

Comments
 (0)