AWS IoT Core
Connect your Raspberry Pi to AWS IoT Core, over a cellular connection
Last updated
Connect your Raspberry Pi to AWS IoT Core, over a cellular connection
Last updated
Easily and securely connect devices to AWS IoT Core. AWS IoT Core uses MQTT to transmit and receive messages, a lightweight IoT messaging protocol. This tutorial explain how to set up AWS IoT Core and start sending IoT data from a Raspberry Pi connected over cellular.
Monogoto SIM
Raspberry Pi 3 or 4
Start by visiting the AWS portal
Search for the IoT Core service
In the left side menu, navigate to Manage > All devices > Things
Click the button Create Things to create your digital Thing.
Name your thing, e.g. mqtt-thing
Select Auto-generate a new certificate
Attach an existing policy, or create a new one by clicking “Create policy”
When creating a new policy, add 4 statements allowing the Thing to Connect, Publish, Receive and Subscribe. Under Policy resource, add an asterisk *
to allow all topic names to connect to AWS IoT Core.
When using AWS IoT Core in production, restrict the Policy resource to specific topics to increase the security of your application.
Download and store the Device certificate, Private key file and Amazon Root CA 1 in a directory called certs
. Make sure to name the files properly as described in the table below.
This section explains how to run a python scrip on a Raspberry Pi, connected to Monogoto. For more information on how to connect the Raspberry Pi to Monogoto, see this tutorial.
Access the Raspberry Pi over ssh or by connecting a screen and keyboard
Install the required libraries
Before you install an AWS IoT Device SDK, run these commands in a terminal window on your Linux device to install the required libraries.
Install the AWS IoT Device SDK for Python and download the sample apps to your device.
Add certificates to the Raspberry Pi
Add the Device certificate, Private key file and Amazon Root CA 1 to a folder called certs
.
If you downloaded the certificates to a different machine, move the certificates to the RPI using the below command: scp -r ~/certspi@<ip address>:~/certs
publish.py
containing the below script Replace <your AWS endpoint>
with your AWS endpoint to the publish.py
file (line 11)
To find your AWS endpoint, go to the AWS IoT console, near the bottom of the navigation pane, choose Settings.
In the Settings page you will find the Endpoint, which is unique to your AWS account and looks something like: abcdef1234567-ats.iot.eu-west-1.amazonaws.com
.
In the AWS IoT Portal, open the MQTT test client and subscribe to the topic device/RPI
Go back to your Raspberry Pi and run the publish.py
script using the command:
Expected response
When looking at the MQTT test client in AWS IoT Core, you can see the messages:
Congratulations! I’ve successfully sent data from a Raspberry Pi connected to Monogoto, to AWS IoT Core using the MQTT protocol.
Trigger actions using Lambdas - learn more
Store data in DynamoDB - learn more
Device certificate
device.pem.crt
Private key file
private.pem.key
Amazon Root CA 1
AmazonRootCA1.pem