コマンドラインツール¶
FIWARE Device Simulator には、./bin に次の2つのコマンドラインツールが含まれています :
- メインの FIWARE Device Simulator コマンドラインツール :
fiwareDeviceSimulatorCLI - FIWARE Device Simulator Transpiler コマンドライン・ツール :
fiwareDeviceSimulatorTranspilerCLI
それぞれをカバーしてみましょう。
FIWARE Device Simulator のコマンドラインツール¶
FIWARE Device Simulator のコマンドラインツールが ./bin ディレクトリにあり、具体的なファイルは、fiwareDeviceSimulatorCLI と呼ばれます。
FIWARE Device Simulator のコマンドライン・ツールを実行するには、次のコマンドを実行します :
./bin/fiwareDeviceSimulatorCLI
これにより、FIWARE Device Simulator のコマンドライン・ツールのヘルプが表示され、正しく使用する方法を説明します :
Usage: fiwareDeviceSimulatorCLI [options]
Options:
-h, --help output usage information
-V, --version output the version number
-c, --configuration <configuration-file-path> Absolute or relative path (from the root of the Node application) to the device simulator configuration file (mandatory)
-d, --delay <milliseconds> The delay in milliseconds for future updates when the number of update requests waiting for response is bigger than the value set with the -m option (defaults to 1 second if -m is set and -d is not set, it has no effect if -m is not set)
-m, --maximumNotRespondedRequests <requests> The maximum number of update requests not responded before applying delay
-p, --progressInfoInterval <milliseconds> The interval in milliseconds to show progress information for fast-forward simulation
-s, --silent No progress information will be output by the console
-w, --dweet <dweet-configuration> Configuration information to publish the simulation progress information in dweet.io (it must be an object containing a 'name' property for the dweet thing and optionally an 'apiKey' property in case the thing is locked, for example: -w "{\"name\": \"fds:Test:001\"}")
-l, --timeline <google-sheets-configuration Configuration information to publish the scheduled updates into Google Sheets for its visualization as a Timeline Google Chart in Freeboard.io (it must be an object including a 'sheetKey' property for the long Google Sheet key where the data will be stored, a 'credentialsPath' property for the path to the Google generated credentials (more information about how to generate this credentials is available in the documentation), a 'dateFormat' property for the date format used by Google Sheets in your locale according to the dateformat NPM package (for further information, please visit: https://github.com/felixge/node-dateformat#mask-options) and a 'refreshInterval' property for the minimum interval in milliseconds the scheduled updates will be refreshed in the associated Google Sheet (i.e., the Google Sheet will be udpated in the next progress information tick (see the -p option) once this interval has passed since the last refresh), for example: -l "{\"sheetKey": \"1rGEpgC38kf_AC7FFlM71wev_-fKeuPKEOTvVY9I7e2Y", \"credentialsPath\": \"FIWARE Device Simulator-f11816817451.json\", \"dateFormat": \"dd/mm/yyyy HH:MM:ss\", \"refreshInterval\": 15000}")
-f, --from <from-date> The start date to begin the fast-forward simulation (if not set, the current time will be used)
-t, --to <to-date> The end date to stop the fast-forward simulation (if not set, the fast-forward will progress to the future and never end)
-x, --all <cli-configuration-file-path> Absolute or relative path (from the root of the Node application) to the command line tool configuration file (a JSON file including all the previous configuration options) (the long option names are used as properties of the JSON object) (options set in the comand line prevail)
ご覧のとおり、FIWARE Device Simulator のコマンドラインツールでは、実行するシミュレーションの詳細を示すシミュレーション設定ファイルへのパスが必要です。このシミュレーション構成ファイルは、FIWARE Device Simulator ツールの基礎であり、このドキュメントの別のセクションで詳しく説明しています。
一方、FIWARE Device Simulator のコマンドラインツールは、早送りシミュレーション機能をサポートしているため、ある日から特定の日付(過去または将来)にシミュレーションを実行することができます。時刻は自動的に from 日付から to 日付まで、更新エンティティに更新され、それに応じてデバイス更新が送信されます。
早送りシミュレーションの場合、-m と -d オプションを使用して1秒間に Context Broker のインスタンスに送信されるリクエストの数を制御できます。通常 -m は十分な設定です。リクエストを送信している Context Broker または IoT Agent が処理できる場合は、-m オプションに渡される値を大きくしてスループットを上げます。
シミュレーションの進捗についての情報を入手したい場合は、進捗情報の更新の間にミリ秒数を渡す -p オプションを使用してください。コンソールが進捗情報を出力しないようにするには、-s オプションを設定します。シミュレーションの進行状況を、"dweeting thing" に設定した name を使用して、dweet.io で直接視覚化するか、Freeboard.io でシミュレーションしたい場合は、-w オプションを使用できます。FIWARE Device Simulator Dashboard を複製して Dweet データソースを "dweeting thing"の name に更新して、シミュレーション進捗情報を視覚化するか、いくつかのエンティティの属性に割り当てられた値の進化を視覚化したい場合は、Dweet データソースを "dweeting thing"の name に更新する、FIWARE Device Simulator Dashboard を使用してください。例としていくつかの属性を持つ2つのエンティティを含めました。それに応じて関連するデータソースを更新してください。
前述の -p オプションと組み合わせて、"simulations DNA"を視覚化することもできます。これは属性であり、エンティティは将来の実行のためにシミュレーション・スケジュールを更新します。それを行うには、次の手順に従ってください :
- Google で認証されたら、Google Sheets のウェブサイトにアクセスしてください
- 新しい Google スプレッドシートを作成するには、ページの右下にある
+ボタンをクリックします - この新しい Google シートドキュメントの URL は、次のようなものになります :
https://docs.google.com/spreadsheets/d/1SvLfPobfq8VM0eJZweEIty8SosEs8ODmarV8EwmZPks/edit#gid=0。Googleシートの
https://docs.google.com/spreadsheets/d/と/edit#gid=0セクション間のドキュメント・キーをメモしてください - この Google シートのドキュメントを共有し、ページの右上にある
Shareボタンをクリックすると読み込みアクセスだけでなく、編集や書き込みのリンクからアクセスできます - Google のデベロッパ・コンソールのプロジェクト・セクションに移動します
- たとえば、以下のような新しいプロジェクトを作成します :
FIWARE Device Simulator。もちろん、他の名前を選択することもできます。新しいプロジェクトが作成されると、そのページは新しいプロジェクトのコンソールに移動します Google Sheets APIを検索し、それをクリックし、ENABLEリンクをクリックして有効にします- ページの右上にある
Go to Credentialsボタンをクリックします Where will you be calling the API from?の選択で、Web server (たとえば、 node.js, Tomcat)オプションを選択しますWhat data will you be accessing?オプションから、Application data (access data belonging to your own application)オプションを有効にしますAre you using Google App Engine or Google Compute Engine?オプションから、シミュレータを実行する場合を除いて、No, I'm not using them.オプションを有効にしますWhat credentials do I need?ボタンをクリックしますService account name入力フィールドで、サービス名を入力します。例えば、FIWARE Device Simulatorです。もちろん、他の名前を選択することもできますRoleの選択で、ロールを選択します。Google シートの所有者の場合は、Project->Ownerを選択します。Google シートの所有者でない場合は、Project->Editorを選択しますKey typeセクションで、JSON (recommended)オプションが有効になっていない場合は、有効にしますContinueボタンをクリックします。資格情報を含む JSON ファイルのダウンロードが開始されます。スケジュールされた更新を視覚化できるようにシミュレーションを実行するために必要なので、安全な場所に保存してください- FIWARE Device Simulator Dashboard (timeline)をクローンします
- Dweetデータソースを "dweeting thing"の
nameに更新してください。コマンドラインツールの-wオプションで渡されます。例えば :fds:Test:1234。 - 前の手順で取得したデータ、Dweet thing name、Google シートのドキュメント・キー、Google の資格情報をパスをパスする、
-p,-w,-lオプションを使用して、シミュレータ・コマンドライン・ツールを実行します。例えば、./bin/fiwareDeviceSimulatorCLI -c simulation-5s-2-attributes.json -p 5000 -w "{\"name\": \"fds:Test:1234\"}" -s -l "{\"sheetKey\": \"1SvLfPobfq8VM0eJZweEIty8SorEs8ODmarV8EwmZPks\", \"credentialsPath\": \"FIWARE Device Simulator-f11816817451.json\", \"dateFormat\": \"dd/mm/yyyy HH:MM:ss\", \"refreshInterval\": 15000}"です。タイムライン・オプションの一部として、データ形式が含まれていることに注意してください。Google スプレッドシートでは具体的なロケールに応じて異なるフォーマットが使用されるため、これが必要です。使用する必要があるものを確認するには、Google シートのドキュメントに移動し、フォーマットメニューの項目をクリックし、番号メニュー項目をクリックし、このマスク・オプションに従って使用する日付の時刻形式を確認します:https://github.com/felixge/node-dateformat#mask-options - シミュレーション・スケジュールのアップデートが
SCHEDULED UPDATES TIMELINEウィジェットに表示されます。青いバーの上にカーソルを置くと、スケジュールされたアップデートに関する詳細情報が表示されます。このアップデートがスケジュールされた日時、エンティティ名、および更新される属性名が含まれます
Google シート・ドキュメントは、スケジュールされた更新を保存するためにのみ使用され、個別のシミュレーション実行の間に再利用することができます。スケジューリングされたタイムラインの視覚化を使って、時系列シミュレーションを同時に実行するには、それらのそれぞれについて具体的な Google シート・ドキュメントが必要です。これらの資格情報に権限がある場合は、同じGoogle資格情報を再利用して異なるGoogleシートドキュメントを更新できるといっても過言ではありません。ターゲットの Google シートドキュメントは、4 で説明したリンクで共有されます。
FIWARE Device Simulator CLI ツールはロギングに logops パッケージを使用するため、ロギングレベルは LOGOPS_LEVEL 環境変数を使用して設定できます。一方、ロギング・フォーマットは、LOGOPS_FORMAT 環境変数を使用して設定することができます。
注 : deasync Node packageに、エンティティ属性参照(これは ${{<entityId>}{<attributeName>}} です) と組み合わせて属性関数補間を使用する早送りシミュレーションを中断すると思われる、問題があります。 セグメンテーション・フォールトエラーが発生します。この問題を回避する策は、参照する必要のある属性の値を更新し、その値を attribute-function-interpolator インスタンスからアクセスできるグローバル状態変数に割り当てるグローバル状態変数の使用です。
FIWARE Device Simulator transpiler コマンドラインツール¶
FIWARE Device Simulator transpiler command line toolは、./bin ディレクトリにあり、具体的なファイルは、fiwareDeviceSimulatorTranspilerCLI と呼ばれます。
FIWARE Device Simulator transpilerコマンドラインツールを実行するには、次のコマンドを実行します :
./bin/fiwareDeviceSimulatorTranspilerCLI
これは、FIWARE Device Simulator の transpiler コマンドツールのヘルプを表示します。これは、適切に使用する方法を学ぶためのガイドです :
Usage: fiwareDeviceSimulatorTranspilerCLI [options]
Options:
-h, --help output usage information
-V, --version output the version number
-c, --configuration <configuration-file-path> Absolute or relative path (from the root of the Node application) to the device simulator configuration input file (mandatory)
-o, --output <output-file-path> Absolute or relative path (from the root of the Node application) to the output device simulator configuration file (mandatory)
FIWARE Device Simulator transpiler のコマンドラインツールを使用すると、シミュレーション構成ファイルに含まれる import ディレクティブを解決して、最終的なシミュレーション構成ファイルを実行することができます。
FIWARE Device Simulator のコマンドラインツールは、シミュレーションを実行する前に入力シミュレーション構成ファイルを転送することに注意することが重要です。この追加のコマンドライン・ツールは、トランスパイレーション・プロセス (transpilation process) が実行され、除外され、最終的に生成されたシミュレーション構成ファイルが予期されたものであることを確認するためのヘルパーとしてのみ意味を持ちます。
import ディレクティブの詳細は、Simulation configuration file セクションに記載されています。