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.
-
Run the following commands to install Python3.8 to be used in Lambda of Greengrass.
sudo apt update sudo apt install python3.8
-
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.
-
To install Java8, run the following commands:
sudo apt update sudo apt install openjdk-8-jdk
-
To establish the connection, run the following command:
sudo ln /etc/alternatives/java /usr/bin/java8
-
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.
-
Open
/boot/firmware/cmdline.txt
.
sudo vi /boot/firmware/cmdline.txt
-
Add the following value to the end of the existing row.
cgroup_enable=memory cgroup_memory=1
-
Restart the device.
sudo reboot
Creating Greengrass Group
Follow these steps to create a Greengrass Group in AWS Cloud:
- In the upper-right corner of the AWS Management Console page, select your region from the menu bar.
- 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. - On the navigation pane, expand Greengrass > Classic (V1) and select Groups, and then click Create Group on the right pane.
- Click Use default creation.
- In the Group Name box, type your group name and click Next.
- 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.
- Click Create Group and Core.
-
Click Download these resources as tar.gz to download the security resource for connecting the device to the cloud.
Note: The tar.gz file cannot be downloaded later and hence, you must download the file before proceeding to the next step.
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
- Open WinSCP and connect to the device by logging on to the e-RT3 terminal.
- Copy the security resource (tar.gz file), which you downloaded while creating Greengrass Group, to the e-RT3 terminal in WinSCP.
-
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
-
Move to
/greengrass/certs
.
cd /greengrass/certs/
-
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
Installing Greengrass Core software
-
Create system account for Greengrass.
sudo adduser --system ggc_user sudo addgroup --system ggc_group
-
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
-
Update package list and install Greengrass Core software.
sudo apt update sudo apt install aws-iot-greengrass-core
-
Start Greengrass Demon.
sudo systemctl start greengrass.service
-
Run the following commands to check if Demon is running correctly. (If the displayed
Active
status isactive(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
-
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:
- On the navigation plane, select Groups, and click the created group.
- From the Actions menu, click Deploy to deploy the group.
- Click Automatic detection.
- Wait for a few minutes until the deployment is complete. If the group is deployed successfully, the connection status is displayed in green.
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:
-
Stop Greengrass if it is already running.
sudo systemctl stop greengrass.service
-
Add write permission to /greengrass/config/config.json and open.
sudo chmod +w /greengrass/config/config.json sudo vi /greengrass/config/config.json
-
Add
iotMqttPort
object andnetworkProxy
object to thecoreThing
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/" } } }, ...
-
Remove write permission for the file and restart Greengrass.
sudo chmod -w /greengrass/config/config.json sudo systemctl start greengrass.service
Top comments (0)