This year, ODTUG sponsored another GeekAThon, challenging nerds to come up with cool ideas using Bluetooth Low Energy beacons. Here is my entry for this year’s contest:
BLE ID Badge for Amazon Echo
ODTUG GeekAThon 2017
Team: Texas Heat
Christoph Alexander Ruepprich, a.k.a Rocket, Christoph Martin Ruepprich
The BLE (Bluetooth Low Energy) beacon from the KScope conference badges serve as personal identifiers for the Amazon Echo. By determining the ID of the nearest badge, the Echo responds with personal data for the badge bearer.
Using the noble library for Node.js, I was able to determine the individual IDs of the two Bluetooth beacons. Using Node.js on a MacBook Pro, I wrote an Alexa skill that would scan Bluetooth signals. If a signal with one of the previously identified IDs was found the Alexa skill could respond with individualized information.
1 Laptop computer (in this case a MacBook, but a Windows or Linux PC with built in Bluetooth would work, too).
- 2 BLE Beacons
- 1 Amazon Echo Dot
Node.js version 8.4.0
- express (web server) (https://www.npmjs.com/package/express)
- body-parser (handle incoming JSON) (https://www.npmjs.com/package/body-parser)
- noble (Bluetooth) (https://github.com/sandeepmistry/noble)
Ngrok (https://ngrok.com/) to set up a secure tunnel to laptop. This provides a https address with a valid certificate to the localhost, and thus to the Node.js application.
There are two parts to this application: One to handle the Alexa skill, the other to do the Bluetooth scanning.
When the application starts, an express.js webserver is instantiated and the noble Bluetooth module starts scanning immediately. The scanner looks for the two identified BLE beacon IDs and keeps track of them in two variables: closeBle, for the beacon with the stronger signal, and farBle for the beacon with the weaker signal. The signal strength and other attributes of the beacons are recognized by noble, and provided in JSON format.
The webserver waits for incoming POST requests from Alexa. When a request comes in from Alexa, the application checks the ID of closeBle, and then formats the response depending who the owner is.
In this demo we have two beacons: One for the police officer, and one for the hacker. If the application sees that the police officer is closer, it responds with data pertinent to the officer. If the hacker’s badge signal is stronger, the application pretends that the beacon’s ID is not recognized and responds with a message saying that a hacking attempt was made.
The Alexa skill uses the invocation Police Headquarters. This is the name by which the skill can be invoked on the Echo. It is configured to use the ngrok URI pointing to the Node.js application on the laptop. The interaction model simply consists of an intent called briefing which is called when the police officer asks for his briefing or mission.