Dr. Torq: Install an AWS IoT Connect Kit on the Raspberry Pi
It’s nice to be able to say “Alexa, turn on the dining room light” and have the light come on. Wouldn’t it be cool to be able to control Linux-powered projects?
For example, I’d love to say something like “Alexa, make Barkley speak” and have my new skeletal robotic dog bark out a few “woofs”, in response. Barkley is the soon-to-be faithful companion of my ever-evolving robotic skull, Hedley and will use some type of Linux-powered “Pi” like a brain.
At first, I tried to get the shortcut Python fauxmo libraries to work on a stock Raspberry Pi 4. A “fauxmo” tricks Alexa into thinking that the light is a commercial WeMo Internet of Things gadget. It has been very reliable — I built a little NodeMCU-controlled switch project using the “fauxmo” Arduino library. There are lots of fauxmo examples on the web.
In this case, it didn’t work out, so I dug into the Amazon AWS development environment and discovered a lot of new possibilities. I also realized that there are quite a few parts and pieces to connecting things using “the Amazon way.” Fortunately, Amazon has simplified the process through AWS Core IoT connect kits. You configure “the kit” on the dev site and then download and install the result on your target Pi. It configures all the authentication and security data needed for a Python program, running on the Pi to connect to Amazon services on the back end. Even better, MQTT is baked into the Amazon Core IoT environment. MQTT is a distributed lightweight messaging system that lets machines easily communicate amongst themselves. With any luck, Barkley and Hedley will be able to interact with each other and Alexa via my voice commands.
The first step to get Alexa to pass my wishes on to Barkley is to build the communication link between the Pi and the Amazon IoT cloud. This is done with the “connect kit.” We’ll discuss the Alexa voice service piece in a future article.
Building Your Own Connect Kit
You’ll need a developer account. Go to the AWS IoT account setup screen and follow the directions. You should also create an IAM user for regular use. That whole process is spelled out very well. Everything can be done on the Raspberry Pi (with a monitor, keyboard and mouse) in a web browser and the command line, in a terminal. I used a Raspberry Pi 4 Model B with the latest version of Raspberry Pi OS. I initially explored the Connect kit on my ASUS Xubuntu notebook and everything worked without issues on that machine, too. Of course, you don’t have any general-purpose input/output (GPIO) capabilities, like with the Pi, on an Intel-powered Linux laptop. Alexa to laptop connectivity might still be interesting for kicking off applications, adjusting the volume in audio playback or integrating text-to-speech output capabilities.
Start by logging into your AWS IoT account as the IAM user. My user name was “Administrator.” Enter your password.
The main AWS IoT screen will appear.
- Select “Onboard” and then “get started” from the left-hand side navigation pane.
- Select “Get started” on the Onboard A Device pane.
- Push the “Get started” button at the bottom of the Connect To AWS IoT screen.
- Choose “Linux as your platform” and “Python” as the AWS IoT Device SDK, follow by the “Next” button at the bottom of the screen.
- Name your device in the Register A Thing text box, followed by the “Next” button. I called my Raspberry device “robthing-pi”.
- Now download the connection kit to your Pi. Save it to a directory. I used the Pi’s default “Downloads” directory.
Setup and Test the Kit on the Pi
Next open a Linux terminal on the Pi and use the follow commands to build the Python program. I created a “rob-aws” directory under my home directory to consolidate my AWS development efforts.
rob-pi% mkdir rob-aws
rob-pi% cd rob-aws
Copy the downloaded zip file to the local directory.
rob-pi% cp ~/Downloads/connect_device_package.zip .
Don’t forget the “.” at the end so the file lands in the local directory.
rob-pi% unzip connect-device_package.zip
The resultant start.sh script needs to be made executable before attempting to build the Connect kit.
rob-pi% chmod +x start.sh
You can next run the start.sh script.
At this point, start.sh ran on my ASUS Xubuntu notebook, but failed on my Pi, due to a security problem. cmake also wasn’t installed by default on the Pi. Follow these steps to make start.sh function properly on the Pi.
rob-pi% sudo apt update
rob-pi% sudo apt upgrade
rob-pi% sudo apt install cmake
rob-pi% sudo apt install libssl-dev
Run the start.sh script to install required libraries and build the Python program. A bunch of status text will scroll by and take a few minutes to configure/compile. At the end, the Pi will connect to the Amazon IoT cloud and start publishing/subscribing MQTT test messages to the AWS broker. You’ll see the messages scroll by in the terminal window.
Type the usual Ctrl-C combination to stop the MQTT test messages and return to the command line.
We’ve seen how to download and install an AWS IoT Connect kit on the Raspberry Pi. You can also build a kit for Node.js and Java, if you favor those programming languages.
There is a lot to learn about using AWS Core IoT services. We’ll dive deeper as we move forward with developing Barkley and Hedley. With a little imagination, lessons learned here can easily be applied to other Alexa/Linux/Pi projects. A future story will talk about connecting Alexa to the MQTT messages so we can make Barkley and Hedley do cool things, like talk or move servos.
As always, it’s the greatest time in history to be in tech, Linux and physical computing.
Amazon Web Services is a sponsor of The New Stack.
At this time, The New Stack does not allow comments directly on this website. We invite all readers who wish to discuss a story to visit us on Twitter or Facebook. We also welcome your news tips and feedback via email: email@example.com.