So this is a quick practise / exploration for me to play with an Inky PHAT, the output display for my new alarm clock.
The alarm clock uses node-red already, but for the sake of argument I am setting up an rPi3 to practise. So let's pretend for the sake of arguments that you have a brand new Pi* compatible board, and you've setup an SD card with raspbian (pi zero not supported by new Raspberry Pi OS).
Firstly we need:
- to setup SSH (and wifi if required) - https://howchoo.com/g/ote0ywmzywj/how-to-enable-ssh-on-raspbian-without-a-screen or https://learn.pimoroni.com/tutorial/sandyj/setting-up-a-headless-pi
- to plug everything in with a suitable power supply and network cable (or setup wifi in a config file following a guide)
- to then login over ssh (username: pi password: raspberry) and update the software with any fixes and get nodered
sudo apt update && sudo apt upgrade -y && sudo apt install nodered
- to enable SPI using the raspi-config utility under interfaces and then reboot!
sudo raspi-config
- and to get the latest inky python library as recommended by the official pimoroni guide (assuming you don't have a 4yr old inky-phat in which case there is a fully functional old library called inky-phat).
Install the examples when asked!
curl https://get.pimoroni.com/inky | bash
At this point you should have everything you need to test the inky PHAT/WHAT - examples in ~/Pimoroni/inky/examples/
- and the nodered installation - execute node-red
and load a browser at http://IP_OF_PI:1880/
We create a simple test to execute the name badge example with our custom text.I've added a CATCH node to get any errors linked to a DEBUG node with the entire msg object selected.Next is a TRIGGER node with a payload (I have a TEMPLATE node to alter the payload further) linked to the EXEC node which will fire off the python script.
Then we setup the exec node with outputs pointing to debug nodes, with the exec node configured with the script as COMMAND and with the required arguments. If you run the name-badge.py from the commandline you will see the usage:
So the first time I ran it on node-red I had additional arguments set, but these were appended after the msg.payload, and this showed up in the error message in the debug nodes.
I moved the additional arguments to the main commandline (first box in config) and then the command ran successfully.
Now that we have the basic test conducted we can move onto the thinking about the next task which is to have a weather display combined with alarm clock time and activation status, so I know the alarms been set the night before, and the upcoming weather for the next few hours or days rather than now.
Weather / GraphicsThe example for weather included is nice enough (remember to change the city and country defined in the python file), but the most useful bit is the assets to allow me to easily create my desired output.
Ideally I'd have the BBC weather's assets and information as that's my goto (https://bbc.co.uk/weather/bs2), but I would have to avoid copyright and just be influenced by the style of it instead ☺
My basic mockup looks like this, and the idea is to separate out each section into a block of code and then combine into the final image. Rather than a whole day, I will have the last column or two as tomorrow etc.
Now to reduce this to three colours and a grid of sprites (separate images), find a source for the moon and sunset info I need and get programming!
API usageThe old version of the inky-phat library relied on Yahoo Weather API, the new one relies on another source (unsure of usage), and I have signed up to yahoo weather api however there is a 3day delay in the application process so in the meantime I have gone over to using the MetOffice API instead.
The Met Office is the UK weather authority and provides their data via 3 APIs under a free tier (if you accept their terms) allowing 360 calls per day.
https://metoffice.apiconnect.ibmcloud.com/metoffice/production/
If you follow their API examples (I'm looking at the 3hour forecase api at https://metoffice.apiconnect.ibmcloud.com/metoffice/production/node/173 ) then you will quickly see it is a simple HTTP GET request that includes the location latitude and longitude, with 3 additional headers added to the request to provide the accepted response type and API credentials.
My example request in python would look like this (fix both REPLACE_THIS_KEY):
import http.client
# urls for apis:
# https://api-metoffice.apiconnect.ibmcloud.com/metoffice/production/v0/forecasts/point/daily
# https://api-metoffice.apiconnect.ibmcloud.com/metoffice/production/v0/forecasts/point/three-hourly
conn = http.client.HTTPSConnection("api-metoffice.apiconnect.ibmcloud.com")
headers = {
'x-ibm-client-id': "REPLACE_THIS_KEY",
'x-ibm-client-secret': "REPLACE_THIS_KEY",
'accept': "application/json"
}
conn.request("GET", "/metoffice/production/v0/forecasts/point/daily?excludeParameterMetadata=false&includeLocationName=false&latitude=51.465820&longitude=-2.577353", headers=headers)
res = conn.getresponse()
data = res.read()
print(data.decode("utf-8"))
Which results in this (only relevant output included):
And the 3 Hour forecast example output is here (Headers omitted this time):
Comments
Please log in or sign up to comment.