junydania / greengrass-ehealth-workshop

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

logo

AWS Healthcare Greengrass Workshop

Introduction

Greengrass is a software that allows you to extend AWS cloud capabilities to local devices, making it possible to collect data and securely communicate with local network and AWS Cloud. Fits very well for IoT solutions as gateway that could handle communication with Bluetooth, Zigbee devices, for example.

logo

Greengrass Group, Core and Devices

  • Greengrass Group: a set of Cores and Devices
  • Greengrass Core: a set of lambdas and devices, runs greengrass daemon
  • Greengrass Device: small devices, no greengrass daemon

logo

More information about Green Grass

Table of Content

1.Configure Permissions and Raspberry Pi

Before we start using Greengrass we need to configure our Raspberry PI AWS credentials for awscli and also be sure you have access to your Pi using SSH.

Step #1: Open IAM Console to create an access key

screen

Step #2: Click in your AWS user

screen

Step #3: Click "Security Credentials"

screen

Step #4: Click "Create Access Key"

screen

Step #5: Copy the Access Key ID and Secret Access

You can also download a CSV file with your keys! screen

Step #6: Access your Raspberry Pi using SSH and configure awscli

  • Open ssh: ssh pi@RASP-IP-ADDRESSS
  • Type: aws configure
  • Enter your keys
  • Choose us-east-1 as region
  • Choose json as output

screen

Step #7: Return to IAM Console and select your user

screen

Step #8: Click "Add permissions"

screen

Step #9: Click "Attach existing policies directly"

screen

Step #10: Choose "AdministratorAccess"

screen

Step #11: Choose "AmazonDynamoDBFullAccess"

screen

Step #12: Choose "AWSGreengrassFullAccess"

screen

Step #13: Choose "AWSIoTFullAccess" and click "Next Review"

screen

Step #14: Click "Add permissions" and done!

screen

2.Create a Lambda Function

Now we are going to create a Lambda function that we will deploy to our Raspberry Pi later. This Lambda will be sending simulated blood pressure data.

Step #1: Open Lambda Console and click "Create a function"

screen

Step #2: Select "Author from scratch"

  • Name: healthcare-data-generator
  • Runtime: Python 2.7
  • Existing Role: lambda_basic_execution

screen

Step #3: Scroll down to Function code panel

  • Download this .ZIP project to your machine
  • Select "Upload a .ZIP file" in "Code entry type" combo

screen

Step #4: Click "Upload" and select the .ZIP file downloaded in the previous step and then click "Save"

screen

Step #5: Select "Edit code line" in "Code entry type" to see the Lambda code

screen

Step #6: Click "Actions -> Publish new version"

screen

Step #7: Name it "v1" and done!

screen

3.Create Greengrass Group

It's time to create a Greengrass Group that represents our Raspberry Pi as a Core Device.

Step #1: Open Greengrass console and click "Get started" to create a group

screen

Step #2: Select "Use easy creation"

screen

Step #3: Name your group as "healthcare"

screen

Step #4: Accept the suggested core name

screen

Step #5: Click "Create group and core"

screen

Step #6: Click "Download these resoures as .tar.gz"

screen

Step #7: Download Greengrass security resources to your machine

screen

Step #8: Click "Finish"

screen

Step #9: Access your Raspberry Pi and type this command to create a fresh Greengrass core

screen

Step #10: Type "cd greengrass"

screen

Step #11: Upload your .tar.gz security resources file and uncompress into Greengrass directory

screen

Step #12: Type these commands to copy the root.ca.pem certificatre

screen

Step #13: Now you can start your Greengrass core!

screen

4.Deploy Lambda to your Raspberry Pi

Let's deploy our Lambda function to run locally in our Raspberry Pi.

Step #1: Open Greengrass console, select "healthcare" group and click "Lambdas"

screen

Step #2: Select "Use existing Lambda"

screen

Step #3: Select "helthcare-data-generator" Lambda

screen

Step #4: Select the published version

screen

Step #5: Click "Edit configuration"

screen

Step #6: Change Lambda Life-cycle to Long-lived function

screen

Step #7: Your configuration should be like this

screen

Step #8: Back to healthcare group and click "Subscriptions"

screen

Step #12: Select "Lambdas -> healthcare-data-genertor" as Source

screen

Step #13: Selecr "IoT Cloud" as Target

screen

Step #14: With this subscrition our Lambda will be able to reach any topic in the Cloud

screen

Step #15: Click finish

screen

Step #16: Now let's deploy by clicking "Actions -> Deploy" menu

screen

Step #17: Click "Automatic detection"

screen

Step #18: Grant the required permissions

screen

Step #19: In Group Role click "Add role" link

screen

Step #20: Choose "Greengrass_ServiceRole" and click "Save"

screen

Step #21: Now let's do the final deploy, click "Actions -> Deploy" again

screen

Step #22: You should see "Successfully completed message"

screen

5.Monitoring and Processing AWS IoT Messages

Now it's time to monitor AWS IoT to check for incoming MQTT messages from your Raspberry Pi.

Step #1: Open AWS IoT Console

screen

Step #2: Click "Test" and then subscribe to healthcare/data topic

screen

Step #3: You should start seeing health data generated by Greengrass / Raspi

screen

Step #4: Now let's start processing this data

  • Open Lambda console and create a new Lambda
  • Name: Healthcare-Data-JSONToDynamoDB

screen

Step #5: Use the following code

  • Lambda Code screen

Step #6: Open IoT Console and click "Act"

screen

Step #7: Click "Create a rule"

  • This rule will trigger our lambda function for each message received on healthcare/data topic
  • Name: HealthData screen

Step #8: As topic filter, type healthcare/data

screen

Step #9: Add an action and select Lambda

screen

Step #10: Select your lambda function and done!

  • After you finish this, your healthcare data will be stored on DynamoDB, let's check it! screen

Step #11: Open DynamoDB Console

screen

Step #12: Click "Tables", choose the "patient" table and click "Items"

  • If you can see the data coming to the data, congrats, evertything is working! screen

6.Greengrass Controlling Bluetooth Blood Pressure Sensor

Now that we simulated the blood pressure and heart beat data, we will progress to a real example using a Bluetooth Low-energy Blood Pressure monitor. For this case we are using Libelium / MySignals that provides an open platform for e-helath hardware and software development.

screen

We are going to use a Python script to control and collect the readout from the blood pressure sensor:

screen

Step #1: Open your Lambda console and create a new Python 2.7 function

screen

Step #2: Select "Upload a .ZIP file"

screen

Step #3: Download this .zip project file and upload to your function

screen

Step #4: Click "Save"

screen

Step #5: You should see the source code in Python to communicate with BLE blood pressure sensor

screen

Step #6: Click "Actions" and "Publish new version"

screen

Step #7: Name the version

screen

Step #8: Return to your Greengrass console and select your Greeengrass group

screen

Step #9: Click "Lambdas" and "Add Lambda"

screen

Step #10: Click "Use existing Lambda"

screen

Step #11: Select "BloodPressureBLE" Lambda function

screen

Step #12: Click "Next"

screen

Step #13: Select the version and click finish

screen

Step #14: Go to Subscritions menu and click "Add Subscription"

screen

Step #15: Select "BloodPressureBLE" Lambda as Source and IoT Cloud as target

screen

Step #16: Enter "healthcare/data" as filter topic

screen

Step #17: Click "Finish" to confirm the subscription

screen

Step #18: Add a new Subscrition and Select IoT Cloud as source and "BloodPressureBLE" Lambda as target

screen

Step #19: As filter topic, enter "healthcare/bloodpressure". This is the topic that will trigger the lambda / blood pressure sensor.

screen

Step #20: Click finish to confirm the subscription

screen

Step #21: Go to Deployments and Click "Actions -> Deploy"

screen

Step #22: After the deplotyment, go to AWS IoT Console and click "Test"

screen

Step #23: Click "Publish to a topic", enter "healthcare/bloodpressure" as a topic and click "Publish to topic". If everything is working the blood pressure sensor should start working! You need to change the bluetooth Mac addrress to yours!

screen

About

License:Apache License 2.0


Languages

Language:Python 99.8%Language:JavaScript 0.1%Language:Shell 0.0%