XEP-0325: IoT Control

class slixmpp.plugins.xep_0325.XEP_0325(xmpp, config=None)[source]

XEP-0325: IoT Control

Actuators are devices in sensor networks that can be controlled through the network and act with the outside world. In sensor networks and Internet of Things applications, actuators make it possible to automate real-world processes. This plugin implements a mechanism whereby actuators can be controlled in XMPP-based sensor networks, making it possible to integrate sensors and actuators of different brands, makes and models into larger Internet of Things applications.

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

Events:

Control Event:DirectSet – Received a control message Control Event:SetReq – Received a control request

Control Event:SetResponse – Received a response to a

control request, type result

Control Event:SetResponseError – Received a response to a

control request, type error

Attributes:
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.

set_request – Initiates a control request to modify data in

sensor(s). Non-blocking, a callback function will be called when the sensor has responded.

set_command – Initiates a control command to modify data in

sensor(s). Non-blocking. The sensor(s) will not respond regardless of the result of the command, so no callback is made.

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

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()[source]

Init complete. Register our features in Service discovery.

register_node(nodeId, device, commTimeout, sourceId=None, cacheType=None)[source]

Register a sensor/device as available for control requests/commands through this XMPP instance.

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

has_control_field set_control_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

set_command(from_jid, to_jid, fields, nodeIds=None)[source]

Called on the client side to initiade a control command. Composes a message with the set commandand sends it to the device(s). Does not block. Device(s) will not respond, regardless of result.

Arguments:

from_jid – The jid of the requester to_jid – The jid of the device(s)

fields – Fields to set. List of tuple format: (name, typename, value). nodeIds – [optional] Limits the request to the node Ids in this list.

set_request(from_jid, to_jid, callback, fields, nodeIds=None)[source]

Called on the client side to initiade a control request. Composes a message with the request and sends it to the device(s). Does not block, the callback will be called when the device(s) has responded.

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 result of the control request. Valid values are:

“OK” - Control request completed successfully “NotFound” - One or more nodes or fields are missing “InsufficientPrivileges” - Not authorized. “Locked” - Field(s) is locked and cannot

be changed at the moment.

“NotImplemented” - Request feature not implemented. “FormError” - Error while setting with

a form (not implemented).

“OtherError” - Indicates other types of

errors, such as timeout. Details in the error_msg.

nodeId – [optional] Only applicable when result == “error”

List of node Ids of failing device(s).

fields – [optional] Only applicable when result == “error”

List of fields that failed.[optional] Mandatory when result == “rejected” or “failure”.

error_msg – Details about why the request failed.

fields – Fields to set. List of tuple format: (name, typename, value). nodeIds – [optional] Limits the request to the node Ids in this list.

Stanza elements