You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 14 Next »

AWS IoT Greengrass software is readily available on PHYTEC's phyBOARD-Zeta to enable cloud capabilities.  Greengrass allows data to be collected, analyzed, and acted upon at the source, while using the cloud for storage, analytics, and securely connecting to other devices.  Code can be deployed to individual SOMs or to device fleets through the cloud in AWS Lambda functions via Greengrass, facilitating the process of remote software updates and certificate rotation.  This quick-start will demonstrate how to deploy a simple "Hello World" Lambda function to the phyBOARD-Zeta and view the results in the AWS IoT Console. 

This tutorial is based off of "Getting Started with AWS IoT Greengrass" in the AWS IoT Greengrass Developer Guide, which can be found here: https://docs.aws.amazon.com/greengrass/latest/developerguide/gg-gs.html.


StepImage
1Create or log into your AWS account. Here is the current link to the console sign-in: https://portal.aws.amazon.com/billing/signup#/start

2

Connect the phyBoard-Zeta to the Internet. If this is the first time booting the board you will need to bring up the ethernet interfaces:

  • If using ethernet, power on the phyBOARD-Zeta, boot into Linux and log in
  • Run the listed commands to set up the Internet
    • (modify to the ethernet port that you're using)
ifconfig eth0 up
udhcpc -i eth0


# To prevent commands from wrapping over themselves: 
shopt -s checkwinsize && resize
3

Run the following commands to make sure everything is correctly configured for Greengrass:






If there are missing dependencies beyond Node v6.10 and Java 8, then the Greengrass option was not correctly configured in the image build. Try rebuilding the image and then proceed to the next step when all of the required dependencies are configured and installed.

mkdir ~/Downloads && cd ~/Downloads
wget https://github.com/aws-samples/aws-greengrass-samples/raw/master/greengrass-dependency-checker-GGCv1.7.1.zip
unzip greengrass-dependency-checker-GGCv1.7.1.zip
cd greengrass-dependency-checker-GGCv1.7.1
sudo modprobe configs
chmod +700 check_ggc_dependencies
sudo ./check_ggc_dependencies | more

4

Create a Greengrass group.

  • On the AWS IoT console, click "Greengrass" on the left
  • Click "Create a group".

5
  • Select "use easy creation" to automatically generate certificates for the phyBoard-Zeta to connect to AWS Greengrass
  • Select "provision a core" in the IoT Registry

6Name your group in the "Group Name" box and click "Next".

7Use the name provided for the core, and click "Next".

8Click "Create Group and Core" to finalize creating the Greengrass Group (AWS-side resources for the your set of devices).

9On the confirmation page, download the certificate package. No need to download the software configuration package. Click "Finish".

10Transfer the certificate package from your computer to the i.MX7.

from Windows (not tested):

cd <insert path-to-downloaded-files>
pscp <insert hash>-setup.tar.gz root@<insert IP-address>:~/Downloads

from macOS/Unix

cd <insert path-to-downloaded-files>
sudo scp <insert hash>-setup.tar.gz root@<insert IP-address>:~/Downloads
11Return to the i.MX7. Decompress the certificate file and copy the root CA to the device. Check that the root.ca.pem isn't empty.
cd ~/Downloads
tar -xzvf <insert hash-setup>.tar.gz -C /greengrass
cd /greengrass/certs/
wget -O root.ca.pem https://www.amazontrust.com/repository/AmazonRootCA1.pem


# Check that the last command was successful
cat root.ca.pem
12Start AWS GG daemon on the i.MX7 and check that the daemon is running (there will be a root entry for /greengrass/ggc/packages/1.7.0/bin/daemon).
cd /greengrass/ggc/core
sudo ./greengrassd start

# Check that daemon is running
ps aux | grep -E 'greengrass.*daemon'
13Create the "Hello World" Lambda function. Return to the AWS IoT Core Console and select "Software"

14

Download the SDK:

  • Scroll down to "SDKs" and under "AWS IoT Greengrass Core SDK", select "View all SDKs"
  • Click "v1.3.0" under "Python 2.7" to download the AWS IoT Greengrass Core SDK for Python

15Decompress the "greengrass-core-python-sdk-1.3.0.tar.gz" downloaded from the last step.

Windows: install 7-Zip, right click on file, and choose "7-Zip" → "Open archive" → drag folder to desired location (image shows contents of folder)

macOS: double click the file, open "sdk", and then unzip python_sdk_1_3_0.zip

Unix: use the command line:

tar -xzf <path to greengrass-core-python-sdk-1.3.0.tar.gz>/greengrass-core-python-sdk-1.3.0.tar.gz
cd aws_greengrass_core_sdk/sdk
sudo unzip python_sdk_1_3_0.zip

16Now actually create the Lambda function. Move the greengrasssdk folder into the "examples"→ "HelloWorld" folder and zip them together.

Unix (including macOS):

sudo zip -r hello_world_python_lambda.zip greengrasssdk greengrassHelloWorld.py

Windows:

17Package the Lambda. On the group page in the AWS IoT Console, select "Lambda" → "Add Lambda" → "Create new Lambda".

18In the AWS Lambda Console, fill out the "Author from Scratch" box like in the following screenshot, and then select "Create function" on the bottom:

19
  • Upload the Lambda function deployment package created in Step 17 (could be named something different)
  • Fill out the fields like in the image.

20

Publish the Lambda function:

  • "Actions" → "Publish new version"
  • In "Version Description" , enter anything (e.g. "First version" and then "Publish"

21

Create an alias/ nickname for the Lambda function:

  • "Actions" → "Create alias"
  • Enter a name (e.g. "GG_HelloWorld")
  • Set version to "1"
  • Click "Create"

22

Add the Lambda to your GG group to deploy:

  • Return to the group created in the AWS IoT Console
  • Choose "Use existing Lambda"
  • Select the Lambda created in the last step

23

Edit the Lambda's configuration for the group:

  • For version, choose "Alias: GG_HelloWorld", or whatever alias was chosen for the Lambda
  • Set the settings as the ones in the lower image
  • Choose "Update"


24

Create a subscription to the MQTT topic:

  • Choose "Subscriptions"
  • For "Select a source", choose "Select"
  • Choose the "Lambdas" tab and then "Greengrass_HelloWorld"
  • For "Select a target" choose "Select"
  • Choose the "Services" tab, and then choose "IoT Cloud", "Next"
  • In the "Topic filter" section, type "hello/world", and then hit "Next"


25

Deploy the Lambda:

  • Select "Actions" → "Deploy"
    • The first time may take awhile
    • If deployment takes more than 20 - 30 minutes, try:
      • "Actions" → "Reset Deployments"
      • Check the box that says "Do you want to force the reset"
      • Click "Reset deployment"
      • Redeploy like before
  • The "Deployments" tab will contain a log of successes/failures, also indicated by the colored dot in the heading
  • Choose "Automatic detection" in the next window


26

See the MQTT messages:

  • In the side bar of the AWS IoT Core console, choose "Test"
  • Choose "Subscribe to topic" in the left-hand column and set the settings to look like the lower image
  • Now click "Subscribe to topic" to the right of the "Subscription Topic" field

27

There should now be a "Hello world!" MQTT message appearing in the AWS IoT test console every five or so seconds!





  • No labels