Skip to content

Better reuse of objects with Adafruit IO #26

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 1 commit into from
Apr 2, 2021
Merged
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
9 changes: 8 additions & 1 deletion adafruit_portalbase/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ def __init__(
except OSError:
self.uselocal = False

self._io_client = None

gc.collect()

def neo_status(self, value):
Expand Down Expand Up @@ -341,8 +343,12 @@ def connect(self):
print("Could not connect to internet", error)
print("Retrying in 3 seconds...")
time.sleep(3)
gc.collect()

def _get_io_client(self):
if self._io_client is not None:
return self._io_client

self.connect()

try:
Expand All @@ -353,7 +359,8 @@ def _get_io_client(self):
"Adafruit IO secrets are kept in secrets.py, please add them there!\n\n"
) from KeyError

return IO_HTTP(aio_username, aio_key, self._wifi.requests)
self._io_client = IO_HTTP(aio_username, aio_key, self._wifi.requests)
return self._io_client

def push_to_io(self, feed_key, data):
"""Push data to an adafruit.io feed
Expand Down