Skip to content

Commit

Permalink
Merge pull request #125 from FoamyGuy/recv_timeout
Browse files Browse the repository at this point in the history
match cpython recv timeout behavior. new httpserver example
  • Loading branch information
FoamyGuy authored Jan 29, 2024
2 parents ab349c6 + 8217dc3 commit 3bd953e
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 3 deletions.
2 changes: 1 addition & 1 deletion adafruit_wiznet5k/adafruit_wiznet5k.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@
_MAX_PACKET = const(4000)
_LOCAL_PORT = const(0x400)
# Default hardware MAC address
_DEFAULT_MAC = (0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED)
_DEFAULT_MAC = "DE:AD:BE:EF:FE:ED"

# Maximum number of sockets to support, differs between chip versions.
_MAX_SOCK_NUM = {"w5100s": const(0x04), "w5500": const(0x08), "w6100": const(0x08)}
Expand Down
4 changes: 2 additions & 2 deletions adafruit_wiznet5k/adafruit_wiznet5k_socket.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ def setdefaulttimeout(_timeout: Optional[float]) -> None:
:param Optional[float] _timeout: The default timeout in seconds or None.
"""
global _default_socket_timeout # pylint: disable=global-statement
if _timeout is None or (isinstance(timeout, (int, float)) and timeout >= 0):
_default_socket_timeout = timeout
if _timeout is None or (isinstance(_timeout, (int, float)) and _timeout >= 0):
_default_socket_timeout = _timeout
else:
raise ValueError("Timeout must be None, 0.0 or a positive numeric value.")

Expand Down
36 changes: 36 additions & 0 deletions examples/wiznet5k_httpserver.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# SPDX-FileCopyrightText: 2023 Tim C for Adafruit Industries
# SPDX-License-Identifier: MIT

import board
import digitalio
from adafruit_httpserver import Server, Request, Response
from adafruit_wiznet5k.adafruit_wiznet5k import WIZNET5K
import adafruit_wiznet5k.adafruit_wiznet5k_socket as socket

print("Wiznet5k HTTPServer Test")

# For Adafruit Ethernet FeatherWing
cs = digitalio.DigitalInOut(board.D10)
# For Particle Ethernet FeatherWing
# cs = digitalio.DigitalInOut(board.D5)
spi_bus = board.SPI()

# Initialize ethernet interface with DHCP
eth = WIZNET5K(spi_bus, cs)

# set the interface on the socket source
socket.set_interface(eth)

# initialize the server
server = Server(socket, "/static", debug=True)


@server.route("/")
def base(request: Request):
"""
Serve a default static plain text message.
"""
return Response(request, "Hello from the CircuitPython HTTP Server!")


server.serve_forever(str(eth.pretty_ip(eth.ip_address)))

0 comments on commit 3bd953e

Please sign in to comment.