Teaching How to Use Alexa to Take Off your Drone using NodeJS

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:

  1. You say something like: “Alexa turn on my drone please
  2. Alexa detects the voice command. It validates within its already discovered HA devices if there is anything called “My Drone
  3. 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.
  4. 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).
  5. 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:

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:

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.

Any question let me know via Linked or Twitter.

Advertisement

Author: Carlos Rodriguez Iturria

I am extremely passionate about people, technology and the most effective ways to connect the two by sharing my knowledge and experience. Working collaboratively with customers and partners inspires and excites me, especially when the outcome is noticeable valuable to a business and results in true innovation. I enjoy learning and teaching, as I recognise that this is a critical aspect of remaining at the forefront of technology in the modern era. Over the past 10+ years, I have developed and defined solutions that are reliable, secure and scalable, working closely with a diverse range of stakeholders. I enjoy leading engagements and am very active in the technical communities – both internal and external. I have stood out as a noticeable mentor running technology events across major cities in Australia and New Zealand, including various technology areas such as, Enterprise Integrations, API Management, Cloud Integration, IaaS and PaaS adoption, DevOps, Continuous Integration, Continuous Automation among others. In recent years, I have shaped my role and directed my capabilities towards educating and architecting benefits for customers using Oracle and AWS Cloud technologies. I get especially excited when I am able to position both as a way to exceed my customers’ expectations. I hold a bachelor degree in Computer Science and certifications in Oracle and AWS Solutions Architecture.

3 thoughts on “Teaching How to Use Alexa to Take Off your Drone using NodeJS”

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: