Skip to content

Recreating #34 #38

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

Merged
merged 11 commits into from
Jun 7, 2021
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