Skip to content

IoT to Timestream configuration to store data for every 5 min

0

Hi,

  1. The IoT device we are working on has no control on the rate to send data. It sends data for every 2 to 3 secs. We are storing it in timestream database by creating a rule.
  2. Now we want to store data for every 5 min interval. For this we want to store the payload which has timestamp to be taken as reference and after 5 minutes w.r.t timestamp need to trigger the timestream to store the data. Can I achieve it by just changing IoT rule or I need to use other AWS service. Kindly suggest me with step-by-step configuration.

Thanks, Kartheek

asked a year ago184 views
1 Answer
0

To achieve your goal of storing data in Amazon Timestream at 15-minute intervals from your IoT device that sends data every 2 to 3 seconds, you'll need to modify your existing setup and potentially incorporate additional AWS services. Here's a step-by-step approach to accomplish this:

  1. Modify your existing AWS IoT Core rule:
  • Keep your current rule that routes data to Timestream, but add a condition to filter messages based on a timestamp.
  • In the SQL statement of your rule, use a function like timestamp() or extract the timestamp from your payload, and use the MOD function to only process messages at 15-minute intervals.

Example SQL statement:

SELECT * FROM 'iot/topic' WHERE MOD(FLOOR(timestamp() / 60000), 15) = 0

This will only process messages when the minute is divisible by 15 (i.e., every 15 minutes).

  1. Create an AWS IoT Analytics pipeline:
  • Set up an IoT Analytics channel to ingest your IoT data.
  • Create a pipeline that includes an activity to filter messages based on the 15-minute interval.
  • Add a datastore to temporarily hold the filtered data.
  1. Create an IoT Analytics dataset:
  • Set up a dataset with a schedule trigger to run every 15 minutes.
  • Configure the dataset to query the datastore and select the most recent data point within the 15-minute window.
  1. Use AWS Lambda with IoT Analytics:
  • Create a Lambda function that is triggered by the IoT Analytics dataset.
  • This function will receive the dataset content (the selected data point) and write it to Timestream.
  1. Set up IAM roles and permissions:
  • Ensure that your IoT Core rule has permissions to write to IoT Analytics.
  • Grant necessary permissions to the Lambda function to read from IoT Analytics and write to Timestream.

This approach allows you to continue receiving all data from your IoT device while selectively storing data points at 15-minute intervals in Timestream. The IoT Analytics pipeline and dataset provide the mechanism for time-based data selection, while Lambda gives you the flexibility to process and store the data as needed.

Remember to adjust the exact implementation details based on your specific payload structure and requirements. You may need to fine-tune the SQL queries and Lambda function logic to ensure you're selecting the most appropriate data point for each 15-minute interval.
Sources
Using the CreateDataset API via Java and the AWS CLI - AWS IoT Analytics
AWS IoT Core - Amazon Timestream

answered a year ago
  • SELECT * FROM 'iot/topic' WHERE MOD(FLOOR(timestamp() / 60000), 15) = 0, using this SQL gives data at 15th minute. But gives other packets from 0th sec to 59th sec. Here we need only first 0th or 1st sec packet. How we can achieve this?

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.