Technical Articles
Raspberry PIへの Internet of Things Edge Platform のセットアップ
はじめに
pi@raspberrypi:~ $ uname -a Linux raspberrypi 5.10.17-v7l+ #1403 SMP Mon Feb 22 11:33:35 GMT 2021 armv7l GNU/Linux |
JREのインストール
pi@raspberrypi:~ $ sudo apt-get update |
pi@raspberrypi:~ $ sudo apt-get install openjdk-8-jre |
pi@raspberrypi:~ $ java -version
openjdk version “1.8.0_212”
OpenJDK Runtime Environment (build 1.8.0_212-8u212-b01-1+rpi1-b01)
OpenJDK Client VM (build 25.212-b01, mixed mode)
|
Edgeゲートウェイのセットアップ
pi@raspberrypi:~ $ mkdir IOTCHCP
pi@raspberrypi:~ $ cd IOTCHCP
pi@raspberrypi:~/IOTCHCP $ unzip ../IOTCHCP69_0-70002561.ZIP
Archive: ../IOTCHCP69_0-70002561.ZIP
creating: documentation-4.69.0/
inflating: documentation-4.69.0/all-4.69.0-fortify.pdf
inflating: documentation-4.69.0/common-4.69.0-fortify.pdf
inflating: documentation-4.69.0/iot.cf.edge.platform.coap.pdf
inflating: documentation-4.69.0/iot.cf.edge.platform.file.pdf
inflating: documentation-4.69.0/iot.cf.edge.platform.modbus.pdf
inflating: documentation-4.69.0/iot.cf.edge.platform.mqtt.pdf
inflating: documentation-4.69.0/iot.cf.edge.platform.opc.ua.pdf
inflating: documentation-4.69.0/iot.cf.edge.platform.rest.pdf
inflating: documentation-4.69.0/iot.cf.edge.platform.sigfox.pdf
inflating: documentation-4.69.0/iot.cf.edge.platform.snmp.pdf
inflating: gateway-4.69.0.zip
inflating: sdk-4.69.0.zip
inflating: SIGNATURE.SMF
pi@raspberrypi:~/IOTCHCP $
|
このディレクトリに更にgatewayというフォルダを作り、その中にgateway-4.69.0.zipを展開します。
pi@raspberrypi:~/IOTCHCP $ mkdir gateway
pi@raspberrypi:~/IOTCHCP $ cd gateway
pi@raspberrypi:~/IOTCHCP/gateway $ unzip ../gateway-4.69.0.zip
pi@raspberrypi:~/IOTCHCP/gateway $ ls
adapters gateway-upgrade.jar plugins
build.bat merge.bat upgrade.bat
build.sh merge.sh upgrade.sh
config migrate.bat version.json
configuration migrate.sh
gateway-upgrade-migration.jar org.eclipse.osgi.jar
pi@raspberrypi:~/IOTCHCP/gateway $
|
そしてBuildを行います。今回はRESTゲートウェイを使用しますので下記のように
pi@raspberrypi:~/IOTCHCP/gateway $ ./build.sh REST
Build script … starting
PARAMETRS: REST
Merge script … starting
WARN: Custombundles dir is NOT present in system
Plugin configuration … starting
Removing unnecessary files … starting
pi@raspberrypi:~/IOTCHCP/gateway $
|
build.shの引数にRESTを指定してビルドします。

https://xxxxxxx-xxxx-xxxxx-xxxx-xxxxxx.xxxx.cp.iot.sap/yyyyyy-yyyyyy-yyyyyy-yyyyyy-yyyyyyyyyy/iot/cockpit/#/tenant/zzzzzzzzzz
上で色を変えた部分を <HOSTNAME>,<INSTANCENAME>,<TENANTNAME>とします。
<HOSTNAME> = xxxxxxx-xxxx-xxxxx-xxxx-xxxxxx.xxxx.cp.iot.sap
<INSTANCENAME> = yyyyy-yyyyyy-yyyyyy-yyyyyy-yyyyyyyyy
<TENANTNAME> = zzzzzzzzzz

まず9行目のcnf:connectionStringの部分の部分の127.0.0.1を<HOST_NAME>で置換します。
<cnf:connectionString>failover:(nio+ssl://<HOST_NAME>:61616?daemon=true&soTimeout=60000&verifyHostName=true)?initialReconnectDelay=5000</cnf:connectionString> |
次は23行目付近、<cnf:coreconnetion>タグで囲まれた中の<cnf:address>タグの記述を変更します。

<cnf:address>https:/<HOSTNAME>/<INSTANCENAME>/iot/core/api/v1/tenant/<TENANTNAME></cnf:address> |


<cnf:gateway gatewayAlternateId=”EDGERESTGATEWAYONRPI”>
|
pi@raspberrypi:~/IOTCHCP/gateway/config/services $ vi sap.NettyConfiguration.cfg
# Enables a Netty server
enabled = true
# Host name or IP address to identify a specific network interface on which to listen
host = localhost
# TCP/IP port on which the server listens for connections
port = 8699
# Expose service on https
enableSSL = false
|
pi@raspberrypi:~/IOTCHCP/gateway/config/services $ vi sap.RestAdapterConfiguration.cfg
# Enable/Disable the device authorization checks
useDeviceAuth = false
|

pi@raspberrypi:~/IOTCHCP/gateway/config $ mkdir certificates
pi@raspberrypi:~/IOTCHCP/gateway/config/certificates $ cd certificates
pi@raspberrypi:~/IOTCHCP/gateway/config/certificates $ mv $HOME/gateway-registration-certificate.json ./
|
Edgeゲートウェイの起動
pi@raspberrypi:~/IOTCHCP/gateway $ ./gateway.sh
(中略)
234 18:12:43,986 [Start Level: Equinox Container: 073cb859-f660-4e54-bafe-1bb28ccef272] INFO (KeepAliveStarter:64) – *** BUNDLE 2 EVENT for com.sap.iotservices.gateway.command-cache-service_4.69.0[239] – ID=239
234 18:12:44,279 [DiscoveryManager] INFO (DiscoveryManager:62) – Initialization successfully finished, start loading API endpoint
234 18:12:44,280 [DiscoveryManager] INFO (DiscoveryManager:71) – API endpoint loaded, start network configuration
234 18:12:44,280 [DiscoveryManager] INFO (DiscoveryManager:75) – Network configuration performed, retrieving the network nodes
234 18:12:44,280 [DiscoveryManager] INFO (DiscoveryManager:78) – Nodes successfully retrieved, start node configuration
234 18:12:44,280 [DiscoveryManager] INFO (DiscoveryManager:642) – +————– Gateway Initialization Complete ———————+
|

オプション:エッジゲートウェイを自動起動にする
この末端に置くシステムというのはエンタープライズのシステムと違い、管理者が常時近くにいるわけではないということがほとんどかと思います。私は元々組み込みシステムのエンジニアでもあったのですが、このような環境のシステムで求められるのは、問題が発生したときに現地にいるあまりコンピューターに詳しくない方でも対応できることでした。ただし、詳しくない方ができることというのは限られます。特にLinuxを操作しろというのは難しいでしょう。ただ、電源ボタンを押して再起動してくださいということくらいはできるはずです。
ということで、Raspberry PIの電源を入れたときに自動的にエッジゲートウェイが起動するように設定します。
[Unit] Description=SAP IoT Edge Gateway(REST) After=syslog.target[Service] Type=simple WorkingDirectory=/home/pi/IOTCHCP/gateway ExecStart=/home/pi/IOTCHCP/gateway/gateway.sh TimeoutStopSec=5 StandardOutput=null[Install] WantedBy = multi-user.target |
*Working DirectoryとExecStartは環境に応じて書き換える必要があります。
pi@raspberrypi:~ $ sudo mv iotedgegateway.service /etc/systemd/system pi@raspberrypi:~ $ sudo systemctl daemon-reload pi@raspberrypi:~ $ sudo systemctl start iotedgegateway pi@raspberrypi:~ $ sudo systemctl status iotedgegateway 2021-05-13 16:55:57 raspberrypi systemd[1]: Started SAP IoT Edge Gateway(R pi@raspberrypi:~ $ sudo systemctl stop iotedgegateway |
正常に起動できたかは sudo systemctl status iotedgegateway で確認できます。
動作していることが確認できたら一旦停止させます。これはsudo systemctl stop iotedgegatewayで行います。
これでサービス化は出来ましたが、自動起動にはなっていません。自動起動に設定するには
pi@raspberrypi:~ $ sudo systemctl enable iotedgegateway |
を実行します。Raspberry PIを再起動させてsudo systemctl status iotedgegatewayを実行して確認してみましょう。Activeになっていれば成功です。
まとめとポイント
RESTのEdge gatewayをRaspberry PIにセットアップし、動作させてみました。
ここでゲートウェイの選択のポイントをご紹介します。
RESTゲートウェイとMQTTゲートウェイはCloud側にも用意されています。そしてEdge側にも同じMQTTゲートウェイとRESTゲートウェイが用意されています。これには違いが有り、Cloud上のゲートウェイはすべてクライアント証明書による認証が必須です。対してEdge側のゲートウェイは認証方法を選択することが可能で、認証なしということも可能です。これはEdgeゲートウェイはそれなりにセキュリティが確保された同一ネットワーク上に存在する機器からアクセスされるという前提があるためです。それに対しCloudゲートウェイはインターネット上へのアクセスとなるためセキュリティ担保に何らかの機構が必要となり、それでクライアント証明書によるアクセスを要求しています。
Edgeゲートウェイは使用するセンサー、接続する機器が通信機能を有しているものの、証明書を使用した通信が機能的に出来ないという場合に有用です。実際にIoTサービスに接続するのはEdgeゲートウェイであり、それはOnboarding Certificateにより機器の認証がされている状態となります。Edgeゲートウェイ間とセンサー・機器の間のセキュリティを担保すれば良いのです。プライベートな無線LANネットワークで良い場合もありますし、そこにもクライアント証明書による認証を使用するかは要件や機器の仕様次第です。
次回はひょんなことから触ることになったIchigo Jam(+Mix Juice)をこのRaspberryPI上のRESTゲートウェイを介してSAP IoT services for SAP BTP for the Cloud Foundry Environmentにデータを送ってみようと思います。