Difference between revisions of "R-Car/Boards/Yocto-Gen3/AWS IoT Greengrass/v5.9.0"
< R-Car | Boards/Yocto-Gen3 | AWS IoT Greengrass
(4 intermediate revisions by the same user not shown) | |||
Line 87: | Line 87: | ||
* [[R-Car/Boards/M3SK#Hardware]] | * [[R-Car/Boards/M3SK#Hardware]] | ||
− | == | + | == Getting Started using prebuilt binaries == |
+ | # Download prebuilt binaries | ||
+ | #* Download Yocto BSP binary with Greengrass Core from following page: | ||
+ | #*: Binary: | ||
+ | #*:: [https://www.renesas.com/node/1602171 Download for Starter Kit Premiere(H3)] | ||
+ | #*:: [https://www.renesas.com/node/1602181 Download for Starter Kit Pro(M3)] | ||
+ | #*:: [https://www.renesas.com/node/1602176 Download for CCPF-SK + Starter Kit Premiere(H3)] | ||
+ | #*:: [https://www.renesas.com/node/1602216 Download for CCPF-SK + Starter Kit Pro(M3)] | ||
+ | #*: {{Note}} '''Source code is not needed for this guide'''. But, if source code is required, please refer to following: | ||
+ | #*:: Source: | ||
+ | #*::: [https://www.renesas.com/node/1602211 Download for Starter Kit Premiere(H3)] | ||
+ | #*::: [https://www.renesas.com/node/1602196 Download for Starter Kit Pro(M3)] | ||
+ | #*::: [https://www.renesas.com/node/1602186 Download for CCPF-SK + Starter Kit Premiere(H3)] | ||
+ | #*::: [https://www.renesas.com/node/1602241 Download for CCPF-SK + Starter Kit Pro(M3)] | ||
+ | #* Extract downloaded files | ||
+ | #*: ex.) R-Car Starter Kit Premier(H3) | ||
+ | #*:: Unzip Yocto-v5.9.0-ccpfsk-ggc-h3ulcb-binary.zip -d <working directory> | ||
+ | # Setup SW | ||
+ | #* Setup SW (Prepare SD card, Flashing IPL, Booting). Please refer to [[R-Car/Boards/CCPF-SK/GettingStarted/Linux#SW_Setup]] | ||
+ | == Building the BSP == | ||
+ | === Required packages === | ||
# Install required packages | # Install required packages | ||
#: <syntaxhighlight lang="bash"> | #: <syntaxhighlight lang="bash"> | ||
Line 105: | Line 125: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
− | == Building the BSP == | + | === Building the BSP === |
# Create the following script(build.sh) for building | # Create the following script(build.sh) for building | ||
#: <syntaxhighlight lang="bash"> | #: <syntaxhighlight lang="bash"> | ||
Line 112: | Line 132: | ||
BOARD_LIST=("h3ulcb" "m3ulcb" "h3ulcb-ccpf-sk" "m3ulcb-ccpf-sk") | BOARD_LIST=("h3ulcb" "m3ulcb" "h3ulcb-ccpf-sk" "m3ulcb-ccpf-sk") | ||
TARGET_BOARD=$1 | TARGET_BOARD=$1 | ||
− | WORK=`pwd`/${TARGET_BOARD} | + | WORK=`pwd`/${TARGET_BOARD}-build |
− | + | repolist=( \ | |
− | + | "git://git.yoctoproject.org/poky;74b22db6879b388d700f61e08cb3f239cf940d18" \ | |
− | + | "git://git.openembedded.org/meta-openembedded;814eec96c2a29172da57a425a3609f8b6fcc6afe" \ | |
− | + | "https://github.com/renesas-rcar/meta-renesas;13fd24957b9acc29a235ee0c7f398fd867f38b47" \ | |
− | + | "https://github.com/renesas-rcar/meta-renesas-ccpf;09dd815616cce3a2bdcf8906c0d21403df8b93bd" \ | |
− | + | "https://github.com/yhamamachi/meta-rcar-dev-utils;remotes/origin/v5.9.0" | |
− | + | ) | |
− | + | repolist_ggc=( \ | |
− | + | "git://git.yoctoproject.org/meta-virtualization;c4f156fa93b37b2428e09ae22dbd7f5875606f4d" \ | |
+ | "git://git.yoctoproject.org/meta-java;eeb136c64ecaa364d4e332d0182865dc65f2a83b" \ | ||
+ | "https://github.com/tkomagata/meta-docker;f8f83a7b15930b74b4af2ae5e7c4c55607fafa86" \ | ||
+ | "https://github.com/aws/meta-aws;9979cfa676105cb68cfadfdaeabf044d7c919319" \ | ||
+ | "https://github.com/tkomagata/yocto_templateconf;516f8b22b68fc8539cee483a5565ed7665d8e6efd" \ | ||
+ | ) | ||
− | + | _usage () { | |
− | echo "Usage: $0 \${ | + | echo "Usage: $0 \${BOARD_NAME} [release package option]" |
echo "BOARD_NAME list: " | echo "BOARD_NAME list: " | ||
for i in ${BOARD_LIST[@]}; do echo " - $i"; done | for i in ${BOARD_LIST[@]}; do echo " - $i"; done | ||
+ | echo "release package options:" | ||
+ | echo " -r: Create core-image-minimal-release" | ||
exit | exit | ||
} | } | ||
− | + | repo_clone () { | |
− | + | mkdir -p ${WORK} | |
− | + | for repo in ${repolist[@]}; do | |
− | + | URL=$(echo $repo | cut -d';' -f1) | |
+ | COMMIT=$(echo $repo | cut -d';' -f2) | ||
+ | NAME=${URL##*/} | ||
+ | if [[ ! -d "${WORK}/${NAME}" ]]; then | ||
+ | git clone ${URL} ${WORK}/${NAME} | ||
+ | fi | ||
+ | cd ${WORK}/${NAME}; git checkout -B tmp ${COMMIT} | ||
+ | done | ||
+ | } | ||
− | + | check_target_board () { | |
− | + | if ! `IFS=$'\n'; echo "${BOARD_LIST[*]}" | grep -qx "${TARGET_BOARD}"`; then | |
+ | _usage | ||
+ | fi | ||
+ | } | ||
− | + | set_build_type () { | |
− | + | BUILD_TARGET=core-image-minimal | |
− | + | BUILD_TYPE=bsp | |
− | + | repolist=(${repolist[@]} ${repolist_ggc[@]}) | |
− | + | } | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | + | build_yocto () { | |
− | + | cd ${WORK} | |
+ | BUILD_DIR=${WORK}/build_${TARGET_BOARD}_${BUILD_TYPE}${RELEASE} | ||
+ | rm -rf ${BUILD_DIR}/conf | ||
+ | TEMPLATECONF=${WORK}/yocto_templateconf/ggc/rcar-gen3/${TARGET_BOARD}/${BUILD_TYPE}/ \ | ||
+ | source poky/oe-init-build-env ${BUILD_DIR} | ||
+ | echo "DL_DIR = '${DL_DIR:-${WORK}/yocto_dl_dir}'" >> ${BUILD_DIR}/conf/local.conf | ||
+ | echo "SSTATE_DIR = '${SSTATE_DIR:-${WORK}/yocto_sstate_dir}'" >> ${BUILD_DIR}/conf/local.conf | ||
+ | echo "${LOCAL_CONF_APPEND}" >> ${BUILD_DIR}/conf/local.conf | ||
+ | bitbake-layers add-layer ${WORK}/meta-rcar-dev-utils/meta-rcar-gen3 | ||
+ | if [[ "${RELEASE}" != "" ]]; then | ||
+ | cp -f ${WORK}/meta-rcar-bsp-release/meta-rcar-gen3/docs/sample/site.conf.sample \ | ||
+ | ${BUILD_DIR}/conf/site.conf | ||
+ | bitbake-layers add-layer ${WORK}/meta-rcar-bsp-release/meta-rcar-gen3 | ||
+ | fi | ||
+ | bitbake ${BUILD_TARGET}${RELEASE} | ||
+ | } | ||
− | + | build_32bit_rom_writer () { | |
− | cd ${WORK} | + | cd ${WORK} |
− | + | BUILD_32_DIR=${WORK}/build_32 | |
− | + | source poky/oe-init-build-env ${BUILD_32_DIR} | |
− | + | cp -f ${BUILD_DIR}/conf/* -t ${BUILD_32_DIR}/conf/ | |
− | + | echo "MACHINE ??= 'qemuarm'" >> ${BUILD_32_DIR}/conf/local.conf | |
− | + | echo "DEFAULTTUNE = 'armv7a'" >> ${BUILD_32_DIR}/conf/local.conf | |
− | + | bitbake flash-writer renesas-bsp-rom-writer | |
− | + | cp -rf ${BUILD_32_DIR}/tmp/deploy/images/qemuarm/renesas-bsp-rom-writer_32bit \ | |
− | + | -t ${BUILD_DIR}/tmp/deploy/release/binary/ipl/ | |
− | + | } | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | + | ## main process ## | |
− | + | RELEASE="" | |
+ | check_target_board $@ | ||
+ | set_build_type $@ | ||
+ | if [[ "$(echo $*' ' | grep ' -r ')" != "" ]]; then | ||
+ | repolist+=("https://github.com/yhamamachi/meta-rcar-bsp-release;remotes/origin/v5.9.0") | ||
+ | RELEASE=-release | ||
fi | fi | ||
− | + | repo_clone | |
− | + | build_yocto | |
− | + | if [[ "$(echo $*' ' | grep ' -r ')" != "" ]]; then | |
− | + | build_32bit_rom_writer | |
− | if [ "$ | ||
− | |||
− | |||
fi | fi | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
</syntaxhighlight> | </syntaxhighlight> | ||
− | # | + | # Build |
#: <syntaxhighlight lang="bash"> | #: <syntaxhighlight lang="bash"> | ||
− | $ chmod a+x | + | $ chmod a+x build.sh |
− | $ ./ | + | $ ./build.sh <target_board_name> <release package option> |
+ | Ex.) | ||
+ | h3ulcb build: | ||
+ | ./build.sh h3ulcb | ||
+ | m3ulcb-ccpf-sk build for release: | ||
+ | ./build.sh m3ulcb-ccpf-sk -r | ||
</syntaxhighlight> | </syntaxhighlight> | ||
#: target_board_name is specified for each board according to the following table: | #: target_board_name is specified for each board according to the following table: | ||
#: [[File:R-car-sk-target-board-name.png|400px]]<br> | #: [[File:R-car-sk-target-board-name.png|400px]]<br> | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
#: Depending on the performance of the host PC, it may take several hours for the build to complete. | #: Depending on the performance of the host PC, it may take several hours for the build to complete. | ||
#: When the build completes successfully, you will see the following output: | #: When the build completes successfully, you will see the following output: | ||
Line 239: | Line 246: | ||
# Check the built images | # Check the built images | ||
#: The built images are stored in the following: | #: The built images are stored in the following: | ||
− | #: <target_board_name>/ | + | #: <target_board_name>-build/build_<target_board_name>_bsp(-release)/tmp/deploy/images/<target_board_name>/ |
# Write the images to the SD card | # Write the images to the SD card | ||
#: Write the images to the SD card with reference to [[R-Car/Boards/Yocto-Gen3/v5.5.0#Loading_kernel_and_rootfs_via_eMMC.2FSD_card|Loading kernel and rootfs via eMMC/SD card]]. | #: Write the images to the SD card with reference to [[R-Car/Boards/Yocto-Gen3/v5.5.0#Loading_kernel_and_rootfs_via_eMMC.2FSD_card|Loading kernel and rootfs via eMMC/SD card]]. |
Latest revision as of 06:09, 20 April 2022
|
Introduction
This page describes how to setup the Yocto environment to use the AWS IoT Greengrass with R-Car and run it.
This page contains information abot building and running AWS IoT Greengrass on Yocto environment on:
- Renesas R-Car-H3 Starter Kit Premier (unofficial name - H3ULCB)
- Renesas R-Car-M3 Starter Kit Pro (unofficial name - M3ULCB)
- R-Car/Boards/CCPF-SK
Topic
EOL Notification of the M3SK
Production of M3SK is discontinued.
See M3SK page for detail.
The new version of R-Car Starter Kit Premier is now on sale !!
- Equipped with R-Car H3e-2G
-
(En) https://www.renesas.com/jp/en/about/press-room/renesas-launches-r-car-gen3e-20-percent-higher-cpu-speed-automotive-infotainment-cockpit-and-digital
(Zh) https://www.renesas.com/jp/zh/about/press-room/renesas-launches-r-car-gen3e-20-percent-higher-cpu-speed-automotive-infotainment-cockpit-and-digital
(Jp) https://www.renesas.com/jp/ja/about/press-room/renesas-launches-r-car-gen3e-20-percent-higher-cpu-speed-automotive-infotainment-cockpit-and-digital
- CPU performance is increased 20% by supporting up to 2GHz frequency over past products.
- You can buy from here.
SW Release Information
Board name | SW name | Release date | Note |
---|---|---|---|
R-Car Starter Kit ( Premier / Pro ) | Yocto v5.9.0 (stable) [New!!] | 2022/02/08 | |
Kingfisher Infotainment Board | Yocto v5.9.0 (stable) [New!!] | 2022/02/14 | To check for latest information, please refer to the meta-rcar/tree/v5.9.0. |
Android 10 (stable) | 2021/07/26 | R-Car Starter Kit Premier(R-Car H3) + Kingfisher is supported. R-Car Starter Kit Pro(RTP8J77961ASKB0SK0SA05A) + Kingfisher is also supported from 2021/11/25. | |
Android P (stable) | 2020/09/29 | R-Car Starter Kit Premier(R-Car H3) + Kingfisher is supported. R-Car Starter Kit Pro(RTP8J77961ASKB0SK0SA05A) + Kingfisher is also supported from 2021/03/16. | |
CCPF-SK Board | Yocto v5.9.0 (stable) [New!!] | 2022/02/08 | Prebuilt binary is available in Quick startup guide page. (Updated on 2022/03/18) |
Software revisions
Software | Revision |
---|---|
Yocto Project | 3.1.11 |
aarch64-poky-linux-gcc (GCC) | 9.3 |
Kernel Ver | 5.10.41 |
Userland 64/32bit | 64 |
U-Boot | 2020.10 |
OP_TEE | 3.13.0 |
Greengrass | 2.4.0 |
Environment
Host PC
OS | Ubuntu 20.04 LTS (64bit) |
Memory | 8 GB or more |
Storage | At least 100 GB free |
Boards confirmed to work
Board | SoC | Confirmed |
---|---|---|
R-Car Starter Kit Premier(H3) | H3e-2G v3.0 | OK |
R-Car Starter Kit Premier(H3) | H3 v3.0 (1rank DDR) | OK |
R-Car Starter Kit Premier(H3) | H3 v3.0 (2rank DDR) | NT |
R-Car Starter Kit Premier(H3) | H3 v2.0 with 4GB DDR | OK |
R-Car Starter Kit Pro | M3 v3.0 | OK |
R-Car Starter Kit Pro | M3 v1.0 | OK |
CCPF-SK + R-Car Starter Kit Premier(H3) | H3e-2G v3.0 | OK |
CCPF-SK + R-Car Starter Kit Premier(H3) | H3 v3.0 (1rank DDR) | OK |
CCPF-SK + R-Car Starter Kit Premier(H3) | H3 v3.0 (2rank DDR) | NT |
CCPF-SK + R-Car Starter Kit Premier(H3) | H3 v2.0 with 4GB DDR | OK |
CCPF-SK + R-Car Starter Kit Pro | M3 v3.0 | OK |
CCPF-SK + R-Car Starter Kit Pro | M3 v1.0 | OK |
18px <translate> Note:</translate> NT='Not Tested' but will work
See also:
Getting Started using prebuilt binaries
- Download prebuilt binaries
- Download Yocto BSP binary with Greengrass Core from following page:
- Binary:
- 18px <translate> Note:</translate> Source code is not needed for this guide. But, if source code is required, please refer to following:
- Extract downloaded files
- ex.) R-Car Starter Kit Premier(H3)
- Unzip Yocto-v5.9.0-ccpfsk-ggc-h3ulcb-binary.zip -d <working directory>
- ex.) R-Car Starter Kit Premier(H3)
- Download Yocto BSP binary with Greengrass Core from following page:
- Setup SW
- Setup SW (Prepare SD card, Flashing IPL, Booting). Please refer to R-Car/Boards/CCPF-SK/GettingStarted/Linux#SW_Setup
Building the BSP
Required packages
- Install required packages
$ sudo apt-get install gawk wget git-core diffstat unzip texinfo gcc-multilib \ build-essential chrpath socat cpio python3 python3-pip python3-pexpect \ xz-utils debianutils iputils-ping python3-git python3-jinja2 libegl1-mesa \ libsdl1.2-dev pylint3 xterm docker.io
- Refer to Yocto Project Quick Start for more information.
- 18px <translate> Note:</translate>If the OS version of the host PC is earlier than "Ubuntu 20.04", the default gcc version is old, so use "gcc-9/g++-9" or later version.
- Set up initial git configuration
$ git config --global user.email "you@example.com" $ git config --global user.name "Your Name"
Building the BSP
- Create the following script(build.sh) for building
#!/bin/bash BOARD_LIST=("h3ulcb" "m3ulcb" "h3ulcb-ccpf-sk" "m3ulcb-ccpf-sk") TARGET_BOARD=$1 WORK=`pwd`/${TARGET_BOARD}-build repolist=( \ "git://git.yoctoproject.org/poky;74b22db6879b388d700f61e08cb3f239cf940d18" \ "git://git.openembedded.org/meta-openembedded;814eec96c2a29172da57a425a3609f8b6fcc6afe" \ "https://github.com/renesas-rcar/meta-renesas;13fd24957b9acc29a235ee0c7f398fd867f38b47" \ "https://github.com/renesas-rcar/meta-renesas-ccpf;09dd815616cce3a2bdcf8906c0d21403df8b93bd" \ "https://github.com/yhamamachi/meta-rcar-dev-utils;remotes/origin/v5.9.0" ) repolist_ggc=( \ "git://git.yoctoproject.org/meta-virtualization;c4f156fa93b37b2428e09ae22dbd7f5875606f4d" \ "git://git.yoctoproject.org/meta-java;eeb136c64ecaa364d4e332d0182865dc65f2a83b" \ "https://github.com/tkomagata/meta-docker;f8f83a7b15930b74b4af2ae5e7c4c55607fafa86" \ "https://github.com/aws/meta-aws;9979cfa676105cb68cfadfdaeabf044d7c919319" \ "https://github.com/tkomagata/yocto_templateconf;516f8b22b68fc8539cee483a5565ed7665d8e6efd" \ ) _usage () { echo "Usage: $0 \${BOARD_NAME} [release package option]" echo "BOARD_NAME list: " for i in ${BOARD_LIST[@]}; do echo " - $i"; done echo "release package options:" echo " -r: Create core-image-minimal-release" exit } repo_clone () { mkdir -p ${WORK} for repo in ${repolist[@]}; do URL=$(echo $repo | cut -d';' -f1) COMMIT=$(echo $repo | cut -d';' -f2) NAME=${URL##*/} if [[ ! -d "${WORK}/${NAME}" ]]; then git clone ${URL} ${WORK}/${NAME} fi cd ${WORK}/${NAME}; git checkout -B tmp ${COMMIT} done } check_target_board () { if ! `IFS=$'\n'; echo "${BOARD_LIST[*]}" | grep -qx "${TARGET_BOARD}"`; then _usage fi } set_build_type () { BUILD_TARGET=core-image-minimal BUILD_TYPE=bsp repolist=(${repolist[@]} ${repolist_ggc[@]}) } build_yocto () { cd ${WORK} BUILD_DIR=${WORK}/build_${TARGET_BOARD}_${BUILD_TYPE}${RELEASE} rm -rf ${BUILD_DIR}/conf TEMPLATECONF=${WORK}/yocto_templateconf/ggc/rcar-gen3/${TARGET_BOARD}/${BUILD_TYPE}/ \ source poky/oe-init-build-env ${BUILD_DIR} echo "DL_DIR = '${DL_DIR:-${WORK}/yocto_dl_dir}'" >> ${BUILD_DIR}/conf/local.conf echo "SSTATE_DIR = '${SSTATE_DIR:-${WORK}/yocto_sstate_dir}'" >> ${BUILD_DIR}/conf/local.conf echo "${LOCAL_CONF_APPEND}" >> ${BUILD_DIR}/conf/local.conf bitbake-layers add-layer ${WORK}/meta-rcar-dev-utils/meta-rcar-gen3 if [[ "${RELEASE}" != "" ]]; then cp -f ${WORK}/meta-rcar-bsp-release/meta-rcar-gen3/docs/sample/site.conf.sample \ ${BUILD_DIR}/conf/site.conf bitbake-layers add-layer ${WORK}/meta-rcar-bsp-release/meta-rcar-gen3 fi bitbake ${BUILD_TARGET}${RELEASE} } build_32bit_rom_writer () { cd ${WORK} BUILD_32_DIR=${WORK}/build_32 source poky/oe-init-build-env ${BUILD_32_DIR} cp -f ${BUILD_DIR}/conf/* -t ${BUILD_32_DIR}/conf/ echo "MACHINE ??= 'qemuarm'" >> ${BUILD_32_DIR}/conf/local.conf echo "DEFAULTTUNE = 'armv7a'" >> ${BUILD_32_DIR}/conf/local.conf bitbake flash-writer renesas-bsp-rom-writer cp -rf ${BUILD_32_DIR}/tmp/deploy/images/qemuarm/renesas-bsp-rom-writer_32bit \ -t ${BUILD_DIR}/tmp/deploy/release/binary/ipl/ } ## main process ## RELEASE="" check_target_board $@ set_build_type $@ if [[ "$(echo $*' ' | grep ' -r ')" != "" ]]; then repolist+=("https://github.com/yhamamachi/meta-rcar-bsp-release;remotes/origin/v5.9.0") RELEASE=-release fi repo_clone build_yocto if [[ "$(echo $*' ' | grep ' -r ')" != "" ]]; then build_32bit_rom_writer fi
- Build
$ chmod a+x build.sh $ ./build.sh <target_board_name> <release package option> Ex.) h3ulcb build: ./build.sh h3ulcb m3ulcb-ccpf-sk build for release: ./build.sh m3ulcb-ccpf-sk -r
- target_board_name is specified for each board according to the following table:
- Depending on the performance of the host PC, it may take several hours for the build to complete.
- When the build completes successfully, you will see the following output:
NOTE: Tasks Summary: Attempted 5383 tasks of which 5 didn't need to be rerun and all succeeded.
- Check the built images
- The built images are stored in the following:
- <target_board_name>-build/build_<target_board_name>_bsp(-release)/tmp/deploy/images/<target_board_name>/
- Write the images to the SD card
- Write the images to the SD card with reference to Loading kernel and rootfs via eMMC/SD card.
- 18px <translate> Note:</translate> Please replace "core-image-weston" with "core-image-minimal".
Confirmation of Greengrass Core activation
- Turn on the target board
- Insert the SD card into the target board, and connect the LAN cable to it.
- Use a microUSB cable to connect the target board, connect a power supply to it, and connect to serial console.
- The PC will start the terminal software and make a serial connection.
- Power on.
- Short-press SW8 "Power" to switch the board on.
- If the board is attached to the CCPF board, short-press SW4 "Power" instead of SW8.
- Configure U-Boot to boot from SD card
- Refer to the Configure U-Boot to boot from SD card.
- Check that the Greengrass Core is running.
Configure and check AWS IoT Greengrass
In subsequent chapters, the tags will be included in the title as follows.
- Work on the target board (R-Car SK) is described as <Terminal>.
- Work on the AWS Cloud is described as <Web>.
- Work on the host PC is described as <PC>.
- <Web> Create an AWS account
- https://console.aws.amazon.com/console/home
- Create an AWS account and log in to the AWS Management Console as the root user.
- <Web> Creating an IAM user
- Create an IAM user for work with reference to the following.
- https://docs.aws.amazon.com/ja_jp/IAM/latest/UserGuide/id_users_create.html#id_users_create_console
- The following policies should be attached at the time of creation.
- AWSLambda_FullAccess
- IAMFullAccess
- AWSIoTFullAccess
- AWSGreengrassFullAccess
- IAMAccessAnalyzerFullAccess
- 18px <translate> Note:</translate>Be sure to write down the "Access Key ID", "Secret Access Key", and "Password" that are displayed when users access the system. Note that the secret access key and password can only be confirmed at this time.
Warning: These three items are very important information for security reasons, and should be managed with great care.
- Sign out the AWS root user and log in with the IAM user you created.
- https://console.aws.amazon.com/console/home
- <Web> Setting up a region
- Set the desired region from the upper right corner of the screen.
- In this procedure, we will set "Asia Pacific(Tokyo) ap-northeast-1".
- <Web><Terminal> Creating an IoT Core device
- Run "Confirmation of Greengrass Core activation" beforehand and make sure that the terminal can connect to the Internet by connecting a LAN cable.
- <Web> Select "IoT Core" from AWS services.
- <Web> Select "Greengrass" → "Getting started" from the side menu.
- <Web> Press "Set up one core device".
- <Web><Terminal> Follow the instructions on the screen to perform the following tasks.
- <Web> "Step 1: Register a Greengrass core device"
- Enter a core device name of your choice.
- In this procedure, the core device name shall be "R-CarH3SKDevice".
- <Web> "Step 2: Add to a thing group to apply a continuous deployment"
- Check "Enter a new group name" and enter a name of your choice.
- In this procedure, the thing group name shall be "R-CarH3SKDeviceGroup".
- <Terminal> "Step 3: Install the Greengrass Core software"
- "Step 3.1: Install Java on the device"
- No work required as it is included in the image generated by the R-Car SK build.
- "Step 3.2: Configure AWS credentials on the device"
- Execute the following command to set the information to access AWS as an environment variable.
$ export AWS_DEFAULT_REGION=ap-northeast-1 $ export AWS_ACCESS_KEY_ID=<your "Access Key ID"> $ export AWS_SECRET_ACCESS_KEY=<your "Secret Access Key">
- "Step 3.3: Run the installer"
- "Download the installer" requires no work.
- "Run the installer" does not match the path displayed in the web browser, so execute the following command in the terminal.
$ java -Droot="/greengrass/v2" -Dlog.store=FILE -jar /greengrass/v2/alts/init/distro/lib/Greengrass.jar \ --aws-region ap-northeast-1 --thing-name R-CarH3SKDevice --thing-group-name R-CarH3SKDeviceGroup \ --component-default-user ggc_user:ggc_group --provision true --setup-system-service true \ --deploy-dev-tools true
- Replace "R-CarH3SKDevice" and "R-CarH3SKDeviceGroup" with the values set in "Step 1" and "Step 2".
- When the above command is executed, the R-Car SK terminal communicates with AWS IoT and is registered as a Greengrass core device.
- After the command finishes, Greengrass CLI will be deployed to the terminal, and check if the following commands can be executed.
$ /greengrass/v2/bin/greengrass-cli -V
- 18px <translate> Note:</translate>You can check the deployment status in the following log.
$ tail -f /greengrass/v2/logs/greengrass.log
- "Step 3.1: Install Java on the device"
- <Web> "Step 1: Register a Greengrass core device"
- <Web> Add policies to be sent to IoT Core
- 18px <translate> Note:</translate> The examples in this document are intended only for dev environments.
- All devices in your production fleet must have credentials with privileges that authorize only intended actions on specific resources.
- The specific permission policies can vary for your use case. Identify the permission policies that best meet your business and security requirements.
- For more information, refer to Example policies and Security Best practices.
- Add a policy for the Lambda function running on the terminal to send messages to the IoT Core in the AWS cloud.
- Select "IAM" from AWS services.
- Select "Policies" from the side menu.
- Select "Create Policy".
- Select "IoT" for Service, "Publish" for Actions, and "All Resources" for Resources.
- Click on "Next: Tags" and "Next: Review", then enter any "Name" in the "Review policy", and click on the "Create Policy" button.
- In this procedure, the name shall be "R-CarH3SKDevice-IoT-Publish".
- Return to the IAM screen and select "Roles" from the side menu.
- Enter "GreengrassV2TokenExchangeRole" in the search and select the role with the same name.
- Click "Attach Policies", search for the policy you just created, and click "Attach Policy".
- <Terminal> Preparing the execution environment for Lambda functions
- Build an environment to run the sample program on a terminal.
- Execute the following commands.
$ mkdir -p /home/ggc_user $ chown ggc_user:ggc_group /home/ggc_user $ pip3 install numpy
- <Web><PC> Creating a Lambda Function
- Create a Lambda function to deploy to the terminal.
- <PC> Run the following command to create a template for a Lambda function.
$ mkdir -p ~/lambda && touch ~/lambda/lambda_function.py
- <PC> Copy and paste the following code into the lambda_function.py that you created.
import datetime import json import numpy import boto3 class DummyTemperatureSensor(object): def __init__(self, loc=25, scale=1, size=1): self.loc = loc self.scale = scale self.size = size def get_value(self): return numpy.random.normal(self.loc, self.scale, self.size)[0] def lambda_handler(event, context): print(event) # AWS IoT connection iot = boto3.client('iot-data', endpoint_url='https://xxxxxxxxxxxxxxx-ats.iot.ap-northeast-1.amazonaws.com') # get temperature sensor = DummyTemperatureSensor() # set publish paramater topic='topic/sensor/temperature' payload = { "timestamp": str( datetime.datetime.now() ), "temperature": sensor.get_value() } print(payload) # publish to AWS IoT iot.publish( topic=topic, qos=0, payload=json.dumps(payload, ensure_ascii=False) )
- 18px <translate> Note:</translate>The following part of the above code needs to be replaced with its own endpoint.
- https://xxxxxxxxxxxxxxx-ats.iot.ap-northeast-1.amazonaws.com
- The endpoints can be found below.
- <Web> Select "IoT Core" from AWS services.
- <Web> Select "Settings" from the side menu.
- <Web> Refer to "Endpoint" in Device data endpoint.
- <PC> Zip the packages.
- Zip the lambda_function.py and boto3 packages you have created.
$ cd ~/lambda $ sudo docker run --rm -v $(pwd):/var/task amazon/aws-sam-cli-build-image-python3.8:latest \ pip install boto3 -t ./ $ zip -r lambda_artifact.zip ./
- The zip file is copied to a PC that has access to the AWS cloud for uploading to the cloud.
- <Web> Registering the Lambda function
- Register the created Lambda function to the AWS cloud.
- Select "Lambda" from AWS services.
- Select "Functions" from the side menu.
- Select "Create function".
- Check the "Author from scratch" box.
- Give an arbitrary name to the "Function name". In this procedure, "DummyTemperatureSensor" is used.
- Select "Python 3.8" as the Runtime.
- Select "arm64" as the Architecture.
- Other items keep the default values and press "Create Function".
- When the screen changes, from the right side of "Code source", select "Upload from" → ".zip file", and upload → save the zip file you created.
- Select "Actions" → "Publish new version" in the upper right corner and press Publish.
- <Web> Deploying the Lambda function
- Deploy the registered Lambda function to the terminal.
- Select "IoT Core" from AWS services.
- Select "Greengrass" → "Components" from the side menu.
- Click on "Create component".
- Check the "Import Lambda function" box.
- Select the function that you created in "Lambda function".
- Enter "topic/sensor/get" in the "Topic" field of the Event sources.
- Select "AWS IoT Core MQTT" as the "Type" of the Event sources.
- Set the "Memory size" of Container parameters to "64 MB".
- Other items keep the default values and press "Create component".
- When the screen changes, press "Deploy" in the upper right corner.
- Select the group you created for the deployment destination and click "Next".
- Other items keep the default values and press "Next" several times, and press "Deploy" at the last confirmation screen.
- <WEB> <Terminal> Operation check
- Confirm that the function you created will be deployed on the terminal side.
- Also, check the log on the terminal side to see if messages are being received by AWS IoT → terminal.
- <Terminal> Checking the operation of R-Car SK
- Confirm that the Lambda function has been deployed.
- Execute the following command to confirm.
$ /greengrass/v2/bin/greengrass-cli component list
- When you execute the command the following log will be output, and you can see that the deployed function (DummyTemperatureSensor) is displayed in the list.
root@m3ulcb:~# /greengrass/v2/bin/greengrass-cli component list : : Component Name: DummyTemperatureSensor Version: 1.0.0 State: RUNNING Configuration: {"containerMode":"GreengrassContainer","containerParams":{"devices":{},"memorySize":64000.0,"mountROSysfs":false,"volumes":{}},"inputPayloadEncodingType":"json","lambdaExecutionParameters":{"EnvironmentVariables":{}},"maxIdleTimeInSeconds":60.0,"maxInstancesCount":100.0,"maxQueueSize":1000.0,"pinned":true,"pubsubTopics":{"0":{"topic":"topic/sensor/get","type":"IOT_CORE"}},"statusTimeoutInSeconds":60.0,"timeoutInSeconds":3.0}
- Check the log.
- Run the following command to check the log.
$ cd /greengrass/v2/logs/ $ tail -f <name of created function>.log
- Verify that the following log is output.
serviceName=<name of created function>, currentState=RUNNING
- Confirm that the Lambda function has been deployed.
- <Web><Terminal> Checking the operation of the AWS cloud
- <Web> Select "IoT Core" from AWS services.
- <Web> Select "Test" → "MQTT Test Client" from the side menu.
- <Web> Enter "topic/sensor/temperature" in the Topic filter and press "SUBSCRIBE".
- <Web> Enter "topic/sensor/get" in the "Topic name" of "Publish to a topic" and click "Publish.
- 18px <translate> Note:</translate>The default message payload will be garbled on the terminal side, so change it to any alphanumeric text if necessary.
- <Terminal> The message received will be displayed in the log as follows.
root@m3ulcb:/greengrass/v2/logs# tail -f DummyTemperatureSensor.log 2021-12-06T04:50:40.524Z [INFO] (pool-2-thread-38) DummyTemperatureSensor: lambda_function.py:17,{'message': 'AWS IoT ??????????????????????????????'}. {serviceInstance=0, serviceName=DummyTemperatureSensor, currentState=RUNNING} 2021-12-06T04:50:41.172Z [INFO] (pool-2-thread-38) DummyTemperatureSensor: lambda_function.py:31,{'timestamp': '2021-12-06 04:50:41.168002', 'temperature': 27.381898093845034}. {serviceInstance=0, serviceName=DummyTemperatureSensor, currentState=RUNNING} 2021-12-06T04:51:14.939Z [INFO] (pool-2-thread-38) DummyTemperatureSensor: lambda_function.py:17,{'message': 'hello world'}. {serviceInstance=0, serviceName=DummyTemperatureSensor, currentState=RUNNING} 2021-12-06T04:51:14.969Z [INFO] (pool-2-thread-38) DummyTemperatureSensor: lambda_function.py:31,{'timestamp': '2021-12-06 04:51:14.964931', 'temperature': 25.003559249938885}. {serviceInstance=0, serviceName=DummyTemperatureSensor, currentState=RUNNING
- <Web> A message is received in the subscription.