In a galaxy far, far away...
A droid named BB-8 needed to communicate large amounts of data to the rebellion so large super computers could analyze and explore the remote planet of MyOfficeCube.
Equipped with only a short range communicator, BB-8 was forced to proxy it's sensor data to a local node and pass it through it's broadband connection to rebels AWS outpost.
We begin our adventure as BB-8 connects to the lone Intel Edison and starts its transmission...
------------------------------------------------
This project will connect a Sphero BB-8 to the AWS-IOT via an Intel Edison.
Once connected the BB-8 will be set loose in a space and begin transmitting sensor data to AWS.
Sensor data available on BB-8 includes:
- Temperature
- Location (based on 2D internal map set from start)
- Acceleration
- Gyroscopic reading
- Odometer
- Velocity
- Collision Detection
To get started in our project, we are going to be collecting BB-8's location including:
- X-Position
- Y-Position
- X-Velocity
- Y-Velocity
- Speed Over Ground
BB-8 will be moving in a random direction, switching it's direction every 5 seconds. These values will be transmitted up to AWS-IOT every 5 seconds.
There is some setup to make this process easier, lets start with getting your Intel Edison set up.
(Adapted and improved from https://github.com/intel-iot-devkit/aws-iot-intel)
Prepare your Intel Edison:
Get started with your Intel Edison by updating to the latest firmware and setting up a serial terminal. You can find instructions here: Get started with Intel Edison technology
Install dependencies:
npm install -g inherits
npm install -g mqtt
npm install -g minimist
Install AWS CLI:
Install pip (Python package manager):
$ curl https://bootstrap.pypa.io/ez_setup.py -o - | python
$ easy_install pip
Install AWS CLI with pip:
$ pip install awscli
Install dependencies: In order to view help files ("aws iot help"), install Groff and a non-BusyBox version of less.
Groff:
$ wget http://ftp.gnu.org/gnu/groff/groff-1.22.3.tar.gz
$ tar -zxvf groff-1.22.3.tar.gz
$ cd groff-1.22.3
$ ./configure
$ make
$ make install
$ export PATH=$PATH:/usr/local/bin/
$ cd ~
Less: First rename the old version of less.
$ mv /usr/bin/less /usr/bin/less-OLD
Then install the new version of less:
$ wget http://www.greenwoodsoftware.com/less/less-458.zip
$ unzip less-458.zip
$ cd less-458
$ chmod 777 *
$ ./configure
$ make
$ make install
$ cd ~
To make sure everything has installed correctly, run the iot help file:
$ aws iot help
Aws Cli is now installed. Make new user and get credentials from the aws console following instructions at:
http://docs.aws.amazon.com/cli/latest/userguide/cli-chap-getting-set-up.html#cli-signup. Once you have an access ID and key you can configure aws and enter the ID and key with:
aws configure
NOTE: for default region you must enter us-east-1 in order to be able to configure AWS for IoT. The default format can be left as json.
In order to get permission to download the AWS IoT tools, attach the administrator account policy to the user. To do this go to the "Users Panel" in the IAM console, select the user you created, attach policy, and select administrator account.
Generate Certificates:
First create a folder to store your certificates in:
mkdir aws_certs
cd aws_certs
Generate a private key with open ssl:
$ openssl genrsa -out privateKey.pem 2048
$ openssl req -new -key privateKey.pem -out cert.csr
- Fill out the fields with your info.
- Run the following to activate the certificate:
$ aws iot --endpoint-url https://i.internal.iot.us-east-1.amazonaws.com create-certificate-from-csr --certificate-signing-request file://cert.csr --set-as-active > certOutput.txt
Run the following to save the certificate into a cert.pem file:
null
$ aws iot --endpoint-url https://i.internal.iot.us-east-1.amazonaws.com describe-certificate --certificate-id <certificateID> --output text --query certificateDescription.certificatePem > cert.pem
null
null
NOTE: Replace with the ID stored in the "certificateId" field in certOutput.txt. To view the file enter:
$ more certOutput.txt
Create a Json policy document for AWS IoT SDK: Copy the following text (ctrl-c):
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"iot:*"
],
"Resource": [
"*"
]
}
]
}
- Enter "$ vi policy.doc" hit "a" and right-click to paste the text.
- Hit escape and type in ":wq" to save and quit.
** Attach the policy to your certificate ** First enter:
$ aws iot --endpoint-url https://i.internal.iot.us-east-1.amazonaws.com create-policy --policy-name PubSubToAnyTopic --policy-document file://policy.doc
Then attach the policy to the certificate with:
$ aws iot --endpoint-url https://i.internal.iot.us-east-1.amazonaws.com attach-principal-policy --principal <certificateArn> --policy-name "PubSubToAnyTopic"
NOTE: replace with the value stored in "certificateArn" in the certOutput.txt file.
NOTE:
To interact with AWS IoT from your device using the certificates you created, you will also need a root certificate. Click here to download the root certificate. Save this file to your desktop and name it “aws-iot-rootCA.crt”
or
curl https://www.symantec.com/content/en/us/enterprise/verisign/roots/VeriSign-Class%203-Public-Primary-Certification-Authority-G5.pem > ~/aws_certs/aws-iot-rootCA.crt
(from http://rexstjohn.com/configure-intel-edison-for-bluetooth-le-smart-development/ )
Lets turn on BLE :
rfkill unblock bluetooth
hciconfig hci0 up
vi /etc/opkg/base-feeds.conf (insert only following lines)
src/gz all http://repo.opkg.net/edison/repo/all
src/gz edison http://repo.opkg.net/edison/repo/edison
src/gz core2-32 http://repo.opkg.net/edison/repo/core2-32
Note: “vi” is a barebones text editor which has some confusing syntax. Copy and paste (e.g. vi’s insert mode) the above three lines into the .conf file indicated and then close vi by hitting “Shift + :” (to leave Insert mode) after making the above edit and then typing “wq” and hitting enter to write the change and then quit.
Before we proceed, make sure your Edison is online via Wi-Fi.
Now run:
opkg update
opkg install bluez5-dev
Next, we will install Bleno and Noble, useful Node.js utilities for doing fun stuff with BLE and Javascript:
npm install -g async
npm install noble
npm install bleno
The key to getting Bleno working seems to be this (see the bug linked above):
rfkill unblock bluetooth
killall bluetoothd (or, more permanently) systemctl disable bluetooth
hciconfig hci0 up
Once this is done, you should be able to use Edison with Bluetooth LE.
Comments