diff --git a/src/modules/SX126x/SX126x.cpp b/src/modules/SX126x/SX126x.cpp index 2a308f1a..a8f4b013 100644 --- a/src/modules/SX126x/SX126x.cpp +++ b/src/modules/SX126x/SX126x.cpp @@ -563,9 +563,10 @@ int16_t SX126x::readData(uint8_t* data, size_t len) { } // get packet length - size_t length = len; - if(len == RADIOLIB_SX126X_MAX_PACKET_LENGTH) { - length = getPacketLength(); + size_t length = getPacketLength(); + if((len != 0) && (len < length)) { + // user requested less data than we got, only return what was requested + length = len; } // read packet data diff --git a/src/modules/SX126x/SX126x.h b/src/modules/SX126x/SX126x.h index 79564f2f..bd9525ce 100644 --- a/src/modules/SX126x/SX126x.h +++ b/src/modules/SX126x/SX126x.h @@ -550,7 +550,8 @@ class SX126x: public PhysicalLayer { \param data Pointer to array to save the received binary data. - \param len Number of bytes that will be received. Must be known in advance for binary transmissions. + \param len Number of bytes that will be read. When set to 0, the packet length will be retreived automatically. + When more bytes than received are requested, only the number of bytes requested will be returned. \returns \ref status_codes */