AWS IoT TwinMaker쿠키 팩토리 예제 시계열 커넥터 - AWS IoT TwinMaker

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

AWS IoT TwinMaker쿠키 팩토리 예제 시계열 커넥터

쿠키 팩토리 Lambda 함수의 전체 코드는 에서 사용할 수 있습니다. GitHub 커넥터를 구성 요소 유형에 연결한 후에도 구현을 업데이트할 수 있지만 AWS IoT TwinMaker와(과) 통합하기 전에 Lambda 커넥터를 확인하는 것이 좋습니다. Lambda 콘솔에서 또는 AWS CDK에서 로컬로 Lambda 함수를 테스트할 수 있습니다. Lambda 함수 테스트에 대한 자세한 내용은 Lambda 함수 테스트 및 애플리케이션 로컬 테스트를 참조하십시오. AWS CDK

쿠키 팩토리 구성 요소 유형의 예

구성 요소 유형에서는 구성 요소 간에 공유되는 공통 속성을 정의합니다. 쿠키 팩토리 예제의 경우 동일한 유형의 물리적 구성 요소가 동일한 측정값을 공유하므로 구성 요소 유형에서 측정 스키마를 정의할 수 있습니다. 예를 들어, 믹서 유형은 다음 예제에 정의되어 있습니다.

{ "componentTypeId": "com.example.cookiefactory.mixer" "propertyDefinitions": { "RPM": { "dataType": { "type": "DOUBLE" }, "isTimeSeries": true, "isRequiredInEntity": false, "isExternalId": false, "isStoredExternally": true }, "Temperature": { "dataType": { "type": "DOUBLE" }, "isTimeSeries": true, "isRequiredInEntity": false, "isExternalId": false, "isStoredExternally": true } } }

예를 들어 물리적 구성요소에는 Timestream 데이터베이스의 측정값, SQL 데이터베이스의 유지 관리 기록 또는 경보 시스템의 경보 데이터가 있을 수 있습니다. 여러 구성 요소를 만들고 이를 개체와 연결하면 여러 데이터 소스가 개체에 연결되고 개체-구성 요소 그래프가 채워집니다. 이러한 맥락에서 각 구성 요소에는 해당 데이터 소스에 있는 구성 요소의 고유 키를 식별할 수 있는 telemetryId 속성이 필요합니다. telemetryId속성을 지정하면 두 가지 이점이 있습니다. 즉, 속성을 데이터 커넥터에서 해당 구성 요소의 값만 쿼리하는 필터 조건으로 사용할 수 있고, 데이터 플레인 API 응답에 telemetryId 속성 값을 포함하면 클라이언트 측에서 ID를 가져와 필요한 경우 역방향 조회를 수행할 수 있다는 것입니다.

를 구성 요소 유형에 외부 ID로 추가하면 테이블에 있는 구성 요소가 식별됩니다TimeStream. TelemetryId

{ "componentTypeId": "com.example.cookiefactory.mixer" "propertyDefinitions": { "telemetryId": { "dataType": { "type": "STRING" }, "isTimeSeries": false, "isRequiredInEntity": true, "isExternalId": true, "isStoredExternally": false }, "RPM": { "dataType": { "type": "DOUBLE" }, "isTimeSeries": true, "isRequiredInEntity": false, "isExternalId": false, "isStoredExternally": true }, "Temperature": { "dataType": { "type": "DOUBLE" }, "isTimeSeries": true, "isRequiredInEntity": false, "isExternalId": false, "isStoredExternally": true } } }

마찬가지로 다음 JSON 예와 같이 WaterTank의 구성 요소 유형이 있습니다.

{ "componentTypeId": "com.example.cookiefactory.watertank", "propertyDefinitions": { "flowRate1": { "dataType": { "type": "DOUBLE" }, "isTimeSeries": true, "isRequiredInEntity": false, "isExternalId": false, "isStoredExternally": true }, "flowrate2": { "dataType": { "type": "DOUBLE" }, "isTimeSeries": true, "isRequiredInEntity": false, "isExternalId": false, "isStoredExternally": true }, "tankVolume1": { "dataType": { "type": "DOUBLE" }, "isTimeSeries": true, "isRequiredInEntity": false, "isExternalId": false, "isStoredExternally": true }, "tankVolume2": { "dataType": { "type": "DOUBLE" }, "isTimeSeries": true, "isRequiredInEntity": false, "isExternalId": false, "isStoredExternally": true }, "telemetryId": { "dataType": { "type": "STRING" }, "isTimeSeries": false, "isRequiredInEntity": true, "isExternalId": true, "isStoredExternally": false } } }

TelemetryType은(는) 개체 범위의 속성 값을 쿼리하기 위한 경우 구성 요소 유형의 선택적 속성입니다. 예를 들어 AWS IoT TwinMaker 샘플 GitHub 리포지토리에서 정의된 구성 요소 유형을 참조하십시오. 동일한 테이블에 경보 유형도 포함되어 있으므로 TelemetryType이(가) 정의되고 다른 하위 유형이 공유할 수있도록 TelemetryIdTelemetryType와(과) 같은 공통 속성을 상위 구성 요소 유형으로 추출합니다.

Lambda 예시

Lambda 커넥터는 데이터 소스에 액세스하고 입력을 기반으로 쿼리 문을 생성하여 데이터 소스에 전달해야 합니다. Lambda로 전송된 예제 요청은 다음 JSON 예제에 나와 있습니다.

{ 'workspaceId': 'CookieFactory', 'selectedProperties': ['Temperature'], 'startDateTime': 1648796400, 'startTime': '2022-04-01T07:00:00.000Z', 'endDateTime': 1650610799, 'endTime': '2022-04-22T06:59:59.000Z', 'properties': { 'telemetryId': { 'definition': { 'dataType': { 'type': 'STRING' }, 'isTimeSeries': False, 'isRequiredInEntity': True, 'isExternalId': True, 'isStoredExternally': False, 'isImported': False, 'isFinal': False, 'isInherited': True, }, 'value': { 'stringValue': 'Mixer_22_680b5b8e-1afe-4a77-87ab-834fbe5ba01e' } } 'Temperature': { 'definition': { 'dataType': { 'type': 'DOUBLE' }, 'isTimeSeries': True, 'isRequiredInEntity': False, 'isExternalId': False, 'isStoredExternally': True, 'isImported': False, 'isFinal': False, 'isInherited': False } } 'RPM': { 'definition': { 'dataType': { 'type': 'DOUBLE' }, 'isTimeSeries': True, 'isRequiredInEntity': False, 'isExternalId': False, 'isStoredExternally': True, 'isImported': False, 'isFinal':False, 'isInherited': False } }, 'entityId': 'Mixer_22_d133c9d0-472c-48bb-8f14-54f3890bc0fe', 'componentName': 'MixerComponent', 'maxResults': 100, 'orderByTime': 'ASCENDING' }

Lambda 함수의 목표는 지정된 개체에 대한 과거 측정 데이터를 쿼리하는 것입니다. AWS IoT TwinMaker 구성 요소-속성 맵을 제공하므로 구성 요소 ID의 인스턴스화된 값을 지정해야 합니다. 예를 들어, 경보 사용 사례에서 흔히 사용되는 구성 요소 유형 수준 쿼리를 처리하고 작업 공간에 있는 모든 구성 요소의 경보 상태를 반환하려면 속성 맵에 구성 요소 유형 속성 정의가 있습니다.

가장 간단한 예로, 이전 요청에서처럼 주어진 구성 요소에 대해 주어진 시간 범위 내의 온도 샘플을 오름차순으로 정렬하여 일련의 온도를 샘플링하려고 합니다. 쿼리문은 다음과 같이 요약될 수 있습니다.

... SELECT measure_name, time, measure_value::double FROM {database_name}.{table_name} WHERE time < from_iso8601_timestamp('{request.start_time}') AND time >= from_iso8601_timestamp('{request.end_time}') AND TelemetryId = '{telemetry_id}' AND measure_name = '{selected_property}' ORDER BY time {request.orderByTime} ...