在用於農業的 Azure 資料管理員中,同時以合作夥伴和客戶的身分進行感應器整合
請遵循下列步驟以感應器合作夥伴的身分進行註冊,以便開始將資料推送至用於農業的資料管理員執行個體。
步驟 1:啟用感應器整合
- 必須先啟用感應器整合,才能起始感應器。 此步驟會佈建必要的內部 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"
}
- 上述作業可能需要幾分鐘的時間才能完成。 若要掌握作業的狀態,應執行下列 armclient 命令:
armclient get /subscriptions/<subscription-id>/resourceGroups/<resource-group-name> /providers/Microsoft.AgFoodPlatform/farmBeats/<datamanager-instance-name>?api-version=2023-06-01-preview
- 若要確認作業是否已完成,請查看醒目提示的屬性。 狀態應該從上一步中的「建立中」更新為「已成功」。 指出感應器整合已啟用的此屬性,是由在 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:建立感應器
使用對應的整合識別碼和感應器資料模型識別碼建立感應器。 DeviceId 和 HardwareId 是選擇性參數,如有需要,您可以使用裝置 - 建立或更新以建立裝置。
API 文件:感應器 - 建立或更新
步驟 5:取得 IoTHub 連接字串
取得 IoTHub 連接字串,以將感應器遙測推送至所建立感應器的平台。
API 文件:感應器 - 取得連接字串
步驟 6:使用 IoT 中樞推送資料
使用 IoT 中樞裝置 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。