I have gotten the above example to work for checking the context. I took it further such that I got an e-mail when data was received. However, I don't see, and maybe it is a naming problem how "data_change_state" is the even to be used. I had that event, but I didn't seem to get any activity until I changed the event to "data_received".

In the context, and in the view, there is the Status. I suspect this status is changed based on receiving of streams and the value set in frequency. What I would like is an email when the Status changes. In other words, when a device is detected coming online, I'd like an e-mail. And then another e-mail if the device isn't detected online after a timeout.

For the context you describe you have to define a listener watching the device (or the set of devices: group, service or project) for a data_state_change event to happen. Then you can track status changes and react.

Where “reason” holds the device data that has caused the change state event. In this example the device goes to a disconnected status.

If you don’t have seen any activity is probably because you don’t have a “seed” stream. This stream is not a particular one, it is simply a stream (data or status) needed by Carriots to calculate the next stream expected arrival time by adding the frequency (stream or status) to the stream “at” timestamp.

So, you need to send a stream to let Carriots know when you expect the next one to arrive and fire the event if it does not occur.

I seem to have a listener working on the group. I have it setup so that it send an e-mail when the Status changes by looking at context.hierarchy.status. Well, it was working and then I changed some coding, so I am just waiting for the device to be revived to see if the changes work.

I have a listener setup. The following is the code. The event is "data_change_state". The If expression is true. What I am seeing in the behavior is that I get the "Status is OK for..." message only after the device has been offline for a time (set by Data Stream Frequency". I am expecting to get "Status is not OK...". I also don't seem to get a message when the device comes back online. Any thoughts?

Answering your first question, I think you should try with the expression if (context.data.reason.status=="ok") in your if condition instead of if (context.hierarchy.device.status=="ok")

The context hierarchy represents the context when the causing stream is received and the "reason" is holds the device's destination status.

Regarding the second question we will need more details about it. Can you please tell us in which context you get that error? Is this message part of an alarm? Is it a query response? If it's in a listener execution, try to execute the code in the console to get the execution response message.

The error message was listed in my alarms and was caused by a listener.

For the moment I've changed my two listeners, which are nearly identical, to use the if statement as you recommend. So I'll see how that performs. I'm looking forward to deeper details on Context.data and context.hierarchy so that I can understand them better.

My listener is working as I would like. Thank you for the help. The following is summary of the complete setup so that others can make use of this knowledge.

This is a listener that sends an e-mail when a device goes online or offline in a Group. That is when the "status" changes.

1. Set up your device in Carriots. Choose a value for "Data Stream Frequency". For me, I choose a value that was slightly longer than what my device is programmed to update as there can be various network delays and tolerances. So, say you have a device that posts data once a minute to Carriots, I'd recommend a value of 2, for 2 minutes. If your device is posting once every 10 minutes, then maybe a value of 11 or 12 minutes. Status of the device is based on this frequency. Lets say your device has been logging away at 1 minute intervals. If, your frequency is set to 2 and you device goes offline, the Status will change 2 minutes after the last data point was logged. As soon as you device begins logging again, the status is changed again.

2. Create a new listener. The listener in this example is setup to monitor a Group, but the listener could be for a specific device, asset, project, etc. In creating the listener, enter the name, description, entity type and ID.

We've detected that in some cases status sent in context.hierarchy.device.status is not accurate due to the asynchronous processing of events. To prevent collecting wrong previous status from the context data we have included context.data.reason.before_status property to hold that info. Thanks sdeancos for pointing and solving it!

Not exactly... I will try to explain a little bit this "status change" topic.

Some introduction topics can be useful. A device can have the following inner status:

· Disconnected: no status stream nor data stream received in the expected time range defined by frequency_status and frequency_stream device’s properties

· No_data: no data stream received in the expected time range defined by frequency_stream device’s property. Status stream received.

· No_status: no status stream received in the expected time range defined by frequency_status device’s property. Data stream received.

· OK: Data and status streams received in the expected time range defined by frequency_status and frequency_stream device’s properties.

When a device changes its inner status, Carriots raise an event and injects the context to be used in listeners and rules scripts. A status change implies to statuses: one before the change takes place and another when the change is done. For example, a device can be in a “no_data” status and change to “disconnected” or from “OK” to “no_status” and so on.

when a change in the status occurs, the listener is triggered, the "if Expression" evaluated and the "then expression" executed if the "if" is true (normal behaviour), but if the "if expression" is false, the "Else Expression" is never executed