Displaying daily weather information on an e-ink screen
I decided I wanted to see today’s weather information on my bedside, so I can see today’s weather without needing to get out my phone.
I bought an Inky pHAT and popped it on a Pi Zero, and then started working out how to do it.
My original approach was to get all the weather information in Python. This required lots of knowledge I didn’t have, and I did get pulling the information in working but the process of trial and error - changing the python code directly on the Pi, then updating the screen - proved too tiresome (20 seconds for the screen to update!) for regular updates.
Additionally, I didn’t want the headache of breaking text onto multiple lines! But it would definitely be possible in this manner.
How it works
Here’s the final result. It may look a bit round the houses, but it goes as follows. This was inspired by Dave, who suggested doing it this way round.
A website deployed on Netlify pulls in weather information. This uses a Netlify Function to pull in from the Dark Sky API for Bournemouth.
Meanwhile, Python running on the Pi downloads a screenshot of that website. This is produced by another Netlify Function that uses Puppeteer to return a lovely PNG of the website.
Displaying a PNG on the Inky pHAT
The big speed bump I found writing this was that the Inky pHAT simply can’t show any PNG you throw at it. It needs to be a specific palette. So, my python script converts to the correct palette - black, red, and white. Depending on your model of pHAT, that red will be shown as red or yellow. The GitHub repo for Inky pHAT includes a palette file for exporting PNGs from Gimp, so this gave me a good start.
This was almost the point I gave up, but I was encouraged along by Sean “Evil Magician” Tracey, who also agreed that wrapping text in Python wasn’t worth the effort.
Hopefully you’ll stumble across this blog post specifically because you’re also trying to convert your PNG programmatically to work on the Inky pHAT. Take a look at my Python script and it’ll save you some stress. I was helped along the way by some StackOverflow answers, and with a bit of poking, got it working.
Why?
So, why did I do it this way? The first was convenience - by getting the Python script right, I likely never need to update it. It’ll simply display whatever I put on the website. This reduces the amount of time I need to SSH into the Pi and keep running the script to test it, reducing trial and error.
This means I can move fast, and make regular updates - writing HTML and CSS is second nature to me (and many others). I can preview my changes in the browser locally, push them up to Netlify and have high confidence by the time I wake up tomorrow, I’ll be staring at lovely new changes.
Useful links
Links I found useful as part of researching and building this project:
- https://bitsofco.de/how-to-use-puppeteer-in-a-netlify-aws-lambda-function/
- https://github.com/ireade/netlify-puppeteer-screenshot-demo
- https://github.com/simonbugler/inkyphat
- https://pptr.dev/#?product=Puppeteer&version=v2.0.0&show=api-pagescreenshotoptions
- https://stackoverflow.com/questions/29433243/convert-image-to-specific-palette-using-pil-without-dithering
- https://stackoverflow.com/questions/236692/how-do-i-convert-any-image-to-a-4-color-paletted-image-using-the-python-imaging
Other links I found interesting but didn’t use: