头图

Internet of Things (IoT) is the ability to obtain contextual insights from sensor data, such as analyzing device abnormalities or performing predictive maintenance, and promptly notify users. In this article, we will focus on predictive maintenance of equipment through multiple indicators of equipment, use machine learning algorithms to predict the operating status of equipment, detect possible abnormalities in advance, and perform maintenance in time to avoid serious production accidents.

{Scheme Overview}

This article uses machine learning methods for predictive maintenance, uses wind turbine simulation data as an example data set, uses Amazon SageMaker for model training , and deploys inference endpoints. The edge device publishes the data to Amazon IoT Core, and uses IoT rules to trigger the Lambda function to call the API of the predictive maintenance endpoint deployed on Sagemaker to determine whether the device will be abnormal. If there is an abnormality, update the Amazon IoT Shadow to automatically shut down the device And send notifications.

The algorithm we use is called XGBoost (eXtreme Gradient Boosting) , which is a supervised learning algorithm that tries to combine a series of estimates from a set of simpler and weaker models to accurately predict the target variable. Can be used to deal with regression, classification (binary and multi-class) and ranking problems. Use XGBoost to predict whether equipment will be damaged and perform predictive maintenance in advance.

The demonstration in this article uses wind turbine simulation data, and the data fields include:

Wind speed: wind_speed
Blade speed: RPM_blade
Oil temperature: oil_temperature
Oil level: oil_level
Temperature: temperature
Humidity: humidity
Vibrations_frequency
Pressure: pressure
Wind direction: wind_direction
Whether it is damaged: breakdown

You can use this solution to automatically detect potential equipment failures and provide recommended actions. The solution is easy to deploy and includes a sample data set. You can also modify the solution and use other data sets to build your own IoT predictive maintenance solution.

The following figure shows the architecture adopted by this solution

1. The model used for predictive maintenance uses historical device data stored on S3 for training on Amazon SageMaker.

2. The trained model uses SageMaker to deploy and expose Endpoints to provide prediction services.

3. The data is sent from the sensor to the IoT Core and routed to the Lambda function through the IoT Rules Engine. The Lambda function calls the machine learning model of predictive maintenance through Sagemaker Endpoints. When an abnormality is detected, the Lambda function will send a notification and perform corresponding operations on the device through IoT Shadow.

In this article, we will guide you through the following operations:

1. Set up the connected device to communicate with IoT Core
2. Train and deploy the SageMaker model
3. Create cloud resources to monitor and detect devices that may behave abnormally
4. Use simulated equipment to conduct predictive maintenance tests and send notifications

{Experiment preparation: IoT device simulation}

This article uses Cloud9 as the simulation of IoT devices, and sends simulated IoT messages from Cloud9.

In the EC2 console, start an EC2 instance and search for Cloud9 on the Marketplace.

** {Create IoT Policy}

1. Open the IoT console
https://console.amazonaws.cn/iot/home

2. Select Secure -> Policies on the You don't have a policy yet page, select Create a policy . If your account has previously created a strategy, please select Create .

3. Create policy page

Name (name) , enter the name of the strategy Windturbine_Policy

Action field, enter iot:Connect,iot:Receive,iot:Publish,iot:Subscribe. These are the permissions that the device needs to execute when running the sample program from the device development kit. For more information about the IoT strategy, see IoT Core Strategy.
https://samick-blog.s3.cn-north-1.amazonaws.com.cn/xgboost_model_training_and_deployment.ipynb

Resource ARN (Resource ARN) field, enter *. This will select any client (device).

Allow checkbox

entering the policy information, select 161cbc12c76a56 Create

{Create IoT device}

1. Open IoT console
https://console.amazonaws.cn/iot/home

2. Select Management -> Things (Things) on You don't have any things yet (you don't have any things yet) , select Register a thing (registered things) . If your account has already created something, please select Create .

3. On the Create IoT item , select create a single item

4. Name In the field, enter the name of the windturbine . Leave the remaining fields on this page blank. Select Next .

5. On Add a certificate for your thing , select Create certificate

6. On the Certificate created! (Certificate has been created!) on the page

-Download each certificate and key file and save them for future use

AmazonRootCA1.pem:https://www.amazontrust.com/repository/AmazonRootCA1.pem

-Click Activate to activate the certificate

7. Select Attach a policy to attach the policy you created in the previous section to this certificate

8. On Add a policy for your thing Windturbine_Policy you created in the previous section.

9. Select Register Thing

For detailed steps, please refer to:
https://docs.amazonaws.cn/iot/latest/developerguide/create-iot-resources.html

{Create an Amazon SageMaker notebook instance, train and deploy the model}

1. Create a notebook instance windturbine , select t2.medium . Select or create a IAM Role (IAM Role)

2. Select the default options for other parts, click create (Create)

3. After the notebook is created, open Jupyter Lab and upload the notebook ipynb to Jupyter Lab. Select the kernel as conda_python3

4. According to the comment requirements in the code, replace with your own S3 bucket/prefix

5. Run Notebook for model training and deployment

-Training data has been included in the code and can be downloaded directly.

-Data cleaning (delete the turbine_id column, according to the XGBoost training data format requirements, delete the header and move the breakdown of the inference result of the last column to the first column)

-Split the training set, validation set and test set according to the ratio of 7: 2: 1 and upload to S3

-Training model

trained model and generate 161cbc12c76d4b Endpoint for inference, record this value, and then use it in the Lambda function triggered by the IoT rule engine.

{Create Lambda function and SNS Topic for reasoning, device status change and notification}

1. Create an SNS notification topic, and use your own email address to subscribe to the topic to receive predictive maintenance notifications.

2. Create a Lambda function

: 161cbc12c76e19 windturbine_prediction

-Runtime: Python 3.8

-Permission: Choose an IAM Role to use IoT, SNS and SageMaker Endpoint

-Memory: 128 MB

-Timeout: 30s

3. lambda_function.py , pay attention to modify the following constants:

#修改成自己的Sagemaker Endpoint Name
ENDPOINT_NAME = 'xgboost-2021-03-08-10-43-34-693'
#修改成自己的SNS Topic
SNS_TOPIC_ARN = 'arn:aws-cn:sns:cn-northwest-1:account-id:NotifyMe'
#修改成自己的手机号 (海外区SNS发短信)
PHONE_NUMBER = '+8613812345678'

{Create IoT rule to trigger windturbine_ prediction Lambda function}

1. In the navigation pane of Amazon IoT console Act (action) .

2. On the Rules page, select Create

3. Select Create

-Name: Invoke_windturbine_prediction

-Rule Query statement:

 SELECT * FROM ‘windturbine/xgboost’

- In provided one or more operations , select add operation : sending message to Lambda function (A Message to Send A Lambda function) selected windturbine_ Prediction

-(Optional), error operation: send a message to CloudWatch logs (Send message data to CloudWatch logs):

windturbine_prediction

Create rule

{end-to-end test}

1. Create a cert folder in the user's home directory on the Cloud9 instance and upload the IoT Things certificate downloaded and saved in the third step above to this folder

2. Upload the device_simulator.py file to the user's home directory on the Cloud9 instance

3. Upload the simulated data device_data.csv file to the user's home directory on the Cloud9 instance

4. Modify the py code according to your actual configuration

# 将host修改为自己AWS账户的IoT Endpoint
host = "a1hk0pcc0as07l.ats.iot.cn-north-1.amazonaws.com.cn"

#证书路径修改为自己环境下的证书路径
rootCAPath = "cert/AmazonRootCA1.pem"
certificatePath = "cert/windturbine.cert.pem"
privateKeyPath = "cert/windturbine.private.key"

5. Run the code

python device_simulator.py device_data.csv

6. When the deployed XGBoost model endpoint predicts that the device is abnormal, the Lambda function updates the IoT device shadow (Shadows) to set the device state to Off (off state), and the edge IoT device receives the state setting flag and stops the device, as follows As shown in the figure:

At the same time, Lambda will also trigger notifications to remind staff to perform predictive maintenance. As shown below:

{Summary}

You have just completed how to use IoT and Amazon SageMaker together to perform end-to-end hands-on experiments on predictive maintenance of a series of devices, and use Lambda and SNS to alert and monitor their status. We hope this article helps you understand how to effectively insight into IoT device data on Amazon Web Services and provides a good starting point for your specific use case.

【References】

IoT console:
https://console.amazonaws.cn/iot/home

Jpynb:
https://samick-blog.s3.cn-north-1.amazonaws.com.cn/xgboost_model_training_and_deployment.ipynb

lambda_function.py:
https://samick-blog.s3.cn-north-1.amazonaws.com.cn/lambda_function.py

Amazon IoT console:
https://console.aws.amazon.com/iot/home

device_simulator.py:
https://samick-blog.s3.cn-north-1.amazonaws.com.cn/device_simulator.py

device_data.csv:
https://samick-blog.s3.cn-north-1.amazonaws.com.cn/device_data.csv

[Author of this article]


Guo Song
Amazon Cloud Technology Solution Architect, responsible for architectural consulting and design optimization for enterprise-level customers, and dedicated to the application and promotion of Amazon IoT and storage services to domestic and global enterprise customers. Prior to joining Amazon Cloud Technology, he worked as a system engineer in the EMC R&D Center. He has in-depth research on the high-availability architecture, solutions and performance tuning of enterprise-level storage applications.


Liang Rui
Amazon Cloud Technology Solution Architect, mainly responsible for the cloud work of enterprise-level customers, serving customers ranging from automobiles, traditional manufacturing, finance, hotels, aviation, tourism, etc., and is good at DevOps. 11 years of IT professional service experience, has served as program development, software architect, solution architect.


亚马逊云开发者
2.9k 声望9.6k 粉丝

亚马逊云开发者社区是面向开发者交流与互动的平台。在这里,你可以分享和获取有关云计算、人工智能、IoT、区块链等相关技术和前沿知识,也可以与同行或爱好者们交流探讨,共同成长。


引用和评论

0 条评论