Standard vs Custom Battery Packs - Decoding the Power Play
Raspberry pi and AWS
1. AWS & Raspberry Pi
Please Follow my Youtube Account for video tutorials.
http://www.youtube.com/c/FaisalMehmoodAvan
Also follow me on my LinkedIn Account
https://kr.linkedin.com/in/faisalavan
Contact Information:
Phone: +82-10-6876-6805
Email: FAISAL.AVAN@HOTMAIL.COM
2. Table of Contents
S.No Topic
1. Sign in to the AWS IoT Console
2. Create and Attach a Thing (Device)
3. Set Up the Runtime Environment for the AWS IoT Embedded C SDK
4. Sample App Configuration
5. Run Sample Applications
6. Send sensing data to AWS
3. Sign in to the AWS IoT Console (1/3)
1. Install Raspbian OS on SD card and insert it in Raspberry Pi
2. Power ON Raspberry pi and confirm you have an Internet
connection.
3. Sign in to the AWS Management Console and choose AWS IoT
service.
4. https://us-east-2.console.aws.amazon.com/iotv2/home?region=us-
east-2#/dashboard
5. If this is your first time using the AWS IoT console, you will see the
Welcome to the AWS IoT Console page. In the left navigation pane,
choose Registry to expand the choices, and then choose Things.
4. Sign in to the AWS IoT Console (2/3)
4. If its first time, then there are no things in this section.
On the page that says You don't have any things yet, choose Register a thing.
Click Learn More to how to register a thing.
Register and Manage IoT Things
IoT thing Registration
5. Sign in to the AWS IoT Console (3/3)
4. If you want to create a new thing, Click Create
On the left side there is list of Created Things
You can View and Edit Things that are already created.
List of Created Things
Click to Create New Thing
6. Create and Attach a Thing (Device) (1/12)
A thing represents a device whose status or data is stored in the AWS cloud.
The Thing Shadows service maintains a thing shadow for each device
connected to AWS IoT. Thing shadows allow you to access and modify thing
state data.
1. Type a name for the thing, and then choose Create thing.
Enter Name for Thing
If you are new to Thing, then Hide Other
Options,
7. Create and Attach a Thing (Device) (2/12)
2. On the Details page, choose Interact.
Every new Thing created is assigned a unique address.
In this case arn:aws:iot:us-east-2:213604715346:thing/MyraspberryPi is the
unique address of Thing
Unique Identifier: Unique address of
newly created thing
8. Create and Attach a Thing (Device) (3/12)
3. Make a note of the REST API endpoint. You will need this value later.
Choose Security.
Update thing using Rest API endpoint
9. Create and Attach a Thing (Device) (4/12)
4. Choose Create certificate. This will generate an X.509 certificate and
key pair.
Certificates are for secure connection
10. Create and Attach a Thing (Device) (5/12)
5. Create a working directory called deviceSDK where your files will be
stored. Choose the links to download your public and private keys,
certificate, and root CA and save them in the deviceSDK directory. Choose
Activate to activate the X.509 certificate, then choose Attach a policy.
Download public, private and certificate
files and Place it in multiple places for
backup
Click to Attach a Policy to newly
activated certificate
First click Activate, Then click Attach a
policy
11. Create and Attach a Thing (Device) (6/12)
6. Choose Create new policy.
By default there are no Policies, Click
create new policy to add a policy
After creating Policy, Click Done
12. Create and Attach a Thing (Device) (7/12)
7. On the Create a policy page, in the Name field, type a name for the
policy. In the Action field, type iot:*. In the Resource ARN field, type *.
Select the Allow check box. This allows your Raspberry Pi to publish
messages to AWS IoT.
8. Choose Create.
Unique and Meaningful Name of
Policy
By enabling, it will allow raspberry pi
to publish message to AWS IoT Thing
13. Create and Attach a Thing (Device) (8/12)
9. In the left navigation pane, under Security, choose Certificates.
You can list Active Certificates. Attach IoT Things and Policies to
Certificates.
List of Certificates
14. Create and Attach a Thing (Device) (9/12)
10. In the box for the certificate you created, choose ... to open a drop-
down menu, and then choose Attach policy.
Attach the required Policies from list
15. Create and Attach a Thing (Device) (10/12)
11. In the Attach policies to certificate(s) dialog box, select the check
box next to the policy you created, and then choose Attach.
Select the policy from the list and Click Attach
16. Create and Attach a Thing (Device) (11/12)
12. In the box for the certificate you created, choose ... to open a drop-
down menu, and then choose Attach thing.
Attach the required Thing from list
17. Create and Attach a Thing (Device) (12/12)
13. In the Attach things to certificate(s) dialog box, select the check
box next to the thing you created to represent your Raspberry Pi, and
then choose Attach.
Select the Thing from the list and Click Attach
18. Setting Runtime Environment for the AWS IoT Embedded C SDK
1. Download the AWS IoT Device SDK for C from the following GitHub repository:
git clone https://github.com/aws/aws-iot-device-sdk-embedded-C.git –b release
2. Before you can use the AWS IoT Embedded C SDK, you must download all
required third-party libraries from GitHub.
Instructions:
You can find instructions for doing this in the deviceSDK/external_libs folder.
19. Sample App Configuration (1/3)
The AWS IoT Embedded C SDK includes sample apps for you to try. For
simplicity, we are going to run subscribe_publish_sample.
1. Copy your certificate, private key and root CA certificate into the
deviceSDK/certs directory.
2. Refer to Slide 10, for private key and certificate
Note:
Device and root CA certificates are subject to expiration and/or
revocation. If this should occur, you will need to copy new a CA
certificate or a new private key and device certificate onto your device.
Locate These files and copy to deviceSDK/certs folder
20. Sample App Configuration (2/3)
2. Navigate to the deviceSDK/samples/linux/subscribe_publish_sample directory. You will
need to configure your personal endpoint, private key, and certificate. The personal
endpoint is the REST API endpoint you noted earlier. Refer to slide 10 to find out
REST API endpoint.
If you don't remember the endpoint and you have access to a machine with the
AWS CLI installed, you can use the aws iot describe-endpoint command to find your
personal endpoint URL.
Or, go to the AWS IoT console. Choose Manage, choose Things, and then choose
the thing that represents your Raspberry Pi. On the Details page for the thing, in
the left navigation pane, choose Interact. Copy everything, including ".com", from
REST API endpoint.
21. Sample App Configuration (3/3)
3. Open the aws_iot_config.h file and, in the //Get from console section,
update the values for the following:
AWS_IOT_MQTT_HOST -- Your personal endpoint.
AWS_IOT_MY_THING_NAME -- Your thing name.
AWS_IOT_ROOT_CA_FILENAME -- Your root CA certificate.
AWS_IOT_CERTIFICATE_FILENAME -- Your certificate.
AWS_IOT_PRIVATE_KEY_FILENAME -- Your private key.
22. Run Sample Applications (1/2)
1. Compile the subscribe_publish_sample app using the included makefile.
make -f Makefile
This will generate an executable file.
… …
23. Run Sample Applications (2/2)
2. Run the subscribe_publish_sample_app. You should see output similar to
the following:
Your Raspberry Pi is now connected to AWS IoT using the AWS IoT Device
SDK for C.
24. Send sensing data to AWS (1/6)
1. Install AWS IoT Python SDK.
> git clone https://github.com/aws/aws-iot-device-sdk-python
> cd aws-iot-device-sdk-python
> sudo python setup.py install
The following successful message should be seen, otherwise run the
last step again.
Running install
…
Running install_egg_info
Removing…
Writing /usr/local/…
25. Send sensing data to AWS (2/6)
2. In AWS IoT platform, click Test and Subscribe to a topic, input
“thing01/data”, make a note for the MQTT client ID.
26. Send sensing data to AWS (3/6)
3. Connect the DHT11 sensor to the Raspberry Pi.
27. Send sensing data to AWS (4/6)
4. Download DHT11 Python library and create our script that will read data from
the sensor and publish to AWS IoT.
> git clone https://github.com/szazo/DHT11_Python
> cd DHT11_Python > vi read_and_publish.py
28. Send sensing data to AWS (5/6)
5. Run the script and check the result in AWS IoT Platform.
Python script result:
30. Contact Information
Please Follow my Youtube Account for video tutorials.
http://www.youtube.com/c/FaisalMehmoodAvan
Also follow me on my LinkedIn Account
https://kr.linkedin.com/in/faisalavan
Contact Information:
Phone: +82-10-6876-6805
Email: FAISAL.AVAN@HOTMAIL.COM