%ents; ]>
Internet of Things - Events This specification describes an architecture based on the XMPP protocol whereby Things can subscribe to events from other Things based on sensor data available. &LEGALNOTICE; xxxx ProtoXEP Standards Track Standards Council XMPP Core XEP-0001 XEP-0030 XEP-0323 XEP-0324 XEP-0326 iot-events Peter Waher peter.waher@clayster.com peter.waher@jabber.org http://www.linkedin.com/in/peterwaher 0.0.1 2014-08-13 pw

First draft.

This document specifies a method whereby devices or applications can subscribe to events from a Thing, based on sensor data, as defined in XEP-0323: &xep0323;. While XEP-0323 defines a method whereby the device or application can request sensor data information from a Thing when the device or application requires it, this document specifies a method whereby the Thing itself informs the device or application of desired sensor data, when certain conditions have been met, defined by the device or application.

The architecture defined in this document, permits the specification of conditions individually, something that would not be possible, or very difficult to achieve, if a centralized publish/subscribe or multi-cast pattern would have been used. By allowing individual conditions to be specified, devices or applications can be informed of information that best suit them, and when it suits them, instead of having to figure out, from the Thing perspective, a common denominator, sufficiently good for all intended devices or applications. Furthermore, by aligning itself with XEP-0323 and the request/response pattern, the Thing can easily integrate with a provisioning server, as defined in XEP-0324: &xep0324;, to allow for delegation of trust and allowing detailed provisioning of who is allowed to receive what information. Through the use of attributes defined in XEP-0326: &xep0326; subscriptions can be extended to underlying nodes controlled by the Thing as well.

Internet of Things contains many different architectures and use cases. For this reason, the IoT standards have been divided into multiple XEPs according to the following table:

XEP Description
xep-0000-IoT-BatteryPoweredSensors Defines how to handle the peculiars related to battery powered devices, and other devices intermittently available on the network.
xep-0000-IoT-Events This specification. Defines how Things send events, how event subscription, hysteresis levels, etc., are configured.
xep-0000-IoT-Interoperability Defines guidelines for how to achieve interoperability in Internet of Things, publishing interoperability interfaces for different types of devices.
xep-0000-IoT-Multicast Defines how sensor data can be multicast in efficient ways.
xep-0000-IoT-PubSub Defines how efficient publication of sensor data can be made in Internet of Things.
xep-0000-IoT-Chat Defines how human-to-machine interfaces should be constructed using chat messages to be user friendly, automatable and consistent with other IoT extensions and possible underlying architecture.
XEP-0322 Defines how to EXI can be used in XMPP to achieve efficient compression of data. Albeit not an Internet of Things specific XEP, this XEP should be considered in all Internet of Things implementations where memory and packet size is an issue.
XEP-0323 Provides the underlying architecture, basic operations and data structures for sensor data communication over XMPP networks. It includes a hardware abstraction model, removing any technical detail implemented in underlying technologies. This XEP is used by all other Internet of Things XEPs.
XEP-0324 Defines how provisioning, the management of access privileges, etc., can be efficiently and easily implemented.
XEP-0325 Defines how to control actuators and other devices in Internet of Things.
XEP-0326 Defines how to handle architectures containing concentrators or servers handling multiple Things.
XEP-0331 Defines extensions for how color parameters can be handled, based on &xep0004;
XEP-0336 Defines extensions for how dynamic forms can be created, based on &xep0004;, &xep0122;, &xep0137; and &xep0141;.
XEP-0347 Defines the peculiars of Thing discovery in Internet of Things. Apart from discovering Things by JID, it also defines how to discover Things based on location, etc.

The following table lists common terms and corresponding descriptions.

Actuator
Device containing at least one configurable property or output that can and should be controlled by some other entity or device.
Computed Value
A value that is computed instead of measured.
Concentrator
Device managing a set of devices which it publishes on the XMPP network.
Field
One item of sensor data. Contains information about: Node, Field Name, Value, Precision, Unit, Value Type, Status, Timestamp, Localization information, etc. Fields should be unique within the triple (Node ID, Field Name, Timestamp).
Field Name
Name of a field of sensor data. Examples: Energy, Volume, Flow, Power, etc.
Field Type
What type of value the field represents. Examples: Momentary Value, Status Value, Identification Value, Calculated Value, Peak Value, Historical Value, etc.
Historical Value
A value stored in memory from a previous timestamp.
Identification Value
A value that can be used for identification. (Serial numbers, meter IDs, locations, names, etc.)
Localization information
Optional information for a field, allowing the sensor to control how the information should be presented to human viewers.
Meter
A device possible containing multiple sensors, used in metering applications. Examples: Electricity meter, Water Meter, Heat Meter, Cooling Meter, etc.
Momentary Value
A momentary value represents a value measured at the time of the read-out.
Node
Graphs contain nodes and edges between nodes. In Internet of Things, sensors, actuators, meters, devices, gateways, etc., are often depicted as nodes whereas links between sensors (friendships) are depicted as edges. In abstract terms, it's easier to talk about a Node, rather than list different possible node types (sensors, actuators, meters, devices, gateways, etc.). Each Node has a Node ID.
Node ID
An ID uniquely identifying a node within its corresponding context. If a globally unique ID is desired, an architecture should be used using a universally accepted ID scheme.
Parameter
Readable and/or writable property on a node/device. The XEP-0326 &xep0326; deals with reading and writing parameters on nodes/devices. Fields are not parameters, and parameters are not fields.
Peak Value
A maximum or minimum value during a given period.
Precision
In physics, precision determines the number of digits of precision. In sensor networks however, this definition is not easily applicable. Instead, precision determines, for example, the number of decimals of precision, or power of precision. Example: 123.200 MWh contains 3 decimals of precision. All entities parsing and delivering field information in sensor networks should always retain the number of decimals in a message.
Sensor
Device measuring at least one digital value (0 or 1) or analog value (value with precision and physical unit). Examples: Temperature sensor, pressure sensor, etc. Sensor values are reported as fields during read-out. Each sensor has a unique Node ID.
SN
Sensor Network. A network consisting, but not limited to sensors, where transport and use of sensor data is of primary concern. A sensor network may contain actuators, network applications, monitors, services, etc.
Status Value
A value displaying status information about something.
Timestamp
Timestamp of value, when the value was sampled or recorded.
Token
A client, device or user can get a token from a provisioning server. These tokens can be included in requests to other entities in the network, so these entities can validate access rights with the provisioning server.
Unit
Physical unit of value. Example: MWh, l/s, etc.
Value
A field value.
Value Status
Status of field value. Contains important status information for Quality of Service purposes. Examples: Ok, Error, Warning, Time Shifted, Missing, Signed, etc.
Value Type
Can be numeric, string, boolean, Date & Time, Time Span or Enumeration.
WSN
Wireless Sensor Network, a sensor network including wireless devices.
XMPP Client
Application connected to an XMPP network, having a JID. Note that sensors, as well as applications requesting sensor data can be XMPP clients.

Subscribing to events is performed much the same way as requesting sensor data from a device, as defined in XEP-0323. Instead of requesting the data using the req element of the urn:xmpp:iot:sensordata namespace, it is done using the subscribe element of the urn:xmpp:iot:events namespace. Much of the syntax of this subscribe element coincides with that of the req element, with some differences, as will be described in this document.

Responses and sensor data is then sent from the device to the subscriber, in the same way as defined in XEP-0323, with one notable difference: The sequence number seqnr provided in the request, is not forgotten once a readout has been completed, but will be reused every time the Thing reports data to the subscriber. The subscriber must use this sequence number to correlate incoming sensor data with original request. Furthermore, the subscriber must not reuse the sequence number in other sensor data requests to the Thing, while the subscription is alive.

A subscription is cancelled by the subscriber sending a request with an unsubscribe element in it to the Thing. The Thing can also automatically remove subscriptions if the corresponding friendship ends. Furthermore, event conditions should only be evaluated if the corresponding subscriber is online. This, to avoid offline messages to pile up. Once a friend comes online, any subscription conditions corresponding to that friend should be evaluated to inform it of the current state of the Thing.

The client that wishes to receive momentary values regularly from the sensor initiates the request using the subscribe element sent to the device. In the following example, a subscription is made to receive momentary values every five minutes (specified by the maxInterval attribute), with no field-specific conditions attached.

]]>

When the device has received and accepted the request, it responds as follows, using the accepted element defined in XEP-0323. Sensor data is later reported in a way similar to XEP-0323, with the exception that the seqnr will be reused every time the event occurs. If the event causes multiple messages to be sent, the receiver knows which one is the last message, by looking at the done attribute. Since the req attribute is set to true, an event will be sent back immediately (i.e. emulating a parallel readout request operation).

]]>

If for some reason, the device rejects the subscription request, the communication sequence might look as follows:

Access denied. ]]>

Depending on the reason for rejecting the request, different XMPP errors can be returned, according to the description in the following table. The table also lists recommended error type for each error. Any custom error message is returned in a text element, as in the example above.

Error Type Error Element Namespace Description
cancel forbidden urn:ietf:params:xml:ns:xmpp-stanzas If the caller lacks privileges to perform the action.
cancel item-not-found urn:ietf:params:xml:ns:xmpp-stanzas If an item or data source could not be found.
modify bad-request urn:ietf:params:xml:ns:xmpp-stanzas If the request was malformed. Examples can include trying to subscribe to information from a device behind a concentrator, without including node information.

To unsubscribe a subscription, send the unsubscribe element in a request to the Thing with the seqnr sequence number corresponding to the subscription. The Thing responds with an empty response to acknowledge the un-subscription, regardless if the subscription existed or not.

]]>

The client that wishes to receive information when a field or a set fields change, can do so by specifying amount of change allowed in the corresponding field elements in the subscription. It can also provide optional current values from which the change is measured. If current values are not provided, the Thing uses its corresponding set of current values at the time it receives the request. Current values use the corresponding unit held by the field. To find out, if unsure, you need to make a sensor data readout first.

In the following example, events are sent when light changes by more than 5 units (of a percent), or if a motion detector changes value. Temperature information at the time of the event is also requested. If the conditions are not met within fifteen minutes, an event is raised anyway (as defined using the maxInterval attribute). The minInterval attribute makes sure events are not sent more often than every five seconds.

]]>

Any type of sensor data can be included in an event subscription, including historical data. To limit the amount of historical data to return in an event, the maxAge attribute can be used, instead of the absolute from and to attributes available in the corresponding req element. The following example requests the last five minutes of historical temperature and light data as soon as the motion detector detects motion (change upwards of 1).

]]>

Any type of sensor data can be included in an event subscription, including historical data. To limit the amount of historical data to return in an event, the maxAge attribute can be used, instead of the absolute from and to attributes available in the corresponding req element. The following example requests the last five minutes of historical temperature and light data as soon as the motion detector detects motion (change upwards of 1).

]]>

To subscribe to events from one or more nodes behind a concentrator, the nodes have to be specified using node elements in the subscription request. If more than one node is present, the subscription request is assumed to be made to each node individually. When the subscription conditions are met, the corresponding node sends its sensor data back to the subscriber. Note that only the node where the conditions are met include data in the message sent to the subscriber. Event subscriptions are handled individually for each node.

In the following example, a subscription of any changes to a sequence of digital inputs handled by a PLC is made.

]]>

If an entity supports the protocol specified herein, it MUST advertise that fact by returning a feature of "urn:xmpp:iot:events" in response to &xep0030; information requests.

]]> ... ... ]]>

In order for an application to determine whether an entity supports this protocol, where possible it SHOULD use the dynamic, presence-based profile of service discovery defined in &xep0115;. However, if an application has not received entity capabilities information from an entity, it SHOULD use explicit service discovery instead.

An integral part of conditions, is the measurement of changes of magnitudes of field values. Three attributes available on the field element, can be used to define how to measure changes. The changedUp attribute provides a numerical value limiting the amount of upwards change in the field before an event is triggered. The changedDown attributes provides a similar means to control the amount of downwards change in the field, before an event is triggered. If only one of these are provided, only changes in that direction trigger events. If the changedBy attribute is provided, the other two attributes are ignored, and assumed to be of the same value as the changedBy attribute value. All changes are specified using positive numbers.

The following table shows how magnitudes are calculated for field values of different types:

Type Magnitude
boolean Magnitude is 0 if false, and 1 if true.
date Number of seconds since an implementation specific point in time. Since only changes are measured, actual point in time is not important.
dateTime Number of seconds since an implementation specific point in time. Since only changes are measured, actual point in time is not important.
duration Corresponding number of seconds.
enum Any change to this value, corresponds to a change by 1. If direction of change is important, values are ordered by lexical order.
int The value itself.
long The value itself.
numeric The value itself, without unit. The magnitude specified in any change attributes is assumed to be specified using the same unit as the corresponding field.
string Any change to this value, corresponds to a change by 1. If direction of change is important, values are ordered by lexical order.
time Corresponding number of seconds.

Event conditions should be checked, if the following conditions are true for the corresponding event:

  • One of the following conditions are true:
    • A new value is available.
    • A subscriber comes online.
    • The minimum interval timer expires, if specified.
    • The maximum interval timer expires, if specified.
  • The corresponding subscriber is online.
  • The corresponding event has not been triggered within minInterval seconds, if specified.

If a friendship is lost, i.e. presence information from the corresponding contact is unsubscribed, the Thing has to automatically remove any event subscriptions available for that contact. If a new friendship is created with the same contact at a later stage, the contact has to request new subscriptions.

It is up to the thing, if it wants to persist event subscriptions or not. If not persisting event subscriptions, they will automatically be lost if the Thing rests or restarts for some reason.

If the subscriber considers an event subscription important, and wants to make sure a subscription survives any resets of the thing, the maxInterval attribute should be used when requesting the subscription. If an event is not delivered within this time and a margin, the subscriber can assume the subscription has been lost, and a new subscription can be made.

A subscriber can only have one active subscription per node on a Thing. If a Thing does not support nodes, each subscriber can only have one active subscription per corresponding Thing. This means, that a new event subscription automatically overrides (or unsubscribes) any existing subscription on the corresponding node or Thing. This in turn makes it easier for subscribers to handle restarts and avoids multiplicity problems due to lack of synchronization between subscriber and Thing.

If a Thing is connected to a provisioning server, as defined in XEP-324: Internet of Things - Provisioning , it should re-evaluate event subscriptions contents if a clearCache command is received from the provisioning server. To be able to do this properly, the contents of the original event subscription should be remembered. Re-evaluating active event subscriptions after a clearCache command enables the owner of the Thing to modify current access rights in the Thing in real-time, including contents send in events.

Existing event subscriptions that are no longer permitted by the new set of rules in the provisioning server, can be removed from memory, without informing the subscriber about the fact. The subscriber will be informed when re-subscribing, that access rights have been lost.

This document requires no interaction with &IANA;.

The protocol schema needs to be added to the list of XMPP protocol schemas.

]]>

For more information, please see the following resources: