Device inner status

Devices in Carriots

When a Carriots device is created there is two kind of streams that can be sent associated to that device: data streams and status streams. Those streams can be controlled in order to expect the reception of one of them in a time range.

For example lets suppose a RFID reader controlling a door opening. When a RFID tag is read, it sends a data stream to Carriots and if credentials are granted then Carriots sends an order to the PLC that opens the door. This door should be opened at least one time in a workday and exceptionally in a weekend. Carriots could check if a data stream has been received in a time range, a day and then check if the reader is working correctly.

Following this example, checking the RFID reader health is a matter of tracking data streams once a day. But if in a weekend the reader is not used, it seems that the reader is not working properly. So, for checking if RFID reader is alive its better done by sending status streams periodically and expect their reception in Carriots in a defined time range, independently from data streams.

Carriots offers two device properties to check streams expected reception in a time range.

  • Data Stream Frequency - It is a number representing the time range in which a data stream should be received for that device. Expressed in minutes.
  • Status Stream Frequency - It is a number representing the time range in which a status stream should be received for that device. Expressed in minutes.

When a stream is not received within the expected time range, Carriots changes it's inner status and fires an event. When events are fired and which are the possible inner status of a device are topics explained in this page.

Device's inner status

These are the different inner device status:

  • Disconnected - no status stream nor data stream received in the expected time range defined by "Status Stream Frequency" and "Data Stream Frequency" device’s properties.
  • No_data - no data stream received in the expected time range defined by "Data Stream Frequency" device’s property. Status stream received.
  • No_status - no status stream received in the expected time range defined by "Status Stream Frequency" device’s property. Data stream received.
  • OK - Data and status streams received in the expected time range defined by "Status Stream Frequency" and "Data Stream Frequency" device’s properties.

There is 3 different situations in which a device can transit between status

  • Only data streams are received
  • Only status streams are received
  • Both data and status streams are received

First use case is when only data streams are received from a defined device. In this case, device's inner status can be Disconnected or OK.
When the device is created at Carriots its status is disconnected and when the first data stream is received Carriots changes it to OK.
If expected receive time defined in Data Stream Frequency is reached, then Carriots sets the device back to disconnected.

  • Device inner status - 2 status - Data streams only

Second use case is when only status streams are received from a defined device. Like the previous use case, device's inner status can be Disconnected or OK.
When the device is created at Carriots its status is disconnected and when the first status stream is received Carriots changes it to OK.
If expected receive time defined in Status Stream Frequency is reached, then Carriots sets the device back to disconnected.

  • Device inner status - 2 status - Status streams only

Finally, the third use case is when both data and status streams are received from a defined device. in this case, device's inner status can be Disconnected, No data, No status or OK.
When the device is created at Carriots its status is disconnected and when the first status or data stream is received Carriots changes it to OK.
If expected receive time defined in Status Stream Frequency is reached, then Carriots sets the device to No status.
If expected receive time defined in Data Stream Frequency is reached, then Carriots set the device to No status.
If the device is in a No data status, Status Stream Frequency time reach set the device to disconnected.
If the device is in a No status status, Data Stream Frequency time reach set the device to disconnected.

  • Device inner status - 4 status

Status change event

When Carriots detects stream absence within a defined time range the event "Event Device Change State" is fired. There is an important concept here. Carriots begins it's stream absence detection from a starting stream, we can call it a seed stream. This means that in order to expect the reception of a stream, a first stream must have been received and then the next stream will be expected from this seed stream detection time until the device's frequency property defined time.

notice  Stream Frequencies: A seed stream is needed to calculate the next stream expected reception time!

Using the previous RFID reader example, it can be defined that a status stream must be received each 12 hours, so the "Status Stream Frequency" for this device is set to 720 (60 minutes x 12 hours = 720 minutes). Carriots needs to receive the first status stream (seed stream) to calculate the expected reception time of next status stream.
If a status stream is received at 14/07/2013 09:17:42, Carriots will expect the next status stream to be received at 15/07/2013 21:17:42 (720 minutes later).
If no status stream is received after the first one Carriots changes the device's inner status from OK (or from no_data) to no_status (or disconnected) and the event is fired.
If no status stream at all is received, device's inner status won't change from disconnected (or from no_data), so no event will be fired.

Listener code

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 two statuses: one before the change takes place and the other when the change is done. For example, a device can be in a "no_data" status and may change to "disconnected" or from "OK" to "no_status" and so on.

So, there is 2 status in an "Event Device Change State" event context:

  • context.data.reason.before_status - device’s status BEFORE the event
  • context.data.reason.status - device’s status AFTER the event

Here is an example using those context fields in a listener script code: