diff --git a/examples/agile_pricing_display.py b/examples/agile_pricing_display.py index 7ba9447..d4aa6e2 100644 --- a/examples/agile_pricing_display.py +++ b/examples/agile_pricing_display.py @@ -3,59 +3,26 @@ Shows the current, next and last energy price for Octopus Energys Agile Price tarrif ''' -import network +import asyncio +import datetime import time -import requests + +import machine import ntptime -import datetime -from picographics import PicoGraphics, DISPLAY_PRESTO +import requests +from ezwifi import EzWiFi +from picographics import DISPLAY_PRESTO, PicoGraphics +from picovector import ANTIALIAS_BEST, PicoVector, Polygon, Transform from presto import Presto -from picovector import PicoVector, ANTIALIAS_BEST, Polygon, Transform -import machine machine.freq(264000000) -# Check and import the Network SSID and Password from secrets.py -# import the Spotify API keys from that file too -try: - from secrets import WIFI_SSID, WIFI_PASSWORD - if WIFI_SSID == "": - raise ValueError("WIFI_SSID in 'secrets.py' is empty!") - if WIFI_PASSWORD == "": - raise ValueError("WIFI_PASSWORD in 'secrets.py' is empty!") -except ImportError: - raise ImportError("'secrets.py' is missing from your Pimoroni Presto!") -except ValueError as e: - print(e) - # Constants API_URL = 'https://api.octopus.energy/v1/products/AGILE-FLEX-22-11-25/electricity-tariffs/E-1R-AGILE-FLEX-22-11-25-C/standard-unit-rates/' -wlan = network.WLAN(network.STA_IF) - - -def network_connect(): - # Connect to the network specified in secrets.py - wlan.active(True) - wlan.connect(WIFI_SSID, WIFI_PASSWORD) - attempts = 0 - while wlan.isconnected() is False: - print("Attempting connection to {}".format(WIFI_SSID)) - time.sleep(1) - attempts += 1 - if attempts > 10: - raise OSError('Unable to connect to wireless network. Check your WIFI_SSID and WIFI_PASSWORD and try again.') - - -# Start connection to the network -network_connect() - -# Store the local IP address -ip_addr = wlan.ipconfig('addr4')[0] - -# Let the user know the connection has been successful -# and display the current IP address of the Pimoroni Presto -print("Successfully connected to {}. Your Pimoroni Presto IP is: {}".format(WIFI_SSID, ip_addr)) +# WiFi setup +wifi = EzWiFi(verbose=True) +connected = asyncio.get_event_loop().run_until_complete(wifi.connect(retries=2)) # Set the correct time using the NTP service. ntptime.settime() diff --git a/examples/cheerlights_bulb.py b/examples/cheerlights_bulb.py index 9853876..9177a64 100644 --- a/examples/cheerlights_bulb.py +++ b/examples/cheerlights_bulb.py @@ -1,13 +1,14 @@ +import asyncio import time import machine -import network import plasma import requests -from ft6236 import FT6236 +from ezwifi import EzWiFi from picographics import DISPLAY_PRESTO, PicoGraphics from picovector import ANTIALIAS_BEST, PicoVector, Polygon, Transform from presto import Presto +from touch import FT6236 BULB_OUTLINE = [(130.44, 0.0), (150.36, 1.51), @@ -105,17 +106,9 @@ machine.freq(264000000) -# Check and import the SSID and Password from secrets.py -try: - from secrets import WIFI_PASSWORD, WIFI_SSID - if WIFI_SSID == "": - raise ValueError("WIFI_SSID in 'secrets.py' is empty!") - if WIFI_PASSWORD == "": - raise ValueError("WIFI_PASSWORD in 'secrets.py' is empty!") -except ImportError: - raise ImportError("'secrets.py' is missing from your Plasma 2350 W!") -except ValueError as e: - print(e) +# WiFi setup +wifi = EzWiFi(verbose=True) +connected = asyncio.get_event_loop().run_until_complete(wifi.connect(retries=2)) # Setup for the Presto display presto = Presto() @@ -134,21 +127,6 @@ BLACK = display.create_pen(0, 0, 0) GRAY = display.create_pen(75, 75, 75) -wlan = network.WLAN(network.STA_IF) - - -def connect(): - # Connect to the network specified in secrets.py - wlan.active(True) - wlan.connect(WIFI_SSID, WIFI_PASSWORD) - while wlan.isconnected() is False: - print("Attempting connection to {}".format(WIFI_SSID)) - time.sleep(1) - - -# Start connection to the network -connect() - # WS2812 / NeoPixelâ„¢ LEDs used for the backlight bl = plasma.WS2812(7, 0, 0, 33) bl.start() @@ -235,11 +213,10 @@ def get_cheerlight(): # Poll the touch so we can see if anything changed since the last time touch.poll() - if wlan.isconnected(): + if connected: # If the user is touching the screen we'll do the following if touch.state: bulb_on = not bulb_on - print(f"Bulb is {bulb_on}") # Wait for the user to stop touching the screen while touch.state: touch.poll() @@ -271,6 +248,6 @@ def get_cheerlight(): draw_bulb((50, 50, 50)) else: - print("Lost connection to network {}".format(WIFI_SSID)) + print("Lost connection to network") presto.update(display) diff --git a/examples/image_gallery.py b/examples/image_gallery.py index 69150fe..a0ebbe7 100644 --- a/examples/image_gallery.py +++ b/examples/image_gallery.py @@ -14,9 +14,9 @@ import plasma import sdcard import uos -from ft6236 import FT6236 from picographics import DISPLAY_PRESTO, PicoGraphics from presto import Presto +from touch import FT6236 machine.freq(264000000) diff --git a/examples/touchscreen_dots.py b/examples/touchscreen_dots.py index bf0c7f6..6a97ad8 100644 --- a/examples/touchscreen_dots.py +++ b/examples/touchscreen_dots.py @@ -1,9 +1,10 @@ -from picographics import PicoGraphics, DISPLAY_PRESTO -from presto import Presto -from ft6236 import FT6236 -from random import randint import time +from random import randint + +from picographics import DISPLAY_PRESTO, PicoGraphics +from presto import Presto from PrestoLight import Reactive +from touch import FT6236 # Setup for the Presto display presto = Presto() diff --git a/examples/touchscreen_dots_vector.py b/examples/touchscreen_dots_vector.py index 14e8f4d..35b8a3a 100644 --- a/examples/touchscreen_dots_vector.py +++ b/examples/touchscreen_dots_vector.py @@ -1,10 +1,11 @@ -from picographics import PicoGraphics, DISPLAY_PRESTO -from presto import Presto -from ft6236 import FT6236 -from random import randint import time -from picovector import PicoVector, ANTIALIAS_FAST, Polygon +from random import randint + import machine +from picographics import DISPLAY_PRESTO, PicoGraphics +from picovector import ANTIALIAS_FAST, PicoVector, Polygon +from presto import Presto +from touch import FT6236 machine.freq(264000000) diff --git a/examples/word_clock.py b/examples/word_clock.py index 8915437..c2f0085 100644 --- a/examples/word_clock.py +++ b/examples/word_clock.py @@ -1,27 +1,15 @@ +import asyncio import time import machine -import network import ntptime import pngdec +from ezwifi import EzWiFi from picographics import DISPLAY_PRESTO, PicoGraphics from presto import Presto machine.freq(264000000) -# Check and import the Network SSID and Password from secrets.py -# import the Spotify API keys from that file too -try: - from secrets import WIFI_PASSWORD, WIFI_SSID - if WIFI_SSID == "": - raise ValueError("WIFI_SSID in 'secrets.py' is empty!") - if WIFI_PASSWORD == "": - raise ValueError("WIFI_PASSWORD in 'secrets.py' is empty!") -except ImportError: - raise ImportError("'secrets.py' is missing from your Pimoroni Presto!") -except ValueError as e: - print(e) - # Length of time between updates in minutes. UPDATE_INTERVAL = 15 @@ -30,31 +18,9 @@ words = ["it", "d", "is", "m", "about", "lv", "half", "c", "quarter", "b", "to", "past", "n", "one", "two", "three", "four", "five", "six", "eleven", "ten", "d", "nin", "eight", "seven", "rm", "twelve", "rtywtqdj", "O'Clock", "grd", "nhelloprestoa"] -wlan = network.WLAN(network.STA_IF) - - -def network_connect(): - # Connect to the network specified in secrets.py - wlan.active(True) - wlan.connect(WIFI_SSID, WIFI_PASSWORD) - attempts = 0 - while wlan.isconnected() is False: - print("Attempting connection to {}".format(WIFI_SSID)) - time.sleep(1) - attempts += 1 - if attempts > 10: - raise OSError('Unable to connect to wireless network. Check your WIFI_SSID and WIFI_PASSWORD and try again.') - - -# Start connection to the network -network_connect() - -# Store the local IP address -ip_addr = wlan.ipconfig('addr4')[0] - -# Let the user know the connection has been successful -# and display the current IP address of the Pimoroni Presto -print("Successfully connected to {}. Your Pimoroni Presto IP is: {}".format(WIFI_SSID, ip_addr)) +# WiFi setup +wifi = EzWiFi(verbose=True) +connected = asyncio.get_event_loop().run_until_complete(wifi.connect(retries=2)) # Set the correct time using the NTP service. ntptime.settime()