diff --git a/adafruit_portalbase/network.py b/adafruit_portalbase/network.py index 955a322..21255fa 100755 --- a/adafruit_portalbase/network.py +++ b/adafruit_portalbase/network.py @@ -110,6 +110,8 @@ def __init__( except OSError: self.uselocal = False + self._io_client = None + gc.collect() def neo_status(self, value): @@ -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: @@ -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