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

Compare with Current View Page History

« Previous Version 5 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. 



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

2Connect the phyBoard-Zeta to the Internet. If using ethernet, power on the phyBOARD-Zeta, boot into Linux and log in. Run the following 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

4Create a Greengrass group. On the AWS IoT console, click "Greengrass" on the left, and the "Create a group".

                             AWS IoT navigation pane with Greengrass highlighted.

5Select "use easy creation" to automatically generate certificates for the phy-Board-Zeta to connect to AWS Greengrass, as well as "provision a core" in the IoT Registry.

                             Set up your Greengrass Group console page with the Use easy                                 creation button highlighted.

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

                             The Name your Group page with MyFirstGroup in the Group Name                                 field and the Next button highlighted.

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

                             The Every Group needs a Core to function page with                                 MyFirstGroup_Core in the Name field and the Next button                                 highlighted.

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

                             The Run a scripted easy Group creation page with the Create                                 Group and Core button highlighted.

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

                                     The Connect your Core device page with Download these resources                                         as a tar.gz highlighted.

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"

                             The navigation pane of the AWS IoT Core console page with Software                                 highlighted.

14Scroll down to "SDKs" and under "AWS IoT Greengrass Core SDK", select "configure download"

                             The SDKs section with Configure download highlighted.

15Choose "Python 2.7 version 1.3.0" and "Download Greengrass Core SDK"

                             Python 2.7 version 1.3.0 and Download Greengrass Core SDK.

16Decompress 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

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

                             Screenshot showing zipped contents of                                 hello_word_python_lambda.zip.

Unix (including macOS):

sudo zip -r hello_world_python_lambda.zip greengrasssdk greengrassHelloWorld.py

Windows:

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

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

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

                                     Screenshot of the Configuration tab with Upload a .zip                                         file, Python 2.7, greengrassHelloWorld.function_handler, and                                         Upload highlighted.

21

Publish the Lambda function:

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

                                     Screenshot of the Actions menu with Publish new version                                         highlighted.

                             Screenshot with the Version description field set to First                                 version and the Publish button highlighted.

22

Create an alias/ nickname for the Lambda function:

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

                             Screenshot of the Actions menu set to Create alias.

                             Screenshot of Create a new alias with the Name field set to                                 GG_HelloWorld, the Version field set to 1, and the Create button                                 highlighted.

23

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

                             Screenshot of Use existing Lambda with Greengrass_HelloWorld and                                 the Next button highlighted.

24

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"

                             Screenshot of MyFirstGroup with the ellipsis and Edit                                 Configuration highlighted.


                             Screenshot of the configuration page with 25 (seconds) and the                                 Make this function long-lived and keep it running indefinitely radio                                 button selected.

25

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 "Next"
  • In the "Topic filter" section, type "hello/world", and then hit "Next"

                             Screenshot of the Group configuration page, with Subscription                                 and Add your first Subscription highlighted.

                             Screenshot of the Select a source page with Lambdas and                                 Greengrass_HelloWorld highlighted.


26

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


                     Screenshot of the Group page with Deployments, Actions menu, and Deploy                         highlighted.

27

See the MQTT messages:

  • In the side bar of the AWS IoT Core console, choose "Test"
  • Choose "Subscribe to topic" and set the settings to look like the lower image
  • Click "Subscribe to topic"

                     Screenshot of AWS IoT Core console with Test highlighted.

                     Screenshot of Subscriptions test page.

28

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


There is no content with the specified labels




  • No labels