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 个月前151 查看次数
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.

您未登录。 登录 发布回答。

一个好的回答可以清楚地解答问题和提供建设性反馈,并能促进提问者的职业发展。

回答问题的准则