[go: nahoru, domu]

Skip to content

aws-samples/predictive-maintenance-demo

Predictive Maintenance Demonstrator

A predictive maintenance demo using a speed controlled motor setup to predict failures before they happen, using data and machine learning. It gathers data from sensors, uses advanced algorithms to forecast problems, and provides actionable insights through visualizations. Ultimately, it shows how predictive maintenance can prevent breakdowns and optimize equipment performance.

demo

Architecture

architecture

Building

To build the physical demo, please take a look go to BuildSpec.md for list of materials.

Deployment

The project is built using CDK IaC. So it can be deployed to your AWS account with a single deploy command.

Pre-requisites

  • Ensure your AWS credentials are in place for your account

  • Ensure you have Node.js and Docker installed

  • Bootstrap your account: In the root folder, run the following commands

    npm ci
    npm run cdk bootstrap -- --toolkit-stack-name CDKToolkit-Predictive-Maintenance --qualifier predmaint
    

Generate Ml Model:

  1. Run the Jupiter NoteBook located in lib/ml to train the model with the example dataset provided. Feel free to run locally if you have a Jupiter instance or use a Notebook Instance in your AWS account (Guide here).
  2. After you finish running the notebook a trained model is created by the default name lstm.h5
  3. Go to your AWS account, create a s3 bucket and upload the model
  4. keep note of bucket name and filename, as we will pass that to the cdk code later.

Follow steps below:

  1. Clone this repo.
  2. in your AWS Account enable AWS IAM Identity Center and create a user for yourself
  3. Go to ckd.json and update the mlBucketPath field with your ml bucket details you created earlier.
  4. In the root folder, run the following commands
    npm run deploy
    
  5. For any future changes you just need to redeploy using npm run deploy

Setup the RaspberryPI

This steps assume you have an SD Card and Raspberry PI

  1. Install Raspeberry Pi OS Lite (64-bit) on a SD card:
    1. Download Raspberry Pi Imager
    2. Launch the imager
    3. Select the right image: Raspeberry Pi OS (other) > Raspeberry Pi OS Lite (64-bit)
    4. Select the right drive
    5. Set up a the Wifi (you can create a hotspot with your phone for instance) and ssh credentials by clicking on the gear on the bottom right:
      1. Check Enable SSH
      2. Set username and password
      3. Check Configure Wireless LAN (This connection will help you connect to the pi from your computer after the first boot)
      4. Set Wifi SSID and Password
      5. Save
    6. Click Write button to write the image to the SD card
  2. Connect to your Raspberry Pi:
    1. Start your Raspberry Pi with SD Card plugged in it
    2. SSH to it by connecting your PC to the network you set up in the previous steps (ssh pi@raspberrypi.local)
  3. Setup up Raspberry Pi:
    1. Configure the interface options:
      1. run raspi-config
      2. Go to Interface options
      3. Enable I4, I5, I6 (enable Hardware Serial port only, not login shell), I7 and I8
      4. Reboot your PI !
    2. Install Java and pip3 using apt
      sudo apt-get update
      sudo apt-get install default-jre python3-pip docker.io
      
    3. Create ggc_user and give it permission to access serial port and GPIO
      useradd ggc_user && sudo groupadd ggc_group && sudo usermod -aG ggc_group ggc_user && sudo usermod -a -G dialout ggc_user && sudo usermod -a -G gpio ggc_user
      
    4. Install Greengrass running the following command
      curl -s https://d2s8p88vqu9w66.cloudfront.net/releases/greengrass-nucleus-latest.zip > greengrass-nucleus-latest.zip && unzip greengrass-nucleus-latest.zip -d GreengrassInstaller
      
    5. Register your PI to your backend
      1. The Greengrass installer uses AWS credentials to provision the AWS resources that it requires. You can provide credentials as environment variables. Copy the command below to your device’s terminal. Replace the text after the ‘=’ sign with the specified information. Learn more
        export AWS_ACCESS_KEY_ID=<AWS_ACCESS_KEY_ID>
        export AWS_SECRET_ACCESS_KEY=<AWS_SECRET_ACCESS_KEY>
        export AWS_SESSION_TOKEN=<AWS_SESSION_TOKEN>
        
      2. Run the command given as output of your backend deployment (aka. npm run deploy). Something like sudo -E java -Droot="/greengrass/v2" ...
  4. Check the device is registered in your account:
    1. Go to AWS IOT Core console > Greengrass devices > Core devices > PredictiveMaintenanceDemoStack-Thing > Deployments
    2. Check the deployments are Completed

You are all set !

Grafana Dashboard

To see everything in action, we can login to Grafana and checkout our Dashboard to view watertank digital twin and all the metrics. After deployment the url for our grafana instance will be printed out in your command line or you could get the url from your AWS console by visiting the Managed Grafana service page, however you won't have access yet. AWS Managed Grafana is using AWS IAM Identity Center for Authorisation previously known as AWS Single Sign-On (SSO).

You should have an IAM Identity User created by now, so we need to give it permission to access our Grafana Instance.

  1. Login to your console and visit the Managed Grafana servie page.
  2. Go to the grafana workspace created by our deployment.
  3. In the Authentication tab, click on Configure users and user groups
  4. Add your IAM Identity User

Now you are ready to visit grafana dashboard.ra

  1. Just visit the grafana url either printed in your terminal or diplayed in your console under Grafana workspace Url.

  2. login using your IAM Identity User credentials

  3. Visit the dashboard section, choose browse and you can view the dashboard created by our deployment as seen below.

    grafana dashboard

Greengrass component changes

To deploy any changes in greengrass components, make sure you upgrade the componenent version in cdk.json, before running npm run deploy again

Clean up

To remove all resources created by this stack run the following

npm run destroy

Security

See CONTRIBUTING for more information.

License

This library is licensed under the MIT-0 License. See the LICENSE file.