- Newest
- Most votes
- Most comments
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:
- Temperature rule, and SiteWise - Asset Measurement field is: AnyTermYouLike
- 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.
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
Relevant content
- asked 3 years ago
- asked 4 years ago
- AWS OFFICIALUpdated 6 months ago
- AWS OFFICIALUpdated a year ago
- AWS OFFICIALUpdated 2 years ago
- AWS OFFICIALUpdated a month 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}