diff --git a/adafruit_wiznet5k/adafruit_wiznet5k.py b/adafruit_wiznet5k/adafruit_wiznet5k.py index ddf798a..9b43c76 100644 --- a/adafruit_wiznet5k/adafruit_wiznet5k.py +++ b/adafruit_wiznet5k/adafruit_wiznet5k.py @@ -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)} diff --git a/adafruit_wiznet5k/adafruit_wiznet5k_socket.py b/adafruit_wiznet5k/adafruit_wiznet5k_socket.py index 7fd3673..e0687a0 100644 --- a/adafruit_wiznet5k/adafruit_wiznet5k_socket.py +++ b/adafruit_wiznet5k/adafruit_wiznet5k_socket.py @@ -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.") diff --git a/examples/wiznet5k_httpserver.py b/examples/wiznet5k_httpserver.py new file mode 100644 index 0000000..7f7d8b3 --- /dev/null +++ b/examples/wiznet5k_httpserver.py @@ -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)))