Skip to content
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
12 changes: 12 additions & 0 deletions adafruit_wiznet5k/adafruit_wiznet5k.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ def __init__(
self.mac_address = mac
self.src_port = 0
self._dns = 0

# Set DHCP
self._dhcp_client = None
if is_dhcp:
Expand All @@ -196,6 +197,17 @@ def set_dhcp(self, hostname=None, response_timeout=30):
"""
if self._debug:
print("* Initializing DHCP")

# First, wait link status is on
# to avoid the code during DHCP - assert self.link_status, "Ethernet cable disconnected!"
start_time = time.monotonic()
while True:
if self.link_status or ((time.monotonic() - start_time) > 5):
break
time.sleep(1)
if self._debug:
print("My Link is:", self.link_status)

# Return IP assigned by DHCP
self._dhcp_client = dhcp.DHCP(
self, self.mac_address, hostname, response_timeout, debug=self._debug
Expand Down
9 changes: 5 additions & 4 deletions examples/wiznet5k_simpleserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,10 @@
server.bind((server_ip, server_port)) # Bind to IP and Port
server.listen() # Begin listening for incoming clients

conn, addr = server.accept() # Wait for a connection from a client.
while True:
conn, addr = server.accept() # Wait for a connection from a client.
with conn:
data = conn.recv()
print(data)
conn.send(data) # Echo message back to client
data = conn.recv(1024)
if data: # Wait for receiving data
print(data)
conn.send(data) # Echo message back to client