Skip to content

Commit d50fe38

Browse files
authored
Merge pull request #38 from bjnhur/master
Recreating #34
2 parents d7c6a9f + 847070e commit d50fe38

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

adafruit_wiznet5k/adafruit_wiznet5k.py

+12
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ def __init__(
178178
self.mac_address = mac
179179
self.src_port = 0
180180
self._dns = 0
181+
181182
# Set DHCP
182183
self._dhcp_client = None
183184
if is_dhcp:
@@ -196,6 +197,17 @@ def set_dhcp(self, hostname=None, response_timeout=30):
196197
"""
197198
if self._debug:
198199
print("* Initializing DHCP")
200+
201+
# First, wait link status is on
202+
# to avoid the code during DHCP - assert self.link_status, "Ethernet cable disconnected!"
203+
start_time = time.monotonic()
204+
while True:
205+
if self.link_status or ((time.monotonic() - start_time) > 5):
206+
break
207+
time.sleep(1)
208+
if self._debug:
209+
print("My Link is:", self.link_status)
210+
199211
# Return IP assigned by DHCP
200212
self._dhcp_client = dhcp.DHCP(
201213
self, self.mac_address, hostname, response_timeout, debug=self._debug

examples/wiznet5k_simpleserver.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,10 @@
2828
server.bind((server_ip, server_port)) # Bind to IP and Port
2929
server.listen() # Begin listening for incoming clients
3030

31+
conn, addr = server.accept() # Wait for a connection from a client.
3132
while True:
32-
conn, addr = server.accept() # Wait for a connection from a client.
3333
with conn:
34-
data = conn.recv()
35-
print(data)
36-
conn.send(data) # Echo message back to client
34+
data = conn.recv(1024)
35+
if data: # Wait for receiving data
36+
print(data)
37+
conn.send(data) # Echo message back to client

0 commit comments

Comments
 (0)