Skip to content

Commit 456fc8a

Browse files
author
Bongjun Hur
committed
link check in set_dhcp
1 parent cde9d66 commit 456fc8a

File tree

2 files changed

+12
-14
lines changed

2 files changed

+12
-14
lines changed

adafruit_wiznet5k/adafruit_wiznet5k.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -176,16 +176,6 @@ def __init__(
176176
self._src_port = 0
177177
self._dns = 0
178178

179-
# First wait link status is on
180-
# to avoid the code during DHCP - assert self.link_status, "Ethernet cable disconnected!"
181-
start_time = time.monotonic()
182-
while True:
183-
if self.link_status or ((time.monotonic() - start_time) > 5) :
184-
break
185-
time.sleep(1)
186-
if self._debug:
187-
print("My Link is:", self.link_status)
188-
189179
# Set DHCP
190180
if is_dhcp:
191181
ret = self.set_dhcp(hostname, dhcp_timeout)
@@ -201,6 +191,17 @@ def set_dhcp(self, hostname=None, response_timeout=3):
201191
"""
202192
if self._debug:
203193
print("* Initializing DHCP")
194+
195+
# First, wait link status is on
196+
# to avoid the code during DHCP - assert self.link_status, "Ethernet cable disconnected!"
197+
start_time = time.monotonic()
198+
while True:
199+
if self.link_status or ((time.monotonic() - start_time) > 5) :
200+
break
201+
time.sleep(1)
202+
if self._debug:
203+
print("My Link is:", self.link_status)
204+
204205
self._src_port = 68
205206
# Return IP assigned by DHCP
206207
_dhcp_client = dhcp.DHCP(

adafruit_wiznet5k/adafruit_wiznet5k_dhcp.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -365,11 +365,8 @@ def request_dhcp_lease(
365365
print("* DHCP: Parsing OFFER")
366366
msg_type, xid = self.parse_dhcp_response(self._response_timeout)
367367
if msg_type == DHCP_OFFER:
368-
# # use the _transaction_id the offer returned,
369-
# # rather than the current one
370-
# self._transaction_id = self._transaction_id.from_bytes(xid, "l")
371368
if self._debug:
372-
print("* DHCP: Request")
369+
print("* DHCP: Request", xid)
373370
self.send_dhcp_message(
374371
DHCP_REQUEST, ((time.monotonic() - start_time) / 1000)
375372
)

0 commit comments

Comments
 (0)