Simple IoT Core thing rule and SiteWise property alias ingestion config

0

Hi,

I am seeking some basic plain english assistance please. Any assistance will be great appreciated.

I have a temperature sensor Thing receiving MQTT data.

  • The Things name is: TestThing
  • The data includes 4 fields: "TS", "datetime", "class", "data"
  • The published Topic is: TestTopic
  • The IoT Core MQTT Test Client payload displays as: {"TS": 1656941515, "datetime": 04/07/2022 23:31:55, "class": Temperature, "data": 11}

I do not know how to fill out the IoT Core rule correctly, and I am also not sure if the SiteWise Asset propertyAlias is correct. Based on what i have read (see below), the latest failure is:

IoT Core Rule config UI

  • SQL Statement: SELECT * FROM 'TestTopic'
  • Property Alias: TestTopic
  • Time in seconds: ${TS}
  • Data type: DOUBLE
  • Value: ${data}
  • IAM role: created via the UI - create new role

I have used Data type: DOUBLE although i note the incoming data is seen within IoT Analytics as integer. The SiteWise model Measurement definitions is also set to DOUBLE

SiteWise config

  • Model Measurement definitions: Temperature
  • Asset Measurement: Temperature
  • Asset Measurement - Temperature field (enter a property alias): TestTopic

I believe i have created the model and asset correctly. Although, I am not sure if i understand the what exactly is the Property, and thus the propertyAlias. based on the above, I believe i created the propertyAlias for the Temperature field as: TestTopic

Setup and read history

The setup is super simple for testing. A single IoT thing, pulling in MQTT topic data. The Thing was created as a single Thing with certificates. A MODBUS sensor connected to a gateway with MQTT. No OPC server, no Greengrass, no Lora. IoT Analytics and AWS QuickSight services can access the data.

I have read: 1) all the AWS suggested questions, 2) the manual - docs pages on SiteWise IoT Core data ingestion, including the tutorial section, 3) the AWS workshop pages, 4) watch every wonderful Youtube on the topic (not many). Key articles read:

https://docs.aws.amazon.com/iot-sitewise/latest/userguide/ingest-data-from-iot-things.html https://docs.aws.amazon.com/iot/latest/developerguide/iotsitewise-rule-action.html https://docs.aws.amazon.com/iot-sitewise/latest/userguide/connect-data-streams.html https://docs.aws.amazon.com/iot-sitewise/latest/userguide/iot-rules.html https://iot-sitewise.workshop.aws/en/40_aws-iot-sitewise-data-ingestion.html https://repost.aws/tags/TAGaSyCvg-SI2w6FYqm1H2RQ/aws-io-t-site-wise

2 Answers
0
Accepted Answer

Hi all,

I am posting an answer to my own question to assist others with what i consider a simple and basic plain english configuration example to: add an IoT Core single Thing to SiteWise. No OPC server, no Greengrass, no Lora. The Thing was created as a single Thing with certificates.

Setup

A single IoT thing, pulling in MQTT topic subscribed data. The Thing was created as a single Thing with certificates. A MODBUS sensor connected to a gateway with MQTT. No OPC server, no Greengrass, no Lora.

Follow the AWS IoT Core guide to create a single Thing. Is this example the Thing is a temperature sensor. Therefore use of the term 'Temperature' below relates to both: 1) the IoT SiteWise model and asset measurement fields - filled with the term 'Temperature' and, 2) the incoming IoT Core JSON payload class "Temperature" from my gateway/sensor.

  • The Things name is: TestThing
  • The data includes 4 fields: "TS", "datetime", "class", "data"
  • The published Topic is: TestTopic
  • The IoT Core MQTT Test Client payload displays as: { "TS": "1657098676", "datetime": "06/07/2022 19:11:16", "class": "Temperature", "data": 13 }
  • NOTE: the JSON payload is an object. The format - with %x defined by the gateway - : {"TS": "%t", "datetime": "%d", "class": "%x", "data": %x}

IoT Core Rule config UI

  • SQL Statement: SELECT * FROM 'TestTopic'
  • Property Alias: AnyTermYouLike
  • Time in seconds: ${TS}
  • Data type: DOUBLE
  • Value: ${data}
  • IAM role: created via the UI - create new role

What is the Property Alias? The Property Alias required for IoT Core rule and SiteWise is the field within: SiteWise - Asset Measurement - (enter a property alias). The property alias (propertyAlias) can be any string term. In this example it is 'AnyTermYouLike'. The term must then be used in the IoT Core rule creation.

Key things to check Both within the IoT Core rule creation and for fields within IoT SiteWise model creation (Measurement definitions) the Data type: DOUBLE is used. Although a model Attribute may use: integer and or others.

SiteWise config

  • Model Measurement definitions: Temperature
  • Asset Measurement: Temperature
  • Asset Measurement - Temperature field (enter a property alias): AnyTermYouLike
  • NOTE: Asset Measurement field is the Property Alias (propertyAlias) that you define. Any term is suitable and is also used within the IoT Core rule.

Whats next?

If the IoT Core rule creation did not report errors, progress! As outlined in the manual, if the IoT Core MQTT test topic subscription is working and data is visible, the data should be following the IoT SiteWise. Within SiteWise under the asset, and measurement tab - the columns 'Latest value', and 'Latest value timestamp' should display data - new data from the subscribed MQTT topic. Switch to another tab and back to the asset, and measurement tab, the data will refresh.

Final NOTES: as described by MassimilianoAWS, the IAM role must provide access to the propertyAlias. The IoT Core rule Time in seconds, must be within the -15min +5min range. Lucky for me, the my JSON package contained Unix time and i was able to simply use: ${TS}

Additional - Two separate rules and SQL syntax to identify sensor reporting class - Temperature and Humidity

-- This is the Iot Core rule SQL syntax to select a topic field type - in this example only Temperature or Humidity - or other type of Iot Core thing field --

The sensor and thus incoming subscribed MQTT topic JSON payload contained a "class" field. Where the sensor is reporting both temperature and humidity. For each reporting period two lines of data is available - "Temperature" and "Humidity", as defined by the class. This displays as:

  • { "TS": "1657101866", "datetime": "06/07/2022 20:04:26", "class": "Temperature", "data": 12}
  • { "TS": "1657101866", "datetime": "06/07/2022 20:04:26", "class": "Humidity", "data": 79}

IoT Core rule config

  • Create two rules.: 1) for Temperature, and 2) for Humidity
  • Temperature rule SQL: SELECT * FROM "TestTopic" WHERE class = "Temperature"
  • Humidity rule SQL: SELECT * FROM "TestTopic" WHERE class = "Humidity"
  • Each rule will need a unique property alias (propertyAlias) that relates to the SiteWise model

SiteWise config

  • Two separate models are required, one for Temperature, and the second for Humidity.
  • Two separate assets, and the relationship to the corresponding model - in this case one for Temperature, and the second for Humidity.
  • A primary model and a primary asset - following the AWS manual re relationships - Associated assets and Hierarchy definitions etc.
  • Each model must have a unique property alias (propertyAlias) - see the section above for guidance.

In this example the property alias (propertyAlias) for the:

  1. Temperature rule, and SiteWise - Asset Measurement field is: AnyTermYouLike
  2. Humidity rule, and SiteWise - Asset Measurement field is: GoodSecondTerm

Close: the question subject should be called - Dummies simple guide to add a single Thing to Sitewise AND IoT Core rule property alias (propertyAlias)

Please make suggestions to improve, or correction of errors.

answered 2 years ago
0

Hi,

ensure your timestamp falls into the time range [-15min, +5min] from current time and that the IAM Role is setup correctly to allow to write to the property.

Massimiliano

AWS
EXPERT
answered 2 years ago
  • Hi MassimilianoAWS and all,

    Thanks for providing comment. I have made changes to the three areas you suggested but no data is flowing into SiteWise and would appreciate further assistance.

    I reviewed the timestamp. The sensors "TS" time is indeed Unix time and roughly correct (within the -15 +5min range). I am located in Australia (UTC +10), so I am not sure if this is something to consider. Am i correct to believe where the reported sensor time, within the JSON data, is roughly correct Unix time, information i added into the IoT Core Rule is correct? Time in seconds: ${TS}

    I have changed the SQL FROM topic to be double quoted as you said. The SQL Statement is now: SELECT * FROM "TestTopic"

    I have checked the role in IAM and I believe it has access, as the "iotsitewise:BatchPutAssetPropertyValue" has access to the 'propertyAlias'

    Thanks.

  • Please disregard the additional assistance request with my comment response. I have resolved the issue and will post an answer to assist others.

    In summary, my original configuration was correct, the problem was a malformed JSON payload, which did not include "" double quotes. The payload should be (and different to that in my question above) - The IoT Core MQTT Test Client payload NOW displays correctly: {"TS": "1656941515", "datetime": "04/07/2022 23:31:55", "class": "Temperature", "data": 11}

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