AWS SDK 또는 CLI와 GetAssetPropertyValue 함께 사용 - AWS SDK 코드 예제

Doc AWS SDK 예제 GitHub 리포지토리에서 더 많은 SDK 예제를 사용할 수 있습니다. AWS

기계 번역으로 제공되는 번역입니다. 제공된 번역과 원본 영어의 내용이 상충하는 경우에는 영어 버전이 우선합니다.

AWS SDK 또는 CLI와 GetAssetPropertyValue 함께 사용

다음 코드 예제는 GetAssetPropertyValue의 사용 방법을 보여 줍니다.

CLI
AWS CLI

자산 속성의 현재 값을 검색하는 방법

다음 get-asset-property-value 예시에서는 풍력 터빈 자산의 현재 총 전력을 검색합니다.

aws iotsitewise get-asset-property-value \ --asset-id a1b2c3d4-5678-90ab-cdef-33333EXAMPLE \ --property-id a1b2c3d4-5678-90ab-cdef-66666EXAMPLE

출력:

{ "propertyValue": { "value": { "doubleValue": 6890.8677520453875 }, "timestamp": { "timeInSeconds": 1580853000, "offsetInNanos": 0 }, "quality": "GOOD" } }

자세한 내용은 AWS IoT SiteWise 사용 설명서Querying current asset property values를 참조하세요.

Java
SDK for Java 2.x
참고

GitHub에 더 많은 내용이 있습니다. AWS 코드 예시 리포지토리에서 전체 예시를 찾고 설정 및 실행하는 방법을 배워보세요.

/** * Fetches the value of an asset property. * * @param propId the ID of the asset property to fetch. * @param assetId the ID of the asset to fetch the property value for. * @return a {@link CompletableFuture} that represents a {@link Double} 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<Double> getAssetPropValueAsync(String propId, String assetId) { GetAssetPropertyValueRequest assetPropertyValueRequest = GetAssetPropertyValueRequest.builder() .propertyId(propId) .assetId(assetId) .build(); return getAsyncClient().getAssetPropertyValue(assetPropertyValueRequest) .handle((response, exception) -> { if (exception != null) { logger.error("Error occurred while fetching property value: {}.", exception.getCause().getMessage()); throw (CompletionException) exception; } return response.propertyValue().value().doubleValue(); }); }
JavaScript
SDK for JavaScript (v3)
참고

GitHub에 더 많은 내용이 있습니다. AWS 코드 예시 리포지토리에서 전체 예시를 찾고 설정 및 실행하는 방법을 배워보세요.

import { GetAssetPropertyValueCommand, IoTSiteWiseClient, } from "@aws-sdk/client-iotsitewise"; import { parseArgs } from "node:util"; /** * Describe an asset property value. * @param {{ entryId : string }} */ export const main = async ({ entryId }) => { const client = new IoTSiteWiseClient({}); try { const result = await client.send( new GetAssetPropertyValueCommand({ entryId: entryId, // The ID of the Gateway to describe. }), ); console.log("Asset property information retrieved successfully."); return result; } catch (caught) { if (caught instanceof Error && caught.name === "ResourceNotFound") { console.warn( `${caught.message}. The asset property entry could not be found. Please check the entry id.`, ); } else { throw caught; } } };
Python
SDK for Python (Boto3)
참고

GitHub에 더 많은 내용이 있습니다. AWS 코드 예시 리포지토리에서 전체 예시를 찾고 설정 및 실행하는 방법을 배워보세요.

class IoTSitewiseWrapper: """Encapsulates AWS IoT SiteWise actions using the client interface.""" def __init__(self, iotsitewise_client: client) -> None: """ Initializes the IoTSitewiseWrapper with an AWS IoT SiteWise client. :param iotsitewise_client: A Boto3 AWS IoT SiteWise client. This client provides low-level access to AWS IoT SiteWise services. """ self.iotsitewise_client = iotsitewise_client self.entry_id = 0 # Incremented to generate unique entry IDs for batch_put_asset_property_value. @classmethod def from_client(cls) -> "IoTSitewiseWrapper": """ Creates an IoTSitewiseWrapper instance with a default AWS IoT SiteWise client. :return: An instance of IoTSitewiseWrapper initialized with the default AWS IoT SiteWise client. """ iotsitewise_client = boto3.client("iotsitewise") return cls(iotsitewise_client) def get_asset_property_value( self, asset_id: str, property_id: str ) -> Dict[str, Any]: """ Gets the value of an AWS IoT SiteWise Asset Property. :param asset_id: The ID of the asset. :param property_id: The ID of the property. :return: A dictionary containing the value of the property. """ try: response = self.iotsitewise_client.get_asset_property_value( assetId=asset_id, propertyId=property_id ) return response["propertyValue"] except ClientError as err: if err.response["Error"]["Code"] == "ResourceNotFoundException": logger.error( "Asset %s or property %s does not exist.", asset_id, property_id ) else: logger.error( "Error getting asset property value. Here's why %s", err.response["Error"]["Message"], ) raise
  • API 세부 정보는 AWS SDK for Python (Boto3) API 참조GetAssetPropertyValue를 참조하세요.