Commit 4109fd64 authored by Peter Waher's avatar Peter Waher

Adding Publish/Subscribe communication patterrn.

parent 6857094b
......@@ -21,6 +21,7 @@ Communication Patterns
* [Sensor Data Request/Response communication pattern](SensorDataRequestResponse.md)
* [Sensor Data Event Subscription communication pattern](SensorDataEventSubscription.md)
* [Sensor Data Publish/Subscribe communication pattern](SensorDataPublishSubscribe.md)
* [Simple Control Actions](ControlSimpleActions.md)
* [Data Form Control Actions](ControlDataForm.md)
* [Clock Synchronization](ClockSynchronization.md)
......@@ -49,10 +50,10 @@ Implementations
### Libraries related to Sensor data
| Project | Language | Environment | Source Code | Description |
|--------------------------------------------------------------------------------------------------------|----------|--------------|------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------|
| [Waher.Networking.XMPP.Sensor](https://www.nuget.org/packages/Waher.Networking.XMPP.Sensor/) | C# | .NET Std 1.3 | [GitHub](https://github.com/PeterWaher/IoTGateway/tree/master/Networking/Waher.Networking.XMPP.Sensor) | Sensor data library. Handles both sensor data requests, as well as event subscriptions. Both client and server side supported. |
| [Waher.Networking.XMPP.Sensor.UWP](https://www.nuget.org/packages/Waher.Networking.XMPP.Sensor.UWP/) | C# | UWP | [GitHub](https://github.com/PeterWaher/IoTGateway/tree/master/Networking/Waher.Networking.XMPP.Sensor.UWP) | Sensor data library for UWP. Handles both sensor data requests, as well as event subscriptions. Both client and server side supported. |
| Project | Language | Environment | Source Code | Description |
|--------------------------------------------------------------------------------------------------------|----------|--------------|------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [Waher.Networking.XMPP.Sensor](https://www.nuget.org/packages/Waher.Networking.XMPP.Sensor/) | C# | .NET Std 1.3 | [GitHub](https://github.com/PeterWaher/IoTGateway/tree/master/Networking/Waher.Networking.XMPP.Sensor) | Sensor data library. Handles sensor data requests, event subscriptions as well as publish/subscribe using PEP. Both client and server side supported. |
| [Waher.Networking.XMPP.Sensor.UWP](https://www.nuget.org/packages/Waher.Networking.XMPP.Sensor.UWP/) | C# | UWP | [GitHub](https://github.com/PeterWaher/IoTGateway/tree/master/Networking/Waher.Networking.XMPP.Sensor.UWP) | Sensor data library for UWP. Handles sensor data requests, event subscriptions as well as publish/subscribe using PEP. Both client and server side supported. |
### Libraries related to Control actions
......@@ -84,10 +85,19 @@ Implementations
### Libraries related to Clock Synchronization
| Project | Language | Environment | Source Code | Description |
|------------------------------------------------------------------------------------------------------------------------|----------|--------------|---------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------|
| [Waher.Networking.XMPP.Synchronization](https://www.nuget.org/packages/Waher.Networking.XMPP.Synchronization/) | C# | .NET Std 1.3 | [GitHub](https://github.com/PeterWaher/IoTGateway/tree/master/Networking/Waher.Networking.XMPP.Synchronization) | Can be used t synchronize clocks between entities in a global federated network. |
| [Waher.Networking.XMPP.Synchronization.UWP](https://www.nuget.org/packages/Waher.Networking.XMPP.Synchronization.UWP/) | C# | UWP | [GitHub](https://github.com/PeterWaher/IoTGateway/tree/master/Networking/Waher.Networking.XMPP.Synchronization.UWP) | Can be used t synchronize clocks between entities in a global federated network, for UWP. |
| Project | Language | Environment | Source Code | Description |
|------------------------------------------------------------------------------------------------------------------------|----------|--------------|---------------------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------|
| [Waher.Networking.XMPP.Synchronization.UWP](https://www.nuget.org/packages/Waher.Networking.XMPP.Synchronization.UWP/) | C# | UWP | [GitHub](https://github.com/PeterWaher/IoTGateway/tree/master/Networking/Waher.Networking.XMPP.Synchronization.UWP) | Can be used to synchronize clocks between entities in a global federated network, for UWP. |
| [Waher.Networking.XMPP.Synchronization](https://www.nuget.org/packages/Waher.Networking.XMPP.Synchronization/) | C# | .NET Std 1.3 | [GitHub](https://github.com/PeterWaher/IoTGateway/tree/master/Networking/Waher.Networking.XMPP.Synchronization) | Can be used to synchronize clocks between entities in a global federated network. |
### Libraries related to Publish/Subscribe
| Project | Language | Environment | Source Code | Description |
|------------------------------------------------------------------------------------------------------|----------|--------------|------------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------|
| [Waher.Networking.XMPP.PEP](https://www.nuget.org/packages/Waher.Networking.XMPP.PEP/) | C# | .NET Std 1.3 | [GitHub](https://github.com/PeterWaher/IoTGateway/tree/master/Networking/Waher.Networking.XMPP.PEP) | Support for the Personal Eventing Protocol (PEP) simplified Publish/Subscrube pattern in XMPP (XEP-0163). |
| [Waher.Networking.XMPP.PEP.UWP](https://www.nuget.org/packages/Waher.Networking.XMPP.PEP.UWP/) | C# | UWP | [GitHub](https://github.com/PeterWaher/IoTGateway/tree/master/Networking/Waher.Networking.XMPP.PEP.UWP) | Support for the Personal Eventing Protocol (PEP) simplified Publish/Subscrube pattern in XMPP (XEP-0163), for UWP. |
| [Waher.Networking.XMPP.PubSub](https://www.nuget.org/packages/Waher.Networking.XMPP.PubSub/) | C# | .NET Std 1.3 | [GitHub](https://github.com/PeterWaher/IoTGateway/tree/master/Networking/Waher.Networking.XMPP.PubSub) | Support for generic Publish/Subscribe in XMPP (XEP-0060). |
| [Waher.Networking.XMPP.PubSub.UWP](https://www.nuget.org/packages/Waher.Networking.XMPP.PubSub.UWP/) | C# | UWP | [GitHub](https://github.com/PeterWaher/IoTGateway/tree/master/Networking/Waher.Networking.XMPP.PubSub.UWP) | Support for generic Publish/Subscribe in XMPP (XEP-0060), for UWP. |
### Client software
......
......@@ -123,7 +123,7 @@ Examples
Subscription request:
```xml
<iq type='get' id='28' to='device@example.org/abcd'>
<iq type='get' id='28' from='client@example.org/1234' to='device@example.org/abcd'>
<subscribe xmlns='urn:ieee:iot:events:1.0' id='d4fe61155cb14e649e302092d3b406a8' m='true' minInt='PT1S' maxInt='PT1M'>
<f n='Light' v='25.72' by='1'/>
<f n='Motion' v='0' by='1'/>
......@@ -155,7 +155,7 @@ Event:
Unsubscription request:
```xml
<iq type='get' id='29' to='device@example.org/abcd'>
<iq type='get' id='29' from='client@example.org/1234' to='device@example.org/abcd'>
<unsubscribe xmlns='urn:ieee:iot:events:1.0' id='d4fe61155cb14e649e302092d3b406a8'/>
</iq>
```
......
Sensor Data Publish/Subscribe communication pattern
========================================================
XMPP supports three Publish/Subscribe communication patterns:
1. Using the `presence` stanza. All presence stanzas will be forwarded to all contacts with an approved presence subscription. Since the presence stanza
can contain custom XML, it is possible to embed sensor data XML in a presence stanza, and have it forwarded to appoved contacts. There is no way for
subscribers to state if they really want the information they are receiving or not.
2. Publishing information on a node on a Publish/Subscribe service on an XMPP broker, in accordance with [XEP-0060](https://xmpp.org/extensions/xep-0060.html).
This is the recommended method for concentrators wishing to publish information from internal nodes.
3. Publishing information using the Personal Eventing Protocol in XMPP, as defined in [XEP-0163](https://xmpp.org/extensions/xep-0163.html). It's a much
simplified way to implement Publish/Subscribe for sensor data from simple devices (not concentrators) using XMPP.
**Note**: The Publish/Subscribe pattern might be an efficient way to distribute sensor data to many subscribers. But it comes at the price of flexibility and
privacy. Only use the Publish/Subscribe patterrn from devices that actually have many subscribers, and in cases where data does not need to be tailored for
individual receivers, such as is the case if using provisioning on a field level. The Publsh/Subscribe pattern also leaves little room for subscribers to tailor
under what circumstances they want to be updated. In all these cases, the [Request/Response](SensoDataRequestResponse.md) or
[Event Subscription](SensorDataEventSubscription.md) patterns might be more efficient.
In all three cases, [sesor data](SensorData.md) is represented using the same XML representation as used in the other sensor data related
communication patterns.
| Sensor Data ||
| ------------|------------------------------------------|
| Namespace: | urn:ieee:iot:sd:1.0 |
| Schema: | [SensorData.xsd](Schemas/SensorData.xsd) |
Examples
-----------------
### Publishing data using the Personal Eventing Protocol (PEP)
PEP is fully described in [XEP-0163](https://xmpp.org/extensions/xep-0163.html). Please read this document for details.
```xml
<iq from='client@example.org/1234' type='set' id='pub1'>
<pubsub xmlns='http://jabber.org/protocol/pubsub'>
<publish node='urn:ieee:iot:sd:1.0'>
<item>
<resp xmlns="urn:ieee:iot:sd:1.0" id="00000001">
<ts v="2017-09-22T15:22:33Z">
<q n="Temperature" v="12.3" u="C" m="true" ar="true"/>
<s n="SN" v="12345678" i="true" ar="true"/>
</ts>
</resp>
</item>
</publish>
</pubsub>
</iq>
```
**Note**: There is no destination address in the `iq` stanza. This means the stanza is sent to the server. A PEP-compliant XMPP server (broker) treats
all accounts as individual Publish/Subscribe services.
### Implicit subscription of data using the Personal Eventing Protocol (PEP)
A contact implicitly subscribes to sensor data if it does the following:
1. Supports [XEP-0030: Service Discovery](https://xmpp.org/extensions/xep-0030.html). (Most XMPP clients do.)
2. Supports [XEP-0115: Entity Capabilities](https://xmpp.org/extensions/xep-0115.html). (Most XMPP clients do.)
3. Publishes support for the feature `urn:ieee:iot:sd:1.0+notify`.
4. Subscribes to the presence of the sensor.
The Publish/Subscribe service managed by PEP, checks all contacts of the sensor for the sensor data feature, and forwards published data to them.
### Receiving data using the Personal Eventing Protocol (PEP)
The PEP service forwards published information as messages. It can optionally append information about the full JID of the published in an
`addresses` element in accordance with [XEP-0033: Extended Stanza Addressing](https://xmpp.org/extensions/xep-0033.html), to make it possible for
the subscriber to differentiate between multiple connections using the same account.
```xml
<message from='device@example.org'
to='client@example.org/1234'
type='normal'
id='event1'>
<event xmlns='http://jabber.org/protocol/pubsub#event'>
<items node='urn:ieee:iot:sd:1.0'>
<item id='22e25a6a-ce75-251a-880b-a4ac42e4101b' publisher='device@example.org'>
<resp id="00000001" xmlns="urn:ieee:iot:sd:1.0">
<ts v="2017-09-22T15:22:33Z">
<q n="Temperature" v="12.3" u="C" m="true" ar="true"/>
<s n="SN" v="12345678" i="true" ar="true"/>
</ts>
</resp>
</item>
</items>
</event>
<addresses xmlns='http://jabber.org/protocol/address'>
<address type='replyto' jid='device@example.org/abcd'/>
</addresses>
</message>
```
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment