Election Countdown
 
 
 

Important Dates

2023

2022

2021

2020

Voting Resources
Arduino / ESP8266

I like doing IoT with the Adafruit Huzzah, which is an ESP8266 (the little brother of the ESP32, having only WiFi, no Bluetooth). It has micro USB and a LiPo charger circuit. It's a little more expensive than a no-name ESP32, but I got hooked on these a while back and always keep a few spares for random projects. At some point I ended up with an two-color eInk “FeatherWing” that fits directly on the Huzzah. I think maybe that was through an old AdaBox?

At any rate, it's a decent little setup to show an example of how to use the election countdown timer on my desk.

Feel free to use and adapt it to your own boards and displays. Note that the code, as written, doesn't do much to conserve power. It keeps the wifi constantly up. If your application will be battery-operated, you may want to take that into consideration.

API

I've made an API available at https://api.electioncountdown.org/ElectionCountdown.

API Parameters

API Results

The following fields are returned, or a subset, depending on the brief parameter:

API Limits

Beyond CORS headers, I have not yet put many restrictions around the API. I'd like to provide the API until election day to help raise awareness. But since the results do not change often, I would like to request you limit your calls to once every 60 minutes.

CORS Restrictions

If a HTTP referrer was passed in, the CORS restrictions are limited to this website. If no referrer was passed in — such as when using curl or connecting from an embedded device — then * is returned.

If you are working on a project that requires a custom CORS header, please contact me and we can discuss adding a new exception.

Infrastructure

This code consists of two parts: a front end and a back end. Both parts are what kids these days call “serverless.”

The back end is a simple REST API that returns a countdown, in terms of days and weeks. It takes care of timezones and time math, giving you a snapshot answer for “now.” While this could have been done entirely in JavaScript on the front end, the intention here is to provide a simple API for Internet of Things (IoT) devices to query. Not all IoT devices have accurate clocks and date math on small form-factor devices adds complexity.

The back end is a simple AWS Lambda function, written in Python. It is fronted by an AWS API Gateway instance running through a custom domain name.

The front end is a simple static website that uses JavaScript to hit the back end API and retrieve the number of days and weeks. It is served from an AWS S3 bucket, routed through AWS Cloudfront for caching and SSL certificates.

Source / License

The source code can be found at https://github.com/BrianEnigma/ElectionCountdown. It is licensed under the the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.