Sending and Storing Events

When defining an Observation. you must configure where to send events to via the Send events to options:

1169

The following subsections outline the various options for handling data within an Observation.

Sending Events to the Cloud Immediately

Observations defined on an Octave edge device, can be configured to route events directly to the cloud, where they are stored in a Stream. From here they can be optionally processed in the cloud using a Cloud Action.

The steps below describe how to configure an Observation to route events directly to the cloud. In this example, the Observation is configured to read the value from the mangOH Red's built-in light sensor, and send an event with its value immediately to the cloud:

  1. Create or edit an Observation for the /redSensor/light/value sensor resource.
  2. Configure the Observation to send events to the cloud stream by setting Send events to to Cloud Stream.
  3. Click Save to save the Observation.
  4. Navigate to Build > Device > Streams and locate the new stream corresponding to the Observation created above.
  5. Click on the stream and inspect its events.

📘

Note

An event is stored in a stream with additional meta-data including the time at the edge, as well as the time received in the cloud. Having both of these times available for each event is important for more sophisticated data orchestration strategies.

Storing and Forwarding Events to the Cloud

While some data benefits from being sent to the cloud instantly, there is a cost for choosing to do so. Firstly, every time you start and stop the cellular data session, power is consumed. Secondly, encapsulating each reading for transmission individually, causes more data to be sent over the air and this is reflected in pricing.

In order to optimize power and bandwidth consumption, you can chose to have your readings stored and forwarded on a periodic basis. The Cloud Interface provides a buffer for events that you wish to store, and allows you to dynamically configure how often that buffer is sent to the cloud. This is referred to as store and forward.

Configuring store and forward involves setting the maximum time between transmissions via the /cloudInterface/store_forward Resource. For example, if the store and forward buffer is set for 60 seconds and a "cloud stream" event is generated 30 seconds after the last transmission, the contents of the buffer will be sent with the "immediate" event, and the 60 second timer resets.

The steps below illustrate how to configure the maximum time between transmissions for store and forward, and how to modify an Observation to use store and forward:

  1. Locate the cloudInterface > store_forward Resource and set its Period property (e.g., to 60). This controls how often the Resource is polled.
  2. Click Set to save the update.
  3. Create or edit an Observation.
  4. Set Send events to to Store & Forward and click Save. Octave returns to the Observation listing screen.
  5. Verify that the Destination column for the edited Observation indicates Store & Forward on this listing screen.
  6. Wait for 60 seconds for the timer to elapse to ensure that the value has been sent to the cloud.
  7. Navigate to Build > Device > Streams and locate the stream corresponding to the Observation.
  8. Click on an event to display its details. Note the time values for Generated date and Creation date which should be approximately 60 seconds or more apart.

Sending Events to an Edge Action

Observations defined on an Octave edge device can be configured to process events directly on the device using an Edge Action, thus avoiding a data transfer to the cloud.

The steps below illustrate how to configure the Observation to send values to an Edge Action:

  1. Create or edit an Observation for the Resource (e.g., /lcd/text1).
  2. Set Send events to to Edge Action.
  3. Click Save.
  4. Follow the steps here to set up an Edge Action for the Observation to process events on the device.

Sending Events to Another Resource

An Observation can be configured to send events directly to another Resource rather than sending them to an Edge Action for processing at the edge, or to the cloud for processing by a Cloud Action. This is useful in cases where you need to forward events directly from one Resource to another (e.g., to send the value of a Sensor or Input to the mangOH Red's LCD screen). An Observation for the destination Resource can then be used to process the event.

The steps below illustrate how to configure an Observation to send events to another Resource. In this example, the Observation creates events from the mangOH Red's built-in light sensor and sends them to the Resource for the mangOH Red's built-in LCD screen:

  1. Create or edit an Observation for the /lcd/text1 output resource.
  2. Set Send events to to Resource.
  3. Click on the Destination resource drop down to display the Resources and select /lcd/txt2.
  4. Enter an Observation name and click Save. The second line of text on the LCD should change to indicate the current light level.

Storing Events

The sections above 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. Create or edit an Observation for the /redSensor/light/value Sensor Resource.
  2. Configure the Observation to send events to Device Storage and to buffer 100 events.
  3. 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)