Skip to content
Back to top
View this page

# XEP-0323 Internet of Things - Sensor Data

XEP-0323 on xmpp.org

class slixmpp.plugins.xep_0323.XEP_0323(xmpp, config=None)

  XEP-0323: IoT Sensor Data

  This XEP 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.

  Also see <http://xmpp.org/extensions/xep-0323.html>

  Configuration Values:
    threaded – Indicates if communication with sensors should be threaded.

      Defaults to True.

  Events:

    Sensordata Event:Req – Received a request for data Sensordata Event:Cancel – Received a cancellation for a request

    Sensordata Event:Accepted – Received a accept from sensor for a request Sensordata Event:Rejected – Received a reject from sensor for a request Sensordata Event:Cancelled – Received a cancel confirm from sensor Sensordata Event:Fields – Received fields from sensor for a request

    > This may be triggered multiple times since the sensor can split up its response in multiple messages.

    Sensordata Event:Failure – Received a failure indication from sensor

      for a request. Typically a comm timeout.

  Attributes:
    threaded – Indicates if command events should be threaded.

      Defaults to True.

    sessions – A dictionary or equivalent backend mapping

      session IDs to dictionaries containing data relevant to a request’s session. This dictionary is used both by the client and sensor side. On client side, seqnr is used as key, while on sensor side, a session_id is used as key. This ensures that the two will not collide, so one instance can be both client and sensor.

    nodes – A dictionary mapping sensor nodes that are serviced through

      this XMPP instance to their device handlers (“drivers”).

    last_seqnr – The last used sequence number (integer). One sequence of

      communication (e.g. –>request, <–accept, <–fields) between client and sensor is identified by a unique sequence number (unique between the client/sensor pair)

  Methods:

    plugin_init – Overrides BasePlugin.plugin_init post_init – Overrides BasePlugin.post_init plugin_end – Overrides BasePlugin.plugin_end

    register_node – Register a sensor as available from this XMPP

      instance.

    request_data – Initiates a request for data from one or more

      sensors. Non-blocking, a callback function will be called when data is available.

  cancel_request(session)

    Called on the client side to cancel a request for data readout. Composes a message with the cancellation and sends it to the device(s). Does not block, the callback will be called when cancellation is confirmed.

    Arguments:

      session – The session id of the request to cancel

  default_config: ClassVar[dict[str, Any]] = {'threaded': True}

    The basic, standard configuration for the plugin, which may be overridden when initializing the plugin. The configuration fields included here may be accessed directly as attributes of the plugin. For example, including the configuration field ‘foo’ would mean accessing plugin.foo returns the current value of plugin.config[‘foo’].

  post_init()

    Init complete. Register our features in Service discovery.

  register_node(nodeId, device, commTimeout, sourceId=None, cacheType=None)

    Register a sensor/device as available for serving of data through this XMPP instance.

    The device object may by any custom implementation to support specific devices, but it must implement the functions:

    > has_field request_fields

    according to the interfaces shown in the example device.py file.

    Arguments:

      nodeId – The identifier for the device device – The device object commTimeout – Time in seconds to wait between each callback from device during

      > a data readout. Float.

      sourceId – [optional] identifying the data source controlling the device cacheType – [optional] narrowing down the search to a specific kind of node

  request_data(from_jid, to_jid, callback, nodeIds=None, fields=None, flags=None)

    Called on the client side to initiate a data readout. Composes a message with the request and sends it to the device(s). Does not block, the callback will be called when data is available.

    Arguments:

      from_jid – The jid of the requester to_jid – The jid of the device(s) callback – The callback function to call when data is available.

      > > The callback function must support the following arguments:

      > from_jid – The jid of the responding device(s) result – The current result status of the readout. Valid values are:

      > > “accepted” - Readout request accepted “queued” - Readout request accepted and queued “rejected” - Readout request rejected “failure” - Readout failed. “cancelled” - Confirmation of request cancellation. “started” - Previously queued request is now started “fields” - Contains readout data. “done” - Indicates that the readout is complete.

      > nodeId – [optional] Mandatory when result == “fields” or “failure”.

      >   The node Id of the responding device. One callback will only contain data from one device.

      > timestamp – [optional] Mandatory when result == “fields”.

      >   The timestamp of data in this callback. One callback will only contain data from one timestamp.

      > fields – [optional] Mandatory when result == “fields”.

      >   > List of field dictionaries representing the readout data. Dictionary format:

      >   {

      >     typename: The field type (numeric, boolean, dateTime, timeSpan, string, enum) name: The field name value: The field value unit: The unit of the field. Only applies to type numeric. dataType: The datatype of the field. Only applies to type enum. flags: [optional] data classifier flags for the field, e.g. momentary.

      >     > Formatted as a dictionary like { “flag name”: “flag value” … }

      >   }

      > error_msg – [optional] Mandatory when result == “rejected” or “failure”.

      >   Details about why the request is rejected or failed. “rejected” means that the request is stopped, but note that the request will continue even after a “failure”. “failure” only means that communication was stopped to that specific device, other device(s) (if any) will continue their readout.

      nodeIds – [optional] Limits the request to the node Ids in this list. fields – [optional] Limits the request to the field names in this list. flags – [optional] Limits the request according to the flags, or sets

      > readout conditions such as timing.

    Return value:
      session – Session identifier. Client can use this as a reference to cancel

        the request.

## Stanza elements