A Fire+Swift Hack

Natanel Niazoff
Dec 28, 2018 · 3 min read
Photo by Pawel Kadysz on Unsplash

I’ve been using a ton of Vapor lately. Coming from more of a front-end background not too long ago, server-side felt way out of my reach. Fortunately, since Swift is such an easy language and Vapor such an amazing library, I’ve been learning a lot more recently and getting way more comfortable. Knowing how to program server-side can save a bunch of time and solve many problems.

I control a lot of the tech at Sammy’s, my family’s restaurant/café in Bergen County, New Jersey. That includes the newly installed digital signage. Basically, several screens used across the shop displaying various ads, menus, videos, etc. Most content is shown using a digital signage app loaded on each screen’s respective Amazon Fire TV which also allows loading a website (perfect for creating personal apps). Besides the app this post details, I have another Vapor app running to display the day’s hours, a posted message management can edit via SMS, and a timer running to takeover the digital signage app with specific content at specific times with the API they provide.

Recently we wanted a way to show “Good Morning America” from 7 AM to 9 AM. It needed to be automated (not to have someone need to constantly turn it on everyday). I had tried using the digital signage app but the only solution they provide akin to this was to show any live YouTube stream like Sky News. I started hacking around and thought maybe I can either embed or parse the show from ABC’s website using my own app. That didn’t work and, for some time, I just gave up.

Last week it hit me that there ought to be some sort of API or something to switch apps on the Fire. I knew that if this was possible, I can simply use the Fire ABC app for the show. I started to do some searching and, since I’m not an Android developer (yet), I found something called ADB, Android Debug Bridge. “A versatile command-line tool that lets you communicate with a device” and “provides access to a Unix shell that you can use to run a variety of commands.” This sounded perfect and, once I found it, everything fell into place.

The core of my newly created app’s functionality lays in the basic adb command:

shell(<adbPath>, "shell", "monkey", "--pct-syskeys", "0", "-p", <packageName>, "1")

Other than that, there’s some Process stuff, connecting the device and disconnecting, futures and promises and that’s pretty much it. The only challenge was really having the server run on the same network (ADB requires that). Luckily, we had an old iMac laying around, so now it’s been redeemed as the local Vapor server. In the future, I can even make an iOS (or anything) app to control the TV using the handy /launch_app endpoint or any others I expose. All-in-all, pretty fun hack.

Read all the code, fork, and give it a star ⭐️ on GitHub: AmazonFireTV

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade