diff --git a/Pico_W_CircuitPython_WiFi_Examples/Pico_W_Adafruit_IO/code.py b/Pico_W_CircuitPython_WiFi_Examples/Pico_W_Adafruit_IO/code.py index 91d535665..2aba104fb 100644 --- a/Pico_W_CircuitPython_WiFi_Examples/Pico_W_Adafruit_IO/code.py +++ b/Pico_W_CircuitPython_WiFi_Examples/Pico_W_Adafruit_IO/code.py @@ -13,10 +13,18 @@ import adafruit_ahtx0 from adafruit_io.adafruit_io import IO_HTTP, AdafruitIO_RequestError -wifi.radio.connect(os.getenv('CIRCUITPY_WIFI_SSID'), os.getenv('CIRCUITPY_WIFI_PASSWORD')) +try: + wifi.radio.connect(os.getenv('CIRCUITPY_WIFI_SSID'), os.getenv('CIRCUITPY_WIFI_PASSWORD')) +except TypeError: + print("Could not find WiFi info. Check your settings.toml file!") + raise -aio_username = os.getenv('aio_username') -aio_key = os.getenv('aio_key') +try: + aio_username = os.getenv('ADAFRUIT_AIO_USERNAME') + aio_key = os.getenv('ADAFRUIT_AIO_KEY') +except TypeError: + print("Could not find Adafruit IO info. Check your settings.toml file!") + raise pool = socketpool.SocketPool(wifi.radio) requests = adafruit_requests.Session(pool, ssl.create_default_context()) diff --git a/Pico_W_CircuitPython_WiFi_Examples/Pico_W_Azure_IoT_Central/code.py b/Pico_W_CircuitPython_WiFi_Examples/Pico_W_Azure_IoT_Central/code.py index e59fef060..3f93762d3 100644 --- a/Pico_W_CircuitPython_WiFi_Examples/Pico_W_Azure_IoT_Central/code.py +++ b/Pico_W_CircuitPython_WiFi_Examples/Pico_W_Azure_IoT_Central/code.py @@ -19,7 +19,11 @@ aht20 = adafruit_ahtx0.AHTx0(i2c) print("Connecting to WiFi...") -wifi.radio.connect(os.getenv('CIRCUITPY_WIFI_SSID'), os.getenv('CIRCUITPY_WIFI_PASSWORD')) +try: + wifi.radio.connect(os.getenv('CIRCUITPY_WIFI_SSID'), os.getenv('CIRCUITPY_WIFI_PASSWORD')) +except TypeError: + print("Could not find WiFi info. Check your settings.toml file!") + raise print("Connected to WiFi!") @@ -38,9 +42,13 @@ # Create an IoT Hub device client and connect esp = None pool = socketpool.SocketPool(wifi.radio) -device = IoTCentralDevice( - pool, esp, os.getenv('id_scope'), os.getenv('device_id'), os.getenv('device_primary_key') -) +try: + device = IoTCentralDevice( + pool, esp, os.getenv('id_scope'), os.getenv('device_id'), os.getenv('device_primary_key') + ) +except TypeError: + print("Could not find Azure IoT info. Check your settings.toml file!") + raise print("Connecting to Azure IoT Central...") diff --git a/Pico_W_CircuitPython_WiFi_Examples/Pico_W_Basic_WiFi_Test/code.py b/Pico_W_CircuitPython_WiFi_Examples/Pico_W_Basic_WiFi_Test/code.py index 53992c0da..cea1e537d 100644 --- a/Pico_W_CircuitPython_WiFi_Examples/Pico_W_Basic_WiFi_Test/code.py +++ b/Pico_W_CircuitPython_WiFi_Examples/Pico_W_Basic_WiFi_Test/code.py @@ -11,7 +11,11 @@ print("Connecting to WiFi") # connect to your SSID -wifi.radio.connect(os.getenv('CIRCUITPY_WIFI_SSID'), os.getenv('CIRCUITPY_WIFI_PASSWORD')) +try: + wifi.radio.connect(os.getenv('CIRCUITPY_WIFI_SSID'), os.getenv('CIRCUITPY_WIFI_PASSWORD')) +except TypeError: + print("Could not find WiFi info. Check your settings.toml file!") + raise print("Connected to WiFi") diff --git a/Pico_W_CircuitPython_WiFi_Examples/Pico_W_JSON_Feed/code.py b/Pico_W_CircuitPython_WiFi_Examples/Pico_W_JSON_Feed/code.py index e70db1f79..65c0eb8b4 100644 --- a/Pico_W_CircuitPython_WiFi_Examples/Pico_W_JSON_Feed/code.py +++ b/Pico_W_CircuitPython_WiFi_Examples/Pico_W_JSON_Feed/code.py @@ -10,15 +10,23 @@ import microcontroller import adafruit_requests -wifi.radio.connect(os.getenv('CIRCUITPY_WIFI_SSID'), os.getenv('CIRCUITPY_WIFI_PASSWORD')) +try: + wifi.radio.connect(os.getenv('CIRCUITPY_WIFI_SSID'), os.getenv('CIRCUITPY_WIFI_PASSWORD')) +except TypeError: + print("Could not find WiFi info. Check your settings.toml file!") + raise # Use cityname, country code where countrycode is ISO3166 format. # E.g. "New York, US" or "London, GB" location = "Manhattan, US" # openweathermap URL, brings in your location & your token -url = "http://api.openweathermap.org/data/2.5/weather?q="+location -url += "&appid="+os.getenv('openweather_token') +try: + url = "http://api.openweathermap.org/data/2.5/weather?q="+location + url += "&appid="+os.getenv('openweather_token') +except TypeError: + print("Could not find OpenWeatherMap token. Check your settings.toml file!") + raise pool = socketpool.SocketPool(wifi.radio) requests = adafruit_requests.Session(pool, ssl.create_default_context()) diff --git a/Pico_W_CircuitPython_WiFi_Examples/Pico_W_Requests/code.py b/Pico_W_CircuitPython_WiFi_Examples/Pico_W_Requests/code.py index 232326c80..c26c5a8d2 100644 --- a/Pico_W_CircuitPython_WiFi_Examples/Pico_W_Requests/code.py +++ b/Pico_W_CircuitPython_WiFi_Examples/Pico_W_Requests/code.py @@ -14,7 +14,11 @@ quotes_url = "https://www.adafruit.com/api/quotes.php" # connect to SSID -wifi.radio.connect(os.getenv('CIRCUITPY_WIFI_SSID'), os.getenv('CIRCUITPY_WIFI_PASSWORD')) +try: + wifi.radio.connect(os.getenv('CIRCUITPY_WIFI_SSID'), os.getenv('CIRCUITPY_WIFI_PASSWORD')) +except TypeError: + print("Could not find WiFi info. Check your settings.toml file!") + raise pool = socketpool.SocketPool(wifi.radio) requests = adafruit_requests.Session(pool, ssl.create_default_context())