Ingesting data using IoT core rules

0

Hi all,

I am a beginner with AWS. I am following the SiteWise tutorial for ingesting data to AWS IoT SiteWise from AWS IoT things. However instead of running the device client script, I want to have actual devices setup to report data via MQTT to AWS IoT core. I am following most of the settings in the tutorial, except that instead of reporting the CPU and memory usage, I am reporting temperature and humidity from my IoT sensor.

In my asset, under the measurement section, I have entered the following as the property alias:
/tutorial/device/SiteWiseTutorialDevice1/temp
/tutorial/device/SiteWiseTutorialDevice1/humid

When I create a rule in AWS IoT Core, in the Configure Action section, I have set the following:
Property alias : /tutorial/device/${topic(3)}/temp
Entry ID: ${concat(topic(3), "-temp-", floor(state.reported.timestamp))}
Value: ${state.reported.temp}
Data type: Double

I have also added another entry for humidity by replacing 'temp' with 'humid' and the Data type: Integer

What I don't know really is to which MQTT topic should my physical IoT device be posting to? And how should the data be formatted if it is a JSON object?

Thanks in advance!

kiany
asked 3 years ago619 views
2 Answers
0

Hello,
if you are following the Sitewise tutorial, then you should be using the IoT Core device shadow service. By doing so, your devices will regularly update their status specifying the actual values of temperature and humidity. This is typically done using the AWS SDK.
What actually happens is that the SDK publishes the status update for a device to a reserved MQTT topic (reserved for the device shadow service) on the IoT Core broker. The IoT Core device shadow service reads that message and updates the shadow object for that device accordingly. Once done, it publishes a message to another reserved topic (which you can subscribe to), named $aws/things/{ThingName}/shadow/update/accepted.
The rule you created in IoT Core should (if you followed the tutorial) have, in the 'from' statement, something like
'$aws/things/+/shadow/update/accepted' . This rule matches the messages published by the IoT core device shadow service. In addition, it should have a 'WHERE' clause specifying 'startsWith(topic(3), "SiteWiseTutorialDevice")', which is used to filter out all device shadow update messages for devices that are not part of the tutorial, i.e. their name don't start with "SiteWiseTutorialDevice".
Eventually, when you configure the action specifying "/tutorial/device/${topic(3)}/temp" as property alias, topic(3) resolves to the third segment of the MQTT topic that triggered the rule. In this case, since the rule is triggered by the reserved topic "$aws/things/{ThingName}/shadow/update/accepted", topic(3) resolves to the name of the IoT Thing the device shadow service publishes an update for.

So following the tutorial you only need to use the Device Shadow APIs of the SDK, you don't have to manually publish messages on custom MQTT topics. You can of course not use the device shadow at all, and publish messages on some custom topic like "iotdevices/data/<deviceIdentifier>", where deviceIdentifier can be a serial number or whatever allows you to identify the device that sent the message. You can then use that to map the corresponding property alias in Sitewise.

For what concerns the message payload, it can be any JSON object. Since the tutorial uses the shadow service, the messages contain the reported state values under "state.reported".

I hope it helped.

Best,
Marco

marco88
answered 3 years ago
0

Thanks Marco. Appreciate the reply. It was very helpful.

kiany
answered 3 years ago

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