Skip to content

Conversation

@bablokb
Copy link
Contributor

@bablokb bablokb commented Dec 15, 2025

This fix dramatically reduces lost packages when polling for packets.

Consider this use case:

while True:
  p = my_rfm95x.receive(keep_listening=True, timeout=2)
  if p:
   do_something(p)

If a packet arrives partially just before the timeout kicks in, the packet is lost because the receive-method switches to idle, clears the queue and the interrupt. This patch does not do and just returns, so the next iteration will pick up the packet.

Note that the problem is independent of the actual value of timeout, because with any timeout-value you can run into this problem. The problem is more prominent with low bitrates, since transfers take much longer and therefore the chance of hitting the timeout is much higher.

The new combined library has the same problem I think, but I did not test because my application still uses this library.

@jerryneedell
Copy link
Contributor

@bablokb Thank you for this. It looks like an excellent improvement. I have been troubled by this for awhile and just never thought of such a simple solution!
Unfortunately, I have very limited internet access today ( my provider is doing "upgrades"). When I can get back online fully. I'll run some tests and will also implement this for the combined RFM library.

Copy link
Contributor

@jerryneedell jerryneedell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good to me - thank you!

@dhalbert dhalbert merged commit ad05a38 into adafruit:main Dec 16, 2025
1 check passed
adafruit-adabot pushed a commit to adafruit/Adafruit_CircuitPython_Bundle that referenced this pull request Dec 17, 2025
@jerryneedell
Copy link
Contributor

@bablokb Thank you for this -- I have also implemented it for the adafruit_rfm69 and adafruit_rfm libraries.
adafruit/Adafruit_CircuitPython_RFM69#58
adafruit/Adafruit_CircuitPython_RFM#21

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants