Skip to content

Commit 3bd953e

Browse files
authored
Merge pull request adafruit#125 from FoamyGuy/recv_timeout
match cpython recv timeout behavior. new httpserver example
2 parents ab349c6 + 8217dc3 commit 3bd953e

File tree

3 files changed

+39
-3
lines changed

3 files changed

+39
-3
lines changed

adafruit_wiznet5k/adafruit_wiznet5k.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@
165165
_MAX_PACKET = const(4000)
166166
_LOCAL_PORT = const(0x400)
167167
# Default hardware MAC address
168-
_DEFAULT_MAC = (0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED)
168+
_DEFAULT_MAC = "DE:AD:BE:EF:FE:ED"
169169

170170
# Maximum number of sockets to support, differs between chip versions.
171171
_MAX_SOCK_NUM = {"w5100s": const(0x04), "w5500": const(0x08), "w6100": const(0x08)}

adafruit_wiznet5k/adafruit_wiznet5k_socket.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,8 @@ def setdefaulttimeout(_timeout: Optional[float]) -> None:
7979
:param Optional[float] _timeout: The default timeout in seconds or None.
8080
"""
8181
global _default_socket_timeout # pylint: disable=global-statement
82-
if _timeout is None or (isinstance(timeout, (int, float)) and timeout >= 0):
83-
_default_socket_timeout = timeout
82+
if _timeout is None or (isinstance(_timeout, (int, float)) and _timeout >= 0):
83+
_default_socket_timeout = _timeout
8484
else:
8585
raise ValueError("Timeout must be None, 0.0 or a positive numeric value.")
8686

examples/wiznet5k_httpserver.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# SPDX-FileCopyrightText: 2023 Tim C for Adafruit Industries
2+
# SPDX-License-Identifier: MIT
3+
4+
import board
5+
import digitalio
6+
from adafruit_httpserver import Server, Request, Response
7+
from adafruit_wiznet5k.adafruit_wiznet5k import WIZNET5K
8+
import adafruit_wiznet5k.adafruit_wiznet5k_socket as socket
9+
10+
print("Wiznet5k HTTPServer Test")
11+
12+
# For Adafruit Ethernet FeatherWing
13+
cs = digitalio.DigitalInOut(board.D10)
14+
# For Particle Ethernet FeatherWing
15+
# cs = digitalio.DigitalInOut(board.D5)
16+
spi_bus = board.SPI()
17+
18+
# Initialize ethernet interface with DHCP
19+
eth = WIZNET5K(spi_bus, cs)
20+
21+
# set the interface on the socket source
22+
socket.set_interface(eth)
23+
24+
# initialize the server
25+
server = Server(socket, "/static", debug=True)
26+
27+
28+
@server.route("/")
29+
def base(request: Request):
30+
"""
31+
Serve a default static plain text message.
32+
"""
33+
return Response(request, "Hello from the CircuitPython HTTP Server!")
34+
35+
36+
server.serve_forever(str(eth.pretty_ip(eth.ip_address)))

0 commit comments

Comments
 (0)