Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

match cpython recv timeout behavior. new httpserver example #125

Merged
merged 3 commits into from
Jan 29, 2024

Conversation

FoamyGuy
Copy link
Contributor

@FoamyGuy FoamyGuy commented Jun 26, 2023

This PR has two primary chagnes:

  1. make recv() function timeout with the same behavior as CPython sockets, and ESP32SPI socket from the changes in: Compatible socket Adafruit_CircuitPython_ESP32SPI#167

This change is necessary in order to have the MiniMQTT library function as expected. Without this change when you call mqtt_client.loop() it will never return until actual data has been recieved. But it should be returning sooner based on the timeout behavior when there is no data.

This comment: adafruit/Adafruit_CircuitPython_ESP32SPI#167 (comment) contains CPython code snippets that illustrate the timeout behavior of the socket. The changes in this PR will make the wiznet socket behave the same.

The CPython socket has a custom exception class called timeout which I've added as well. There were a few other unrelated function arguments that already had the name timeout so pylint started complaining about overwriting from outer scope. I've changed those arguments to have leading underscores.

I tested this change succesfully using an Ethernet Featherwing with a Feather ESP32-S3 TFT 8.2.0-beta.0 I tested with simpletest, simpleserver, and aio_post examples from this repo, the ethernet adafruitio example in the MiniMQTT library, as well as the new HTTPServer example added and explained below.

  1. Add an example that shows how to use this library with: https://github.com/adafruit/Adafruit_CircuitPython_HTTPServer I also opened: adding ethernet example Adafruit_CircuitPython_HTTPServer#59 over there adding this same example code in that repo. I think it makes sense to exist in both places because I could easily imagine people discovering it in either while researching possibilities.

Copy link
Contributor

@dhalbert dhalbert left a comment

Choose a reason for hiding this comment

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

Belated thanks!

# Conflicts:
#	adafruit_wiznet5k/adafruit_wiznet5k_socket.py
@FoamyGuy
Copy link
Contributor Author

Most of this was also done in #139. with the latest commits I've merged main and resolved conflicts as well as one tweak that resolves #141 so that the library can be successfully initialized.

Re-tested successfully on a Feather RP2040 although I've noticed with my setup it consistently fails if my ethernet featherwing is connected to an ethernet switch rather than directly to the router. I have a PC and RasPi on that same switch that work fine but the microcontroller + Ethernet featherwing and this library do not. I suspect that is something specific to my environment and not an issue with this library.

@FoamyGuy FoamyGuy merged commit 3bd953e into adafruit:main Jan 29, 2024
1 check passed
adafruit-adabot added a commit to adafruit/Adafruit_CircuitPython_Bundle that referenced this pull request Jan 30, 2024
Updating https://github.com/adafruit/Adafruit_CircuitPython_Wiznet5k to 5.0.6 from 5.0.5:
  > Merge pull request adafruit/Adafruit_CircuitPython_Wiznet5k#125 from FoamyGuy/recv_timeout

Updating https://github.com/adafruit/Adafruit_CircuitPython_HTTPServer to 4.5.1 from 4.5.0:
  > Merge pull request adafruit/Adafruit_CircuitPython_HTTPServer#76 from michalpokusa/routes-refactor

Updating https://github.com/adafruit/Adafruit_CircuitPython_MiniMQTT to 7.5.8 from 7.5.6:
  > Merge pull request adafruit/Adafruit_CircuitPython_MiniMQTT#199 from vladak/loop_vs_keep_alive
  > Merge pull request adafruit/Adafruit_CircuitPython_MiniMQTT#200 from vladak/loop_timeout_vs_socket_timeout
  > Merge pull request adafruit/Adafruit_CircuitPython_MiniMQTT#184 from rjauquet/rej-fix-loop-blocking

Updating https://github.com/adafruit/Adafruit_CircuitPython_PIOASM to 1.0.0 from 0.8.2:
  > Merge pull request adafruit/Adafruit_CircuitPython_PIOASM#61 from Gebhartj/Gebhartj-patch-1

Updating https://github.com/adafruit/Adafruit_CircuitPython_Bundle/circuitpython_library_list.md to NA from NA:
  > Updated download stats for the libraries
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.

2 participants