The Internet of Things on AWS – Official Blog

Developing a Remote Job Monitoring Application at the edge using AWS IoT Greengrass (part 2)

Introduction

In this second-series blog post, we will continue to showcase a user interface (UI) application at the edge with AWS IoT Greengrass V2, a jointly developed solution by AWS Partner, TensorIoT, and AWS Professional Services. This UI application at the edge contains multiple custom AWS IoT Greengrass V2 components to achieve flexible IoT data ingestion, and streaming data analytics and visualization at the edge.

Part 1 of the blog contains the following steps for use case 1 of this application: ingest IoT job metadata via a JSON file upload component and a UI application.

  • How to setup an Amazon Simple Storage Service (Amazon S3) bucket, AWS IoT Greengrass V2 and dependencies;
  • How to launch UI and JSON file upload applications at the edge device.

In this part 2 post, you will continue building the following use case 2 of this UI application at the edge.

Solution overview of use case 2

Operators need to make judgements with streaming IoT data in a near-real time fashion. The data will help operators make the right decisions if it can be shown in an interactive UI application with low latency. With this application, operators can make sound decisions on-site without delay and improve plant operation efficiency.

In this edge UI application, there is a dummy publisher component that simulates outputs from a wind turbine facility. The publish frequency from this dummy publisher is once every 10 seconds. A WebSocket component subscribes to streaming data from the dummy publisher via Inter-process communication (IPC) pubsub with AWS IoT AWS IoT Greengrass V2, and sends the data to the edge UI app via WebSocket communication. Since the front-end app does not support IPC pubsub communication, we chose WebSocket communication to stream real-time IoT data continuously from the back-end server via asyncio to the front-end app hosted on the edge. Considering the speed of streaming data received from the publisher component, the python module queue is used to store the message using First-In-First-Out before serving it to back-end server. Besides WebSocket communication, now you can also use a local broker, such as the JavaScript MQTT client library, for your web application.

Please note, this dummy publisher component is used for demonstration purposes only. In the industrial plant setting, it would be replaced by a suitable industrial data connector to wind turbines (e.g. SCADA system).

In this blog, we will also show how to manage the health status of this AWS IoT Greengrass V2 component with AWS IoT Greengrass V2 pre-built log manager component and Amazon CloudWatch.

The following Steps 6 to 9 will guide you through how to:

  • Launch a dummy publisher component that simulates outputs from a wind turbine facility. The publish frequency from this dummy publisher is once every 10 seconds.
  • Launch a WebSocket component that subscribes to streaming data from the dummy publisher via IPC pubsub with AWS IoT Amazon Greengrass V2 and sends the data to the edge UI app via WebSocket communication.
  • Configure deployment for log manager component to monitor edge components’ health.
  • Test the IoT job monitor application.

Prerequisites

To build this UI application for use case 2, you will need to have AWS IoT Greengrass V2 and dependencies installed on the edge device, as explained in part 1. You will also need the customer UI component from part 1 to be launched on the edge device. If you haven’t completed these steps, review part 1, Step 1-5 before proceeding.

Walk- through of use case 2

The following walk through steps will provide detailed instructions on developing a UI app at the edge for real-time IoT job monitoring. Please note that this post features the key solution milestones for conciseness, but readers should visit the GitHub repository for details and source code.

Step 6: Launch dummy publisher

To simulate wind turbine outputs, the dummy publisher component will publish some random data related to the following measurements for wind turbine: quality control, tool status, operating parameter, power curve, lv active power, wind speed, and wind direction.  Please use the following steps to launch this component:

1. Change the directory to components/com.example.Publisher/aws-gg-deploy in the directory where the GIT repository was cloned to the Amazon Elastic Compute Cloud (Amazon EC2) instance.

2. Modify the deployment script deploy-edge.sh by replacing the following placeholders with your customized values in _setEnv() section:

YOUR_AWS_ACCOUNT_NUMBER 
YOUR_AWS_REGION 
S3_BUCKET for edge component artifacts 
ROLE_ARN

Press Ctrl-X, then press Y to save the modified deploy3-edge.sh file with the same name.

3. Run the following script to deploy this component:

export AWS_ACCESS_KEY_ID=REPLACE-WITH-YOUR-AWS_ACCESS_KEY_ID
export AWS_SECRET_ACCESS_KEY= REPLACE-WITH-YOUR-AWS_SECRET_ACCESS_KEY
export AWS_SESSION_TOKEN= REPLACE-WITH-YOUR-AWS_SESSION_TOKEN
chmod 744 deploy-edge.sh
./deploy-edge.sh

This bash script takes approximately 10 seconds to finish. Once it exists, please confirm the dummy publisher component publishes messages by checking its AWS IoT Greengrass component log file:

sudo tail –200f ./greengrass/v2/logs/com.uipublisher.log

You can see the log is updated with new JSON messages published at a frequency once of every 10 seconds. The message will send to an IPC topic: runscreen/topic, for the WebSocket component to subscribe to.

Fig 1: log file shows messages published by the publisher component

Step 7: Launch the WebSocket component

The WebSocket component subscribes to the IPC topic: runscreen/topic and receives messages with measurements. This component will then serve the message data via the asyncio server, so the UI can receive data from the WebSocket server.

To launch the WebSocket component:

1.Change the directory to components/com.websocketApp/aws-gg-deploy in the directory where the GIT repository was cloned to the Amazon EC2 instance.

2. Modify the deployment script deploy-edge.sh by replacing the following placeholders with your customized values in _setEnv() section:

YOUR_AWS_ACCOUNT_NUMBER
YOUR_AWS_REGION
S3_BUCKET for edge component artifacts
ROLE_ARN

Press Ctrl-X, then press Y to save the modified deploy3-edge.sh file with the same name.

3. Run the following script to deploy this component:

export AWS_ACCESS_KEY_ID=REPLACE-WITH-YOUR-AWS_ACCESS_KEY_ID
export AWS_SECRET_ACCESS_KEY= REPLACE-WITH-YOUR-AWS_SECRET_ACCESS_KEY
export AWS_SESSION_TOKEN= REPLACE-WITH-YOUR-AWS_SESSION_TOKEN
chmod 744 deploy-edge.sh
./deploy-edge.sh

This bash script takes approximately 10 seconds to finish. Once it exists, please confirm that you have the following component created in your AWS IoT Core console:

Fig 2: the WebSocket component status 

Step 8: Configure log manager component deployment

The log manager component (aws.greengrass.LogManager) uploads component logs from AWS IoT Greengrass core devices to Amazon CloudWatch logs. This pre-built component can effectively monitor custom component status with minimal developer efforts. The log manager component can be added to the current deployment from AWS IoT Core by selecting the component from the list of public components.

Fig 3: the log manager component status

Choose the log manager component and select configure component to modify its configuration.

In the configuration merge, add the following configurations of component logs of individual components:

{
  "logsUploaderConfiguration": {
    "componentLogsConfigurationMap": {
      "com.example.Publisher ": {
        "minimumLogLevel": "INFO",
        "diskSpaceLimit": "20",
        "diskSpaceLimitUnit": "MB",
        "deleteLogFileAfterCloudUpload": "false"
      },
      "com.WebsocketApp ": {
        "minimumLogLevel": "INFO",
        "diskSpaceLimit": "20",
        "diskSpaceLimitUnit": "MB",
        "deleteLogFileAfterCloudUpload": "false"
      },
      "com.fileUploader ": {
        "minimumLogLevel": "INFO",
        "diskSpaceLimit": "20",
        "diskSpaceLimitUnit": "MB",
        "deleteLogFileAfterCloudUpload": "false"
      }
    }
  }
}

Fig 4: the log manager component configuration updates

For more configuration modification choices, please refer to this doc.

After redeploy with the log manager, component logs can be found in the Amazon CloudWatch logs as:

Fig 5: component logs in CloudWatch log groups

Developers can also develop component health dashboards by setting up Amazon CloudWatch metrics to monitor component logs and visualize the metrics with a dashboard in Amazon CloudWatch.

Step 9: Test the IoT job monitor UI Page

In part 1, a JSON file can be uploaded to provide IoT job metadata. After the JSON file is uploaded via the UI page: http://localhost:8080 /Job,  the UI application will be automatically switched to the second UI page: http://localhost:8080 /Job. This page shows the streaming data fetched from the WebSocket server, including sensor data, e.g. power curve, wind speed, wind direction and LV active power. When the inspection job status is shown as normal, the UI page shows relevant job information in green font as below:

Figure 6: Job page shows job status as normal.

When the inspection job status is abnormal, the UI page will be shown in red, and the quality control outcome will be shown as Action Needed:

Figure 7: Job page shows job status as abnormal.

This http://localhost:8080 /Job UI page allows inspectors to perform remote job monitoring with near-real time streaming sensor data. They can also gain quality control information from the UI to help performing detailed diagnosis.

Clean up

(1) AWS IoT

Open the AWS IoT Core console, under AWS IoT

  1. Under AWS IoT Greengrass Core Device tab, select the DemoJetson core device and hit delete on top right.
  2. Under Manage > Thing Group, delete DemoJetsonGroup from Thing Group
  3. Delete things under Manage > Things: DemoJetson
  4. Under Policies > delete GreengrassV2IoTThingPolicy and GreengrassTESCertificatePolicyGreengrassV2TokenExchangeRoleAlias
  5. Under Secure > Role Aliases delete GreengrassV2TokenExchangeRoleAlias

(2) Amazon S3

  1. Navigate to the Amazon S3 console and locate the component bucket you used earlier in the blog.
  2. Empty the component bucket.
  3. Delete the component bucket.
  4. Empty the bucket with data from the stream manager.
  5. Delete the bucket with data from the stream manager.

(3) Amazon EC2 termination

  1. Navigate to the Amazon EC2 console.
  2. Stop the instance by selecting Stop Instance under Instance State.
  3. After the instance stops, select Terminate Instance under Instance State.

(4) IAM Roles

  1. Navigate to IAM console
  2. Delete IAM role created from Ubuntu EC2 instance
  3. Delete AWS EC2 SSM access policy
  4. Delete IAM user created for Amazon Greengrass V2
  5. Delete policy that was attached to Amazon Greengrass V2 user.

(5) Amazon CloudWatch

  1. Delete relevant CloudWatch metrics from the Amazon CloudWatch console

This completes the deletion of the resource created for the blog.

Call to action

1. In this blog, the wind turbine data source is simulated by using a dummy publisher for demonstration purpose. When this application is implemented in industrial settings, various data sources can be used, e.g. PLC, controller, conventional data servers, etc. There are several Greengrass community components can be used as data source connectors. Such community components can be deployed to edge devices via AWS IoT Greengrass v2.

2. The WebSocket component explained in this blog can be further extended to include custom data analytics workflow. Such data analytics can enrich the wind turbine data to generate more operational insights.

Conclusion

In this two-part series, we reviewed the benefits and challenges of remote IoT job monitoring and processes. To address such challenges, we proposed a UI application at the edge solution. It is jointly developed by AWS Professional Services and AWS Partner, TensorIoT. During the solution development phase, developers from both companies used the latest AWS IoT Greengrass V2 run time to significantly accelerate the IoT edge application development. The modularized components developed in this application can be easily deployed and updated to thousands of IoT devices using AWS IoT Device Management and AWS IoT Greengrass. In the future, TensorIoT will be able to build more custom applications for various use cases based on the experiences they learned while developing this IoT UI app at the edge.

Julia Hu is a Sr. AI/ML Solutions Architect with Amazon Web Services. She has extensive experience in IoT architecture and Applied Data Science, and is part of both the Machine Learning and IoT Technical Field Community. She works with customers, ranging from start-ups to enterprises, to develop AWSome IoT machine learning (ML) solutions, at the Edge and in the Cloud. She enjoys leveraging latest IoT and big data technology to scale up her ML solution, reduce latency, and accelerate industry adoption.
Martin Lehofer is Practice Manager for Industrial Data with Amazon Web Services. Martin has extensive Industrial IoT experience in a wide range of verticals and applications; from Predictive Maintenance, Data Analytics, Distributed Computing to Artificial Intelligence. At AWS Professional Services, Martin leads a team of architects and engineers helping strategic industrial customers to achieve their business outcomes using data analytics.
Joyson Neville Lewis is an IoT Data Architect at AWS Professional Services. He has worked as a Software/Data engineer before diving into the Conversational AI and Industrial IoT space where he works with companies to connect the dots between business and AI using Voice Assistant/Chatbot and IoT solutions.
Tanya Lobo Parmar is a Director with TensorIoT, overseeing operations in the EMEA region. She is focussed on getting more customers in European markets to modernize and grow using AWS Cloud. She also enjoys managing challenging projects in IoT, Machine Learning and Managed AI.
Vidya Ramaswamy is a Senior Software Engineer at TensorIoT, an AWS Partner and has 8+ years of experience in software development. She enjoys coding and developing various IoT solutions.
Rajeev Pulleti is a Frontend Engineer from TensorIoT with proficient knowledge in Swift, Objective-C, and Javascript.