About six weeks ago, my Planes Overhead app for the Tidbyt smart display died.
This death wasn’t exactly a surprise - the founder of DHub.io, the backend service I was using which ceased operations, had reached out to give me a heads up - but it did mean that I would need to do some unplanned engineering work to get the app up and running.
I did the bulk of that work last week and tried to document my elegant (if I’m allowed to brag a little, it really is) serverless solution in a blog post.
For those who haven’t read, all you need to know is that I built a new serverless backend on AWS, with a GET
HTTP endpoint exposed as an API Gateway path, triggering a Lambda function, doing a DynamoDB lookup to fetch the data.
Publishing Steps
With the hard work of building an alternative backend wrapped up, the easy task of updating the Tidbyt code was my project for Sunday afternoon… and not quite as easy as I expected! It was a little fiddly to get done, but after a bit of trial and error I was able to get the app re-published to the Tidbyt App Store and back live on my personal display.
Here’s a quick breakdown of the process for those interested!
1. Rewrite the Typecode Lookup Code
First things first, I re-wrote the get_typecode
function in the planes_overhead.star
file, changing the HTTP endpoint to my new API Gateway address and simplifying the lookup, since all we need to pass is the icao24
code of the aircraft.
Pixlet, the SDK that Tidbyt apps are developed using, has a nice web preview tool where you can evaluate and test the code you’re writing - I managed to capture an Asiana A380 from Seoul flying over my house!
pixlet serve planes_overhead.star -w
New Code
def get_typecode(icao24):
URL = "https://<BUILDURL>.execute-api.us-east-1.amazonaws.com/default/aircraft/" + icao24
query_get = http.get(url = URL)
print("Type Lookup HTTP Status:", query_get.status_code)
response = query_get.body()
# Parse JSON safely
data = json.decode(response) if len(response) > 0 else {}
# Return typecode if available, else fallback
return data.get("typecode", "") # or "" if you prefer empty string
Old Code
def get_typecode(icao24, api_key):
print("Looking up ICAO24: " + icao24)
DBOWNER = "cmcl"
DBNAME = "aircraft.sqlite"
URL = "https://api.dbhub.io/v1/query"
query = """
SELECT typecode
FROM aircraft
WHERE icao24 = '%s'
""" % (icao24)
query_base64 = base64.encode(query)
params = {
"apikey": api_key,
"dbowner": DBOWNER,
"dbname": DBNAME,
"sql": query_base64,
}
query_post = http.post(
url = URL,
form_body = params,
)
print("Type Lookup HTTP Status:", +query_post.status_code)
post_response = query_post.body()
typecode = json.decode(post_response)[0][0]["Value"] if len(post_response) > 0 else ""
return typecode
2. Prepare the App for Review
The Tidbyt folks require apps submitted for review be linted and formatted to their specifications - the commands below helped take care of that!
pixlet lint --fix planes_overhead.star
pixlet format planes_overhead.star
pixlet check planes_overhead.star
3. Create a Pull Request to Merge into Main
To update apps in the Tidbyt App Store, users need to:
- Fork the Community repository from Github
- Commit their code changes into the forked repository
- Create a pull request (PR) to merge those changes back into the Community repo
After fishing around for a while setting up Github credentials and building a fun GIF of the app output, I was able to get a PR submitted with my code changes - the moderators approved it in a few hours, and boom, my Tidbyt was back online like it never left!
pixlet render planes_overhead.star --gif --magnify 10 user=USERNAME pass=PASSWORD