Skip to content

Commit 0d7a819

Browse files
committed
Add notes about Serial.available on ESP32
1 parent 8a178e3 commit 0d7a819

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

src/SparkFun_u-blox_SARA-R5_Arduino_Library.cpp

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,14 @@ bool SARA_R5::bufferedPoll(void)
225225

226226
if ((hwAvailable() > 0) || (backlogLen > 0)) // If either new data is available, or backlog had data.
227227
{
228-
// Wait for up to _rxWindowMillis for new serial data to arrive.
228+
//Check for incoming serial data. Copy it into the backlog
229+
230+
// Important note:
231+
// On ESP32, Serial.available only provides an update every ~120 bytes during the reception of long messages:
232+
// https://gitter.im/espressif/arduino-esp32?at=5e25d6370a1cf54144909c85
233+
// Be aware that if a long message is being received, the code below will timeout after _rxWindowMillis = 2 millis.
234+
// At 115200 baud, hwAvailable takes ~120 * 10 / 115200 = 10.4 millis before it indicates that data is being received.
235+
229236
while (((millis() - timeIn) < _rxWindowMillis) && (avail < _RXBuffSize))
230237
{
231238
if (hwAvailable() > 0) //hwAvailable can return -1 if the serial port is NULL
@@ -5648,7 +5655,14 @@ SARA_R5_error_t SARA_R5::sendCustomCommandWithResponse(const char *command, cons
56485655

56495656
void SARA_R5::sendCommand(const char *command, bool at)
56505657
{
5651-
//Spend up to _rxWindowMillis milliseconds copying any incoming serial data into the backlog
5658+
//Check for incoming serial data. Copy it into the backlog
5659+
5660+
// Important note:
5661+
// On ESP32, Serial.available only provides an update every ~120 bytes during the reception of long messages:
5662+
// https://gitter.im/espressif/arduino-esp32?at=5e25d6370a1cf54144909c85
5663+
// Be aware that if a long message is being received, the code below will timeout after _rxWindowMillis = 2 millis.
5664+
// At 115200 baud, hwAvailable takes ~120 * 10 / 115200 = 10.4 millis before it indicates that data is being received.
5665+
56525666
unsigned long timeIn = millis();
56535667
if (hwAvailable() > 0) //hwAvailable can return -1 if the serial port is NULL
56545668
{

src/SparkFun_u-blox_SARA-R5_Arduino_Library.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -600,9 +600,9 @@ class SARA_R5 : public Print
600600

601601
// This function was originally written by Matthew Menze for the LTE Shield (SARA-R4) library
602602
// See: https://github.com/sparkfun/SparkFun_LTE_Shield_Arduino_Library/pull/8
603-
// It does the same job as ::poll but also processed any 'old' data stored in the backlog first
603+
// It does the same job as ::poll but also processes any 'old' data stored in the backlog first
604604
// It also has a built-in timeout - which ::poll does not
605-
// Use this - it is way better than ::poll. Thank you Natthew!
605+
// Use this - it is way better than ::poll. Thank you Matthew!
606606
bool bufferedPoll(void);
607607

608608
// This is the original poll function.
@@ -963,7 +963,7 @@ class SARA_R5 : public Print
963963
bool _pollReentrant = false; // Prevent reentry of poll - just in case it gets called from a callback
964964

965965
#define _RXBuffSize 2056
966-
const unsigned long _rxWindowMillis = 2; // 1ms is not quite long enough for a single char at 9600 baud. millis roll over much less often than micros.
966+
const unsigned long _rxWindowMillis = 2; // 1ms is not quite long enough for a single char at 9600 baud. millis roll over much less often than micros. See notes in .cpp re. ESP32!
967967
char *_saraRXBuffer; // Allocated in SARA_R5::begin
968968
char *_pruneBuffer;
969969
char *_saraResponseBacklog;

0 commit comments

Comments
 (0)