PyPortal Weather

PyPortal Weather

I really like the weather, and I love knowing the the current conditions and forecast will be at a glance. The Adafruit PyPortal seemed like an ideal platform to make a desktop weather display. The PyPortal is relativley inexpensive, connects to your network via wifi, and is powered by Circuit Python. The code makes use of the free API from openweathermap.org.

Requirements:

Setup:

The code and setup instructions can be found on github here.

  • If you haven’t already sign up for an API key at OpenWeatherMap.org
  • Figure out what your CityID will be. A list of city IDs can be found here.
  • Clone the repo to your local system.
  • Rename secrets_example.py to secrets.py
  • Enter in your Wifi details, Timezone name, Openweathermap API Key and CityID
  • Connect the PyPortal to your systems USB. A drive named “CIRCUITPY” will show up. Copy all the files from the repo over to this drive.
  • The PyPortal should restart and if the info in secrets.py is correct you should start seeing the weather!

When powering up the PyPortal will connect to your wifi, sync it’s clock, then grab the conditions from OpenweatherMap. It will recync the forecast every 15 minutes, current conditions every 10 minutes, and recync the clock once an hour.

Clock Challenges:

One weakness of the PyPortal is it’s built in real time clock. Over the course of an hour I would see it skew by as much as 10 minutes. Initially at power on the device gets the time by polling the API at http://worldtimeapi.org. I set the device to repoll every hour to help keep the clock from getting to far out of line.

Another clock issue was worldtimeapi.org itself. I noticed it had frequent outages, and without the ability to poll that site the pyportal will throw an error.

I figured it would be pretty easy to write my own time api server. I containerized it and run it within my home Kubernetes cluster. This also gives me the option to poll for time updates more aggresivley since there won’t be any API rate limiting. It is written in Python / Flask and can be found here, https://github.com/EntropySynthetica/TimeAPI

Future Todos:

I have been using the PyPortal for well over a year now and it’s really great. Some upgrades I would like to do is showing todays forecast, showing severe weather alerts, and adding better error handling if the device loses internet access for a period of time.