By using AWS re:Post, you agree to the Terms of Use

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'\")}"
            }
          }
        ]
      }
    ]
  }
}
asked 7 months ago38 views
1 Answer
1
Accepted Answer

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 picture
EXPERT
answered 7 months ago
  • 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"
    }
    

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions