Skip to content

Commit

Permalink
Merge pull request #38 from bjnhur/master
Browse files Browse the repository at this point in the history
Recreating #34
  • Loading branch information
evaherrada authored Jun 7, 2021
2 parents d7c6a9f + 847070e commit d50fe38
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
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

0 comments on commit d50fe38

Please sign in to comment.