From 340e0c1383bfd94833ccce7fbf22263d29223a0d Mon Sep 17 00:00:00 2001 From: ladyada Date: Sat, 23 Feb 2019 17:37:09 -0500 Subject: [PATCH 1/8] change settings to secrets --- adafruit_pyportal.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/adafruit_pyportal.py b/adafruit_pyportal.py index f6c19b3..5effbe0 100644 --- a/adafruit_pyportal.py +++ b/adafruit_pyportal.py @@ -65,10 +65,10 @@ import supervisor try: - from settings import settings + from secrets import secrets except ImportError: - print("""WiFi settings are kept in settings.py, please add them there! -the settings dictionary must contain 'ssid' and 'password' at a minimum""") + print("""WiFi settings are kept in secrets.py, please add them there! +the secrets dictionary must contain 'ssid' and 'password' at a minimum""") raise __version__ = "0.0.0-auto.0" @@ -529,9 +529,9 @@ def _connect_esp(self): while not self._esp.is_connected: if self._debug: print("Connecting to AP") - # settings dictionary must contain 'ssid' and 'password' at a minimum + # secrets dictionary must contain 'ssid' and 'password' at a minimum self.neo_status((100, 0, 0)) # red = not connected - self._esp.connect(settings) + self._esp.connect(secrets) def fetch(self): """Fetch data from the url we initialized with, perfom any parsing, From 8568888d7fd1e05a1545ab420555168b429e493d Mon Sep 17 00:00:00 2001 From: ladyada Date: Sat, 23 Feb 2019 17:48:43 -0500 Subject: [PATCH 2/8] fix new name for `ure` --- adafruit_pyportal.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/adafruit_pyportal.py b/adafruit_pyportal.py index 5effbe0..32446be 100644 --- a/adafruit_pyportal.py +++ b/adafruit_pyportal.py @@ -575,7 +575,7 @@ def fetch(self): supervisor.reload() if self._regexp_path: - import ure + import re # extract desired text/values from json if self._json_path: @@ -583,7 +583,7 @@ def fetch(self): values.append(PyPortal._json_traverse(json_out, path)) elif self._regexp_path: for regexp in self._regexp_path: - values.append(ure.search(regexp, r.text).group(1)) + values.append(re.search(regexp, r.text).group(1)) else: values = r.text From 01d77b107599cfbdc2c82aaa2be448116a15ad1a Mon Sep 17 00:00:00 2001 From: ladyada Date: Sat, 23 Feb 2019 17:50:00 -0500 Subject: [PATCH 3/8] fix dox mox --- docs/conf.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/conf.py b/docs/conf.py index aedcfd8..3a588f5 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -22,7 +22,7 @@ # autodoc module docs will fail to generate with a warning. autodoc_mock_imports = ["rtc", "supervisor", "pulseio", "audioio", "displayio", "neopixel", "microcontroller", "adafruit_touchscreen", "adafruit_bitmap_font", - "adafruit_display_text", "adafruit_esp32spi", "settings"] + "adafruit_display_text", "adafruit_esp32spi", "secrets"] intersphinx_mapping = {'python': ('https://docs.python.org/3.4', None),'BusDevice': ('https://circuitpython.readthedocs.io/projects/busdevice/en/latest/', None),'CircuitPython': ('https://circuitpython.readthedocs.io/en/latest/', None)} From 299184936bf15fce0b4fa26a99b78e02df76d7a5 Mon Sep 17 00:00:00 2001 From: ladyada Date: Sat, 23 Feb 2019 18:40:48 -0500 Subject: [PATCH 4/8] try caching to SD first to avoid QSPI writes if possible --- adafruit_pyportal.py | 54 ++++++++++++++++++++++++++++++++------------ requirements.txt | 1 + 2 files changed, 40 insertions(+), 15 deletions(-) diff --git a/adafruit_pyportal.py b/adafruit_pyportal.py index 32446be..3ae670d 100644 --- a/adafruit_pyportal.py +++ b/adafruit_pyportal.py @@ -48,11 +48,13 @@ import gc import board import busio +import storage import microcontroller from digitalio import DigitalInOut import pulseio import adafruit_touchscreen import neopixel +import adafruit_sdcard from adafruit_esp32spi import adafruit_esp32spi import adafruit_esp32spi.adafruit_esp32spi_requests as requests @@ -207,6 +209,17 @@ def __init__(self, *, url=None, json_path=None, regexp_path=None, requests.set_interface(self._esp) + if self._debug: + print("Init SD Card") + sd_cs = DigitalInOut(board.SD_CS) + self._sdcard = None + try: + self._sdcard = adafruit_sdcard.SDCard(spi, sd_cs) + vfs = storage.VfsFat(self._sdcard) + storage.mount(vfs, "/sd") + except OSError as e: + print("No SD card found:", e) + if self._debug: print("Init display") self.splash = displayio.Group(max_size=5) @@ -488,11 +501,12 @@ def get_local_time(self, location=None): response = None gc.collect() - def wget(self, url, filename): + def wget(self, url, filename, *, chunk_size=12000): """Download a url and save to filename location, like the command wget. :param url: The URL from which to obtain the data. :param filename: The name of the file to save the data to. + :param chunk_size: how much data to read/write at a time. """ print("Fetching stream from", url) @@ -506,18 +520,19 @@ def wget(self, url, filename): remaining = content_length print("Saving data to ", filename) stamp = time.monotonic() - with open(filename, "wb") as file: - for i in r.iter_content(min(remaining, 12000)): # huge chunks! - self.neo_status((0, 100, 100)) - remaining -= len(i) - file.write(i) - if self._debug: - print("Read %d bytes, %d remaining" % (content_length-remaining, remaining)) - else: - print(".", end='') - if not remaining: - break - self.neo_status((100, 100, 0)) + file = open(filename, "wb") + for i in r.iter_content(min(remaining, chunk_size)): # huge chunks! + self.neo_status((0, 100, 100)) + remaining -= len(i) + file.write(i) + if self._debug: + print("Read %d bytes, %d remaining" % (content_length-remaining, remaining)) + else: + print(".", end='') + if not remaining: + break + self.neo_status((100, 100, 0)) + file.close() r.close() stamp = time.monotonic() - stamp @@ -606,8 +621,17 @@ def fetch(self): print("convert URL:", image_url) # convert image to bitmap and cache #print("**not actually wgetting**") - self.wget(image_url, "/cache.bmp") - self.set_background("/cache.bmp") + filename = "/cache.bmp" + chunk_size = 12000 # default chunk size is 12K (for QSPI) + if self._sdcard: + filename = "/sd" + filename + chunk_size = 512 # current bug in big SD writes -> stick to 1 block + try: + self.wget(image_url, filename, chunk_size=chunk_size) + except OSError as e: + print(e) + raise OSError("""\n\nNo writable filesystem found for saving datastream. Insert an SD card or set internal filesystem to be unsafe by setting 'disable_concurrent_write_protection' in the mount options in boot.py""") # pylint: disable=line-too-long + self.set_background(filename) except ValueError as error: print("Error displaying cached image. " + error.args[0]) self.set_background(self._default_bg) diff --git a/requirements.txt b/requirements.txt index 7b80f3d..f60b0d6 100644 --- a/requirements.txt +++ b/requirements.txt @@ -4,3 +4,4 @@ adafruit-circuitpython-touchscreen adafruit-circuitpython-esp32spi adafruit-circuitpython-bitmap-font adafruit-circuitpython-neopixel +adafruit-circuitpython-sdcard From be133208561495cc9d32e12278c3e5fcbeabf09c Mon Sep 17 00:00:00 2001 From: ladyada Date: Sat, 23 Feb 2019 18:52:36 -0500 Subject: [PATCH 5/8] these are not the droids you are looking for --- requirements.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index f60b0d6..7b80f3d 100644 --- a/requirements.txt +++ b/requirements.txt @@ -4,4 +4,3 @@ adafruit-circuitpython-touchscreen adafruit-circuitpython-esp32spi adafruit-circuitpython-bitmap-font adafruit-circuitpython-neopixel -adafruit-circuitpython-sdcard From f81b048ccdc88cb7a751714c56c34fc43f5cfb75 Mon Sep 17 00:00:00 2001 From: ladyada Date: Sat, 23 Feb 2019 18:56:41 -0500 Subject: [PATCH 6/8] lint --- adafruit_pyportal.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/adafruit_pyportal.py b/adafruit_pyportal.py index 3ae670d..4e41c55 100644 --- a/adafruit_pyportal.py +++ b/adafruit_pyportal.py @@ -48,7 +48,6 @@ import gc import board import busio -import storage import microcontroller from digitalio import DigitalInOut import pulseio @@ -61,6 +60,7 @@ from adafruit_display_text.text_area import TextArea from adafruit_bitmap_font import bitmap_font +import storage import displayio import audioio import rtc @@ -217,8 +217,8 @@ def __init__(self, *, url=None, json_path=None, regexp_path=None, self._sdcard = adafruit_sdcard.SDCard(spi, sd_cs) vfs = storage.VfsFat(self._sdcard) storage.mount(vfs, "/sd") - except OSError as e: - print("No SD card found:", e) + except OSError as error: + print("No SD card found:", error) if self._debug: print("Init display") @@ -628,8 +628,8 @@ def fetch(self): chunk_size = 512 # current bug in big SD writes -> stick to 1 block try: self.wget(image_url, filename, chunk_size=chunk_size) - except OSError as e: - print(e) + except OSError as error: + print(error) raise OSError("""\n\nNo writable filesystem found for saving datastream. Insert an SD card or set internal filesystem to be unsafe by setting 'disable_concurrent_write_protection' in the mount options in boot.py""") # pylint: disable=line-too-long self.set_background(filename) except ValueError as error: From 4445d664d120a680b381b9fe3ecb6d79ad4e09b0 Mon Sep 17 00:00:00 2001 From: ladyada Date: Sat, 23 Feb 2019 18:59:20 -0500 Subject: [PATCH 7/8] tnil --- adafruit_pyportal.py | 2 +- docs/conf.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/adafruit_pyportal.py b/adafruit_pyportal.py index 4e41c55..dd0a83d 100644 --- a/adafruit_pyportal.py +++ b/adafruit_pyportal.py @@ -53,7 +53,6 @@ import pulseio import adafruit_touchscreen import neopixel -import adafruit_sdcard from adafruit_esp32spi import adafruit_esp32spi import adafruit_esp32spi.adafruit_esp32spi_requests as requests @@ -61,6 +60,7 @@ from adafruit_bitmap_font import bitmap_font import storage +import adafruit_sdcard import displayio import audioio import rtc diff --git a/docs/conf.py b/docs/conf.py index 3a588f5..fb7d4ed 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -22,7 +22,7 @@ # autodoc module docs will fail to generate with a warning. autodoc_mock_imports = ["rtc", "supervisor", "pulseio", "audioio", "displayio", "neopixel", "microcontroller", "adafruit_touchscreen", "adafruit_bitmap_font", - "adafruit_display_text", "adafruit_esp32spi", "secrets"] + "adafruit_display_text", "adafruit_esp32spi", "secrets", "adafruit_sdcard"] intersphinx_mapping = {'python': ('https://docs.python.org/3.4', None),'BusDevice': ('https://circuitpython.readthedocs.io/projects/busdevice/en/latest/', None),'CircuitPython': ('https://circuitpython.readthedocs.io/en/latest/', None)} From 449d13d39c71538905c10b0b275d755b59ecf459 Mon Sep 17 00:00:00 2001 From: ladyada Date: Sat, 23 Feb 2019 19:02:08 -0500 Subject: [PATCH 8/8] every module! --- docs/conf.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/conf.py b/docs/conf.py index fb7d4ed..355f02b 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -22,7 +22,8 @@ # autodoc module docs will fail to generate with a warning. autodoc_mock_imports = ["rtc", "supervisor", "pulseio", "audioio", "displayio", "neopixel", "microcontroller", "adafruit_touchscreen", "adafruit_bitmap_font", - "adafruit_display_text", "adafruit_esp32spi", "secrets", "adafruit_sdcard"] + "adafruit_display_text", "adafruit_esp32spi", "secrets", + "adafruit_sdcard", "storage"] intersphinx_mapping = {'python': ('https://docs.python.org/3.4', None),'BusDevice': ('https://circuitpython.readthedocs.io/projects/busdevice/en/latest/', None),'CircuitPython': ('https://circuitpython.readthedocs.io/en/latest/', None)}