AWS 文档 AWS SDK示例 GitHub 存储库中还有更多SDK示例
本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。
与 AWS SDK或BatchPutAssetPropertyValue
一起使用 CLI
以下代码示例演示如何使用 BatchPutAssetPropertyValue
。
- CLI
-
- AWS CLI
-
向资产属性发送数据
以下
batch-put-asset-property-value
示例将功率和温度数据发送到由属性别名标识的资产属性。aws iotsitewise batch-put-asset-property-value \ --cli-input-json
file://batch-put-asset-property-value.json
batch-put-asset-property-value.json
的内容:{ "entries": [ { "entryId": "1575691200-company-windfarm-3-turbine-7-power", "propertyAlias": "company-windfarm-3-turbine-7-power", "propertyValues": [ { "value": { "doubleValue": 4.92 }, "timestamp": { "timeInSeconds": 1575691200 }, "quality": "GOOD" } ] }, { "entryId": "1575691200-company-windfarm-3-turbine-7-temperature", "propertyAlias": "company-windfarm-3-turbine-7-temperature", "propertyValues": [ { "value": { "integerValue": 38 }, "timestamp": { "timeInSeconds": 1575691200 } } ] } ] }
输出:
{ "errorEntries": [] }
有关更多信息,请参阅《物联网 SiteWise 用户指南》 SiteWise API中的使用物 AWS 联网摄取数据。AWS
-
有关API详细信息,请参阅 “BatchPutAssetPropertyValue AWS CLI
命令参考”。
-
- Java
-
- SDK适用于 Java 2.x
-
注意
还有更多相关信息 GitHub。查找完整示例,学习如何在 AWS 代码示例存储库
中进行设置和运行。 /** * Sends data to the SiteWise service. * * @param assetId the ID of the asset to which the data will be sent. * @param tempPropertyId the ID of the temperature property. * @param humidityPropId the ID of the humidity property. * @return a {@link CompletableFuture} that represents a {@link BatchPutAssetPropertyValueResponse} result. The * calling code can attach callbacks, then handle the result or exception by calling * {@link CompletableFuture#join()} or {@link CompletableFuture#get()}. * <p> * If any completion stage in this method throws an exception, the method logs the exception cause and keeps it * available to the calling code as a {@link CompletionException}. By calling * {@link CompletionException#getCause()}, the calling code can access the original exception. */ public CompletableFuture<BatchPutAssetPropertyValueResponse> sendDataToSiteWiseAsync(String assetId, String tempPropertyId, String humidityPropId) { Map<String, Double> sampleData = generateSampleData(); long timestamp = Instant.now().toEpochMilli(); TimeInNanos time = TimeInNanos.builder() .timeInSeconds(timestamp / 1000) .offsetInNanos((int) ((timestamp % 1000) * 1000000)) .build(); BatchPutAssetPropertyValueRequest request = BatchPutAssetPropertyValueRequest.builder() .entries(Arrays.asList( PutAssetPropertyValueEntry.builder() .entryId("entry-3") .assetId(assetId) .propertyId(tempPropertyId) .propertyValues(Arrays.asList( AssetPropertyValue.builder() .value(Variant.builder() .doubleValue(sampleData.get("Temperature")) .build()) .timestamp(time) .build() )) .build(), PutAssetPropertyValueEntry.builder() .entryId("entry-4") .assetId(assetId) .propertyId(humidityPropId) .propertyValues(Arrays.asList( AssetPropertyValue.builder() .value(Variant.builder() .doubleValue(sampleData.get("Humidity")) .build()) .timestamp(time) .build() )) .build() )) .build(); return getAsyncClient().batchPutAssetPropertyValue(request) .whenComplete((response, exception) -> { if (exception != null) { logger.error("An exception occurred: {}", exception.getCause().getMessage()); } }); }
-
有关API详细信息,请参阅 “AWS SDK for Java 2.x API参考 BatchPutAssetPropertyValue” 中的。
-
操作
CreateAsset