AWS Lambda with Temperature data and the ESP32

Updated 02 August 2018

In this project, I'm using an esp32 board combined with a thermistor, plus an Amazon Web Services Lambda API plus some web charting code for temperature sensing. Source code can be found in the GitHub repository: https://github.com/AcrossTheCloud/temperature-iot

Steps

  1. Pick a region from the region list that supports API Gateway, Lambda, DynamoDB, and IoT, and make sure you use that region (from the console drop-down menu) when it comes to configuring AWS IoT, and also update in the serverless.yml file with the corresponding region string from the table here.
  2. Deploy the API per instructions below and update the web code.
  3. Put the web code (under web/) somewhere, e.g. an s3 bucket optionally with CloudFront.
  4. Configure AWS IoT.
  5. Build the sensor.
  6. Configure and transfer the code to the sensor.

API Deployment

Requirements

  • node.js v6 or higher with the corresponding npm
  • serverless: run npm i -g serverless to install.

Installation

Run the following commands in the shell from the top level directory:

cd api
serverless deploy

note the output URL here and update the URL in the web code.

Configure AWS IoT

  1. Create an AWS account if you don't have one and sign in to the IoT console.
  2. Register a thing.
  3. Create the certificate and download and copy the one ending with ".cert.pem" into esp32/main/certs/certificate.pem.crt and the one ending ".private.key" into esp32/main/certs/private.pem.key".
  4. Create a policy and when it comes to the part to add statements, add one for "iot:Connect", replacing "replaceWithAClientId" with "my_temperature_esp32" (without quotes) and effect "allow", then another one for "iot:*", replacing "replaceWithATopic" with "topic/temperature" (without quotes, and note the word topic will appear twice as "topic/topic/temperature" on the end), and effect "allow".
  5. Create a rule to transfer the IoT data into the dynamoDB table created automatically as part of the API deployment step. To do this, go to "act" in the IoT console, then create a rule. On the "create a rule" page, enter a name (e.g. temperature, but can be anything you like here), under "attribute" enter "*" (without quotes), under "topic filter" enter "topic/temperature" (you guessed it, no quotes here although you will see single quotes automatically entered above), then "add an action". On the "select an action page" select "Split messages into multiple columns of a database table (DynamoDBv2)" then configure action. On the "Configure action" page select the "temperature" table under the table name dropdown. Click "create a new IAM role" and an enter a name (e.g. temperature but can be anything), then you need to select it from the dropdown (as it doesn't stay there), and then click "update role", then "add action" then "create rule".

Build the sensor

Connect as per the schematic.

The following photo shows the pins on the feather board you need to connect wires to: aws-lambda-with-temperature-data-and-the-esp32-pins-used-picture

Sometimes you can find packages with the thermistor and resistor combined as in my setup: aws-lambda-with-temperature-data-and-the-esp32-hardware-imageIn that case connect from the pin marked GND on the feather board to the "-" pin on the thermistor unit, from the "A4/36" (input) pin to the "S" pin on the thermistor unit, and the pin marked "3V" (actually 3.3V) on the feather board to the remaining pin on the thermistor unit. aws-lambda-with-temperature-data-and-the-esp32-thermistor-pins

Configure and transfer code to the sensor

Requirements

  1. Set up the esp32 toolchain.
  2. Get the esp32 IoT development framework then setup the path to the esp32 IoT development framework. Note no need to go on to set up a project as there's one supplied here which we just need to configure and transfer.
  3. Grab the USB drivers from [https://www.silabs.com/products/development-tools/software/usb-to-uart-bridge-vcp-drivers] and then connect the feather board over USB to your computer.

Configuration and transfer

Run the following commands in the shell from the top level directory:

cd esp32
make menuconfig

Be sure to set:

  • the path to python2 under "SDK tool configuration",
  • the USB-serial device under "Serial flasher config",
  • your WiFi network and password under "Example config", and
  • the AWS IoT endpoint (from aws iot describe-endpoint in the CLI / the AWS IoT console under "settings") into the field in "Component config" -> "Amazon Web Services IoT Platform". then
make flash

End result

The temperature sensor can then be used to monitor the temperature of a location. It is sending its results to the DynamoDB (NoSQL) database, as exposed by a serverless cloud API, and then these temperature results can be graphed as shown using the web graphing code, as shown in this example: Example graph.You can view the current temperature graph for my study here: https://temperature.acrossthecloud.net

Have a question? Ask the Author of this guide today!

Please enter minimum 20 characters

Your comment will be posted (automatically) on our Support Forum which is publicly accessible. Don't enter private information, such as your phone number.

Expect a quick reply during business hours, many of us check-in over the weekend as well.

Comments


Loading...
Feedback

Please continue if you would like to leave feedback for any of these topics:

  • Website features/issues
  • Content errors/improvements
  • Missing products/categories
  • Product assignments to categories
  • Search results relevance

For all other inquiries (orders status, stock levels, etc), please contact our support team for quick assistance.

Note: click continue and a draft email will be opened to edit. If you don't have an email client on your device, then send a message via the chat icon on the bottom left of our website.

Makers love reviews as much as you do, please follow this link to review the products you have purchased.