Since I learned about AWS IoT Greengrass in my company's business, I would like to introduce Ubuntu-equipped devices and applications using AWS IoT in several parts from this time. For the first time, we will show you how to create a Greengrass Group on the cloud and how to install Greengrass Core on edge devices.
There is also Article using Azure IoT Edge, so please have a look if you are interested.
Operation confirmed device (OS)
e-RT3 Plus F3RP70-2L[^ert3](Ubuntu 18.04 32bit) Yokogawa's edge controller. It is registered in the AWS IoT Greengrass certified device [^ certificate](Click here for the e-RT3 page](https://devices.amazonaws.com/detail/a3G0h000007dE0NEAU/e-RT3-Plus-(F3RP70-2L) ))).
Raspberry Pi 4 Model B (Ubuntu Server 20.04 32bit)
These devices work with packages of the armhf architecture. I also operate the device on a PC running Windows 10.
AWS IoT Greengrass is software for edge computing provided by AWS. By installing Greengrass on your edge device, you can easily connect to the cloud and deploy applications from the cloud. In addition, by extending some functions of the cloud to edge devices, it is possible to collect and analyze data near the data source, take action on local events, communicate between local devices, and so on. For details, please see AWS IoT Greengrass Official Site.
If you don't have an AWS account, create one. https://aws.amazon.com/jp/ There is also a limited free tier. The AWS IoT free usage tier used this time is [here](https://aws.amazon.com/jp/free/?nc2=h_ql_pr_ft&all-free-tier.sort-by=item.additionalFields.SortRank&all-free-tier You can check it with .sort-order = asc & awsf.Free% 20Tier% 20Categories = categories% 23iot).
Install WinSCP on your PC to transfer files from your PC to your device. Please see the official website for installation and usage. https://winscp.net/eng/index.php
Install Python 3.8 for use with Greengrass Lambda.
sudo apt update
sudo apt install python3.8
Confirm the installation is successful.
username@ubuntu:~$ python3.8 --version
Python 3.8.0
Install Java 8 for use with Greengrass Stream Manager.
sudo apt update
sudo apt install openjdk-8-jdk
Link to the installed Java.
sudo ln /etc/alternatives/java /usr/bin/java8
Confirm the installation is successful.
username@ubuntu:~$ java8 -version
openjdk version "1.8.0_275"
OpenJDK Runtime Environment (build 1.8.0_275-8u275-b01-0ubuntu1~18.04-b01)
OpenJDK Client VM (build 25.275-b01, mixed mode)
Enable cgroup to run Lambda in the container.
Open /boot/firmware/cmdline.txt
.
sudo vi /boot/firmware/cmdline.txt
__ Add the following values to the end of the existing line.
cgroup_enable=memory cgroup_memory=1
Reboot the device.
sudo reboot
Follow the steps in the official AWS guide [^ ggconfig] to create a Greengrass Group in the AWS Management Console.
Select the Tokyo region from the menu on the top right.
Open the "Services" menu in the upper left, enter "iot greengrass" in the search window, and click "IoT Greengrass".
From the left navigation pane, go to Greengrass → Introduction and click Create Group.
Click Use Default Creation.
Name the group and click Next. This time, let's call it "eRT3 Group".
Specify the name of the Greengrass Core. Keep the defaults and click Next.
A confirmation screen will be displayed. Confirm and click "Create Group and Core".
Click Download these resources as tar.gz to download the security resources to connect your device to the cloud. This file cannot be downloaded later, so be sure to download it here. After downloading, click "Finish" to complete the settings.
Install and launch the Greengrass Core software on your device. There are multiple ways to install the Greengrass Core software, but here we will install it from the APT repository [^ apt].
Set up the security resources and root CA certificate needed to connect the device to the cloud.
Launch WinSCP, connect to the device, and place the security resource (tar.gz file) downloaded in step 8 of Creating a Greengrass Group (creating a #greengrass-group) in your home directory.
Run the following command to install the security resource.
Replace <hash>
with the file name of the security resource.
sudo mkdir -p /greengrass
sudo tar -xzvf ~/<hash>-setup.tar.gz -C /greengrass
Go 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
Make sure the downloaded root.ca.pem
is not empty (downloaded correctly). If the file is empty, please try the download again.
```bash
cat root.ca.pem
```
Create a Greengrass system account.
sudo adduser --system ggc_user
sudo addgroup --system ggc_group
Install the AWS IoT Greengrass keyring package and add the 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 the list of packages and install the Greengrass Core software.
sudo apt update
sudo apt install aws-iot-greengrass-core
Start the Greengrass daemon.
sudo systemctl start greengrass.service
Execute the following command, and if the displayed Active
status isactive (running)
, the daemon is operating normally.
```bash
username@ubuntu:~$ systemctl status greengrass.service
Execute the following command to start automatically when the device starts.
```bash
sudo systemctl enable greengrass.service
```
Make an empty deployment to see if your device can connect to the cloud.
From the menu on the left, go to "Groups" and click on the group you created.
Click Deploy from the Actions menu to start the deployment.
Click Auto Detect.
Wait a few minutes for the deployment to complete. If the deployment completes successfully, it is successful.
We created a Greengrass Group in the cloud and installed Greengrass Core on our device. Stay tuned for next time we'll be creating and deploying Lambda!
If the device is in a proxy environment, proxy settings are required. The settings differ depending on the environment, but for reference, I will introduce the settings I made this time.
Please see this article.
Set up Greengrass Core according to the official AWS document [^ proxy].
If Greengrass is running, stop it.
sudo systemctl stop greengrass.service
```
2. Add write permission to /greengrass/config/config.json
and open it.
```bash
sudo chmod +w /greengrass/config/config.json sudo vi /greengrass/config/config.json ``` Add the iotMqttPort and networkProxy objects inside the coreThing object. The file after adding is as follows.
```/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:[email protected]:port/" } } }, ... ``` 3. Remove write permissions from the file and restart Greengrass.
```bash
sudo chmod -w /greengrass/config/config.json sudo systemctl start greengrass.service ```
[^ ert3]: [Real-time OS controller e-RT3 Plus F3RP70-2L](https://www.yokogawa.co.jp/solutions/products-platforms/control-system/real-time-os-controller/ert3- ai-platform /)
Recommended Posts