inkyFrame + golang for TFL API and Home Assistant info

Table of contents

Why?
It’s good to know when the next bus is coming, what the weather is like, what’s your next calendar event, etc.
it’s also cool to not look at your phone all the time (at least for me it is).
How?
Enter InkyFrame!
A 5.7” E Ink display from Pimoroni - product page.
The InkyFrame runs micropython as it has a Pico W
board integrated into it, with this you can manipulate any type of data you get. Official example repository to see some bits.
Fun fact, it takes ~30 seconds to render the display, this needs to be factored in, it will never be real time data you’re displaying.
Details
For those who have done this before, the answer on what you do next is fairly standard, you need an API to call, to work out what you need from the API and you render it on the display. Pico W
has a wireless chip as well, so all the data goes via your 2.4GHz WiFi.
Pulling down a load of data from various APIs, who knows how many, may become problematic on a Pico W
, memory is a problem, but you do have an SD Card, so you can store data on a local disk and iterate over that.
But, I’ve seen something interesting over at https://github.com/jinglemansweep/inky-frame-web - basically it’s a photo slideshow solution for inkyframe, so I started thinking, what if I create an image with the information I need and then I just need to download the image and render it. This would allow me to have a separate piece of software where I can iterate over the information I need, I don’t need to constantly deploy to the InkyFrame (and connect it via USB every time I need to do this).
So that’s what I set out to do.
Enter golang
I’ll be honest, I wanted to write some golang, which made this decision even better for me personally. The idea would be:
Create a golang web app
Create an image
Overlay all the information from the APIs on the image
Serve the image
Pull the image from InkyFrame and render it
I was insipred by https://github.com/daniruizcamacho/image-generation-example as I’ve never done image generation before.
The APIs
I started with the London TFL API which is a REST API, it was not easy understanding how I can get the exact information I need, but I was basically going for:
- Get the next arrival time for a bus at my local bus station going into a specific direction
Next up was some weather information, given I’m already running Home Assistant, I do have weather data, so all I needed to do is understand how to call the Home Assistant REST API.
The last piece of information was calendar events, since this is also integrated into Home Assistant, it’s the same mechanism.
The web app is a docker container hosted within my network, so I can easily get to Home Assistant APIs and also the InkyFrame can download the image as well.
How it looks
It’s rough, it’s ugly, but it works. Here’s a rendered image:
I’ve added a timestamp at the bottom so we always know what was the last update time.
The rendering runs on a 5 minute loop, it takes around 30 seconds to render the image, so you always need to factor that in.
On the device it looks like this:
The code
I wanted to use something other than github for this piece of work (and for some of my future bits), so I decided I’ll give codeberg
a try, I highly recommend it for any open source work you may want to do. It can store your packages too, so it also serves as my container registry.
Repository: https://codeberg.org/puck/inkyframe-golang-web
The Future
Oh boy, where do I start, here’s some of the things in my head:
Actually try and see if I can loop over a JSON API via micropython as then I have some cool built in options to render the text
Start using the 5 buttons on the inkyFrame for different views
Add more information from Home Assistant
Rework the code and write tests
Implement auto-deployments
If something fails, write the error message on the inkyFrame display (things can go wrong once in a while)
Subscribe to my newsletter
Read articles from Ákos Veres directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
