Iot Core -> SiteWise ingestion question

0

I have some messages that look like this:

{
  "measurement":"observation",
  "timestamp":"2022-03-08T18:04:48.389Z",
  "fields": {
     "rms0": 0.22936178743839264,
     "max0": 0.22936178743839264,
     "rms1": 0.2076568752527237,
     "max1": 0.2076568752527237,
     "rms2": 0.20974993705749512,
     "max2": 0.20974993705749512
  },
  "tags": {
     "bucket":"powermon",
     "address":"CA64"
  }
}

Using basic ingestion, I'm sending them to this topic: $aws/rules/PowerMonRule

I added three actions to that rule. One was to write the message to CloudWatch Logs for both the normal and the error condition. The second rule attempts to write that data to SiteWise. This is where I'm having a problem. No data ever actually shows up, and I'm not quite sure how to figure out why. What I'm logging now is what comes out of the rule; is there some way to log what happens when it goes into SiteWise so I can figure out what SiteWise is doing with the data?

My timestamp is in an ISO style format so for every property that I write I repeat the conversion. I tested this by writing an IoT Rule that writes to Timestream and that worked correctly, so I think it should work here. For the same reason I think select * then referring to the values as ${fields.rms0} should work OK.

My model has these measurements:

        {
            "id": "5fd1be48-f8ab-44a1-9d93-2c8102f80e02",
            "name": "Irms0",
            "dataType": "DOUBLE",
            "unit": "Amp",
            "type": {
                "measurement": {}
            }
        },
        {
            "id": "085dfa46-3b8a-47a2-b325-1d211b33a6f4",
            "name": "Irms1",
            "dataType": "DOUBLE",
            "unit": "Amp",
            "type": {
                "measurement": {}
            }
        },
        {
            "id": "1ec8a6c6-a9cc-4bde-9ae5-4394b09914c8",
            "name": "Irms2",
            "dataType": "DOUBLE",
            "unit": "Amp",
            "type": {
                "measurement": {}
            }
        }

so what I did was set up an alarm rule with this action (see below). What it does is to take the message (the rule is just SELECT *) and pull out the three fields, which are stored in attributes with IDs matching the above. For now, the rule is set up to write to a specific, hard-coded asset ID, and the property IDs pulled from the model.

{
  "iotSiteWise": {
    "putAssetPropertyValueEntries": [
      {
        "assetId": "e6739e7d-248e-47cd-ba53-bf369126d482",
        "propertyId": "5fd1be48-f8ab-44a1-9d93-2c8102f80e02",
        "propertyValues": [
          {
            "value": {
              "doubleValue": "${fields.rms0}"
            },
            "timestamp": {
              "timeInSeconds": "${time_to_epoch(ts,\"yyyy-MM-dd'T'HH:mm:ss.SSS'Z'\")}"
            }
          }
        ]
      },
      {
        "assetId": "e6739e7d-248e-47cd-ba53-bf369126d482",
        "propertyId": "085dfa46-3b8a-47a2-b325-1d211b33a6f4",
        "propertyValues": [
          {
            "value": {
              "doubleValue": "${fields.rms1}"
            },
            "timestamp": {
              "timeInSeconds": "${time_to_epoch(ts,\"yyyy-MM-dd'T'HH:mm:ss.SSS'Z'\")}"
            }
          }
        ]
      },
      {
        "assetId": "e6739e7d-248e-47cd-ba53-bf369126d482",
        "propertyId": "1ec8a6c6-a9cc-4bde-9ae5-4394b09914c8",
        "propertyValues": [
          {
            "value": {
              "doubleValue": "${fields.rms2}"
            },
            "timestamp": {
              "timeInSeconds": "${time_to_epoch(ts,\"yyyy-MM-dd'T'HH:mm:ss.SSS'Z'\")}"
            }
          }
        ]
      }
    ]
  }
}
profile picture
wz2b
질문됨 2년 전417회 조회
1개 답변
1
수락된 답변

What I'm logging now is what comes out of the rule; is there some way to log what happens when it goes into SiteWise so I can figure out what SiteWise is doing with the data?

I'm unclear on this part. Have you enabled IoT logging?

https://docs.aws.amazon.com/iot/latest/developerguide/configure-logging.html

If you haven't, enabling this will give you a new AWSIotLogsV2 log group in CloudWatch. This will log many IoT event types, including rule executions (and failures on any rule actions): https://docs.aws.amazon.com/iot/latest/developerguide/cwl-format.html#rule-engine-logs

profile pictureAWS
전문가
Greg_B
답변함 2년 전
  • ahhhhhh so I was looking for the logs in the wrong log group!!!

    It doesn't like this:

        "logLevel": "ERROR",
        "status": "Failure",
        "eventType": "RuleExecution",
        "ruleAction": "FunctionEval",
        "resources": {
            "FunctionName": "time_to_epoch"
        },
    
  • I feel like I"m very close to this working.

    {
        "logLevel": "INFO",
        "traceId": "d4c13dc1-79c9-6da1-66aa-0db7a43b8312",
        "status": "Success",
        "eventType": "RuleExecution",
        "clientId": "bay1",
        "topicName": "$aws/rules/PowerMonRule",
        "ruleName": "PowerMonRule",
        "ruleAction": "IotSiteWiseAction",
        "resources": {},
        "details": "No requests were sent. PutAssetPropertyValueEntries was empty after performing substitution templates. Message arrived on: , Action: iotSiteWise"
    }
    

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

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

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