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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)))
Loading