アセットのキャリブレーションオフセットを調べて、各測定値に加算してください。 この例は2の値に20のオフセットを加え、correctedValue: 22を生成します。
Prerequisites
例の共有前提条件を、defaultプロファイルと factory-mqtt エンドポイントも含めて満たします。 デバッグにはYAMLを使い、本番管理にはAzure CLIまたはBicepを使いましょう。
既存の内蔵レジストリエンドポイント「 default」を活用してください。
環境変数については、AIO_INSTANCE_NAMEとRESOURCE_GROUPを既存のインスタンス名とリソースグループ名に設定してください。 Bicep の場合は、CUSTOM_LOCATION_NAME に既存のカスタム ロケーション名も設定してください。
状態ストアライターのクロックをブローカーと同期させます。 測定値を公開する前に、キャリブレーション記録を入力する際に +OK 応答が成功していることを確認します。
エンリッチメントを使って、アプリケーションがステートストアで管理するキャリブレーション記録を読み取ってください。 この参照は処理中に利用可能なコンテキストを使用しますが、必ずしも読み取りがサンプリングされた時点で有効だったコンテキストではありません。 その場合は、タイムスタンプでコンテキストを照合してください。
キャリブレーション グラフを配置する:
運用体験でインスタンスを開き、データフローグラフを選択してください>データ フロー グラフの作成。
グラフに add-calibration 名を付け、 default プロファイルを選択します。
factory-mqttという名前のソースを、エンドポイントfactory/readingsとトピックsourceを使って追加してください。
default というマップ変換を、レジストリエンドポイント calibrate の azureiotoperations/graph-dataflow-map:1.0.0 を使って追加します。
マップ変換設定で、状態ストアのキーfactory-calibration as calibration、Match 入力$source.assetId、$context.assetId、そして Match 式$1 == $2 の順にデータセットを追加します。
以下のマップルールを追加してください:
| 入力 (順番に) |
Output |
Expression |
* |
* |
空のままにします |
value、$context(calibration).offset |
correctedValue |
$1 + $2 |
エンドポイントfactory/calibratedとトピックdestinationを使って、factory-mqttという宛先を追加します。
source → calibrate → destination と接続し、[保存] を選択して有効になったグラフをデプロイします。
これらの完全なグラフ プロパティを graph.json として保存します。 コマンドは既存の default プロファイルを使用します。
{
"mode": "Enabled",
"nodes": [
{
"name": "source",
"nodeType": "Source",
"sourceSettings": {
"endpointRef": "factory-mqtt",
"dataSources": ["factory/readings"]
}
},
{
"name": "calibrate",
"nodeType": "Graph",
"graphSettings": {
"registryEndpointRef": "default",
"artifact": "azureiotoperations/graph-dataflow-map:1.0.0",
"configuration": [
{
"key": "rules",
"value": "{\n \"datasets\": [\n {\n \"key\": \"factory-calibration as calibration\",\n \"inputs\": [\"$source.assetId\", \"$context.assetId\"],\n \"expression\": \"$1 == $2\"\n }\n ],\n \"map\": [\n {\"inputs\": [\"*\"], \"output\": \"*\"},\n {\n \"inputs\": [\"value\", \"$context(calibration).offset\"],\n \"output\": \"correctedValue\",\n \"expression\": \"$1 + $2\"\n }\n ]\n}\n"
}
]
}
},
{
"name": "destination",
"nodeType": "Destination",
"destinationSettings": {
"endpointRef": "factory-mqtt",
"dataDestination": "factory/calibrated"
}
}
],
"nodeConnections": [
{ "from": { "name": "source" }, "to": { "name": "calibrate" } },
{ "from": { "name": "calibrate" }, "to": { "name": "destination" } }
]
}
az iot ops dataflowgraph apply \
--name add-calibration \
--instance $AIO_INSTANCE_NAME \
--resource-group $RESOURCE_GROUP \
--config-file graph.json
このテンプレートを main.bicepとして保存してください。 既存のインスタンス、カスタムロケーション、 default プロファイルを参照します。
param aioInstanceName string
param customLocationName string
resource aioInstance 'Microsoft.IoTOperations/instances@2026-07-01' existing = {
name: aioInstanceName
}
resource customLocation 'Microsoft.ExtendedLocation/customLocations@2021-08-31-preview' existing = {
name: customLocationName
}
resource defaultDataflowProfile 'Microsoft.IoTOperations/instances/dataflowProfiles@2026-07-01' existing = {
parent: aioInstance
name: 'default'
}
resource dataflowGraph 'Microsoft.IoTOperations/instances/dataflowProfiles/dataflowGraphs@2026-07-01' = {
parent: defaultDataflowProfile
name: 'add-calibration'
extendedLocation: {
name: customLocation.id
type: 'CustomLocation'
}
properties: {
mode: 'Enabled'
nodes: [
{
name: 'source'
nodeType: 'Source'
sourceSettings: {
endpointRef: 'factory-mqtt'
dataSources: [ 'factory/readings' ]
}
}
{
name: 'calibrate'
nodeType: 'Graph'
graphSettings: {
registryEndpointRef: 'default'
artifact: 'azureiotoperations/graph-dataflow-map:1.0.0'
configuration: [
{
key: 'rules'
value: '{\n "datasets": [\n {\n "key": "factory-calibration as calibration",\n "inputs": ["$source.assetId", "$context.assetId"],\n "expression": "$1 == $2"\n }\n ],\n "map": [\n {"inputs": ["*"], "output": "*"},\n {\n "inputs": ["value", "$context(calibration).offset"],\n "output": "correctedValue",\n "expression": "$1 + $2"\n }\n ]\n}\n'
}
]
}
}
{
name: 'destination'
nodeType: 'Destination'
destinationSettings: {
endpointRef: 'factory-mqtt'
dataDestination: 'factory/calibrated'
}
}
]
nodeConnections: [
{
from: { name: 'source' }
to: { name: 'calibrate' }
}
{
from: { name: 'calibrate' }
to: { name: 'destination' }
}
]
}
}
az deployment group create \
--resource-group $RESOURCE_GROUP \
--template-file main.bicep \
--parameters aioInstanceName="$AIO_INSTANCE_NAME" customLocationName="$CUSTOM_LOCATION_NAME"
Important
Kubernetes 配置マニフェストの使用は運用環境ではサポートされていないため、デバッグとテストにのみ使用する必要があります。
以下のマニフェストを add-calibration.yamlとして保存してください。
apiVersion: connectivity.iotoperations.azure.com/v1
kind: DataflowGraph
metadata:
name: add-calibration
namespace: azure-iot-operations
spec:
profileRef: default
mode: Enabled
nodes:
- name: source
nodeType: Source
sourceSettings:
endpointRef: factory-mqtt
dataSources: [factory/readings]
- name: calibrate
nodeType: Graph
graphSettings:
registryEndpointRef: default
artifact: azureiotoperations/graph-dataflow-map:1.0.0
configuration:
- key: rules
value: |
{
"datasets": [
{
"key": "factory-calibration as calibration",
"inputs": ["$source.assetId", "$context.assetId"],
"expression": "$1 == $2"
}
],
"map": [
{"inputs": ["*"], "output": "*"},
{
"inputs": ["value", "$context(calibration).offset"],
"output": "correctedValue",
"expression": "$1 + $2"
}
]
}
- name: destination
nodeType: Destination
destinationSettings:
endpointRef: factory-mqtt
dataDestination: factory/calibrated
nodeConnections:
- from: { name: source }
to: { name: calibrate }
- from: { name: calibrate }
to: { name: destination }
kubectl apply -f add-calibration.yaml
読み取りを送信する前に、この合成NDJSONレコードを状態ストアキー factory-calibrationに書き込んでください。
SETで state-store 手続きを使いましょう。
{"assetId":"line-1","offset":2}
この項目を factory/readings に公開します:
{"assetId":"line-1","value":20}
このペイロードは factory/calibrated で受信される想定です。 このマップは元のフィールドを保持し、20 + 2を追加します:
{"assetId":"line-1","value":20,"correctedValue":22}
このグラフは数値オフセット付きの対応するキャリブレーションレコードを前提としています。 本番環境で使用する前に、コンテキスト欠損への対処方法を定義し、ルックアップエラーを監視してください。この例には無効なコンテキスト用のルートは含まれていません。
関連するコンテンツ