Ingest data through AWS IoT Core

On your Cloud9 instance you will find a script that creates random data for generators and publishes these data to AWS IoT Core to the topic sitewise/ingest. Before starting the script create a topic rule to route message from this topic to AWS IoT SiteWise.

To permit the IoT service to transfer data to AWS IoT SiteWise in your account a service role is required. A role has been already created by CloudFormation.

You can find the role name in the AWS CloudFormation console in the outputs section under IoTServiceRoleName. The role name is autogenerated by CloudFormation. It is composed out of stack names the string IoTServiceRole and unique strings. Take a note of the role name you need it to enable logging for AWS IoT Core.

Role name examples:

  • SiteWiseWorkshop-MiscResources-UNIQUE_STRING-IoTServiceRole-UNIQUE_STRING
  • mod-UNIQUE_STRING-SiteWiseWorksh-UNIQUE_STRING-IoTServiceRole-UNIQUE_STRING.
  1. Navigate to the AWS IoT Core console
  2. In the navigation pane, choose Act. If a You don’t have any rules yet dialog box appears, choose Create a rule. Otherwise, choose Create.
  3. Under Name, enter SiteWiseIngestRule.
  4. Under Using SQL version, choose 2016-03-23.
  5. Under Rule query statement, enter SELECT entryId, propertyAlias, value, timeInSeconds, quality FROM 'sitewise/ingest'.
  6. Under Set one or more actions, choose Add action.
  7. Under Select an action, choose Send message data to asset properties in AWS IoT SiteWise, and then choose Configure action.
  8. Under Configure action, choose By property alias.
  9. Enter the following values to configure the AWS IoT SiteWise action:
    • Property alias: ${propertyAlias}
    • Entry ID: ${entryId}
    • Time in seconds: ${timeInSeconds}
    • Offset in nanos: leave empty
    • Value: ${value}
    • Data type: Double
    • Quality: ${quality}
  10. Under Root Asset Name, leave No root asset selected as it is.
  11. Under Role, select the role name which you noted previously.
  12. Choose Add action, and then choose Create rule.

Start the data generator (sitewise-iot-ingest.py) to publish data to AWS IoT Core.

In a Cloud9 terminal (as ec2-user):

cd ~/sitewise
./sitewise-iot-ingest.py

You can see data arriving in AWS IoT Core by subscribing to the topic sitewise/ingest.

You should also see now more data at the topic $aws/sitewise/asset-models/+/assets/+/properties/+.

The SiteWise console can also be used as explained in the previous exercise to find the latest values for an asset. Look at the values for the asset Generator-7.