Skip to content

Commit 1467795

Browse files
authored
Merge pull request #39 from CytronTechnologies/fix-compatibility-issue
Fix compatibility issue with the latest adafruit_requests.py library
2 parents 6656268 + e1cd639 commit 1467795

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

adafruit_espatcontrol/adafruit_espatcontrol.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,7 @@ def socket_receive(self, timeout=5):
283283
bundle.append(self._ipdpacket[0:i])
284284
gc.collect()
285285
i = incoming_bytes = 0
286+
break # We've received all the data. Don't wait until timeout.
286287
else: # no data waiting
287288
self.hw_flow(True) # start the floooow
288289
totalsize = sum([len(x) for x in bundle])
@@ -408,7 +409,7 @@ def nslookup(self, host):
408409
reply = self.at_response('AT+CIPDOMAIN="%s"' % host.strip('"'), timeout=3)
409410
for line in reply.split(b"\r\n"):
410411
if line and line.startswith(b"+CIPDOMAIN:"):
411-
return str(line[11:], "utf-8")
412+
return str(line[11:], "utf-8").strip('"')
412413
raise RuntimeError("Couldn't find IP address")
413414

414415
# *************************** AP SETUP ****************************

adafruit_espatcontrol/adafruit_espatcontrol_socket.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,14 @@ def connect(self, address, conntype=None):
4747
"""Connect the socket to the 'address' (which should be dotted quad IP). 'conntype'
4848
is an extra that may indicate SSL or not, depending on the underlying interface"""
4949
host, port = address
50+
51+
# Determine the conntype from port if not specified.
52+
if conntype is None:
53+
if port == 80:
54+
conntype = "TCP"
55+
elif port == 443:
56+
conntype = "SSL"
57+
5058
if not _the_interface.socket_connect(
5159
conntype, host, port, keepalive=10, retries=3
5260
):
@@ -74,6 +82,10 @@ def recv(self, num=0):
7482
ret = self._buffer + _the_interface.socket_receive(timeout=self._timeout)
7583
self._buffer = b""
7684
else:
85+
if self._buffer == b"":
86+
self._buffer = self._buffer + _the_interface.socket_receive(
87+
timeout=self._timeout
88+
)
7789
ret = self._buffer[:num]
7890
self._buffer = self._buffer[num:]
7991
return ret

0 commit comments

Comments
 (0)