AWS for Industries
Industrial Personnel & Hazard Tracking with Amazon Location Service
Hot work is defined as any operation that could be an origin of ignition in an environment with flammable materials. According to the U.S. Chemical Safety and Hazard Investigation Board (CSB), hot work is one of the most common causes of worker death. It is also leading cause of industrial fires. A hot work environment must be cleaned, monitored, isolated, gas free, and vented to prevent over-pressurization. Oil and gas refineries and petrochemical plants need adequate atmospheric monitoring to detect potential hazardous gas leaks, track worker movements and appropriate alerting mechanism to take necessary actions when a gas leak is detected. Companies use calibrated combustible gas detectors prior to and during hot work activities for effective gas monitoring. However, it remains a challenge to get real-time metrics from these gas detectors and to keep track of worker movement around these hot work areas to notify appropriate actions.
In this blog post, we will demonstrate how to build a real-time industrial personnel and hazard tracking system with AWS IoT, Amazon Location Service, and AWS Amplify using an event-driven architecture to automate the tracking and alerting processes. Amazon Location Service makes it easy for developers to add cost-effective location-based services (LBS) to applications using high-quality data from global, trusted providers like Esri and HERE without compromising data security and user privacy. It is natively integrated with other AWS services, such as Amazon CloudWatch and Amazon EventBridge, so that we can build sophisticated location-enabled applications quickly, operate them easily, and scale them automatically.
- Our solution consists of the following components:
An IoT gas detector simulator running on AWS Lambda, which sends gas detection and position telemetry to AWS IoT Core every few seconds.
- A message queue using Amazon Simple Queue Service (SQS) is used for reliable delivery of the IoT messages, AWS IoT Events to detect and act on events.
- AWS Lambda is used to build a serverless on-demand data transformation function to convert the incoming device telemetry and persist the data in the data storage modules.
- The data storage modules consist of Amazon Timestream to store the gas sensor and location telemetry and Amazon Location Service to save gas leak events and current device locations.
- Lambda functions to convert the data to GeoJSON format that is needed for real time visualization on the front-end webpage.
- Finally, the data visualization component uses Amazon API Gateway to grab the required data from the data storage modules to show on the map, Amazon Cognito to control user access to the application, and AWS Amplify to host front-end webpage that uses Amazon Location Service to display a map, asset positions and gas readings.
Core functions of the solution modules are described below
The Simulated Gas Detector
The solution will use a continuously running Lambda function, triggered by Amazon EventBridge, to simulate a pool of active tracking devices moving about a facility, reporting their location and gas sensor readings to AWS IoT Core. The simulator also has two gas hot spots that will report high readings if a tracker approaches it. In a real application of this solution, a physical device could communicate directly and securely with AWS IoT Core as does this simulator. If AWS IoT Greengrass software is deployed to this device, it can be fully managed, monitored and updated from within the AWS Console.
Data Acquisition and Notification
We will use AWS IoT Core, as it enables the communication between IoT devices and allows routing of the messages to other AWS services without the need to manage infrastructure. The data generated from the device tracker is first published in JSON format over MQTT to AWS IoT Core, and then queued in an Amazon Simple Queue Service (SQS) queue for reliability and downstream processing.
The Rules Engine, which is a component of AWS IoT Core, is setup to continuously evaluate the inbound IoT messages and transforms and delivers them to the destination AWS services based on the business rules defined.
One such destination is AWS IoT Events. With this fully-managed service, we will build detector models that track the state of our devices and can respond to events. In our case, once a tracker enters a hazardous area, it can trigger other AWS services, such as Amazon Simple Notification Service (SNS), CloudWatch Alarms, Simple Email Service and more. With this, real-time hazard response can be automated.
Data Transformation and Data Storage
The ETL (extract, transform, and load) pipeline is created using AWS Lambda functions. The pipeline is designed to read the data from the Amazon SQS queue and transform it for purpose-built data stores. Amazon Timestream is used for storing time-series data, such as the all the device telemetry and sensor readings. Alongside, Amazon Location Service provides a persistence layer where the current position data can be stored for easy map integration.
The map portion utilizes Amazon Location Services, as it simplifies the development process by providing base map tile-sets by Esri and HERE maps. These tile-sets can then be viewed on a web application using MapLibre GL. Amazon Cognito provides user management and authentication functions to secure the backend access the tracking data.
To retrieve the tracker location and readings, the application sends HTTP requests to Amazon API Gateway, which triggers the Lambda functions that retrieve the necessary data from the backend datastores.
Let’s look into implementation instructions of this industrial personnel and hazard tracking system
Before we get started, make sure we have the following prerequisites:
- An active AWS account
- Access to the following AWS services: AWS IoT Core, Amazon SQS, AWS Lambda, Amazon Timestream, Amazon Location Services, AWS Amplify, Amazon Cognito, and Amazon API Gateway
This solution will incur a cost on the AWS platform of $4.50/day on the N. Virginia region (US-East-1). To remove the daily cost, please refer to the Clean Up section below.
- Go to the GitHub repository here. This repository contains all the needed files for this deployment.
- Download the CloudFormation template here. This file contains infrastructure-as-code that will allocate the required services for us.
- Download the HTML webpage we will be hosting here.
- From the folder Lambdas, download the 4 zip files, or use these direct links [File 1] [File 2] [File 3] [File 4]. These contain the required Lambda code.
- Log into your AWS account.
- Go to the Amazon S3 service and create a new S3 bucket, as we will use it to store the required Lambda function code. If you would like to use an existing S3 bucket, take note of the path to where you want to copy the files.
- Copy the 4 Lambda code zip files to the S3 bucket.
- Go to the CloudFormation service and click the button in the top right to Create stack -> With new resources.
- Choose Upload a template file and select the template we downloaded in step 1 as shown in Figure 3
- Choose Next, and then on the Specify stack details page, provide a stack name.
- In the Parameters section, enter the S3 bucket name where the Lambda files reside, e.g. my-tracker-bucket.
- Choose Next, and continue to choose Next on the subsequent pages until we see the Create Stack option.
- Check the box to acknowledge that AWS CloudFormation might create IAM resources with custom names.
- Choose Create Stack to deploy the stack.
- Monitor the status of the stack. When the status is CREATE_COMPLETE, choose the Resources tab for the CloudFormation stack to confirm that all 39 resources are created.
- Go to the Outputs tab in the CloudFormation stack, note the “ApiEndpoint” and “CognitoID” values, they will be needed later.
- Under the Outputs tab in the CloudFormation stack, click on Amplify link, this will take you to the Amplify Console where we will deploy a simple webpage.
- On the AWS Amplify console, scroll down and select Get Started under Amplify Hosting as shown in Figure 5.
- Select the Deploy without Git provider and click Continue. This will allow us to simply upload an HTML file to host.
- Enter a name for the web app, such as Personnel_Tracker_App. Drag and drop the index.zip file that contains the simple web app and click Save and deploy.
- Once the app is successfully deployed, click on the link to load the web app as shown in Figure 8.
- Congratulations! You have hosted a web app on AWS. Now, enter the API Endpoint and Cognito ID Pool we noted earlier and press Start Map. This will load the map with the simulated devices moving about.
- Optionally, we could also inspect the EventBridge Rules, IoT MQTT Test Client, IoT Events Detector Models from the Outputs tab in the CloudFormation stack. Links are provided in the CloudFormation outputs and on the web application.
To terminate most of the resources we created throughout this tutorial, select our CloudFormation stack, and click delete. As the AWS Amplify app was not created with AWS CloudFormation, we will have to remove it manually:
1. Go to AWS Amplify console.
2. Select our app.
3. In the top-right corner, click the Action button.
4. Click Delete App.
This post demonstrated the steps for building a real time industrial personnel and hazard tracking system using AWS IoT services, Amazon Location Service, and AWS Amplify. The solution outlined in this post can help ingest sensor data using AWS IoT Core, detect and respond to events using AWS IoT Events, and track assets/personnel using Amazon Location Service. We also visualized assets/personnel movements using a front-end web application built on AWS Amplify. To learn more about how to build applications with geospatial functionalities such as map visualization, geocoding, and reverse geocoding, please refer to getting started with Amazon Location Service.