|
42 | 42 | i2c = board.I2C() |
43 | 43 | tsc = adafruit_tsc2007.TSC2007(i2c, irq=None) |
44 | 44 |
|
45 | | -# Initialize a requests session |
46 | | -pool = adafruit_connection_manager.get_radio_socketpool(wifi.radio) |
47 | | -ssl_context = adafruit_connection_manager.get_radio_ssl_context(wifi.radio) |
48 | | -requests = adafruit_requests.Session(pool, ssl_context) |
49 | | - |
50 | | -# Set your Adafruit IO Username and Key in secrets.py |
51 | | -# (visit io.adafruit.com if you need to create an account, |
52 | | -# or if you need your Adafruit IO key.) |
53 | | -aio_username = os.getenv("AIO_USERNAME") |
54 | | -aio_key = os.getenv("AIO_KEY") |
55 | | - |
56 | | -# Initialize an Adafruit IO HTTP API object |
57 | | -io = IO_HTTP(aio_username, aio_key, requests) |
| 45 | +try: |
| 46 | + # Initialize a requests session |
| 47 | + pool = adafruit_connection_manager.get_radio_socketpool(wifi.radio) |
| 48 | + ssl_context = adafruit_connection_manager.get_radio_ssl_context(wifi.radio) |
| 49 | + requests = adafruit_requests.Session(pool, ssl_context) |
| 50 | + |
| 51 | + # Set your Adafruit IO Username and Key in secrets.py |
| 52 | + # (visit io.adafruit.com if you need to create an account, |
| 53 | + # or if you need your Adafruit IO key.) |
| 54 | + aio_username = os.getenv("AIO_USERNAME") |
| 55 | + aio_key = os.getenv("AIO_KEY") |
| 56 | + |
| 57 | + # Initialize an Adafruit IO HTTP API object |
| 58 | + io = IO_HTTP(aio_username, aio_key, requests) |
| 59 | +except (RuntimeError, TypeError) as e: |
| 60 | + print("could not connect to AP or AdafruitIO: ", e) |
| 61 | + io = None |
58 | 62 |
|
59 | 63 | # initialize the SpiritBoard class |
60 | 64 | spirit_board = SpiritBoard(display) |
|
0 commit comments