Architecting your IoT App using Raspberry Pi and AWS

James Hamann
Jul 24, 2018 · 4 min read

Having done a lot of work with IoT sensors and Raspberry Pi recently, and considering it’s growing popularity, I thought I’d share how I went about architecting the infrastructure of the application, which can be applied to pretty much any IoT app you may be working on. Whilst the principals will apply to all major cloud hosting providers, I’ll be discussing AWS specific services.

Project Outline

A Smart Watering System for Farms/Plants, driven by data obtained from IoT Sensors and Forecasting APIs.

Hardware Used

  • Raspberry Pi 3 Model B and SD Card loaded with Raspbian
  • Female to Female Dupont Wires
  • DHT11 Temp/Humidity Sensor

The above is obviously still in the prototyping phase, which hopefully explains the mess. The end product will be cased in a watertight enclosure. In addition to the Temperature Sensor, the above picture also contains a Photo Resistor which captures information about light levels, but is currently not being used.

Architecture Diagram

This diagram illustrates all of the components used and how they interact with each other. Let’s break it down a little further and understand what’s happening.

First the Pi IoT sensors publish raw data about the temperature, humidity, soil moisture and hours of sunlight. This is sent to an IoT topic via an MQTT message. This is a super light weight pub/sub messaging protocol designed specifically for devices in locations with limited network bandwidth, which is great for IoT. Next, an AWS IoT rule and action is created, which subscribes to the topic that the sensors are publishing to and sends these messages to a Kinesis data stream and DynamoDB Table.

Using Kinesis is entirely optional and dependant on what you’re building. The benefit of Kinesis is that it allows you the option of creating multiple delivery streams for your data. You could have one stream that delivers to a Lambda Function for record transformation, which writes to DynamoDB, or another stream for a Kinesis’ Analytics Application, even a delivery stream for an ElasticSearch app. It gives you the flexibility of being able to stream the data to multiple destinations for multiple uses. On the other hand, it can over complicate the app and be a bit of overkill in some cases, but it’s worth considering and making a final decision based on your app’s requirements. In this example the Kinesis Delivery Stream writes to an S3 Bucket, as an archive.

Once in DynamoDB, the application looks similar to a typical serverless application. The back-end logic is handled by Lambda and API Gateway and then sent to the client/Raspberry Pi. The React Front End is stored in an S3 bucket and distributed via CloudFront to the client. The client will display the sensor data as well as having the ability to control the water flow manually.

To automate the watering, the data from the sensors will be evaluated alongside data from Forecasting APIs and, based on certain criteria, the app will decide whether the area needs water and, if so, it would calculate the amount required based on all the data available. In the event watering is required a message will be published from Lambda to the Raspberry Pi on another topic, containing the “Open Valve” message as well as the amount of time to keep the valve open.

To add a level of interactivity, a chatbot could be included which would prompt the user the current status and give the user the option to interact back, querying past events. In addition to this, data visualisation tools could be used to create dashboards, historical data could even be loaded into a Machine Learning Model to predict the likelihood of watering and the optimum amount of water. There are lots of applications and ways in which you can expand a small project into something more, to gain experience using new tools and technologies.

Whilst this model explains the infrastructure in the context of this project, it is easily applied to any other IoT app you may have in mind. Connecting a Raspberry Pi to the cloud allows it to do so much more and gives you the opportunity to build new, different apps and explore different technologies.

In another post we’ll look at the specifics of setting this up within the AWS Environment and getting a Raspberry Pi Connected on the IoT Console.

As always, thanks for reading, hit 👏 if you like what you read and be sure to follow to keep up to date with future posts.

Coinmonks

Coinmonks is a technology-focused publication embracing Decentralize technologies. We are non-profit, and education is our core value. Our other project — https://coincodecap.com

James Hamann

Written by

Software Developer https://jameshamann.com

Coinmonks

Coinmonks

Coinmonks is a technology-focused publication embracing Decentralize technologies. We are non-profit, and education is our core value. Our other project — https://coincodecap.com

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade