Dark Sky API PyPortal & Weather Dashboard

This project is a take on one we've done before, the Dark Sky API Weather Dashboard. This time instead of a Raspberry Pi, we'll use an Adafruit PyPortal to display weather data and send that data to Initial State. Two dashboards for the work of one!

Supplies:

Teacher Notes

Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson.

Step 1: Initial State

Initial State is a data visualization platform. We will send data from Dark Sky API and the PyPortal to Initial State. This will allow us to have a log of the weather data and view weather trends.

You'll need to register and create a new account. You get a 14 day free trial and anyone with an edu email address can register for a free student plan.

You'll need your Initial State Access Key to be able to send data from the Dark Sky API and the PyPortal to Initial State. Scroll over your username in the top right and click my settings. There you will see a list of Streaming Access Keys. Select one to use or create a new one. We will need this later for the code.

Step 2: Dark Sky API

Dark Sky specializes in weather forecasting and visualization. The coolest aspect of Dark Sky is their weather API that we can use to retrieve the weather data from almost anywhere in the world. It's not just weather is rainy or sunny but temperature, dew point, wind gust, humidity, precipitation, pressure, UV index, and more, all easily available for wherever you want, whenever you want.

In order to use the Dark Sky API, you first need your own API key. Don't worry, getting an API key is quick and free. All you need to do is go to the website and click "Try for Free" to create an account.

You get 1,000 API calls for free each day. Every API request over the free daily limit costs $0.0001.This limit automatically resets each day at midnight UTC.The Forecast Request returns the current weather forecast for the next week.The Time Machine Request returns the observed or forecast weather conditions for a date in the past or future.

Your secret Dark Sky API key will look something like this:

0123456789abcdef9876543210fedcba. 

We will use this later in the code.

Step 3: Adafruit IO & PyPortal

Adafruit IO is service Adafruit offers to supplement their hardware. We will use this service for the clock part of our code. Sign up for a free account. Click the View AIO Key on the left to see your username and key. We will use both of these later in our code later.

The Adafruit PyPortal is the latest IoT device powered by Circuit Python. The cool thing about the PyPortal is you can interact with API’s and JSONs to display almost anything. We will use it to get data from the Dark Sky API, display that data on the PyPortal, and send that data to Initial State.

If this is your first project on your PyPortal, you'll want to follow this tutorial to download the firmware, connect your PyPortal to WiFi, and get it ready. Once you complete this we will be ready to the Dark Sky API code.

Step 4: Code

This code can be downloaded on to your computer here. Transfer all the files except for the README.md file to your PyPortal. You'll just drag and drop them on the PyPortal, which should show up as CIRCUITPYTHON on your USB list. The only document you should need to edit is the secrets.py. It will pull all your private information into the code so we don't have it out in plain sight.

I would recommend using the Mu Editor to edit and view your code. It has a serial monitor for easy debugging while you make changes. Any code editor will work though.

I want to talk through what each piece of code, libraries, and folders do so it's easier to make changes and

code.py

This is our main file that initiates on the PyPortal since it is named code.py. Here you'll see the WiFi connect, the Dark Sky API call, and the setup for the PyPortal display. There isn't any modifications you need to make to this file.

darksky.py

This script is called from the main code. This is where we parse the Dark Sky API call, setup text location on the PyPortal display, determine which icon to display, and send the API data to Initial State. There isn't any modifications you need to make here.

secrets.py

This holds all your passwords and access keys. You will need to update almost all items in this document. You will need to enter your WiFi name, WiFi password, timezone, Dark Sky API key, Initial State access key, longitude & latitude, city name & state, Adafruit IO username, and Adafruit IO key. Once you have all those entered and saved your code should run without error.

libraries

These are the libraries required to run the PyPortal and modules.

fonts

This is the font used to display the weather information on the PyPortal.

icons

These are the different icons that are display as the picture on the PyPortal based on the current weather conditions.

Step 5: PyPortal

Now that your code is running, your PyPortal will display your city & state, the time, the current weather condition summary and icon to match, and the temperature in Fahrenheit.

You can adjust the size and location of the text displayed in the Dark Sky script. If you want to use different icons, you'll just need to save them as the correct names and put them in the icons folder. Any of the display items are adjustable. You can even change what you display. All you need to do is parse a different part of the Dark Sky API call and that will be displayed instead of temperature or weather summary.

Step 6: Initial State Dashboard

Go to your Initial State account and look at your data. I mapped the temperature and weather icon to emojis, made the temperature value a thermometer gauge graph, made humidity a liquid level gauge graph, made the UV index a bar graph with color thresholds, and created line graphs of humidity, temperature, and UV index.'

You can add a background image to your weather dashboard to give you dashboard more personality.

If you want to use the dashboard layout from a public share as your dashboard, you can import a layout into your data bucket by following the instructions at here.

The public share URL for our dashboard is https://go.init.st/dydonsu.

Now you have not only one, but two weather dashboards and a log of weather data.

Be the First to Share

    Recommendations

    • Made with Math Contest

      Made with Math Contest
    • Multi-Discipline Contest

      Multi-Discipline Contest
    • Robotics Contest

      Robotics Contest

    Discussions