DEV Community

Installing AWS IoT Greengrass on e-RT3 Plus

Introduction

AWS IoT Greengrass is a software that renders enhanced cloud capabilities to field devices. This enables the devices to collect and analyze data locally, react to local events independently, and communicate securely on local networks. The devices can also communicate securely with AWS IoT Core and export IoT data to the AWS Cloud.

In this article, we will create a Greengrass Group on AWS Cloud and install AWS IoT Greengrass Core on the Edge device (e-RT3 Plus). Additionally, we will deploy a sample package to verify the connection with AWS Cloud.

For more information on AWS IoT Greengrass, refer to AWS IoT Greengrass official website.

Azure IoT Edge article is also available for your reference.

Environment

  • e-RT3 Plus F3RP70-2L(Ubuntu 18.04 32-bit) This is the Edge controller of Yokogawa Electric Corporation. It is registered in the AWS IoT Greengrass.
  • Raspberry Pi 4 Model B (Ubuntu Server 20.04 32-bit)

Note: These devices can execute armhf architecture packages.

Preparation

Creation of AWS account

If you do not have an AWS account, create one using this link.
Limited usage slots are available for free.
For more information on using free slots, click here.

Installation of WinSCP

Transferring files from PC to the device requires installation of WinSCP.
For more information on installing and using WinSCP, refer to the official website.

Installation of Python3.8

Note: This setting is required only when using e-RT3. When using e-RT3, sudo setting is required for common users to use the sudo command.

  1. Run the following commands to install Python3.8 to be used in Lambda of Greengrass.

    sudo apt update
    sudo apt install python3.8
    
  2. To confirm whether installation is successful, run the following command to check the version.

    username@ubuntu:~$ python3.8 --version
    Python 3.8.0
    

Installation of Java8

Java8 is required for using the Stream Manager of Greengrass.

  1. To install Java8, run the following commands:

    sudo apt update
    sudo apt install openjdk-8-jdk
    
  2. To establish the connection, run the following command:

    sudo ln /etc/alternatives/java /usr/bin/java8
    
  3. To verify if Java8 is installed properly, run the following commands:

    username@ubuntu:~$ java8 -version
    openjdk version "1.8.0_292"
    OpenJDK Runtime Environment (build 1.8.0_292-8u292-b10-0ubuntu1~18.04-b10)
    OpenJDK Client VM (build 25.292-b10, mixed mode)
    

Validation of cgroup

Note: This setting is required only when using Raspberry Pi.

Validate cgroup for running Lambda in the container.

  1. Open /boot/firmware/cmdline.txt.

    sudo vi /boot/firmware/cmdline.txt
    
  2. Add the following value to the end of the existing row.

    cgroup_enable=memory cgroup_memory=1
    
  3. Restart the device.

    sudo reboot
    

Creating Greengrass Group

Follow these steps to create a Greengrass Group in AWS Cloud:

  1. In the upper-right corner of the AWS Management Console page, select your region from the menu bar. AWS Management Console
  2. On the menu bar, click the Service menu, and in the Search box, type iot greengrass. From the list of services that appear, select IoT Greengrass. AWS Management Console_Search
  3. On the navigation pane, expand Greengrass > Classic (V1) and select Groups, and then click Create Group on the right pane. AWS Management Console_CreateGroup
  4. Click Use default creation. AWS Management Console_useDefault
  5. In the Group Name box, type your group name and click Next. AWS Management Console_Groupname
  6. In the Name box, type the name of the Greengrass Core for the group and click Next. By default, “_Core” is appended with the group name. AWS_managementConsole_Corename
  7. Click Create Group and Core. AWS_managementConsole_CreateCore
  8. Click Download these resources as tar.gz to download the security resource for connecting the device to the cloud.
    AWS_managementConsole_Download

    Note: The tar.gz file cannot be downloaded later and hence, you must download the file before proceeding to the next step.

  9. After downloading the file, click Finish.
    The Greengrass Group is created.

Installing Greengrass Core on e-RT3 Plus

There are several methods to install Greengrass Core on the e-RT3 Plus device. In this exercise, we will install Greengrass Core from the APT repository.

Note: Installing Greengrass Core from APT repository does not support OTA updates. Follow other installation methods if you want to use OTA updates.

To install Greengrass Core, we will first configure the security settings on the e-RT3 Plus device.

Configuring security settings on e-RT3 Plus

Let us install the security resources and CA certificates on the e-RT3 Plus device. This is required to connect the device to AWS Cloud.

Installing security resources

  1. Open WinSCP and connect to the device by logging on to the e-RT3 terminal. AWS_Winscp
  2. Copy the security resource (tar.gz file), which you downloaded while creating Greengrass Group, to the e-RT3 terminal in WinSCP.
  3. Run the following command and install the security resource. Replace the {hash} part to match the file name of the security resource.

    sudo mkdir -p /greengrass
    sudo tar -xzvf ~/{hash}-setup.tar.gz -C /greengrass
    

Downloading root CA certificate

  1. Move to /greengrass/certs.

    cd /greengrass/certs/
    
  2. Download the Amazon Root CA 1 certificate with the name root.ca.pem.

    sudo wget -O root.ca.pem https://www.amazontrust.com/repository/AmazonRootCA1.pem
    

Ensure that the downloaded root.ca.pem file is not empty (downloaded correctly). If the file is empty, try downloading again.

cat root.ca.pem
Enter fullscreen mode Exit fullscreen mode

Installing Greengrass Core software

  1. Create system account for Greengrass.

    sudo adduser --system ggc_user
    sudo addgroup --system ggc_group
    
  2. Install AWS IoT Greengrass keyring package and add repository.

    cd ~
    sudo wget -O aws-iot-greengrass-keyring.deb https://d1onfpft10uf5o.cloudfront.net/greengrass-apt/downloads/aws-iot-greengrass-keyring.deb
    sudo dpkg -i aws-iot-greengrass-keyring.deb
    username@ubuntu:~$ echo "deb https://dnw9lb6lzp2d8.cloudfront.net stable main" | sudo tee /etc/apt/sources.list.d/greengrass.list
    deb https://dnw9lb6lzp2d8.cloudfront.net stable main
    
  3. Update package list and install Greengrass Core software.

    sudo apt update
    sudo apt install aws-iot-greengrass-core
    
  4. Start Greengrass Demon.

    sudo systemctl start greengrass.service
    
  5. Run the following commands to check if Demon is running correctly. (If the displayed Active status is active(running), it means that Demon is running.)

    username@ubuntu:~$ systemctl status greengrass.service
    * greengrass.service - Greengrass Daemon
    Loaded: loaded (/lib/systemd/system/greengrass.service; disabled; vendor preset: enabled)
    Active: active (running) since Fri 2021-03-05 06:31:07 UTC; 14min ago
    Process: 2159 ExecStart=/greengrass/ggc/core/greengrassd start (code=exited, status=0/SUCCESS)
    Main PID: 2163 (5)
    Tasks: 10 (limit: 2366)
    CGroup: /system.slice/greengrass.service
    
  6. To start the software automatically when the device is started, run the following command:

    sudo systemctl enable greengrass.service
    

Note: If the device is in a proxy environment, proxy settings must be configured.

Deployment

Now we will deploy a sample package to check if the device is connected to AWS Cloud.

Follow these steps to test the connection in AWS Greengrass:

  1. On the navigation plane, select Groups, and click the created group. AWS_Deployment_Groups
  2. From the Actions menu, click Deploy to deploy the group. AWS_Deployment_Actions
  3. Click Automatic detection. AWS_Deployment_automaticDetection
  4. Wait for a few minutes until the deployment is complete. If the group is deployed successfully, the connection status is displayed in green. Alt Text

Summary

As demonstrated in this article, it is easy to install and run AWS IoT Greengrass on e-RT3 Plus. In the subsequent articles, we will explore further on deploying applications on e-RT3 Plus using AWS Cloud.

Additional information

Proxy settings

If the device is in proxy environment, configuring proxy setting is mandatory. Although the settings differ based on environment, we will focus on configuring environment variables and Greengrass Core settings.

Configuring environment variables

Refer this article to configure environment variables.

Configuring Greengrass Core settings

Refer this article to configure Greengrass Core settings and then perform these steps:

  1. Stop Greengrass if it is already running.

    sudo systemctl stop greengrass.service
    
  2. Add write permission to /greengrass/config/config.json and open.

    sudo chmod +w /greengrass/config/config.json
    sudo vi /greengrass/config/config.json
    
  3. Add iotMqttPort object and networkProxy object to the coreThing object.

    The file after adding objects is shown below.

    /greengrass/config/config.json
    {
    "coreThing" : {
        "caPath" : "root.ca.pem",
        "certPath" : "3283c6f04d.cert.pem",
        "keyPath" : "3283c6f04d.private.key",
        "thingArn" : "arn:aws:iot:ap-northeast-1:xxxxxxxxxxxx:thing/eRT3Group_Core",
        "iotHost" : "xxxxxxxxxxxx-ats.iot.ap-northeast-1.amazonaws.com",
        "iotMqttPort" : 443,
        "ggHost" : "greengrass-ats.iot.ap-northeast-1.amazonaws.com",
        "keepAlive" : 600,
        "networkProxy":{
            "proxy":{
                "url" : "http://username:password@example.com:port/"
            }
        }
    },
    ...
    
  4. Remove write permission for the file and restart Greengrass.

    sudo chmod -w /greengrass/config/config.json
    sudo systemctl start greengrass.service
    

References

  1. e-RT3 Products - CPU
  2. AWS Partner Device Catalog
  3. Configure AWS IoT Greengrass on AWS IoT
  4. Install the AWS IoT Greengrass Core software from an APT repository
  5. Connect on port 443 or through a network proxy

Top comments (0)