Home

Manage a fleet of drones

with resin.io, AWS IoT, & NodeJS

This article was authored by Excelion Partners, a tech consulting firm located in Wisconsin that specializes in full-stack, globally scalable IoT solutions. Project source code and additional files available on GitHub.

Fleet management concerns, such as securing, updating, and controlling a multitude of devices, are paramount to the success of any IoT initiative. To demonstrate how these concerns can be easily addressed with the right hardware and software stack, we launched a fleet of Parrot minidrones that use resin.io to deploy and run a Dockerized Amazon Web Services (AWS) Lambda service. This service, along with AWS IoT, allows us to configure and manage our fleet from one easy-to-use application. Follow along with this tutorial as we show you how to:

Javascript, specifically the NodeJS runtime, is used to program the drones, which are remotely controlled via Bluetooth from a Raspberry Pi 3.

Requirements

Hardware:
Parrot MAMBO
Raspberry Pi 3 Model B
32 GB MicroSD Card
Amazon Echo (or Dot)

Software:
FreeFlight Mini (App Store/Google Play)
ResinOS 2.0.6

Services:
resin.io
Amazon Web Services (AWS)
AWS Developer Portal

Programming Languages & Frameworks:
NodeJS
Javascript

Step 1: Prepare local development environment
  • Install NodeJS however you please (we use nvm)
  • Install serverless framework:
$ npm install -g serverless
Step 2: Create AWS account and install local tools
  • Create an AWS account
  • Install AWS CLI
  • Configure AWS CLI
  • Decide which region you plan to use in AWS for Lambda deployments and IoT devices. In this tutorial we will use N. Virginia, which has a code of us-east-1
Step 3: Prepare resin.io account, application, and device
  • In your terminal, clone the repo for this project:
$ git clone https://github.com/Excelion-Partners/resin-drones.git
  • Create an account on resin.io
    • For this demo create an account using your email—do NOT use social login
    • Part of signup will include importing an SSH key
  • Create an application:
  • Download an image for your application:
    • If using wifi, be sure to fill out the wifi details so the image is download pre-configured and will connect automatically
  • Using Etcher, flash the downloaded image to your Pi's SD card:
  • Put flashed SD card into Pi and plug in. Within 10 minutes, your Pi should show up within your application as a device:
  • Click on your device
  • In the top right corner, copy the provided git command that will specify a remote repo where you can push code for this application:
  • In your terminal, navigate to the cloned project folder and paste and run the git add remote command:
$ cd resin-drones
$ git remote add resin <username>@git.resin.io:<username>/lucyalexadrone.git
  • Copy the UUID of your device and throw it in a text pad for later use:
  • Click on Environment Variables:
  • Download and install the FreeFlight Mini app (Google Play/App Store). Launch the app and record the unique drone ID (Mambo_xxxxxx):
  • Add a DRONE_IDS environment variable and put the ID of your drone as the value (for multiple drones, comma separate IDs)
  • Add an AWS_REGION environment variable and set the value to the code of the AWS region you decided to use (i.e, us-east-1):
Step 4: Prepare and deploy resin.io self-provisioning API
  • Open the yaml file serverless/ResinAWSLambdaService/serverless.yml and fill in the RESIN_EMAIL and RESIN_PASSWORD using your resin.io account details:
  • In your terminal, navigate into the serverless/ResinAWSLambdaService directory. Install npm dependencies and deploy using serverless:
$ cd serverless/ResinAWSLambdaService
$ npm install
$ serverless deploy

  • Note the URL in the output of serverless deploy. Copy the URL and add it as an environment variable LAMBDA in your resin.io dashboard:
Step 5: Deploy image to resin.io and self-provision device in AWS IoT
  • In your terminal, navigate into the project directory and git push the code to the resin.io directory:
    • This push will kick off a Docker image build. This can take some time. It is not unusual for the first push to last 10 minutes or more as the image has no cached builds to work with
    • After the build is complete, the device will download the resulting Docker image and start it. We are not yet ready for the device to launch any drones, so don't expect anything to happen right away. What we do want is for the device to call your new self-provisioning Lambda and provision itself in AWS IoT
$ cd ~/resin-drones
$ git push resin master

  • In the AWS IoT Console, click on your newly provisioned device (it will be named the same UUID as your device in resin):
  • Click on the Interact link in the left navigation and copy the HTTPS URL that allows you to interact with your device via REST:
Step 6: Prepare and deploy AWS Lambda for Alexa Skill
  • Paste the URL into the yaml file serverless/LucyAlexaService/serverless.yml. Also paste the UUID from your resin device into the file:
  • In your terminal, navigate into the serverless/LucyAlexaService directory. Install npm dependencies and deploy using serverless:
$ cd serverless/LucyAlexaService
$ npm install
$ serverless deploy
Step 7: Create Alexa Skill
  • Head over to the Amazon Developer Console and register/login
    • This MUST be the same account used when setting up your Amazon Echo
  • Click on Alexa in the top navigation and click on Get Started for Alexa Skill Set:
  • Click Add a New Skill
  • In AWS, locate your LucyAlexaService Lambda. Copy the ARN value in the top left corner
  • Fill out the first 3 sections of the New Skill like below. Paste the ARN value of your Lambda where the arrow points:
  • You can test your Lambda in the 4th section of the New Skill:
    • This is as far as you need to go in the New Skill creation process. There is no need to continue on to Publishing Information or Privacy and Compliance
Step 8: Make the Drone Fly!
  • Turn on the Parrot Mambo drone on the floor with open space around it. The lights should be flashing green as it is looking to pair
  • Restart the resin.io application on your device by pressing the restart button on the dashboard:
  • Your Pi will now pair with the drone. You can tell everything is ready to go when the drone's lights turn solid green. You can also look for the completed setup of Mambo_XXXXXXX message in the resin.io log
  • Speak the following phrase to your Amazon Echo: Alexa, tell Lucy to make the drones fly. Your drone should begin flying the preset pattern and eventually land. Music should play through the Amazon Echo speaker
  • In the resin.io dashboard, when you speak the command to Alexa, you should see a message line show up in the log to indicates that your Pi received the command via AWS IoT

Lessons and Notes

The initial idea behind this project was to create a fun demo that served as a bona fide example of fleet management and continuous deployment using IoT resources. The guide above uses a single Raspberry Pi that can control up to 7 drones (based on Bluetooth limitations), but this example could very easily be extended to a much larger fleet. Imagine hundreds of Pis controlling thousands of drones in various locations and being able to manage that entire fleet all via one application.

By utilizing Docker’s containerized deployments, the resin.io platform provides total consistency across all deployed IoT devices. In conjunction with a source control and continuous integration system, containers can be defined and deployed across development, test, and production environments, ensuring optimal testability and customer experience.

Without a continuous delivery system like resin.io, a secure, scalable Linux-based IoT device rollout would be a logistical nightmare. With the stack we've shown here, the rollout is a breeze.

Additional Resources

Click here for a public link to
view videos of our drones on their journey to becoming a fully managed fleet.

Questions?

Feel free to reach out to RMoore@excelionit.com with any questions or check out Parrot's Developer Docs. Special thanks to the resin.io dev team!

comments powered by Disqus