secrets.py

If you've ever done a PyPortal project or other IoT project with CircuitPython, then the secrets.py file will be familiar to you. It allows you to store your WiFi network's SSID and password, along with other sensitive information, separately from your main program, so that you don't accidentally share your info when sharing your code.

In the case of this project, you will need your network information, as well as an Adafruit IO account. Your Adafruit AIO information and your location will also be placed in the file, all formatted to be able to access the correct day and time. By keeping your location in secrets.py, you can easily edit it without diving too deep into the main program or risk breaking anything.

Adafruit IO set up

Using Mu or any text editor, you should add your Adafruit IO Username and Adafruit IO Key to the secrets.py file. This project connects to Adafruit IO to get the time and date. Adafruit IO is free to use, but you'll need to log in with your Adafruit account to use it. If you don't already have an Adafruit login, create one here.

Once you have logged into your account, there are two pieces of information you'll need to place in your secrets.py file: Adafruit IO username, and Adafruit IO key. Head to io.adafruit.com and simply click the View AIO Key link on the left hand side of the Adafruit IO page to get this information.

Then, update the aoi_username and aio_key values in the secrets.py file. Your secrets.py file should look similar to this:

# This file is where you keep secret settings, passwords, and tokens!
# If you put them in the code you risk committing that info or sharing it

secrets = {
    'ssid' : 'your-ssid-here',
    'password' : 'your-password-here',
    'aio_username' : "your-aio-username-here",
    'aio_key' : 'your-aio-key-here',
    'location' : 'New York, US'
}

This guide was first published on Feb 05, 2020. It was last updated on Mar 29, 2024.

This page (Code Walkthrough - secrets.py) was last updated on Mar 08, 2024.

Text editor powered by tinymce.