Recently I was in Auckland, New Zealand running an Integration in Action workshop and I used Alexa to trigger some of my APIs, including some NodeJS APIs that I built to take off a drone. Some people found this interesting and asked me to write this blog to explain in detail how it works… So, here it is, I hope you find it useful.
There are multiple ways in which you can make Alexa to call your own APIs. Perhaps the most versatile way is by adding a new skill (see: blog 1, 2). However I found an even easier way to do so, and in order to achieve the MVP approach I have been attempting to practice in my day-to-day life, I took this simpler option, which is simulating a Phillips Hue HA bridge. By doing so, Alexa detects a new Home Automation (HA) device in “her” network range and accepts voice commands to easily “turn it on” or “turn it off” which you can then leverage to call your own APIs.
This is the idea:
- You say something like: “Alexa turn on my drone please“
- Alexa detects the voice command. It validates within its already discovered HA devices if there is anything called “My Drone“
- Assuming that you had previously started the HA bridge and created a new virtual device called “My Drone“, then you will get a trigger from Alexa in your HA bridge.
- Because you own the HA bridge, you can control what to do next, in my case, I decided to then “publish” a message into a queue (cache) running in Oracle ACCS (Application Container Cloud Service). On the right side, I have a Raspberry Pi which had “subscribed” for event on the same queue (cache).
- The Raspberry Pi pulls the message from the queue and bridges into Bluetooth to “take off” the drone.
This approach supports any number of different consumers of the Drone APIs; be they Alexa, a Mobile App or some sort of bespoke device control webpage; with the requests queued and executed when the drone is able. In this blog, I am going explain a slightly simpler approach, simply getting the Raspberry Pi, Alexa and the Drone to work together in my local environment, and perhaps extend this out to cover multiple consumers in a future blog.
Pre-requisites
I am using the following materials (software and hardware), you can adjust when necessary:
- Parrot Police mini drone
- Raspberry Pi 3 or any Linux Machine with Bluetooth and Wifi capabilities.
- Amazon Echo dot
- NodeJS Parrot Mini drone APIs: https://github.com/barackd222/s2v-iia-nodejs-parrot-apis
- Amazon Echo HA Bridge (simulate a Phillips Hue bulb): https://github.com/armzilla/amazon-echo-ha-bridge
Let’s put it all together
There are 3 main steps that you need to do:
1. Configure your Raspberry Pi or Linux machine to take off the drone, for this go here and make sure that you can take off the drone by invoking any of the APIs using the GET verb. At this point, I support a simple take off and landing, as well as more interesting moves, such as takeoff-forward-backward-land, flips, etc.
Note: I have found some issues to reliably communicate with my drone using the in-built bluetooth interface inside the Raspberry Pi 3. Instead I have had to use an external Bluetooth-USB dongle 4.0 to strengthens the communication. This is the model I use:
Also, I have noticed that if the battery of the drone is less than 50% it can become a little unreliable.
2. Once you can reliably call your local APIs and your drone responds, it is then time to run your HA bridge. For this go here and clone or download & unzip the repository. You should end up with a folder called: amazon-echo-ha-bridge-master – Go inside this folder.
-
It is a Java based application. The easiest way to build it is using Maven. If you don’t have it installed, you might have to yum or apt-get install maven.
- Then simply run:
mvn install
- Make sure to get a Successful Build.
-
Change directory to target and validate that it generated among other files, the amazon-echo-bridge-x.x.x.jar file
-
Then get your local IP address (ifconfig) and run the following command:
java -jar amazon-echo-bridge-*.jar –upnp.config.address=[YOUR IP ADDRESS]
For example:
- Wait until it starts:
- Open a browser window and go to: http://LOCAL-IP-ADDRESS:8080/configurator.html
-
Create a new Device and call it “My Drone” in this case and enter the GET API that you want to execute under On URL, for example:
Then click Add Device and make sure it is added into Current devices list:
3. Then ask “Alexa Discover Devices” or use the mobile app to Discover devices.
Note: Remember that for this to work, Alexa should be in the same reachable local area network as where you are running the HA bridge.
Make sure that Alexa discovered the HA bridge and considered it a Phillips Hue light
That’s it, you can now ask “Alexa turn on My Drone please” and like magic, your drone will take off, back flip and land.
As you can see, the applications are endless, you can ask Alexa to literally trigger any REST API for you by using a simple voice commands. I hope you found this blog useful.
A special dives data collected.Appropriate use and technology based
LikeLiked by 1 person
Hi Misuk, I’m glad you liked it.
LikeLike
That is cool!! i will try out this one
LikeLike