Skip to content

Fix compatibility issue with the latest adafruit_requests.py library #39

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 4 commits into from
Jul 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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