From 28aa5c2a4e1e8be5a10b3f8478718add7a096011 Mon Sep 17 00:00:00 2001 From: brentru Date: Thu, 19 Nov 2020 16:39:36 -0500 Subject: [PATCH 01/16] Init with socket pool and sslcontext rather than a wifimanager for non wifi-interfaces --- adafruit_io/adafruit_io.py | 24 ++++---- .../adafruit_io_simpletest.py | 60 +++++++++---------- 2 files changed, 43 insertions(+), 41 deletions(-) diff --git a/adafruit_io/adafruit_io.py b/adafruit_io/adafruit_io.py index e270a4a..9f0882f 100755 --- a/adafruit_io/adafruit_io.py +++ b/adafruit_io/adafruit_io.py @@ -37,6 +37,8 @@ """ import time import json +import adafruit_requests as requests + from adafruit_io.adafruit_io_errors import ( AdafruitIO_RequestError, AdafruitIO_ThrottleError, @@ -466,18 +468,18 @@ class IO_HTTP: :param str adafruit_io_username: Adafruit IO Username :param str adafruit_io_key: Adafruit IO Key - :param wifi_manager: WiFiManager object from ESPSPI_WiFiManager or ESPAT_WiFiManager + :param socket socket_pool: A pool of socket resources for the provided radio. + :param SSLContext ssl_context: Settings related to SSL that can be applied to a socket by wrapping it. """ - def __init__(self, adafruit_io_username, adafruit_io_key, wifi_manager): + def __init__(self, adafruit_io_username, adafruit_io_key, socket_pool, ssl_context=None): self.username = adafruit_io_username self.key = adafruit_io_key - wifi_type = str(type(wifi_manager)) - if "ESPSPI_WiFiManager" in wifi_type or "ESPAT_WiFiManager" in wifi_type: - self.wifi = wifi_manager - else: - raise TypeError("This library requires a WiFiManager object.") + + # Create new requests Session + self._http = requests.Session(socket_pool, ssl_context) + self._aio_headers = [ {"X-AIO-KEY": self.key, "Content-Type": "application/json"}, {"X-AIO-KEY": self.key}, @@ -519,7 +521,7 @@ def _compose_path(self, path): """Composes a valid API request path. :param str path: Adafruit IO API URL path. """ - return "https://io.adafruit.com/api/v2/{0}/{1}".format(self.username, path) + return "http://io.adafruit.com/api/v2/{0}/{1}".format(self.username, path) # HTTP Requests def _post(self, path, payload): @@ -528,7 +530,7 @@ def _post(self, path, payload): :param str path: Formatted Adafruit IO URL from _compose_path :param json payload: JSON data to send to Adafruit IO """ - response = self.wifi.post( + response = self._http.post( path, json=payload, headers=self._create_headers(self._aio_headers[0]) ) self._handle_error(response) @@ -541,7 +543,7 @@ def _get(self, path): GET data from Adafruit IO :param str path: Formatted Adafruit IO URL from _compose_path """ - response = self.wifi.get( + response = self._http.get( path, headers=self._create_headers(self._aio_headers[1]) ) self._handle_error(response) @@ -554,7 +556,7 @@ def _delete(self, path): DELETE data from Adafruit IO. :param str path: Formatted Adafruit IO URL from _compose_path """ - response = self.wifi.delete( + response = self._http.delete( path, headers=self._create_headers(self._aio_headers[0]) ) self._handle_error(response) diff --git a/examples/adafruit_io_http/adafruit_io_simpletest.py b/examples/adafruit_io_http/adafruit_io_simpletest.py index a347757..cdf1efe 100644 --- a/examples/adafruit_io_http/adafruit_io_simpletest.py +++ b/examples/adafruit_io_http/adafruit_io_simpletest.py @@ -1,45 +1,34 @@ -""" -Sending data to Adafruit IO and receiving it. -""" -from random import randint +# adafruit_circuitpython_adafruitio usage with an esp32spi_socket import board import busio from digitalio import DigitalInOut - -# ESP32 SPI -from adafruit_esp32spi import adafruit_esp32spi, adafruit_esp32spi_wifimanager - -# Import NeoPixel Library -import neopixel - -# Import Adafruit IO HTTP Client +import adafruit_esp32spi.adafruit_esp32spi_socket as socket +from adafruit_esp32spi import adafruit_esp32spi from adafruit_io.adafruit_io import IO_HTTP, AdafruitIO_RequestError -# Get wifi details and more from a secrets.py file +# Add a secrets.py to your filesystem that has a dictionary called secrets with "ssid" and +# "password" keys with your WiFi credentials. DO NOT share that file or commit it into Git or other +# source control. +# pylint: disable=no-name-in-module,wrong-import-order try: from secrets import secrets except ImportError: print("WiFi secrets are kept in secrets.py, please add them there!") raise -# ESP32 Setup -try: - esp32_cs = DigitalInOut(board.ESP_CS) - esp32_ready = DigitalInOut(board.ESP_BUSY) - esp32_reset = DigitalInOut(board.ESP_RESET) -except AttributeError: - esp32_cs = DigitalInOut(board.D9) - esp32_ready = DigitalInOut(board.D10) - esp32_reset = DigitalInOut(board.D5) +# If you are using a board with pre-defined ESP32 Pins: +esp32_cs = DigitalInOut(board.ESP_CS) +esp32_ready = DigitalInOut(board.ESP_BUSY) +esp32_reset = DigitalInOut(board.ESP_RESET) + +# If you have an externally connected ESP32: +# esp32_cs = DigitalInOut(board.D9) +# esp32_ready = DigitalInOut(board.D10) +# esp32_reset = DigitalInOut(board.D5) spi = busio.SPI(board.SCK, board.MOSI, board.MISO) esp = adafruit_esp32spi.ESP_SPIcontrol(spi, esp32_cs, esp32_ready, esp32_reset) -status_light = neopixel.NeoPixel( - board.NEOPIXEL, 1, brightness=0.2 -) # Uncomment for Most Boards -"""Uncomment below for ItsyBitsy M4""" -# status_light = dotstar.DotStar(board.APA102_SCK, board.APA102_MOSI, 1, brightness=0.2) -wifi = adafruit_esp32spi_wifimanager.ESPSPI_WiFiManager(esp, secrets, status_light) + # Set your Adafruit IO Username and Key in secrets.py # (visit io.adafruit.com if you need to create an account, @@ -47,8 +36,19 @@ aio_username = secrets["aio_username"] aio_key = secrets["aio_key"] -# Create an instance of the Adafruit IO HTTP client -io = IO_HTTP(aio_username, aio_key, wifi) +print("Connecting to AP...") +while not esp.is_connected: + try: + esp.connect_AP(secrets["ssid"], secrets["password"]) + except RuntimeError as e: + print("could not connect to AP, retrying: ", e) + continue +print("Connected to", str(esp.ssid, "utf-8"), "\tRSSI:", esp.rssi) + +# Initialize an Adafruit IO HTTP API object with +# a socket and esp32spi interface +socket.set_interface(esp) +io = IO_HTTP(aio_username, aio_key, socket) try: # Get the 'temperature' feed from Adafruit IO From 62bd4e27a6d3ae88ef65d0b0106457724792f6d3 Mon Sep 17 00:00:00 2001 From: brentru Date: Thu, 19 Nov 2020 17:12:41 -0500 Subject: [PATCH 02/16] allow legacy API and requests sessions to co-exist in wrapper class --- adafruit_io/adafruit_io.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/adafruit_io/adafruit_io.py b/adafruit_io/adafruit_io.py index 9f0882f..a3e4ffe 100755 --- a/adafruit_io/adafruit_io.py +++ b/adafruit_io/adafruit_io.py @@ -469,16 +469,22 @@ class IO_HTTP: :param str adafruit_io_username: Adafruit IO Username :param str adafruit_io_key: Adafruit IO Key :param socket socket_pool: A pool of socket resources for the provided radio. - :param SSLContext ssl_context: Settings related to SSL that can be applied to a socket by wrapping it. - + :param esp: A previously declared network interface object. """ - def __init__(self, adafruit_io_username, adafruit_io_key, socket_pool, ssl_context=None): + def __init__(self, adafruit_io_username, adafruit_io_key, socket_pool, esp=None): self.username = adafruit_io_username self.key = adafruit_io_key - # Create new requests Session - self._http = requests.Session(socket_pool, ssl_context) + if esp: + # Use legacy API + requests.set_socket(socket_pool, esp) + self._http = requests + else: + # Use requests Session API + import ssl + self._http = requests.Session(socket_pool, ssl.create_default_context()) + self._aio_headers = [ {"X-AIO-KEY": self.key, "Content-Type": "application/json"}, @@ -521,7 +527,7 @@ def _compose_path(self, path): """Composes a valid API request path. :param str path: Adafruit IO API URL path. """ - return "http://io.adafruit.com/api/v2/{0}/{1}".format(self.username, path) + return "https://io.adafruit.com/api/v2/{0}/{1}".format(self.username, path) # HTTP Requests def _post(self, path, payload): From ed74b997e84b72731530920a7cff263c40b8faae Mon Sep 17 00:00:00 2001 From: brentru Date: Thu, 19 Nov 2020 17:17:03 -0500 Subject: [PATCH 03/16] take in a requests object from user code instead of constructing it in the io interface. --- adafruit_io/adafruit_io.py | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) diff --git a/adafruit_io/adafruit_io.py b/adafruit_io/adafruit_io.py index a3e4ffe..b645743 100755 --- a/adafruit_io/adafruit_io.py +++ b/adafruit_io/adafruit_io.py @@ -37,7 +37,6 @@ """ import time import json -import adafruit_requests as requests from adafruit_io.adafruit_io_errors import ( AdafruitIO_RequestError, @@ -468,23 +467,13 @@ class IO_HTTP: :param str adafruit_io_username: Adafruit IO Username :param str adafruit_io_key: Adafruit IO Key - :param socket socket_pool: A pool of socket resources for the provided radio. - :param esp: A previously declared network interface object. + :param requests: A passed adafruit_requests module. """ - def __init__(self, adafruit_io_username, adafruit_io_key, socket_pool, esp=None): + def __init__(self, adafruit_io_username, adafruit_io_key, requests): self.username = adafruit_io_username self.key = adafruit_io_key - - if esp: - # Use legacy API - requests.set_socket(socket_pool, esp) - self._http = requests - else: - # Use requests Session API - import ssl - self._http = requests.Session(socket_pool, ssl.create_default_context()) - + self._http = requests self._aio_headers = [ {"X-AIO-KEY": self.key, "Content-Type": "application/json"}, From aaffb61590c64ed5f87afca085fdef11f88b26c1 Mon Sep 17 00:00:00 2001 From: brentru Date: Thu, 19 Nov 2020 17:18:05 -0500 Subject: [PATCH 04/16] Add new example, remove cruft from old example and match requests example --- .../adafruit_io_simpletest.py | 141 +++++++++--------- 1 file changed, 72 insertions(+), 69 deletions(-) diff --git a/examples/adafruit_io_http/adafruit_io_simpletest.py b/examples/adafruit_io_http/adafruit_io_simpletest.py index cdf1efe..d3126f4 100644 --- a/examples/adafruit_io_http/adafruit_io_simpletest.py +++ b/examples/adafruit_io_http/adafruit_io_simpletest.py @@ -1,69 +1,72 @@ -# adafruit_circuitpython_adafruitio usage with an esp32spi_socket -import board -import busio -from digitalio import DigitalInOut -import adafruit_esp32spi.adafruit_esp32spi_socket as socket -from adafruit_esp32spi import adafruit_esp32spi -from adafruit_io.adafruit_io import IO_HTTP, AdafruitIO_RequestError - -# Add a secrets.py to your filesystem that has a dictionary called secrets with "ssid" and -# "password" keys with your WiFi credentials. DO NOT share that file or commit it into Git or other -# source control. -# pylint: disable=no-name-in-module,wrong-import-order -try: - from secrets import secrets -except ImportError: - print("WiFi secrets are kept in secrets.py, please add them there!") - raise - -# If you are using a board with pre-defined ESP32 Pins: -esp32_cs = DigitalInOut(board.ESP_CS) -esp32_ready = DigitalInOut(board.ESP_BUSY) -esp32_reset = DigitalInOut(board.ESP_RESET) - -# If you have an externally connected ESP32: -# esp32_cs = DigitalInOut(board.D9) -# esp32_ready = DigitalInOut(board.D10) -# esp32_reset = DigitalInOut(board.D5) - -spi = busio.SPI(board.SCK, board.MOSI, board.MISO) -esp = adafruit_esp32spi.ESP_SPIcontrol(spi, esp32_cs, esp32_ready, esp32_reset) - - -# Set your Adafruit IO Username and Key in secrets.py -# (visit io.adafruit.com if you need to create an account, -# or if you need your Adafruit IO key.) -aio_username = secrets["aio_username"] -aio_key = secrets["aio_key"] - -print("Connecting to AP...") -while not esp.is_connected: - try: - esp.connect_AP(secrets["ssid"], secrets["password"]) - except RuntimeError as e: - print("could not connect to AP, retrying: ", e) - continue -print("Connected to", str(esp.ssid, "utf-8"), "\tRSSI:", esp.rssi) - -# Initialize an Adafruit IO HTTP API object with -# a socket and esp32spi interface -socket.set_interface(esp) -io = IO_HTTP(aio_username, aio_key, socket) - -try: - # Get the 'temperature' feed from Adafruit IO - temperature_feed = io.get_feed("temperature") -except AdafruitIO_RequestError: - # If no 'temperature' feed exists, create one - temperature_feed = io.create_new_feed("temperature") - -# Send random integer values to the feed -random_value = randint(0, 50) -print("Sending {0} to temperature feed...".format(random_value)) -io.send_data(temperature_feed["key"], random_value) -print("Data sent!") - -# Retrieve data value from the feed -print("Retrieving data from temperature feed...") -received_data = io.receive_data(temperature_feed["key"]) -print("Data from temperature feed: ", received_data["value"]) +# adafruit_circuitpython_adafruitio usage with an esp32spi_socket +from random import randint +import board +import busio +from digitalio import DigitalInOut +import adafruit_esp32spi.adafruit_esp32spi_socket as socket +from adafruit_esp32spi import adafruit_esp32spi +import adafruit_requests as requests +from adafruit_io.adafruit_io import IO_HTTP, AdafruitIO_RequestError + +# Add a secrets.py to your filesystem that has a dictionary called secrets with "ssid" and +# "password" keys with your WiFi credentials. DO NOT share that file or commit it into Git or other +# source control. +# pylint: disable=no-name-in-module,wrong-import-order +try: + from secrets import secrets +except ImportError: + print("WiFi secrets are kept in secrets.py, please add them there!") + raise + +# If you are using a board with pre-defined ESP32 Pins: +esp32_cs = DigitalInOut(board.ESP_CS) +esp32_ready = DigitalInOut(board.ESP_BUSY) +esp32_reset = DigitalInOut(board.ESP_RESET) + +# If you have an externally connected ESP32: +# esp32_cs = DigitalInOut(board.D9) +# esp32_ready = DigitalInOut(board.D10) +# esp32_reset = DigitalInOut(board.D5) + +spi = busio.SPI(board.SCK, board.MOSI, board.MISO) +esp = adafruit_esp32spi.ESP_SPIcontrol(spi, esp32_cs, esp32_ready, esp32_reset) + + +# Set your Adafruit IO Username and Key in secrets.py +# (visit io.adafruit.com if you need to create an account, +# or if you need your Adafruit IO key.) +aio_username = secrets["aio_username"] +aio_key = secrets["aio_key"] + +print("Connecting to AP...") +while not esp.is_connected: + try: + esp.connect_AP(secrets["ssid"], secrets["password"]) + except RuntimeError as e: + print("could not connect to AP, retrying: ", e) + continue +print("Connected to", str(esp.ssid, "utf-8"), "\tRSSI:", esp.rssi) + +socket.set_interface(esp) +requests.set_socket(socket, esp) + +# Initialize an Adafruit IO HTTP API object +io = IO_HTTP(aio_username, aio_key, requests) + +try: + # Get the 'temperature' feed from Adafruit IO + temperature_feed = io.get_feed("temperature") +except AdafruitIO_RequestError: + # If no 'temperature' feed exists, create one + temperature_feed = io.create_new_feed("temperature") + +# Send random integer values to the feed +random_value = randint(0, 50) +print("Sending {0} to temperature feed...".format(random_value)) +io.send_data(temperature_feed["key"], random_value) +print("Data sent!") + +# Retrieve data value from the feed +print("Retrieving data from temperature feed...") +received_data = io.receive_data(temperature_feed["key"]) +print("Data from temperature feed: ", received_data["value"]) From 6dbcccae0f88215bfda879163bb5ad5c5bc86166 Mon Sep 17 00:00:00 2001 From: brentru Date: Thu, 19 Nov 2020 17:32:44 -0500 Subject: [PATCH 05/16] add working CPython example --- .../adafruit_io_simpletest_cpython.py | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 examples/adafruit_io_http/adafruit_io_simpletest_cpython.py diff --git a/examples/adafruit_io_http/adafruit_io_simpletest_cpython.py b/examples/adafruit_io_http/adafruit_io_simpletest_cpython.py new file mode 100644 index 0000000..e2cc823 --- /dev/null +++ b/examples/adafruit_io_http/adafruit_io_simpletest_cpython.py @@ -0,0 +1,45 @@ +# adafruit_circuitpython_adafruitio usage with a CPython socket +import socket +import ssl +from random import randint +import adafruit_requests +from adafruit_io.adafruit_io import IO_HTTP, AdafruitIO_RequestError + +# Add a secrets.py to your filesystem that has a dictionary called secrets with "ssid" and +# "password" keys with your WiFi credentials. DO NOT share that file or commit it into Git or other +# source control. +# pylint: disable=no-name-in-module,wrong-import-order +try: + from secrets import secrets +except ImportError: + print("WiFi secrets are kept in secrets.py, please add them there!") + raise + +# Set your Adafruit IO Username and Key in secrets.py +# (visit io.adafruit.com if you need to create an account, +# or if you need your Adafruit IO key.) +aio_username = secrets["aio_username"] +aio_key = secrets["aio_key"] + + +requests = adafruit_requests.Session(socket, ssl.create_default_context()) +# Initialize an Adafruit IO HTTP API object +io = IO_HTTP(aio_username, aio_key, requests) + +try: + # Get the 'temperature' feed from Adafruit IO + temperature_feed = io.get_feed("temperature") +except AdafruitIO_RequestError: + # If no 'temperature' feed exists, create one + temperature_feed = io.create_new_feed("temperature") + +# Send random integer values to the feed +random_value = randint(0, 50) +print("Sending {0} to temperature feed...".format(random_value)) +io.send_data(temperature_feed["key"], random_value) +print("Data sent!") + +# Retrieve data value from the feed +print("Retrieving data from temperature feed...") +received_data = io.receive_data(temperature_feed["key"]) +print("Data from temperature feed: ", received_data["value"]) From a52759be764a8aaec028f1042e111799b879cc5e Mon Sep 17 00:00:00 2001 From: brentru Date: Thu, 19 Nov 2020 17:39:14 -0500 Subject: [PATCH 06/16] update feeds example, reorg. code --- .../adafruit_io_http/adafruit_io_feeds.py | 64 ++++++++++--------- .../adafruit_io_simpletest.py | 13 ++-- 2 files changed, 40 insertions(+), 37 deletions(-) diff --git a/examples/adafruit_io_http/adafruit_io_feeds.py b/examples/adafruit_io_http/adafruit_io_feeds.py index 5240957..64a8719 100644 --- a/examples/adafruit_io_http/adafruit_io_feeds.py +++ b/examples/adafruit_io_http/adafruit_io_feeds.py @@ -1,44 +1,48 @@ -""" -Example of interacting with Adafruit IO feeds -""" +# Adafruit IO HTTP API - Feed Interactions +# Documentation: https://io.adafruit.com/api/docs/#feeds +# adafruit_circuitpython_adafruitio with an esp32spi_socket import board import busio from digitalio import DigitalInOut +import adafruit_esp32spi.adafruit_esp32spi_socket as socket +from adafruit_esp32spi import adafruit_esp32spi +import adafruit_requests as requests +from adafruit_io.adafruit_io import IO_HTTP, AdafruitIO_RequestError -# ESP32 SPI -from adafruit_esp32spi import adafruit_esp32spi, adafruit_esp32spi_wifimanager - -# Import NeoPixel Library -import neopixel - -# Import Adafruit IO HTTP Client -from adafruit_io.adafruit_io import IO_HTTP - -# Get wifi details and more from a secrets.py file +# Add a secrets.py to your filesystem that has a dictionary called secrets with "ssid" and +# "password" keys with your WiFi credentials. DO NOT share that file or commit it into Git or other +# source control. +# pylint: disable=no-name-in-module,wrong-import-order try: from secrets import secrets except ImportError: print("WiFi secrets are kept in secrets.py, please add them there!") raise -# ESP32 Setup -try: - esp32_cs = DigitalInOut(board.ESP_CS) - esp32_ready = DigitalInOut(board.ESP_BUSY) - esp32_reset = DigitalInOut(board.ESP_RESET) -except AttributeError: - esp32_cs = DigitalInOut(board.D9) - esp32_ready = DigitalInOut(board.D10) - esp32_reset = DigitalInOut(board.D5) +# If you are using a board with pre-defined ESP32 Pins: +esp32_cs = DigitalInOut(board.ESP_CS) +esp32_ready = DigitalInOut(board.ESP_BUSY) +esp32_reset = DigitalInOut(board.ESP_RESET) + +# If you have an externally connected ESP32: +# esp32_cs = DigitalInOut(board.D9) +# esp32_ready = DigitalInOut(board.D10) +# esp32_reset = DigitalInOut(board.D5) spi = busio.SPI(board.SCK, board.MOSI, board.MISO) esp = adafruit_esp32spi.ESP_SPIcontrol(spi, esp32_cs, esp32_ready, esp32_reset) -status_light = neopixel.NeoPixel( - board.NEOPIXEL, 1, brightness=0.2 -) # Uncomment for Most Boards -"""Uncomment below for ItsyBitsy M4""" -# status_light = dotstar.DotStar(board.APA102_SCK, board.APA102_MOSI, 1, brightness=0.2) -wifi = adafruit_esp32spi_wifimanager.ESPSPI_WiFiManager(esp, secrets, status_light) + +print("Connecting to AP...") +while not esp.is_connected: + try: + esp.connect_AP(secrets["ssid"], secrets["password"]) + except RuntimeError as e: + print("could not connect to AP, retrying: ", e) + continue +print("Connected to", str(esp.ssid, "utf-8"), "\tRSSI:", esp.rssi) + +socket.set_interface(esp) +requests.set_socket(socket, esp) # Set your Adafruit IO Username and Key in secrets.py # (visit io.adafruit.com if you need to create an account, @@ -46,8 +50,8 @@ aio_username = secrets["aio_username"] aio_key = secrets["aio_key"] -# Create an instance of the Adafruit IO HTTP client -io = IO_HTTP(aio_username, aio_key, wifi) +# Initialize an Adafruit IO HTTP API object +io = IO_HTTP(aio_username, aio_key, requests) # Create a new 'circuitpython' feed with a description print("Creating new Adafruit IO feed...") diff --git a/examples/adafruit_io_http/adafruit_io_simpletest.py b/examples/adafruit_io_http/adafruit_io_simpletest.py index d3126f4..6444252 100644 --- a/examples/adafruit_io_http/adafruit_io_simpletest.py +++ b/examples/adafruit_io_http/adafruit_io_simpletest.py @@ -31,13 +31,6 @@ spi = busio.SPI(board.SCK, board.MOSI, board.MISO) esp = adafruit_esp32spi.ESP_SPIcontrol(spi, esp32_cs, esp32_ready, esp32_reset) - -# Set your Adafruit IO Username and Key in secrets.py -# (visit io.adafruit.com if you need to create an account, -# or if you need your Adafruit IO key.) -aio_username = secrets["aio_username"] -aio_key = secrets["aio_key"] - print("Connecting to AP...") while not esp.is_connected: try: @@ -50,6 +43,12 @@ socket.set_interface(esp) requests.set_socket(socket, esp) +# Set your Adafruit IO Username and Key in secrets.py +# (visit io.adafruit.com if you need to create an account, +# or if you need your Adafruit IO key.) +aio_username = secrets["aio_username"] +aio_key = secrets["aio_key"] + # Initialize an Adafruit IO HTTP API object io = IO_HTTP(aio_username, aio_key, requests) From 1d7e14bb89be945d01d0e025ace6c7ec8db20b7f Mon Sep 17 00:00:00 2001 From: brentru Date: Thu, 19 Nov 2020 17:42:56 -0500 Subject: [PATCH 07/16] update groups example for esp32spi --- .../adafruit_io_http/adafruit_io_groups.py | 64 ++++++++++--------- 1 file changed, 35 insertions(+), 29 deletions(-) diff --git a/examples/adafruit_io_http/adafruit_io_groups.py b/examples/adafruit_io_http/adafruit_io_groups.py index 436d321..b1d915e 100644 --- a/examples/adafruit_io_http/adafruit_io_groups.py +++ b/examples/adafruit_io_http/adafruit_io_groups.py @@ -1,52 +1,58 @@ -""" -Example of performing group operations -""" +# Adafruit IO HTTP API - Group Interactions +# Documentation: https://io.adafruit.com/api/docs/#groups +# adafruit_circuitpython_adafruitio with an esp32spi_socket import board import busio from digitalio import DigitalInOut +import adafruit_esp32spi.adafruit_esp32spi_socket as socket +from adafruit_esp32spi import adafruit_esp32spi +import adafruit_requests as requests +from adafruit_io.adafruit_io import IO_HTTP, AdafruitIO_RequestError -# ESP32 SPI -from adafruit_esp32spi import adafruit_esp32spi, adafruit_esp32spi_wifimanager -# Import NeoPixel Library -import neopixel - -# Import Adafruit IO HTTP Client -from adafruit_io.adafruit_io import IO_HTTP - -# Get wifi details and more from a secrets.py file +# Add a secrets.py to your filesystem that has a dictionary called secrets with "ssid" and +# "password" keys with your WiFi credentials. DO NOT share that file or commit it into Git or other +# source control. +# pylint: disable=no-name-in-module,wrong-import-order try: from secrets import secrets except ImportError: print("WiFi secrets are kept in secrets.py, please add them there!") raise -# ESP32 Setup -try: - esp32_cs = DigitalInOut(board.ESP_CS) - esp32_ready = DigitalInOut(board.ESP_BUSY) - esp32_reset = DigitalInOut(board.ESP_RESET) -except AttributeError: - esp32_cs = DigitalInOut(board.D9) - esp32_ready = DigitalInOut(board.D10) - esp32_reset = DigitalInOut(board.D5) +# If you are using a board with pre-defined ESP32 Pins: +esp32_cs = DigitalInOut(board.ESP_CS) +esp32_ready = DigitalInOut(board.ESP_BUSY) +esp32_reset = DigitalInOut(board.ESP_RESET) + +# If you have an externally connected ESP32: +# esp32_cs = DigitalInOut(board.D9) +# esp32_ready = DigitalInOut(board.D10) +# esp32_reset = DigitalInOut(board.D5) spi = busio.SPI(board.SCK, board.MOSI, board.MISO) esp = adafruit_esp32spi.ESP_SPIcontrol(spi, esp32_cs, esp32_ready, esp32_reset) -status_light = neopixel.NeoPixel( - board.NEOPIXEL, 1, brightness=0.2 -) # Uncomment for Most Boards -"""Uncomment below for ItsyBitsy M4""" -# status_light = dotstar.DotStar(board.APA102_SCK, board.APA102_MOSI, 1, brightness=0.2) -wifi = adafruit_esp32spi_wifimanager.ESPSPI_WiFiManager(esp, secrets, status_light) + +print("Connecting to AP...") +while not esp.is_connected: + try: + esp.connect_AP(secrets["ssid"], secrets["password"]) + except RuntimeError as e: + print("could not connect to AP, retrying: ", e) + continue +print("Connected to", str(esp.ssid, "utf-8"), "\tRSSI:", esp.rssi) + +socket.set_interface(esp) +requests.set_socket(socket, esp) + # Set your Adafruit IO Username and Key in secrets.py # (visit io.adafruit.com if you need to create an account, # or if you need your Adafruit IO key.) aio_username = secrets["aio_username"] aio_key = secrets["aio_key"] -# Create an instance of the Adafruit IO HTTP client -io = IO_HTTP(aio_username, aio_key, wifi) +# Initialize an Adafruit IO HTTP API object +io = IO_HTTP(aio_username, aio_key, requests) # Create a new group print("Creating a new Adafruit IO Group...") From f5e03240032234203f4968ae8d94c2b9a03ae102 Mon Sep 17 00:00:00 2001 From: brentru Date: Thu, 19 Nov 2020 17:46:43 -0500 Subject: [PATCH 08/16] update metadata example for esp32s2pi, add line to display feed after its updated --- .../adafruit_io_http/adafruit_io_metadata.py | 62 ++++++++++--------- 1 file changed, 32 insertions(+), 30 deletions(-) diff --git a/examples/adafruit_io_http/adafruit_io_metadata.py b/examples/adafruit_io_http/adafruit_io_metadata.py index dcabe10..00aa3bc 100644 --- a/examples/adafruit_io_http/adafruit_io_metadata.py +++ b/examples/adafruit_io_http/adafruit_io_metadata.py @@ -1,45 +1,47 @@ -""" -Example of attaching metadata -to data sent to Adafruit IO. -""" +# Adafruit IO HTTP API - Sending values with optional metadata +# adafruit_circuitpython_adafruitio with an esp32spi_socket import board import busio from digitalio import DigitalInOut - -# ESP32 SPI -from adafruit_esp32spi import adafruit_esp32spi, adafruit_esp32spi_wifimanager - -# Import NeoPixel Library -import neopixel - -# Import Adafruit IO HTTP Client +import adafruit_esp32spi.adafruit_esp32spi_socket as socket +from adafruit_esp32spi import adafruit_esp32spi +import adafruit_requests as requests from adafruit_io.adafruit_io import IO_HTTP, AdafruitIO_RequestError -# Get wifi details and more from a secrets.py file +# Add a secrets.py to your filesystem that has a dictionary called secrets with "ssid" and +# "password" keys with your WiFi credentials. DO NOT share that file or commit it into Git or other +# source control. +# pylint: disable=no-name-in-module,wrong-import-order try: from secrets import secrets except ImportError: print("WiFi secrets are kept in secrets.py, please add them there!") raise -# ESP32 Setup -try: - esp32_cs = DigitalInOut(board.ESP_CS) - esp32_ready = DigitalInOut(board.ESP_BUSY) - esp32_reset = DigitalInOut(board.ESP_RESET) -except AttributeError: - esp32_cs = DigitalInOut(board.D9) - esp32_ready = DigitalInOut(board.D10) - esp32_reset = DigitalInOut(board.D5) +# If you are using a board with pre-defined ESP32 Pins: +esp32_cs = DigitalInOut(board.ESP_CS) +esp32_ready = DigitalInOut(board.ESP_BUSY) +esp32_reset = DigitalInOut(board.ESP_RESET) + +# If you have an externally connected ESP32: +# esp32_cs = DigitalInOut(board.D9) +# esp32_ready = DigitalInOut(board.D10) +# esp32_reset = DigitalInOut(board.D5) spi = busio.SPI(board.SCK, board.MOSI, board.MISO) esp = adafruit_esp32spi.ESP_SPIcontrol(spi, esp32_cs, esp32_ready, esp32_reset) -status_light = neopixel.NeoPixel( - board.NEOPIXEL, 1, brightness=0.2 -) # Uncomment for Most Boards -"""Uncomment below for ItsyBitsy M4""" -# status_light = dotstar.DotStar(board.APA102_SCK, board.APA102_MOSI, 1, brightness=0.2) -wifi = adafruit_esp32spi_wifimanager.ESPSPI_WiFiManager(esp, secrets, status_light) + +print("Connecting to AP...") +while not esp.is_connected: + try: + esp.connect_AP(secrets["ssid"], secrets["password"]) + except RuntimeError as e: + print("could not connect to AP, retrying: ", e) + continue +print("Connected to", str(esp.ssid, "utf-8"), "\tRSSI:", esp.rssi) + +socket.set_interface(esp) +requests.set_socket(socket, esp) # Set your Adafruit IO Username and Key in secrets.py # (visit io.adafruit.com if you need to create an account, @@ -47,8 +49,8 @@ aio_username = secrets["aio_username"] aio_key = secrets["aio_key"] -# Create an instance of the Adafruit IO HTTP client -io = IO_HTTP(aio_username, aio_key, wifi) +# Initialize an Adafruit IO HTTP API object +io = IO_HTTP(aio_username, aio_key, requests) try: # Get the 'location' feed from Adafruit IO From c8ef29a4f18a99faba437354fc09482c141cbefc Mon Sep 17 00:00:00 2001 From: brentru Date: Thu, 19 Nov 2020 17:51:40 -0500 Subject: [PATCH 09/16] add digital out, TODO: improve example to track LED state --- .../adafruit_io_digital_out.py | 62 ++++++++++--------- 1 file changed, 32 insertions(+), 30 deletions(-) diff --git a/examples/adafruit_io_http/adafruit_io_digital_out.py b/examples/adafruit_io_http/adafruit_io_digital_out.py index 1f57b12..58418e9 100644 --- a/examples/adafruit_io_http/adafruit_io_digital_out.py +++ b/examples/adafruit_io_http/adafruit_io_digital_out.py @@ -1,46 +1,48 @@ -""" -Example of turning on and off a LED -from an Adafruit IO Dashboard. -""" +# Turn on and off a LED from your Adafruit IO Dashboard. +# adafruit_circuitpython_adafruitio with an esp32spi_socket import time import board import busio from digitalio import DigitalInOut, Direction - -# ESP32 SPI -from adafruit_esp32spi import adafruit_esp32spi, adafruit_esp32spi_wifimanager - -# Import NeoPixel Library -import neopixel - -# Import Adafruit IO HTTP Client +import adafruit_esp32spi.adafruit_esp32spi_socket as socket +from adafruit_esp32spi import adafruit_esp32spi +import adafruit_requests as requests from adafruit_io.adafruit_io import IO_HTTP, AdafruitIO_RequestError -# Get wifi details and more from a secrets.py file +# Add a secrets.py to your filesystem that has a dictionary called secrets with "ssid" and +# "password" keys with your WiFi credentials. DO NOT share that file or commit it into Git or other +# source control. +# pylint: disable=no-name-in-module,wrong-import-order try: from secrets import secrets except ImportError: print("WiFi secrets are kept in secrets.py, please add them there!") raise -# ESP32 Setup -try: - esp32_cs = DigitalInOut(board.ESP_CS) - esp32_ready = DigitalInOut(board.ESP_BUSY) - esp32_reset = DigitalInOut(board.ESP_RESET) -except AttributeError: - esp32_cs = DigitalInOut(board.D9) - esp32_ready = DigitalInOut(board.D10) - esp32_reset = DigitalInOut(board.D5) +# If you are using a board with pre-defined ESP32 Pins: +esp32_cs = DigitalInOut(board.ESP_CS) +esp32_ready = DigitalInOut(board.ESP_BUSY) +esp32_reset = DigitalInOut(board.ESP_RESET) + +# If you have an externally connected ESP32: +# esp32_cs = DigitalInOut(board.D9) +# esp32_ready = DigitalInOut(board.D10) +# esp32_reset = DigitalInOut(board.D5) spi = busio.SPI(board.SCK, board.MOSI, board.MISO) esp = adafruit_esp32spi.ESP_SPIcontrol(spi, esp32_cs, esp32_ready, esp32_reset) -status_light = neopixel.NeoPixel( - board.NEOPIXEL, 1, brightness=0.2 -) # Uncomment for Most Boards -"""Uncomment below for ItsyBitsy M4""" -# status_light = dotstar.DotStar(board.APA102_SCK, board.APA102_MOSI, 1, brightness=0.2) -wifi = adafruit_esp32spi_wifimanager.ESPSPI_WiFiManager(esp, secrets, status_light) + +print("Connecting to AP...") +while not esp.is_connected: + try: + esp.connect_AP(secrets["ssid"], secrets["password"]) + except RuntimeError as e: + print("could not connect to AP, retrying: ", e) + continue +print("Connected to", str(esp.ssid, "utf-8"), "\tRSSI:", esp.rssi) + +socket.set_interface(esp) +requests.set_socket(socket, esp) # Set your Adafruit IO Username and Key in secrets.py # (visit io.adafruit.com if you need to create an account, @@ -48,8 +50,8 @@ aio_username = secrets["aio_username"] aio_key = secrets["aio_key"] -# Create an instance of the Adafruit IO HTTP client -io = IO_HTTP(aio_username, aio_key, wifi) +# Initialize an Adafruit IO HTTP API object +io = IO_HTTP(aio_username, aio_key, requests) try: # Get the 'digital' feed from Adafruit IO From 8db940750faee66cb1651bc41d32cd1679c1302c Mon Sep 17 00:00:00 2001 From: brentru Date: Thu, 19 Nov 2020 17:54:26 -0500 Subject: [PATCH 10/16] update analog input example for esp32spi, make it less pyportal-specific --- .../adafruit_io_http/adafruit_io_analog_in.py | 72 ++++++++++--------- 1 file changed, 37 insertions(+), 35 deletions(-) diff --git a/examples/adafruit_io_http/adafruit_io_analog_in.py b/examples/adafruit_io_http/adafruit_io_analog_in.py index a1c4c53..6acdbc3 100644 --- a/examples/adafruit_io_http/adafruit_io_analog_in.py +++ b/examples/adafruit_io_http/adafruit_io_analog_in.py @@ -1,48 +1,49 @@ -""" -Example of reading an analog light sensor -and sending the value to Adafruit IO -""" +# Example of publishing the value of an ADC to Adafruit IO +# adafruit_circuitpython_adafruitio with an esp32spi_socket import time import board import busio -from digitalio import DigitalInOut from analogio import AnalogIn -from adafruit_esp32spi import adafruit_esp32spi, adafruit_esp32spi_wifimanager - -# Import NeoPixel Library -import neopixel - -# Import Adafruit IO HTTP Client +from digitalio import DigitalInOut +import adafruit_esp32spi.adafruit_esp32spi_socket as socket +from adafruit_esp32spi import adafruit_esp32spi +import adafruit_requests as requests from adafruit_io.adafruit_io import IO_HTTP, AdafruitIO_RequestError -# Delay between polling and sending light sensor data, in seconds -SENSOR_DELAY = 30 - -# Get wifi details and more from a secrets.py file +# Add a secrets.py to your filesystem that has a dictionary called secrets with "ssid" and +# "password" keys with your WiFi credentials. DO NOT share that file or commit it into Git or other +# source control. +# pylint: disable=no-name-in-module,wrong-import-order try: from secrets import secrets except ImportError: print("WiFi secrets are kept in secrets.py, please add them there!") raise -# ESP32 Setup -try: - esp32_cs = DigitalInOut(board.ESP_CS) - esp32_ready = DigitalInOut(board.ESP_BUSY) - esp32_reset = DigitalInOut(board.ESP_RESET) -except AttributeError: - esp32_cs = DigitalInOut(board.D9) - esp32_ready = DigitalInOut(board.D10) - esp32_reset = DigitalInOut(board.D5) +# If you are using a board with pre-defined ESP32 Pins: +esp32_cs = DigitalInOut(board.ESP_CS) +esp32_ready = DigitalInOut(board.ESP_BUSY) +esp32_reset = DigitalInOut(board.ESP_RESET) + +# If you have an externally connected ESP32: +# esp32_cs = DigitalInOut(board.D9) +# esp32_ready = DigitalInOut(board.D10) +# esp32_reset = DigitalInOut(board.D5) spi = busio.SPI(board.SCK, board.MOSI, board.MISO) esp = adafruit_esp32spi.ESP_SPIcontrol(spi, esp32_cs, esp32_ready, esp32_reset) -status_light = neopixel.NeoPixel( - board.NEOPIXEL, 1, brightness=0.2 -) # Uncomment for Most Boards -"""Uncomment below for ItsyBitsy M4""" -# status_light = dotstar.DotStar(board.APA102_SCK, board.APA102_MOSI, 1, brightness=0.2) -wifi = adafruit_esp32spi_wifimanager.ESPSPI_WiFiManager(esp, secrets, status_light) + +print("Connecting to AP...") +while not esp.is_connected: + try: + esp.connect_AP(secrets["ssid"], secrets["password"]) + except RuntimeError as e: + print("could not connect to AP, retrying: ", e) + continue +print("Connected to", str(esp.ssid, "utf-8"), "\tRSSI:", esp.rssi) + +socket.set_interface(esp) +requests.set_socket(socket, esp) # Set your Adafruit IO Username and Key in secrets.py # (visit io.adafruit.com if you need to create an account, @@ -50,8 +51,8 @@ aio_username = secrets["aio_username"] aio_key = secrets["aio_key"] -# Create an instance of the Adafruit IO HTTP client -io = IO_HTTP(aio_username, aio_key, wifi) +# Initialize an Adafruit IO HTTP API object +io = IO_HTTP(aio_username, aio_key, requests) try: # Get the 'light' feed from Adafruit IO @@ -60,12 +61,13 @@ # If no 'light' feed exists, create one light_feed = io.create_new_feed("light") -# Set up an analog light sensor on the PyPortal -adc = AnalogIn(board.LIGHT) +# Set up an ADC +adc = AnalogIn(board.A0) +SENSOR_DELAY = 30 while True: light_value = adc.value - print("Light Level: ", light_value) + print("ADC Value: ", light_value) print("Sending to Adafruit IO...") io.send_data(light_feed["key"], light_value) print("Sent!") From 215b5a44bcd4192b9526dd24bcbdffa8a3d05e4d Mon Sep 17 00:00:00 2001 From: brentru Date: Thu, 19 Nov 2020 17:59:34 -0500 Subject: [PATCH 11/16] add randomizer service --- .../adafruit_io_randomizer.py | 79 +++++++++---------- 1 file changed, 38 insertions(+), 41 deletions(-) diff --git a/examples/adafruit_io_http/adafruit_io_randomizer.py b/examples/adafruit_io_http/adafruit_io_randomizer.py index b2889ed..6c9438b 100644 --- a/examples/adafruit_io_http/adafruit_io_randomizer.py +++ b/examples/adafruit_io_http/adafruit_io_randomizer.py @@ -1,46 +1,48 @@ -""" -Example of using Adafruit IO's -random data service. -""" +# Example for using Adafruit IO's random data (randomizer) service +# adafruit_circuitpython_adafruitio with an esp32spi_socket import time import board import busio from digitalio import DigitalInOut +import adafruit_esp32spi.adafruit_esp32spi_socket as socket +from adafruit_esp32spi import adafruit_esp32spi +import adafruit_requests as requests +from adafruit_io.adafruit_io import IO_HTTP, AdafruitIO_RequestError -# ESP32 SPI -from adafruit_esp32spi import adafruit_esp32spi, adafruit_esp32spi_wifimanager - -# Import NeoPixel Library -import neopixel - -# Import Adafruit IO HTTP Client -from adafruit_io.adafruit_io import IO_HTTP - -# Get wifi details and more from a secrets.py file +# Add a secrets.py to your filesystem that has a dictionary called secrets with "ssid" and +# "password" keys with your WiFi credentials. DO NOT share that file or commit it into Git or other +# source control. +# pylint: disable=no-name-in-module,wrong-import-order try: from secrets import secrets except ImportError: print("WiFi secrets are kept in secrets.py, please add them there!") raise -# ESP32 Setup -try: - esp32_cs = DigitalInOut(board.ESP_CS) - esp32_ready = DigitalInOut(board.ESP_BUSY) - esp32_reset = DigitalInOut(board.ESP_RESET) -except AttributeError: - esp32_cs = DigitalInOut(board.D9) - esp32_ready = DigitalInOut(board.D10) - esp32_reset = DigitalInOut(board.D5) +# If you are using a board with pre-defined ESP32 Pins: +esp32_cs = DigitalInOut(board.ESP_CS) +esp32_ready = DigitalInOut(board.ESP_BUSY) +esp32_reset = DigitalInOut(board.ESP_RESET) + +# If you have an externally connected ESP32: +# esp32_cs = DigitalInOut(board.D9) +# esp32_ready = DigitalInOut(board.D10) +# esp32_reset = DigitalInOut(board.D5) spi = busio.SPI(board.SCK, board.MOSI, board.MISO) esp = adafruit_esp32spi.ESP_SPIcontrol(spi, esp32_cs, esp32_ready, esp32_reset) -status_light = neopixel.NeoPixel( - board.NEOPIXEL, 1, brightness=0.2 -) # Uncomment for Most Boards -"""Uncomment below for ItsyBitsy M4""" -# status_light = dotstar.DotStar(board.APA102_SCK, board.APA102_MOSI, 1, brightness=0.2) -wifi = adafruit_esp32spi_wifimanager.ESPSPI_WiFiManager(esp, secrets, status_light) + +print("Connecting to AP...") +while not esp.is_connected: + try: + esp.connect_AP(secrets["ssid"], secrets["password"]) + except RuntimeError as e: + print("could not connect to AP, retrying: ", e) + continue +print("Connected to", str(esp.ssid, "utf-8"), "\tRSSI:", esp.rssi) + +socket.set_interface(esp) +requests.set_socket(socket, esp) # Set your Adafruit IO Username and Key in secrets.py # (visit io.adafruit.com if you need to create an account, @@ -48,8 +50,8 @@ aio_username = secrets["aio_username"] aio_key = secrets["aio_key"] -# Create an instance of the Adafruit IO HTTP client -io = IO_HTTP(aio_username, aio_key, wifi) +# Initialize an Adafruit IO HTTP API object +io = IO_HTTP(aio_username, aio_key, requests) # Random Data ID # (to obtain this value, visit @@ -58,14 +60,9 @@ random_data_id = 1234 while True: - try: - print("Fetching random data from Adafruit IO...") - random_data = io.receive_random_data(random_data_id) - print("Random Data: ", random_data["value"]) - print("Data Seed: ", random_data["seed"]) - print("Waiting 1 minute to fetch new randomized data...") - except (ValueError, RuntimeError) as e: - print("Failed to get data, retrying\n", e) - wifi.reset() - continue + print("Fetching random data from Adafruit IO...") + random_data = io.receive_random_data(random_data_id) + print("Random Data: ", random_data["value"]) + print("Data Seed: ", random_data["seed"]) + print("Waiting 1 minute to fetch new randomized data...") time.sleep(60) From f95ce6a9ab9e2052dde04761f1eefa5db2265d27 Mon Sep 17 00:00:00 2001 From: brentru Date: Thu, 19 Nov 2020 18:03:40 -0500 Subject: [PATCH 12/16] add weather service --- .../adafruit_io_http/adafruit_io_weather.py | 65 ++++++++++--------- 1 file changed, 35 insertions(+), 30 deletions(-) diff --git a/examples/adafruit_io_http/adafruit_io_weather.py b/examples/adafruit_io_http/adafruit_io_weather.py index 33fc0f4..cd2b593 100644 --- a/examples/adafruit_io_http/adafruit_io_weather.py +++ b/examples/adafruit_io_http/adafruit_io_weather.py @@ -4,44 +4,49 @@ NOTE: This example is for Adafruit IO Plus subscribers only. """ +import time import board import busio from digitalio import DigitalInOut +import adafruit_esp32spi.adafruit_esp32spi_socket as socket +from adafruit_esp32spi import adafruit_esp32spi +import adafruit_requests as requests +from adafruit_io.adafruit_io import IO_HTTP, AdafruitIO_RequestError -# ESP32 SPI -from adafruit_esp32spi import adafruit_esp32spi, adafruit_esp32spi_wifimanager - -# Import NeoPixel Library -import neopixel - -# Import Adafruit IO HTTP Client -from adafruit_io.adafruit_io import IO_HTTP - -# Get wifi details and more from a secrets.py file +# Add a secrets.py to your filesystem that has a dictionary called secrets with "ssid" and +# "password" keys with your WiFi credentials. DO NOT share that file or commit it into Git or other +# source control. +# pylint: disable=no-name-in-module,wrong-import-order try: from secrets import secrets except ImportError: print("WiFi secrets are kept in secrets.py, please add them there!") raise -# ESP32 Setup -try: - esp32_cs = DigitalInOut(board.ESP_CS) - esp32_ready = DigitalInOut(board.ESP_BUSY) - esp32_reset = DigitalInOut(board.ESP_RESET) -except AttributeError: - esp32_cs = DigitalInOut(board.D9) - esp32_ready = DigitalInOut(board.D10) - esp32_reset = DigitalInOut(board.D5) +# If you are using a board with pre-defined ESP32 Pins: +esp32_cs = DigitalInOut(board.ESP_CS) +esp32_ready = DigitalInOut(board.ESP_BUSY) +esp32_reset = DigitalInOut(board.ESP_RESET) + +# If you have an externally connected ESP32: +# esp32_cs = DigitalInOut(board.D9) +# esp32_ready = DigitalInOut(board.D10) +# esp32_reset = DigitalInOut(board.D5) spi = busio.SPI(board.SCK, board.MOSI, board.MISO) esp = adafruit_esp32spi.ESP_SPIcontrol(spi, esp32_cs, esp32_ready, esp32_reset) -status_light = neopixel.NeoPixel( - board.NEOPIXEL, 1, brightness=0.2 -) # Uncomment for Most Boards -"""Uncomment below for ItsyBitsy M4""" -# status_light = dotstar.DotStar(board.APA102_SCK, board.APA102_MOSI, 1, brightness=0.2) -wifi = adafruit_esp32spi_wifimanager.ESPSPI_WiFiManager(esp, secrets, status_light) + +print("Connecting to AP...") +while not esp.is_connected: + try: + esp.connect_AP(secrets["ssid"], secrets["password"]) + except RuntimeError as e: + print("could not connect to AP, retrying: ", e) + continue +print("Connected to", str(esp.ssid, "utf-8"), "\tRSSI:", esp.rssi) + +socket.set_interface(esp) +requests.set_socket(socket, esp) # Set your Adafruit IO Username and Key in secrets.py # (visit io.adafruit.com if you need to create an account, @@ -49,17 +54,17 @@ aio_username = secrets["aio_username"] aio_key = secrets["aio_key"] -# Create an instance of the Adafruit IO HTTP client -io = IO_HTTP(aio_username, aio_key, wifi) +# Initialize an Adafruit IO HTTP API object +io = IO_HTTP(aio_username, aio_key, requests) # Weather Location ID # (to obtain this value, visit # https://io.adafruit.com/services/weather # and copy over the location ID) -location_id = 1234 +location_id = 2127 -print("Getting weather record from IO...") -# Get the specified weather record with current weather +print("Getting forecast from IO...") +# Fetch the specified record with current weather # and all available forecast information. forecast = io.receive_weather(location_id) From ed1f9d4032f5cb99a401ebaff536fad0fc621467 Mon Sep 17 00:00:00 2001 From: brentru Date: Fri, 20 Nov 2020 10:34:08 -0500 Subject: [PATCH 13/16] add temp sensor, weather --- .../adafruit_io_temperature.py | 70 +++++++++---------- .../adafruit_io_http/adafruit_io_weather.py | 8 +-- 2 files changed, 35 insertions(+), 43 deletions(-) diff --git a/examples/adafruit_io_http/adafruit_io_temperature.py b/examples/adafruit_io_http/adafruit_io_temperature.py index f124b48..aaf3420 100644 --- a/examples/adafruit_io_http/adafruit_io_temperature.py +++ b/examples/adafruit_io_http/adafruit_io_temperature.py @@ -1,53 +1,49 @@ -""" -Example of sending temperature -values to an Adafruit IO feed. - -Dependencies: - * CircuitPython_ADT7410 - https://github.com/adafruit/Adafruit_CircuitPython_ADT7410 -""" +# Example of sending ADT7410 sensor temperature values to IO +# adafruit_circuitpython_adafruitio with an esp32spi_socket import time import board import busio from digitalio import DigitalInOut - -# ESP32 SPI -from adafruit_esp32spi import adafruit_esp32spi, adafruit_esp32spi_wifimanager - -# Import NeoPixel Library -import neopixel - -# Import ADT7410 Library -import adafruit_adt7410 - -# Import Adafruit IO HTTP Client +import adafruit_esp32spi.adafruit_esp32spi_socket as socket +from adafruit_esp32spi import adafruit_esp32spi +import adafruit_requests as requests from adafruit_io.adafruit_io import IO_HTTP, AdafruitIO_RequestError +import adafruit_adt7410 -# Get wifi details and more from a secrets.py file +# Add a secrets.py to your filesystem that has a dictionary called secrets with "ssid" and +# "password" keys with your WiFi credentials. DO NOT share that file or commit it into Git or other +# source control. +# pylint: disable=no-name-in-module,wrong-import-order try: from secrets import secrets except ImportError: print("WiFi secrets are kept in secrets.py, please add them there!") raise -# ESP32 Setup -try: - esp32_cs = DigitalInOut(board.ESP_CS) - esp32_ready = DigitalInOut(board.ESP_BUSY) - esp32_reset = DigitalInOut(board.ESP_RESET) -except AttributeError: - esp32_cs = DigitalInOut(board.D9) - esp32_ready = DigitalInOut(board.D10) - esp32_reset = DigitalInOut(board.D5) +# If you are using a board with pre-defined ESP32 Pins: +esp32_cs = DigitalInOut(board.ESP_CS) +esp32_ready = DigitalInOut(board.ESP_BUSY) +esp32_reset = DigitalInOut(board.ESP_RESET) + +# If you have an externally connected ESP32: +# esp32_cs = DigitalInOut(board.D9) +# esp32_ready = DigitalInOut(board.D10) +# esp32_reset = DigitalInOut(board.D5) spi = busio.SPI(board.SCK, board.MOSI, board.MISO) esp = adafruit_esp32spi.ESP_SPIcontrol(spi, esp32_cs, esp32_ready, esp32_reset) -status_light = neopixel.NeoPixel( - board.NEOPIXEL, 1, brightness=0.2 -) # Uncomment for Most Boards -"""Uncomment below for ItsyBitsy M4""" -# status_light = dotstar.DotStar(board.APA102_SCK, board.APA102_MOSI, 1, brightness=0.2) -wifi = adafruit_esp32spi_wifimanager.ESPSPI_WiFiManager(esp, secrets, status_light) + +print("Connecting to AP...") +while not esp.is_connected: + try: + esp.connect_AP(secrets["ssid"], secrets["password"]) + except RuntimeError as e: + print("could not connect to AP, retrying: ", e) + continue +print("Connected to", str(esp.ssid, "utf-8"), "\tRSSI:", esp.rssi) + +socket.set_interface(esp) +requests.set_socket(socket, esp) # Set your Adafruit IO Username and Key in secrets.py # (visit io.adafruit.com if you need to create an account, @@ -55,8 +51,8 @@ aio_username = secrets["aio_username"] aio_key = secrets["aio_key"] -# Create an instance of the Adafruit IO HTTP client -io = IO_HTTP(aio_username, aio_key, wifi) +# Initialize an Adafruit IO HTTP API object +io = IO_HTTP(aio_username, aio_key, requests) try: # Get the 'temperature' feed from Adafruit IO diff --git a/examples/adafruit_io_http/adafruit_io_weather.py b/examples/adafruit_io_http/adafruit_io_weather.py index cd2b593..42e394b 100644 --- a/examples/adafruit_io_http/adafruit_io_weather.py +++ b/examples/adafruit_io_http/adafruit_io_weather.py @@ -1,9 +1,5 @@ -""" -Example of getting weather -from the Adafruit IO Weather Service -NOTE: This example is for Adafruit IO -Plus subscribers only. -""" +# Example of using the Adafruit IO+ Weather Service +# adafruit_circuitpython_adafruitio with an esp32spi_socket import time import board import busio From cb346e6439218a987e6b3eafb58b0bf970b0791e Mon Sep 17 00:00:00 2001 From: brentru Date: Fri, 20 Nov 2020 10:36:58 -0500 Subject: [PATCH 14/16] remove atcontrol example --- .../adafruit_io_http/adafruit_io_esp_at.py | 91 ------------------- 1 file changed, 91 deletions(-) delete mode 100644 examples/adafruit_io_http/adafruit_io_esp_at.py diff --git a/examples/adafruit_io_http/adafruit_io_esp_at.py b/examples/adafruit_io_http/adafruit_io_esp_at.py deleted file mode 100644 index cf703b3..0000000 --- a/examples/adafruit_io_http/adafruit_io_esp_at.py +++ /dev/null @@ -1,91 +0,0 @@ -""" -Usage example of the ESP32 over UART -using the CircuitPython ESP_ATControl library. - -Dependencies: - * https://github.com/adafruit/Adafruit_CircuitPython_ESP_ATcontrol -""" -from random import randint -import board -import busio -from digitalio import DigitalInOut - -# ESP32 AT -from adafruit_espatcontrol import ( - adafruit_espatcontrol, - adafruit_espatcontrol_wifimanager, -) - -# Use below for Most Boards -import neopixel - -# Import Adafruit IO HTTP Client -from adafruit_io.adafruit_io import IO_HTTP, AdafruitIO_RequestError - -status_light = neopixel.NeoPixel( - board.NEOPIXEL, 1, brightness=0.2 -) # Uncomment for Most Boards - -# Uncomment below for ItsyBitsy M4# -# import adafruit_dotstar as dotstar -# status_light = dotstar.DotStar(board.APA102_SCK, board.APA102_MOSI, 1, brightness=0.2) - -# Uncomment below for Particle Argon# -# status_light = None - -# Get wifi details and more from a secrets.py file -try: - from secrets import secrets -except ImportError: - print("WiFi secrets are kept in secrets.py, please add them there!") - raise - -# With a Metro or Feather M4 -uart = busio.UART(board.TX, board.RX, timeout=0.1) -resetpin = DigitalInOut(board.D5) -rtspin = DigitalInOut(board.D6) - -# With a Particle Argon -""" -RX = board.ESP_TX -TX = board.ESP_RX -resetpin = DigitalInOut(board.ESP_WIFI_EN) -rtspin = DigitalInOut(board.ESP_CTS) -uart = busio.UART(TX, RX, timeout=0.1) -esp_boot = DigitalInOut(board.ESP_BOOT_MODE) -from digitalio import Direction -esp_boot.direction = Direction.OUTPUT -esp_boot.value = True -""" - -esp = adafruit_espatcontrol.ESP_ATcontrol( - uart, 115200, reset_pin=resetpin, rts_pin=rtspin, debug=False -) -wifi = adafruit_espatcontrol_wifimanager.ESPAT_WiFiManager(esp, secrets, status_light) - -# Set your Adafruit IO Username and Key in secrets.py -# (visit io.adafruit.com if you need to create an account, -# or if you need your Adafruit IO key.) -aio_username = secrets["aio_username"] -aio_key = secrets["aio_key"] - -# Create an instance of the Adafruit IO HTTP client -io = IO_HTTP(aio_username, aio_key, wifi) - -try: - # Get the 'temperature' feed from Adafruit IO - temperature_feed = io.get_feed("temperature") -except AdafruitIO_RequestError: - # If no 'temperature' feed exists, create one - temperature_feed = io.create_new_feed("temperature") - -# Send random integer values to the feed -random_value = randint(0, 50) -print("Sending {0} to temperature feed...".format(random_value)) -io.send_data(temperature_feed["key"], random_value) -print("Data sent!") - -# Retrieve data value from the feed -print("Retrieving data from temperature feed...") -received_data = io.receive_data(temperature_feed["key"]) -print("Data from temperature feed: ", received_data["value"]) From db78907790baef8972380bd7a32e28f323f20487 Mon Sep 17 00:00:00 2001 From: brentru Date: Fri, 20 Nov 2020 11:03:44 -0500 Subject: [PATCH 15/16] add exampel for native wifi networking --- .../adafruit_io_simpletest_wifi.py | 51 +++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 examples/adafruit_io_http/adafruit_io_simpletest_wifi.py diff --git a/examples/adafruit_io_http/adafruit_io_simpletest_wifi.py b/examples/adafruit_io_http/adafruit_io_simpletest_wifi.py new file mode 100644 index 0000000..7bdd44c --- /dev/null +++ b/examples/adafruit_io_http/adafruit_io_simpletest_wifi.py @@ -0,0 +1,51 @@ +# adafruit_circuitpython_adafruitio usage with native wifi networking +import ssl +from random import randint +import adafruit_requests +import socketpool +import wifi +from adafruit_io.adafruit_io import IO_HTTP, AdafruitIO_RequestError + +# Add a secrets.py to your filesystem that has a dictionary called secrets with "ssid" and +# "password" keys with your WiFi credentials. DO NOT share that file or commit it into Git or other +# source control. +# pylint: disable=no-name-in-module,wrong-import-order +try: + from secrets import secrets +except ImportError: + print("WiFi secrets are kept in secrets.py, please add them there!") + raise + +# Set your Adafruit IO Username and Key in secrets.py +# (visit io.adafruit.com if you need to create an account, +# or if you need your Adafruit IO key.) +aio_username = secrets["aio_username"] +aio_key = secrets["aio_key"] + +print("Connecting to %s"%secrets["ssid"]) +wifi.radio.connect(secrets["ssid"], secrets["password"]) +print("Connected to %s!"%secrets["ssid"]) + + +pool = socketpool.SocketPool(wifi.radio) +requests = adafruit_requests.Session(pool, ssl.create_default_context()) +# Initialize an Adafruit IO HTTP API object +io = IO_HTTP(aio_username, aio_key, requests) + +try: + # Get the 'temperature' feed from Adafruit IO + temperature_feed = io.get_feed("temperature") +except AdafruitIO_RequestError: + # If no 'temperature' feed exists, create one + temperature_feed = io.create_new_feed("temperature") + +# Send random integer values to the feed +random_value = randint(0, 50) +print("Sending {0} to temperature feed...".format(random_value)) +io.send_data(temperature_feed["key"], random_value) +print("Data sent!") + +# Retrieve data value from the feed +print("Retrieving data from temperature feed...") +received_data = io.receive_data(temperature_feed["key"]) +print("Data from temperature feed: ", received_data["value"]) From 1ebad058e17b93ea051b1975171d7e7acd7fe10b Mon Sep 17 00:00:00 2001 From: brentru Date: Fri, 20 Nov 2020 11:39:53 -0500 Subject: [PATCH 16/16] reorganize examples, 1st class native networking --- .../adafruit_io_http/adafruit_io_feeds.py | 2 +- .../adafruit_io_http/adafruit_io_groups.py | 2 +- .../adafruit_io_randomizer.py | 2 +- .../adafruit_io_simpletest.py | 122 ++++++++---------- .../adafruit_io_simpletest_wifi.py | 51 -------- .../adafruit_io_temperature.py | 21 ++- .../adafruit_io_http/adafruit_io_weather.py | 3 +- 7 files changed, 63 insertions(+), 140 deletions(-) delete mode 100644 examples/adafruit_io_http/adafruit_io_simpletest_wifi.py diff --git a/examples/adafruit_io_http/adafruit_io_feeds.py b/examples/adafruit_io_http/adafruit_io_feeds.py index 64a8719..d70819e 100644 --- a/examples/adafruit_io_http/adafruit_io_feeds.py +++ b/examples/adafruit_io_http/adafruit_io_feeds.py @@ -7,7 +7,7 @@ import adafruit_esp32spi.adafruit_esp32spi_socket as socket from adafruit_esp32spi import adafruit_esp32spi import adafruit_requests as requests -from adafruit_io.adafruit_io import IO_HTTP, AdafruitIO_RequestError +from adafruit_io.adafruit_io import IO_HTTP # Add a secrets.py to your filesystem that has a dictionary called secrets with "ssid" and # "password" keys with your WiFi credentials. DO NOT share that file or commit it into Git or other diff --git a/examples/adafruit_io_http/adafruit_io_groups.py b/examples/adafruit_io_http/adafruit_io_groups.py index b1d915e..e894dff 100644 --- a/examples/adafruit_io_http/adafruit_io_groups.py +++ b/examples/adafruit_io_http/adafruit_io_groups.py @@ -7,7 +7,7 @@ import adafruit_esp32spi.adafruit_esp32spi_socket as socket from adafruit_esp32spi import adafruit_esp32spi import adafruit_requests as requests -from adafruit_io.adafruit_io import IO_HTTP, AdafruitIO_RequestError +from adafruit_io.adafruit_io import IO_HTTP # Add a secrets.py to your filesystem that has a dictionary called secrets with "ssid" and diff --git a/examples/adafruit_io_http/adafruit_io_randomizer.py b/examples/adafruit_io_http/adafruit_io_randomizer.py index 6c9438b..96e4039 100644 --- a/examples/adafruit_io_http/adafruit_io_randomizer.py +++ b/examples/adafruit_io_http/adafruit_io_randomizer.py @@ -7,7 +7,7 @@ import adafruit_esp32spi.adafruit_esp32spi_socket as socket from adafruit_esp32spi import adafruit_esp32spi import adafruit_requests as requests -from adafruit_io.adafruit_io import IO_HTTP, AdafruitIO_RequestError +from adafruit_io.adafruit_io import IO_HTTP # Add a secrets.py to your filesystem that has a dictionary called secrets with "ssid" and # "password" keys with your WiFi credentials. DO NOT share that file or commit it into Git or other diff --git a/examples/adafruit_io_http/adafruit_io_simpletest.py b/examples/adafruit_io_http/adafruit_io_simpletest.py index 6444252..26749d1 100644 --- a/examples/adafruit_io_http/adafruit_io_simpletest.py +++ b/examples/adafruit_io_http/adafruit_io_simpletest.py @@ -1,71 +1,51 @@ -# adafruit_circuitpython_adafruitio usage with an esp32spi_socket -from random import randint -import board -import busio -from digitalio import DigitalInOut -import adafruit_esp32spi.adafruit_esp32spi_socket as socket -from adafruit_esp32spi import adafruit_esp32spi -import adafruit_requests as requests -from adafruit_io.adafruit_io import IO_HTTP, AdafruitIO_RequestError - -# Add a secrets.py to your filesystem that has a dictionary called secrets with "ssid" and -# "password" keys with your WiFi credentials. DO NOT share that file or commit it into Git or other -# source control. -# pylint: disable=no-name-in-module,wrong-import-order -try: - from secrets import secrets -except ImportError: - print("WiFi secrets are kept in secrets.py, please add them there!") - raise - -# If you are using a board with pre-defined ESP32 Pins: -esp32_cs = DigitalInOut(board.ESP_CS) -esp32_ready = DigitalInOut(board.ESP_BUSY) -esp32_reset = DigitalInOut(board.ESP_RESET) - -# If you have an externally connected ESP32: -# esp32_cs = DigitalInOut(board.D9) -# esp32_ready = DigitalInOut(board.D10) -# esp32_reset = DigitalInOut(board.D5) - -spi = busio.SPI(board.SCK, board.MOSI, board.MISO) -esp = adafruit_esp32spi.ESP_SPIcontrol(spi, esp32_cs, esp32_ready, esp32_reset) - -print("Connecting to AP...") -while not esp.is_connected: - try: - esp.connect_AP(secrets["ssid"], secrets["password"]) - except RuntimeError as e: - print("could not connect to AP, retrying: ", e) - continue -print("Connected to", str(esp.ssid, "utf-8"), "\tRSSI:", esp.rssi) - -socket.set_interface(esp) -requests.set_socket(socket, esp) - -# Set your Adafruit IO Username and Key in secrets.py -# (visit io.adafruit.com if you need to create an account, -# or if you need your Adafruit IO key.) -aio_username = secrets["aio_username"] -aio_key = secrets["aio_key"] - -# Initialize an Adafruit IO HTTP API object -io = IO_HTTP(aio_username, aio_key, requests) - -try: - # Get the 'temperature' feed from Adafruit IO - temperature_feed = io.get_feed("temperature") -except AdafruitIO_RequestError: - # If no 'temperature' feed exists, create one - temperature_feed = io.create_new_feed("temperature") - -# Send random integer values to the feed -random_value = randint(0, 50) -print("Sending {0} to temperature feed...".format(random_value)) -io.send_data(temperature_feed["key"], random_value) -print("Data sent!") - -# Retrieve data value from the feed -print("Retrieving data from temperature feed...") -received_data = io.receive_data(temperature_feed["key"]) -print("Data from temperature feed: ", received_data["value"]) +# adafruit_circuitpython_adafruitio usage with native wifi networking +import ssl +from random import randint +import adafruit_requests +import socketpool +import wifi +from adafruit_io.adafruit_io import IO_HTTP, AdafruitIO_RequestError + +# Add a secrets.py to your filesystem that has a dictionary called secrets with "ssid" and +# "password" keys with your WiFi credentials. DO NOT share that file or commit it into Git or other +# source control. +# pylint: disable=no-name-in-module,wrong-import-order +try: + from secrets import secrets +except ImportError: + print("WiFi secrets are kept in secrets.py, please add them there!") + raise + +# Set your Adafruit IO Username and Key in secrets.py +# (visit io.adafruit.com if you need to create an account, +# or if you need your Adafruit IO key.) +aio_username = secrets["aio_username"] +aio_key = secrets["aio_key"] + +print("Connecting to %s" % secrets["ssid"]) +wifi.radio.connect(secrets["ssid"], secrets["password"]) +print("Connected to %s!" % secrets["ssid"]) + + +pool = socketpool.SocketPool(wifi.radio) +requests = adafruit_requests.Session(pool, ssl.create_default_context()) +# Initialize an Adafruit IO HTTP API object +io = IO_HTTP(aio_username, aio_key, requests) + +try: + # Get the 'temperature' feed from Adafruit IO + temperature_feed = io.get_feed("temperature") +except AdafruitIO_RequestError: + # If no 'temperature' feed exists, create one + temperature_feed = io.create_new_feed("temperature") + +# Send random integer values to the feed +random_value = randint(0, 50) +print("Sending {0} to temperature feed...".format(random_value)) +io.send_data(temperature_feed["key"], random_value) +print("Data sent!") + +# Retrieve data value from the feed +print("Retrieving data from temperature feed...") +received_data = io.receive_data(temperature_feed["key"]) +print("Data from temperature feed: ", received_data["value"]) diff --git a/examples/adafruit_io_http/adafruit_io_simpletest_wifi.py b/examples/adafruit_io_http/adafruit_io_simpletest_wifi.py deleted file mode 100644 index 7bdd44c..0000000 --- a/examples/adafruit_io_http/adafruit_io_simpletest_wifi.py +++ /dev/null @@ -1,51 +0,0 @@ -# adafruit_circuitpython_adafruitio usage with native wifi networking -import ssl -from random import randint -import adafruit_requests -import socketpool -import wifi -from adafruit_io.adafruit_io import IO_HTTP, AdafruitIO_RequestError - -# Add a secrets.py to your filesystem that has a dictionary called secrets with "ssid" and -# "password" keys with your WiFi credentials. DO NOT share that file or commit it into Git or other -# source control. -# pylint: disable=no-name-in-module,wrong-import-order -try: - from secrets import secrets -except ImportError: - print("WiFi secrets are kept in secrets.py, please add them there!") - raise - -# Set your Adafruit IO Username and Key in secrets.py -# (visit io.adafruit.com if you need to create an account, -# or if you need your Adafruit IO key.) -aio_username = secrets["aio_username"] -aio_key = secrets["aio_key"] - -print("Connecting to %s"%secrets["ssid"]) -wifi.radio.connect(secrets["ssid"], secrets["password"]) -print("Connected to %s!"%secrets["ssid"]) - - -pool = socketpool.SocketPool(wifi.radio) -requests = adafruit_requests.Session(pool, ssl.create_default_context()) -# Initialize an Adafruit IO HTTP API object -io = IO_HTTP(aio_username, aio_key, requests) - -try: - # Get the 'temperature' feed from Adafruit IO - temperature_feed = io.get_feed("temperature") -except AdafruitIO_RequestError: - # If no 'temperature' feed exists, create one - temperature_feed = io.create_new_feed("temperature") - -# Send random integer values to the feed -random_value = randint(0, 50) -print("Sending {0} to temperature feed...".format(random_value)) -io.send_data(temperature_feed["key"], random_value) -print("Data sent!") - -# Retrieve data value from the feed -print("Retrieving data from temperature feed...") -received_data = io.receive_data(temperature_feed["key"]) -print("Data from temperature feed: ", received_data["value"]) diff --git a/examples/adafruit_io_http/adafruit_io_temperature.py b/examples/adafruit_io_http/adafruit_io_temperature.py index aaf3420..0d25f05 100644 --- a/examples/adafruit_io_http/adafruit_io_temperature.py +++ b/examples/adafruit_io_http/adafruit_io_temperature.py @@ -7,8 +7,8 @@ import adafruit_esp32spi.adafruit_esp32spi_socket as socket from adafruit_esp32spi import adafruit_esp32spi import adafruit_requests as requests -from adafruit_io.adafruit_io import IO_HTTP, AdafruitIO_RequestError import adafruit_adt7410 +from adafruit_io.adafruit_io import IO_HTTP, AdafruitIO_RequestError # Add a secrets.py to your filesystem that has a dictionary called secrets with "ssid" and # "password" keys with your WiFi credentials. DO NOT share that file or commit it into Git or other @@ -67,17 +67,12 @@ adt.high_resolution = True while True: - try: - temperature = adt.temperature - # set temperature value to two precision points - temperature = "%0.2f" % (temperature) + temperature = adt.temperature + # set temperature value to two precision points + temperature = "%0.2f" % (temperature) - print("Current Temperature: {0}*C".format(temperature)) - print("Sending to Adafruit IO...") - io.send_data(temperature_feed["key"], temperature) - print("Data sent!") - except (ValueError, RuntimeError) as e: - print("Failed to get data, retrying\n", e) - wifi.reset() - continue + print("Current Temperature: {0}*C".format(temperature)) + print("Sending to Adafruit IO...") + io.send_data(temperature_feed["key"], temperature) + print("Data sent!") time.sleep(0.5) diff --git a/examples/adafruit_io_http/adafruit_io_weather.py b/examples/adafruit_io_http/adafruit_io_weather.py index 42e394b..6239d24 100644 --- a/examples/adafruit_io_http/adafruit_io_weather.py +++ b/examples/adafruit_io_http/adafruit_io_weather.py @@ -1,13 +1,12 @@ # Example of using the Adafruit IO+ Weather Service # adafruit_circuitpython_adafruitio with an esp32spi_socket -import time import board import busio from digitalio import DigitalInOut import adafruit_esp32spi.adafruit_esp32spi_socket as socket from adafruit_esp32spi import adafruit_esp32spi import adafruit_requests as requests -from adafruit_io.adafruit_io import IO_HTTP, AdafruitIO_RequestError +from adafruit_io.adafruit_io import IO_HTTP # Add a secrets.py to your filesystem that has a dictionary called secrets with "ssid" and # "password" keys with your WiFi credentials. DO NOT share that file or commit it into Git or other