2021/12/13に販売開始されたArmadillo-IoT G4上のアプリケーションをNode-REDで開発しようと思ったので、メモ代わりに記事を書いてます。
Armadillo-IoT G4とは
Armadillo-IoT G4は、IoT向けのゲートウェイ開発・運用用として開発されているLinuxマシンでエッジAIにも対応できるNPUや映像用のエンコーダー/デコーダーも積んでいます。
なのでコロナ禍でよく店頭に見かけるようになった顔を認識して熱を測って、それをリアルタイムに映像で表示する装置(一般的になんて名前??)みたいなものを作れるスペックを持っています。(もっと高度なこともできそうですが)
公式ドキュメントも充実していてファーストステップも迷わず行えました。
アットマークテクノのArmadilloシリーズは、実運用やそれを見込んだPoCを行う際に使用されるのを想定している感じです。RaspberyPiでPocして、本番はArmadilloなんて流れは結構ありそうですね。
Armadillo Base OSとは
Armadillo-IoT G4には標準で、Armadillo Base OSというAlpine LinuxベースのOSがインストールされています。アプリケーションはコンテナ上で動作させる想定で設計されていて、Dockerとコマンド体系が近いPodmanがコンテナ管理ツールとしてインストールされています。
Armadillo-IoT G4では、OSやBootloaderが多重化されていて、アップデート時のエラーなどで破損した場合などはもう一方でフォローできるようになっています。
Node-REDをインストールする
Armadillo-IoT G4の初期設定は、公式ドキュメントに従って行いました。
Node-REDのインストール方法はいくつか種類がありますが、Dockerイメージを使う方法とnpmでインストールする方法両方でやってみます。
ちなみに標準ではOverlayFSが有効なため、以下のコマンドで無効にしないと再起動したときにすべて消えてしまいます。
# podman_switch_storage --disk
Dockerイメージでインストール
Node-REDは、Dockerイメージが公開されているので、それを使ってインストールします。
# podman run -it -p 1880:1880 -v node_red_data:/data --name mynode-red docker.io/nodered/node-red
コマンドを実行すると以下のように表示され、Node-REDが起動します。
[32951.009668] IPv6: ADDRCONF(NETDEV_CHANGE): vethadf8afcd: link becomes ready
[32951.016806] IPv6: ADDRCONF(NETDEV_CHANGE): eth0: link becomes ready
[32951.023416] cni-podman0: port 1(vethadf8afcd) entered blocking state
[32951.029819] cni-podman0: port 1(vethadf8afcd) entered disabled state
[32951.036326] device vethadf8afcd entered promiscuous mode
[32951.041773] cni-podman0: port 1(vethadf8afcd) entered blocking state
[32951.048137] cni-podman0: port 1(vethadf8afcd) entered forwarding state
> node-red-docker@2.1.4 start /usr/src/node-red
> node $NODE_OPTIONS node_modules/node-red/red.js $FLOWS "--userDir" "/data"
31 Dec 02:36:48 - [info]
Welcome to Node-RED
===================
31 Dec 02:36:48 - [info] Node-RED version: v2.1.4
31 Dec 02:36:48 - [info] Node.js version: v14.18.2
31 Dec 02:36:48 - [info] Linux 5.10.52-1-at arm64 LE
31 Dec 02:36:49 - [info] Loading palette nodes
31 Dec 02:36:51 - [info] Settings file : /data/settings.js
31 Dec 02:36:51 - [info] Context store : 'default' [module=memory]
31 Dec 02:36:51 - [info] User directory : /data
31 Dec 02:36:51 - [warn] Projects disabled : editorTheme.projects.enabled=false
31 Dec 02:36:51 - [info] Flows file : /data/flows.json
31 Dec 02:36:51 - [info] Server now running at http://127.0.0.1:1880/
31 Dec 02:36:51 - [warn]
---------------------------------------------------------------------
Your flow credentials file is encrypted using a system-generated key.
If the system-generated key is lost for any reason, your credentials
file will not be recoverable, you will have to delete it and re-enter
your credentials.
You should set your own key using the 'credentialSecret' option in
your settings file. Node-RED will then re-encrypt your credentials
file using your chosen key the next time you deploy a change.
---------------------------------------------------------------------
31 Dec 02:36:51 - [info] Starting flows
31 Dec 02:36:51 - [info] Started flows
PC等のブラウザからArmadillo-IoT G4のIPアドレス、ポート番号にアクセスすればNode-REDの編集画面が表示されます。
http://{IPアドレス}:1880
npmでインストール
まずはコンテナを作ります。
私は使い慣れているDebianのイメージがArmadillo-IoT G4向けに用意されている公式から公開されていたので、それを使用しました。
# wget https://armadillo.atmark-techno.com/files/downloads/armadillo-iot-g4/container/at-debian-image-dockerfile-#v1.0.1.tar.gz
# tar xzf at-debian-image-dockerfile-v1.0.1.tar.gz
# cd at-debian-image-dockerfile-v1.0.1
# podman_switch_storage --disk
# podman build -t at-debian-image:latest .
以下のコマンドでコンテナを起動します。
H/Wリソースや機能に自由にアクセスできるように--privileged
と--volume=/dev:/dev
のオプション等いろいろ付けています。
# podman run -itd --name=mynodered \
--env=XDG_RUNTIME_DIR=/tmp \
--env=LD_LIBRARY_PATH=/opt/firmware/usr/lib/aarch64-linux-gnu \
--env=QT_QPA_PLATFORM=wayland \
--volume=/sys:/sys \
--volume=/dev:/dev \
--volume=/run/udev:/run/udev \
--volume=/opt/firmware:/opt/firmware \
--privileged \
-p 1880:1880 \
localhost/at-debian-image:latest /bin/bash
必要なものをインストールするため、以下のコマンドでコンテナに入ります。
# podman exec -it mynodered /bin/bash
コンテナ内でNode-REDの必要なものをインストールします。Nodejsのバージョン管理ツールとしてnを使用しています。
# apt update
# apt install -y wget
# apt install -y npm
# npm install n -g
# apt purge -y npm
# n 14.18.2
コンテナ内でNode-REDをnpmインストールします。
# npm install -g --unsafe-perm node-red
以下のコマンドでNode-REDを起動すれば、Dockerの場合と同様にアクセスできました。
# node-red
ホストからコンテナに対して、リソースを開放しているので、USBシリアルを使用するオムロン環境センサーにもNode-REDからアクセスできました。センサー値が取得できています。