Code Monkey home page Code Monkey logo

environmentalsensing's Introduction

Environmental Sensing with AWS IoT

A project for environmental sensing - pH, various gases, particulate matter, sound and capturing images

This is multi-part project to demonstrate environmental monitoring using several types of sensors and AWS services. The first part focuses on building the hardware and monitoring environmental parameters such as CO2, particulate matter, sound and capturing images. This project can be used for environmental monitoring in several use cases such as Industrial Manufacturing, Distribution Warehouses etc.

The first version of the environmental sensor box and the software along with it is capable of the following features:

  1. Sense temperature, humidity, pressure, CO2, tvoc, proximity, and range and publish them to AWS IoT Core.
  2. Capture and upload images to an Amazon S3 bucket.
  3. The project also uses the AWS Systems Manager to enable remote access to the Raspberry Pi.
  4. How to use AWS IoT Rules to log data to Amazon Elasticsearch Service

A second version of the project retains the temperature, humidity, pressure, CO2, tvoc, proximity, and replaces the camera and the range sensor with a pH sensor from Atlas Scientific in a smaller enclosure. The source code remains the same.

Applications

pH

The pH sensor can be used to monitor several industrial and agricultural parameters:

  1. Dough Fermentation
  2. Soil pH - different crops and plants need specific levels of pH in the soil.

Hardware and Mechanical

List of off the shelf hardware used to build the environmental sensing unit:

The unit supports a camera with Raspberry Pi to capture images and load them to AWS S3. The camera used:

You could use any other compatible camera as well.

Here is the information on the pH sensor, pH reading circuit and the smaller enclosure:

Please note that the code was tested with an earlier version of the Spear Tip probe and EZO circuits - however the new probe and circuit will work fine. Also important to note that by default the carrier board is in UART mode, and has to be re-programmed to support the I2C mode which is used in this project. The carrier board interfaces with a Qwiic cable to the Qwiic hat.

A baseplate was designed and 3D printed to house the components in the following case bought from Amazon.com:

Here is an image of the assembled unit:

Sensor Unit

The first iteration of this does not support the PM2.5 (Particulate Matter 2.5) sensing - but you can see the sensor PMS7003 below the camera in the image.

Here is an image of the version with pH support:

pH Sensing

Architecture

Here is a high level architecture of the first iteration/part of this project:

Architecture

Configure & Setup AWS IoT

Read through Setting up AWS IoT and Create a Thing. Once you have created a thing for the Raspberry Pi - make sure that the keys are present in the 'keys' subfolder. Also copy the sampleenv file as .env and provide the specifics - you will need these

Logging data to AWS IoT Core

Prior to logging data - you should take the sampleenv file - copy it to .env and then make sure that al parameters are set correctly. Run the script rpiQwiicAWSIoT.py to read sensor data and log to AWS IoT Core. The script calls two helper modules:

  • imageCapture.py - to capture an image using hte picamera package, and upload it to S3. Note that the S3 bucket name has to be specified in the .env file.
  • ultraSonic.py - this script reads the value from the Range Finder sensor if connected.

Two flags are used to control the import and execution of the above modules - S3_ENABLE and ULTRA_ENABLE in the .env file.

  • If you want to exclude both or one of them - set the flag to an emptry string.
  • If the module is to be included then set it to 'True'

See example below:

S3_ENABLE='True'
ULTRA_ENABLE=''

Once the .env file is configured correctly - you can start tbe execution as follows:

python3 rpiQwiicAWSIoT.py

If you want to run the program in the background, and ensure it keeps running when you disconnect your remote session in to the Raspberry Pi then execute the following:

nohup python3 -u ./rpiQwiicAWSIoT.py > output.log &

You can now go to the "Test" secion of the AWS IoT Console, and subscribe to the topic that you are using. The topic used for testing was the following:

telemetry/<thing_name>

Sample output from the unit:

{
  "timestamp": 1583361438,
  "time": "03-04-2020 17:37:17",
  "tempc": 27.63,
  "tempf": 81.752,
  "humidity": 34.475,
  "pressure": 106.863,
  "tvoc": 0,
  "co2": 400,
  "proximity": 2556,
  "ambient": 128,
  "image": "pzb827ebed3f9a-1583361438"
}

The data above is not using the Ultrasonic sensor readings and does not have them. The data packet also provides the image that was captured and the filename used to store in the S3 bucket.

Storing data with Amazon Elasticsearch

We will use Amazon Elasticsearch to store transformed data and later on use it for visualization. Setup a Amazon Elasticsearch in the same region as you have used to create the IoT thing. Once your Elasticsearch is setup, go to the AWS IoT console, and setup an IoT rule. See the image below on how it is setup.

This the specific IoT rule being used to transform the incoming packets:

SELECT topic(2) as thing_name, timestamp, parse_time("yyyy-MM-dd'T'HH:mm:ssZZ", timestamp(), "America/New_York" ) as ts, tempf, tempc, humidity, pressure, co2, ambient, tvoc, proximity FROM 'telemetry/+'

This rule does minor transformation of the incoming data message, and the output should look as follows:

{
  "thing_name": "pzb827ebed3f9a",
  "timestamp": 1583361502,
  "ts": "2020-03-04T17:38:26-05:00",
  "tempf": 82.058,
  "tempc": 27.81,
  "humidity": 34.288,
  "pressure": 106.548,
  "co2": 400,
  "ambient": 125,
  "tvoc": 0,
  "proximity": 2555
}

environmentalsensing's People

Contributors

ashujoshi avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.