Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 5 Next »

Table of contents


Overview


Here we will explain the steps to build the iPRO Camera SDK app using the Azure IoT Edge container and check its operation. Also, in this tutorial, the SDK installation directory is described as ${SDK_DIR}.

This tutorial only supports SDK ver.2.00 or later. Please note that it cannot be used with SDK ver.2.00 or lower.

Operation confirmation procedure


Create a new IoT Edge Solution on Visual Studio Code

The following describes the case where the sample app to be referenced is skeleton_sample_app for the C version, additional_info_sample_app for the Python version, and test_app for the Edge Solution to be created. Please note that the Edge Solution name must be in all lowercase letters.

Description of C version/Python version application

The operation confirmation method for both the C version and Python version of the application is almost the same. I will explain using the C version as an example, and the different parts will be explained as appropriate. Also, the application path is as follows, so please read it as appropriate.

C version app path
${SDK_DIR}/src/adamapp

Python version app path
${SDK_DIR}/src/adamapp-py

Launch Visual Studio Code directly under [SDK folder].

cd ${SDK_DIR}
code .

 

Copy the ”${SDK_DIR}/src/adamapp/skeleton_sample_app” folder into the same folder.

Rename the copied folder to test_app.

Rename the "skeleton_sample_app" folder in [copied folder]/container/modules to test_app.

Right-click the folder (test_app) copied from Visual Studio Code's EXPLORER and select "Find in Folder..." to display the SEARCH window.

Search for "skeleton_sample_app" and replace everything with "test_app". The targets are as follows.

  • ${SDK_DIR}\src\adamapp\test_app\container\deployment.template.json

  • ${SDK_DIR}\src\adamapp\test_app\container\modules\test_app\module.json

Enter the information for the container registry to which you want to push the created image.

Log in to Azure portal(Cloud Computing Services | Microsoft Azure) and select the container registry you want to target. The screen below is an example.

20240124-110900.png

Display "Settings" - "Access Keys" from the left menu.

20240124-110901.png

Based on the information displayed, enter the following:

  • ${SDK_DIR}\src\adamapp\test_app\container\deployment.template.json
    Enter “registryCredentials” in the above file as follows. "Container Registry Name" is the "Registry Name" of Azure Portal in lower case (same as the string before .azurecr.io in "Login Server").

    "registryCredentials": {
      "[container registry name]": {
        "username": "$CONTAINER_REGISTRY_USERNAME_[container registry name]",
        "password": "$CONTAINER_REGISTRY_PASSWORD_[container registry name]",
        "address": "[login server]"
      }
    }

    For example, if the container registry name is “iprocv5xcontainerregistry” and the container registry login server is “iprocv5xcontainerregistry.azurecr.io”, it will be as follows.

     

  • ${SDK_DIR}\src\adamapp\test_app\container\modules\test_app\module.json
    Enter “repository” in the above file as follows.

    "repository": "[login server]/test_app"

    If the container registry login server is "iprocv5xcontainerregistry.azurecr.io", it will be as follows.

  • ${SDK_DIR}\src\adamapp\test_app\container
    Create an .env file in the directory, write the container registry user name and password, and save it.

    CONTAINER_REGISTRY_USERNAME_[container registry name]=[user name]
    CONTAINER_REGISTRY_PASSWORD_[container registry name]=[password]

    An example is shown below.

    20240124-110902.png
20240123-103105.png

Coding the app

Now code as you like on Visual Studio Code. If you copy skeleton_sample_app etc., the source file name will be the one before copying (skeletonSampleApp.cpp for skeleton_sample_app), so please rename it if necessary. Below is an example.

Before
${SDK_DIR}\src\adamapp\test_app\skeletonSampleApp.cpp
After
${SDK_DIR}\src\adamapp\test_app\testApp.cpp

 

Please also modify SRC_FILES in Makefile as necessary. Below is an example.

${SDK_DIR}\src\adamapp\test_app\Makefile
Before
SRC_FILES=	skeletonSampleApp.cpp
After
SRC_FILES=	testApp.cpp

Please also modify PROG_NAME in Makefile, APPLICATION in configuration.txt, and APPLICATION_NAME in deployment.template.json as necessary. Below is an example.

${SDK_DIR}\src\adamapp\test_app\Makefile
Before
PROG_NAME= SkeletonSampleApp
After
PROG_NAME= TestApp

${SDK_DIR}\src\adamapp\test_app\configuration.txt
Before
APPLICATION	SkeletonSampleApp
After
APPLICATION	TestApp

${SDK_DIR}\src\adamapp\test_app\container\deployment.template.json
Before
"APPLICATION_NAME=SkeletonSampleApp"
After
"APPLICATION_NAME=TestApp"

  

Build the app

When building, use the built-in functionality of the Azure IoT extension. In Visual Studio Code's Explorer Right-click on "${SDK_DIR}\src\adamapp\test_app\container\deployment.template.json" to display the build menu.

Select “Build IoT Edge Solution”. This operation only performs a build.

For your first build, you will be asked to log in to your container registry. The following is an example when the container registry is "iprocv5xcontainerregistry.azurecr.io".

ERROR: failed to solve: iprocv5xcontainerregistry.azurecr.io/cadamappbase:0.0.2: failed to authorize: failed to fetch anonymous token: unexpected status: 401 Unauthorized

At this time, enter the following command on the Visual Studio Code terminal.

docker login iprocv5xcontainerregistry.azurecr.io

Then enter the Username and Password that are displayed. Enter the container registry user name and password.

20240124-110903.png
Username: [user name]
Password: [password]

Login Succeeded is displayed, the login is successful.

Next, right-click "${SDK_DIR}\src\adamapp\test_app\container\deployment.template.json" and Select “Build and Push IoT Edge Solution”. This operation builds and pushes to the container registry.

The build is done by running Docker buildx build as described in the Dockerfile.arm64v8 file located under “${SDK_DIR}\src\adamapp\test_app\”. The environment name (arm64v8) after Dockerfile. is the architecture selected in the above step. (You can see the current architecture at the bottom of Visual Studio Code)

20240124-110904.png

Check the built image

ビルドが成功すれば、そのイメージは docker images で存在が確認できます。下記は一例です。

$ docker images
REPOSITORY                                                             TAG             IMAGE ID       CREATED          SIZE
iprocv5xcontainerregistry.azurecr.io/azureiot/test_app  0.0.5-arm64v8   f1772ccfed77   35 minutes ago   91.4MB

   

カメラへのデプロイ

左下の「AZURE IOT HUB」以下からデプロイしたいデバイスを選択し、右クリックして「1つのIoT Edgeに配置」を選択することで、カメラへデプロイされます。デプロイする内容は
${SDK_DIR}\src\adamapp\test_app\container\deployment.template.json に従います。

20240124-110905.png

Visual Studio Codeの上部にプルダウンが表示されるので下記を選択します。
${SDK_DIR}\src\adamapp\test_app\container\config\deployment.arm64v8.json

20240124-110906.png

Deployment Succeeded と表示されたらデプロイ成功です。

20240124-110907.png

Azure上でランタイム状態の確認

Azure Portal にログインして、IoT Hub - IoT Edge画面で追加したIoT Edgeデバイスを選択します。

20240124-110908.png

画面下部に表示されているデプロイしたアプリのランタイムの状態を確認します。「running」になっていればエラーが発生していない状態です。「エラー」と表示されている場合は選択するとエラーメッセージが表示されるので、デバッグしてください。

20240124-110909.png

デプロイしてしばらくはランタイムの状態は「エラー」になります。「running」になるまで時間が必要です。ただし、「running」になるまでに必要な時間はアプリに依存します。

アプリの動作確認

カメラと接続可能なPCで下記URLにアクセスします。

http://[カメラのローカルIPアドレス]/cgi-bin/cadam.cgi?methodName=getApplicationList

カメラの応答が表示されます。下記は一例です。

{
    "appCount": "1",
    "limitationMode": "Shared",
    "maxAppCount": "9",
    "appList": [
        {
            "appType": "0",
            "funcId": "0000FF01",
            "appInfo": {
                "installId": "124B569A",
                (中略)
}

"installId": "124B569A",と表示されている情報を使います。

下記のURLにアクセスします。

http://[カメラのローカルIPアドレス]/cgi-bin/cadam.cgi?Language=1&methodName=sendDataToAdamApplication&installId=[インストールID]&s_appDataType=0&s_appData=e3tMYW5ndWFnZToxfX0%3D

カメラのIPアドレスが192.168.100.33、"installId": "124B569A",の場合は下記になります。

http://192.168.100.33/cgi-bin/cadam.cgi?Language=1&methodName=sendDataToAdamApplication&installId=124B569A&s_appDataType=0&s_appData=e3tMYW5ndWFnZToxfX0%3D

下記のようにアプリ動作を確認できます。下記はskeleton_sample_appを動作させた例です。

20240124-110910.png

Checkpoints if things don't work in the WSL environment


If it does not work in WSL environment, please check the following.

  • The following must be enabled in the Visual Studio Code "LOCAL" extension

    • Dev Containers

    • Remote - SSH, Remote - SSH: Editing Configuration FIles, Remote - Tunnels, Remote Development, Remote Explorer

    • WSL

  • The following must be enabled in Visual Studio Code's "WSL: UBUNTU-20.04" extension:

    • Azure Account

    • Azure IoT Edge

    • Azure IoT Hub

  • "WSL: Ubuntu-20.04" is displayed at the bottom left of the Visual Studio Code screen.

  • If permission denied is displayed in Build IoT Edge Solution, check whether the current user has access rights to the target directory.

    sudo chown -r ipro:ipro [development directory]
    ※ipro:ipro is an example, so please set it according to each environment.

    Run the above to change the owner.

 

  • No labels