Storing Events

The previous topics described how to configure an Observation to send events to other destinations (e.g., to the cloud, to another resource, etc.). However, sometimes it can be useful to store data and query it at a later point. This is done by configuring an Observation with a buffer and choosing to store the data rather than sending it onward. The Observation can then be queried programmatically from an Edge Action associated with another Observation.

The steps below illustrate how create an Observation to store data, and how to query that data from and Edge Action:

  1. Navigate to Device > Observations.
  2. Click Add Observation.
  3. Click the Observed resource drop down and select /redSensor/light/value.
  4. Enter an Observation name.
  5. Set Send events to to Device Storage.
  6. Enter 100 into Buffer size. This specifies the number of values to hold in the buffer.
  7. Enable Buffer Events and set Buffer function to Last value.
  8. Click Save.
  9. Verify that the Observation indicates Store only. The event data observed by this Observation will be available for querying.
  10. Create an Edge Action and add code to it that invokes Datahub.query() to get the buffered event data from the Observation created above. The following shows an example:
//Query the Datahub for the mean buffered event value
var queryResult = Datahub.query('my_observation', 'mean', 10000)