How to measure temperature and send it to AWS IoT using a Raspberry Pi

Leo Kyrpychenko
We’ve moved to freeCodeCamp.org/news
3 min readSep 10, 2018

--

What if you want to self-correct the temperature in your office? Or what if you are curious to understand your office environment using IoT sensors?

If this sounds interesting to you, please read on.

To begin with, we need to set up a temperature reading sensor. We connect it to an Arduino which connects to a RaspberryPi.

The next step is to set up AWS IoT SDK on your Raspberry Pi.

Setup the Thing

  1. Create a thing in AWS IoT:

2. Create a single thing to begin with:

3. Create a thing of a particular type. We are using RaspberryPi here (the types are made up by you).

4.Create a certificate for your Thing to communicate with AWS:

5. Download the certificates, a root certificate authority (CA), activate the Thing, and attach the policy.

6. The policy code is here. It may seem a bit permissive, but it is OK for the demo App.

Setup your RaspberryPi

Before you start the setup, please copy all certificates and all root CA files over to the RaspberryPI (scp might help you). You also need to install Node.js if you don’t have it already.

You will also need to install the AWS IoT device SDK.

Here is the code that reads the data from the serial port and sends temperature readings using the AWS IoT device SDK. The code is based on the examples from Amazon.

So now what can you do with that data?

You can write a Lambda that enqueues the data for processing. It may look like this:

And your serverless.com file may look like this:

I hope this post has saved you some time setting up your device. Thanks for reading!

--

--