Show AWS Monitron Data on SiteWise portal

1

Hi I wonder how I can forward the data from AWS Monitron in to AWS Sitewise? Thanks

Maryam
질문됨 3달 전152회 조회
2개 답변
4

I believe there is no direct integration, but you can do live data export from Monitron into an Amazon Kinesis data stream. From this stream, you can use AWS Lambda to process the data and push it into AWS IoT SiteWise.

profile pictureAWS
전문가
Tasio
답변함 3달 전
0

Hi, Thanks for your suggestion, so I started doing that, but it is not working. Here is what I did hopefully some one can help me resolve the issue with it.

I started by defining requirements for lambda function.

I started with Live data export in Monitron and created "on demand" Kinesis Data Stream to be used for lambda trigger.

Then I created a Role for Lambda, I added these permission: AWSIoTSiteWiseFullAccess, AWSIoTSiteWiseMonitorPortalAccess, AWSKeyManagementServicePowerUser, AWSLambdaKinesisExecutionRole.

Then I created the python Lambda function as the following:


import json  
import base64  
import uuid  
import time  
import boto3  
  
def map_sitewise_data(kinesis_data):  
    """Map incoming Kinesis data into Sitewise data objects"""  
    data = json.loads(kinesis_data)  
    return {  
        'value': {  
            'doubleValue': data['Temperature']  
        },  
        'timestamp': {  
            'timeInSeconds': int(time.time()),  
            'offsetInNanos': 0  
        },  
        'quality': 'GOOD'  
    }  
  
def lambda_handler(event, context):  
    # Incoming event is Kinesis data from Monitron  
    print(event)  
      
    # List used to send data to Sitewise  
    temp_list = []  
      
    # Loop through the list of records  
    for record in event['Records']:  
        # Kinesis data is base64 encoded so decode here  
        payload = base64.b64decode(record['kinesis']['data'])  
        print("Decoded payload: " + str(payload))  
          
        # Map data for Sitewise  
        mapped_data = map_sitewise_data(payload)  
          
        # Append mapped data to list  
        temp_list.append(mapped_data)  
      
    # Sitewise section  
    # Use temp_list as the "entries" value      
    sitewise = boto3.client('iotsitewise')  
    try:  
        response = sitewise.batch_put_asset_property_value(  
            entries=[  
                {  
                    'entryId': str(uuid.uuid4()),  
                    'propertyAlias': 'Monitron_VTS_1/Temperature',  
                    'propertyValues': [mapped_data]  
                },  
            ]  
        )  
        print(response)  
    except Exception as error:  
        # Log errors  
        print(error)  

It is still not working and I don't see any streams in SiteWise. I appreciate any suggestions.

Maryam
답변함 3달 전
  • Hi Maryam, looking at the code I see you are referring values that don't exist within the event coming from Monitron. For example within the function map_sitewise_data to read the temperature you must first check if data['eventType'] == 'measurement' and then get the temperature reading from data['eventPayload']['features']['temperature']. You can view the data schema form the CloudWatch logs when you printed them out or view them from the documentation

    There is also an AWS Sample repository with a working example of processing Monitron events for SiteWise in a Lambda function.

  • Thank you so much Gary, it worked, Thanks a lot.

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인