R-Car/Boards/Yocto-Gen3/Azure IoT Edge/v5.5.0

From eLinux.org
< R-Car‎ | Boards/Yocto-Gen3‎ | Azure IoT Edge
Revision as of 23:47, 20 December 2021 by H-yamagu (talk | contribs) (Introduction)
Jump to: navigation, search

Introduction

This page describes how to build the images to connect to the Azure IoT Hub on the R-Car, and run the sample module.

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) v2.0 OK
CCPF + R-Car Starter Kit Premier(H3) v2.0 OK
R-Car Starter Kit Pro(M3) v1.0 OK
R-Car Starter Kit Pro(M3) v3.0 OK
CCPF + R-Car Starter Kit Pro(M3) v1.0 OK
CCPF + R-Car Starter Kit Pro(M3) v3.0 OK

Set up in the Azure

  1. Create an Azure account
    Create an Azure account with reference to https://azure.microsoft.com/en-us/free/.
  2. Create an Azure IoT Hub
    Create an Azure IoT Hub with reference to Create an IoT hub.
  3. Register an Azure Device
    Access https://portal.azure.com/ and select the IoT Hub you created in the previous step.
    Select "IoT Edge" under "Device Management" in the side menu, and then press "+ Add IoT Edge Device".
    Azure-device-1.png
    Then, set an arbitrary name for "Device ID" and click "Save" without changing the other settings.
    Finally, select "IoT Edge" among "Device Management" in the side menu, and press the device ID you created to check the "Primary Connection String".
    (The "Primary Connection String" is used in the "Procedure on the target board" section.)
    Azure-device-3.png
  4. Add the Azure module
    Add the Simulated Temperature Sensor module with reference to Deploy a module.

Build

  1. Install the 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
    
  2. Set up initial git configuration
    $ git config --global user.email "you@example.com"
    $ git config --global user.name "Your Name"
    
  3. 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}
    
    # Commit ID
    POKY_COMMIT=6ebb33bdaccaeadff0c85aab27acf35723df00d8
    META_OE_COMMIT=c38d2a74f762a792046f3d3c377827b08aade513
    META_RENESAS_COMMIT=0fe77668f5d9a31a5d10449988c3d8fb8dc475c5
    META_RENESAS_CCPF_COMMIT=b49b57d6e68d5cda70aefbed34e06903484c573b
    META_VIRTUALIZATION_COMMIT=92cd3467502bd27b98a76862ca6525ce425a8479
    META_DOCKER_COMMIT=1ca1b5caf6f373dcc49db82dce50f4d8ab9f25cd
    META_RUST_COMMIT=7ff669d8cedd83a2d3efb73073a63b0a7efffddc
    META_IOTEDGE_COMMIT=06a968a4a662dc5c26aac8d72738767ed72aef52
    
    Usage () {
        echo "Usage: $0 \${TARGET_BOARD_NAME}"
        echo "BOARD_NAME list: "
        for i in ${BOARD_LIST[@]}; do echo "  - $i"; done
        exit
    }
    
    # Check Param.
    if ! `IFS=$'\n'; echo "${BOARD_LIST[*]}" | grep -qx "${TARGET_BOARD}"`; then
        Usage
    fi
    
    mkdir -p ${WORK}
    cd ${WORK}
    
    # Clone basic Yocto layers in parallel
    git clone git://git.yoctoproject.org/poky &
    git clone git://git.openembedded.org/meta-openembedded &
    git clone git://github.com/renesas-rcar/meta-renesas &
    git clone git://git.yoctoproject.org/meta-virtualization &
    git clone git://github.com/tkomagata/meta-docker &
    git clone git://github.com/meta-rust/meta-rust &
    git clone git://github.com/tkomagata/meta-iotedge &
    if [ "${TARGET_BOARD}" = "h3ulcb-ccpf-sk" ] || [ "${TARGET_BOARD}" = "m3ulcb-ccpf-sk" ]; then
        git clone git://github.com/renesas-rcar/meta-renesas-ccpf &
    fi
    
    # Wait for all clone operations
    wait
    
    # Switch to proper branches/commits
    cd ${WORK}/poky
    git checkout -b tmp ${POKY_COMMIT}
    cd ${WORK}/meta-openembedded
    git checkout -b tmp ${META_OE_COMMIT}
    cd ${WORK}/meta-renesas
    git checkout -b tmp ${META_RENESAS_COMMIT}
    cd ${WORK}/meta-virtualization
    git checkout -b tmp ${META_VIRTUALIZATION_COMMIT}
    cd ${WORK}/meta-docker
    git checkout -b tmp ${META_DOCKER_COMMIT}
    cd ${WORK}/meta-rust
    git checkout -b tmp ${META_RUST_COMMIT}
    cd ${WORK}/meta-iotedge
    git checkout -b tmp ${META_IOTEDGE_COMMIT}
    if [ "${TARGET_BOARD}" = "h3ulcb-ccpf-sk" ] || [ "${TARGET_BOARD}" = "m3ulcb-ccpf-sk" ]; then
        cd ${WORK}/meta-renesas-ccpf
        git checkout -b tmp ${META_RENESAS_CCPF_COMMIT}
    fi
    
    TEMPLATECONF=${WORK}/meta-iotedge/conf/machine/${TARGET_BOARD}/bsp/
    
    cd ${WORK}
    source poky/oe-init-build-env ${WORK}/build
    
  4. Run build.sh
    $ chmod a+x build.sh
    $ ./build.sh <target_board_name>
    
    target_board_name is specified for each board according to the following table:
    R-car-sk-target-board-name.png
  5. Build
    $ cd <target_board_name>
    $ source poky/oe-init-build-env
    $ bitbake core-image-minimal
    
    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 4704 tasks of which 31 didn't need to be rerun and all succeeded.
    
  6. Check the built images
    The built images are stored in the following:
     <target_board_name>/build/tmp/deploy/images/<target_board_name>/
  7. 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".

Run the sample module

  1. Procedure on the target board
    1. R-Car SK の起動
      1. R-Car SK に uSD カードを挿入して、LANケーブルを接続する。
      2. USB デバッグシリアルケーブルを PC と接続して、AC 電源を投入する。
      3. PC 側では、ターミナルソフトを起動して、シリアル接続を行う。
      4. 電源をONにする。
        R-Car SK の POWER SW(SW8) を押下する。
        CCPFが付いている場合は、CCPF基板のPOWER SW(SW4)を押下する。
    2. SD ブートを U-Boot で設定
      SDブートの設定方法は、Configure U-Boot to boot from SD cardを参照。
    3. IoT Hub 接続設定
      IoT Hub へ接続するための設定を追加する。
      1. 「/etc/iotedge/config.yaml」に書き込み権限を追加する。
        $ chmod +w /etc/iotedge/config.yaml
        
      2. 「/etc/iotedge/config.yaml」内の「device_connection_string」の「<ADD DEVICE CONNECTION STRING HERE>」をプライマリ接続文字列に書き換える。
        $ vi /etc/iotedge/config.yaml
          device_connection_string: "<ADD DEVICE CONNECTION STRING HERE>" ← ★
        
        18px <translate> Note:</translate>プライマリ接続文字列はRegister an Azure Deviceを参照。
      3. 「/etc/iotedge/config.yaml」の書き込み権限を削除する。
        $ chmod -w /etc/iotedge/config.yaml
        
      4. 設定内容を反映させるため、デーモンを再起動する。
        $ systemctl restart iotedge
        
    4. IoT Edge Device の動作確認
      端末側でiotedge daemon Active となっていることを確認する。
      $ systemctl status iotedge --no-page
      
      Azure-status-no-page.png
      端末側でモジュールがデプロイされ running 状態になっていることを確認する。
      18px <translate> Note:</translate>デプロイされるまでには数分時間がかかるため、注意すること。
      $ iotedge list
      
      Azure-list.png
  2. Azure IoT Explorer での動作手順
    Azure IoT Explorer で端末からメッセージが送信されていることを確認する。
    1. Azure IoT Explorer をダウンロード / インストール
      下記サイトからインストーラーをダウンロードする。
      https://github.com/Azure/azure-iot-explorer/releases
      18px <translate> Note:</translate>最新版のAzure.IoT.Explorer.preview.0.14.7 では、テレメトリが受信できなかったため、Azure.IoT.Explorer.preview.0.14.1 を使用
    2. Azure IoT Explorer を起動する
    3. IoT Hub の iothubowner 接続文字列を取得する。
      Azure ポータルの「IoT Hub」→ 作成した IoT Hub を選択し、サイドメニューから「共有アクセスポリシー」→「iothubowner」→「プライマリ接続文字列」をコピーする。
      Azure-iot-exp-1.png
    4. IoT Hub を IoT Explorer に登録する
      Azure IoT Explorerのサイドメニューから「IoT hubs」を選択し、「+ Add connection」を押下する。
      「Connection string」に上記でコピーした「iothubowner 接続文字列」をペーストして、「Save」を押下する。
    5. テレメトリを確認する
      サイドメニューの「Telemetry」を選択して、「Start」を押下する。
      しばらくすると以下のようにテレメトリが表示される。
      Azure-iot-exp-3.png