你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn

传感器集成作为 Azure Data Manager for Agriculture 中的合作伙伴和客户

按照以下步骤注册为传感器合作伙伴,以便你可以开始将数据推送到农业数据管理器实例。

步骤 1:启用传感器集成

  1. 在启动传感器集成之前,应启用传感器集成。 此步骤为用于农业数据管理器实例的传感器集成预配所需的内部 Azure 资源。 可以通过运行以下 armclient 命令来完成此操作。
armclient patch /subscriptions/<subscription-id>/resourceGroups/<resource-group-name>/providers/Microsoft.AgFoodPlatform/farmBeats/<datamanager-instance-name>?api-version=2023-04-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-04-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 中心 推送数据

使用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
} 

后续步骤