Skip to content

Commit

Permalink
Merge pull request #39 from CytronTechnologies/fix-compatibility-issue
Browse files Browse the repository at this point in the history
Fix compatibility issue with the latest adafruit_requests.py library
  • Loading branch information
ladyada authored Jul 24, 2021
2 parents 6656268 + e1cd639 commit 1467795
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
3 changes: 2 additions & 1 deletion adafruit_espatcontrol/adafruit_espatcontrol.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,7 @@ def socket_receive(self, timeout=5):
bundle.append(self._ipdpacket[0:i])
gc.collect()
i = incoming_bytes = 0
break # We've received all the data. Don't wait until timeout.
else: # no data waiting
self.hw_flow(True) # start the floooow
totalsize = sum([len(x) for x in bundle])
Expand Down Expand Up @@ -408,7 +409,7 @@ def nslookup(self, host):
reply = self.at_response('AT+CIPDOMAIN="%s"' % host.strip('"'), timeout=3)
for line in reply.split(b"\r\n"):
if line and line.startswith(b"+CIPDOMAIN:"):
return str(line[11:], "utf-8")
return str(line[11:], "utf-8").strip('"')
raise RuntimeError("Couldn't find IP address")

# *************************** AP SETUP ****************************
Expand Down
12 changes: 12 additions & 0 deletions adafruit_espatcontrol/adafruit_espatcontrol_socket.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,14 @@ def connect(self, address, conntype=None):
"""Connect the socket to the 'address' (which should be dotted quad IP). 'conntype'
is an extra that may indicate SSL or not, depending on the underlying interface"""
host, port = address

# Determine the conntype from port if not specified.
if conntype is None:
if port == 80:
conntype = "TCP"
elif port == 443:
conntype = "SSL"

if not _the_interface.socket_connect(
conntype, host, port, keepalive=10, retries=3
):
Expand Down Expand Up @@ -74,6 +82,10 @@ def recv(self, num=0):
ret = self._buffer + _the_interface.socket_receive(timeout=self._timeout)
self._buffer = b""
else:
if self._buffer == b"":
self._buffer = self._buffer + _the_interface.socket_receive(
timeout=self._timeout
)
ret = self._buffer[:num]
self._buffer = self._buffer[num:]
return ret
Expand Down

0 comments on commit 1467795

Please sign in to comment.