Azure Data Manager for Agriculture でのパートナーと顧客の両方としてのセンサー統合

Data Manager for Agriculture インスタンスへのデータのプッシュを開始できるように、センサー パートナーとして登録するには、次の手順に従います。

手順 1: センサー統合を有効にする

  1. 開始するには、センサー統合を有効にする必要があります。 この手順では、Data Manager for Agriculture インスタンスでのセンサー統合に必要な内部 Azure リソースをプロビジョニングします。 これを行うには、次の armclient コマンドを実行します。
armclient patch /subscriptions/<subscription-id>/resourceGroups/<resource-group-name>/providers/Microsoft.AgFoodPlatform/farmBeats/<datamanager-instance-name>?api-version=2023-06-01-preview "{properties:{sensorIntegration:{enabled:'true'}}}"

サンプル出力:

{
  "id": "/subscriptions/<subscription-id>/resourceGroups/<resource-group-name>/providers/Microsoft.AgFoodPlatform/farmBeats/<datamanager-instance-name>",
  "type": "Microsoft.AgFoodPlatform/farmBeats",
  "sku": {
    "name": "A0"
  },
  "systemData": {
    "createdBy": "<customer-id>",
    "createdByType": "User",
    "createdAt": "2022-03-11T03:36:32Z",
    "lastModifiedBy": "<customer-id>",
    "lastModifiedByType": "User",
    "lastModifiedAt": "2022-03-11T03:40:06Z"
  },
  "properties": {
    "instanceUri": "https://<datamanager-instance-name>.farmbeats.azure.net/",
    "provisioningState": "Succeeded",
    "sensorIntegration": {
      "enabled": "True",
      "provisioningState": "**Creating**"
    },
    "publicNetworkAccess": "Enabled"
  },
  "location": "eastus",
  "name": "myfarmbeats"
}
  1. 上記のジョブが完了するまでに数分かかることがあります。 ジョブの状態を把握するには、次の armclient コマンドを実行します。
armclient get /subscriptions/<subscription-id>/resourceGroups/<resource-group-name> /providers/Microsoft.AgFoodPlatform/farmBeats/<datamanager-instance-name>?api-version=2023-06-01-preview
  1. 完了したかどうかを確認するには、強調表示されている属性を確認します。 これは、前の手順の "作成中" から "成功" に更新されているはずです。 センサー統合が有効であることを示す属性は、sensorIntegration オブジェクト 内の provisioningState です。

サンプル出力:

{
  "id": "/subscriptions/<subscription-id>/resourceGroups/<resource-group-name>/providers/Microsoft.AgFoodPlatform/farmBeats/<datamanager-instance-name>",
  "type": "Microsoft.AgFoodPlatform/farmBeats",
  "sku": {
    "name": "A0"
  },
  "systemData": {
    "createdBy": "<customer-id>",
    "createdByType": "User",
    "createdAt": "2022-03-11T03:36:32Z",
    "lastModifiedBy": "<customer-id>",
    "lastModifiedByType": "User",
    "lastModifiedAt": "2022-03-11T03:40:06Z"
  },
  "properties": {
    "instanceUri": "https://<customer-host-name>.farmbeats.azure.net/",
    "provisioningState": "Succeeded",
    "sensorIntegration": {
      "enabled": "True",
      "provisioningState": "**Succeeded**"
    },
    "publicNetworkAccess": "Enabled"
  },
  "tags": {
    "usage": "<sensor-partner-id>"
  },
  "location": "eastus",
  "name": "<customer-id>"
}

センサー統合のプロビジョニング状態が完了すると、センサー統合オブジェクトを作成できます。

手順 2: センサー パートナー統合の作成

センサー パートナー統合の作成手順を実行して、顧客とプロバイダーを接続する必要があります。 integrationId は、後でセンサーの作成に使用します。

API ドキュメント: センサー パートナーの統合 - 作成または更新

手順 3: センサー データ モデルを作成する

センサー データ モデルを使用して、送信されるテレメトリのモデルを定義します。 センサーによって送信されるすべてのテレメトリは、このデータ モデルに従って検証されます。

API ドキュメント: センサー データ モデル - 作成または更新

サンプル テレメトリ

{
	"pressure": 30.45,
	"temperature": 28,
	"name": "sensor-1"
}

対応するセンサー データ モデル

{
  "type": "Sensor",
  "manufacturer": "Some sensor manufacturer",
  "productCode": "soil m",
  "measures": {
    "pressure": {
      "description": "measures soil moisture",
      "dataType": "Double",
      "type": "sm",
      "unit": "Bar",
      "properties": {
        "abc": "def",
        "elevation": 5
      }
    },
	"temperature": {
      "description": "measures soil temperature",
      "dataType": "Long",
      "type": "sm",
      "unit": "Celsius",
      "properties": {
        "abc": "def",
        "elevation": 5
      }
    },
	"name": {
      "description": "Sensor name",
      "dataType": "String",
      "type": "sm",
      "unit": "none",
      "properties": {
        "abc": "def",
        "elevation": 5
      }
    }
  },
  "sensorPartnerId": "sensor-partner-1",
  "id": "sdm124",
  "status": "new",
  "createdDateTime": "2022-01-24T06:12:15Z",
  "modifiedDateTime": "2022-01-24T06:12:15Z",
  "eTag": "040158a0-0000-0700-0000-61ee433f0000",
  "name": "my sdm for soil moisture",
  "description": "description goes here",
  "properties": {
    "key1": "value1",
    "key2": 123.45
  }
}

手順 4: センサーを作成する

対応する統合 ID とセンサー データ モデル ID を使用してセンサーを作成します。 DeviceId と HardwareId は省略可能なパラメータです。必要に応じて、[デバイス - 作成または更新] を使用してデバイスを作成できます。

API ドキュメント: センサー - 作成または更新

手順 5: IoTHub 接続文字列を取得する

IoTHub 接続文字列を取得して、作成したセンサーのプラットフォームにセンサー テレメトリをプッシュします。

API ドキュメント: センサー - 接続文字列の取得

手順 6: IoT Hub を使用してデータをプッシュする

IoT Hub デバイス SDK を使用して、接続文字列を使用してテレメトリをプッシュします。

すべてのセンサー テレメトリ イベントにおいて、"timestamp" は必須プロパティであり、ISO 8601 形式 (YYYY-MM-DDTHH:MM:SSZ) である必要があります。

これで、各センサーについて提供されたそれぞれの接続文字列を使用して、すべてのセンサーに対しセンサー データのプッシュを開始する準備ができました。 ただし、センサー データは、手順 3 で作成したセンサー データ モデルで定義されている形式で送信する必要があります。 次のテレメトリ スキーマの例を参照してください。

{
	"timestamp": "2022-02-11T03:15:00Z",
	"bar": 30.181,
	"bar_absolute": 29.748,
	"bar_trend": 0,
	"et_day": 0.081,
	"humidity": 55,
	"rain_15_min": 0,
	"rain_60_min": 0,
	"rain_24_hr": 0,
	"rain_day": 0,
	"rain_rate": 0,
	"rain_storm": 0,
	"solar_rad": 0,
	"temp_out": 58.8,
	"uv_index": 0,
	"wind_dir": 131,
	"wind_dir_of_gust_10_min": 134,
	"wind_gust_10_min": 0,
	"wind_speed": 0,
	"wind_speed_2_min": 0,
	"wind_speed_10_min": 0
} 

次のステップ

  • API のテストはここで行います。