Subscribe to data

Subscribing to data is accomplished with the subscribe operation.

A subscription will let you know if changes have been made to the subscribed resources. When data has been changed a notification will received by the subscriber and the subscriber will then have the option to re-subscribe to the subscription by reading the data and stating an explicit re-subscribe.

Subscription examples

Example request

<iq xml:lang="en" to="testsource@xmpphost.clayster.com/sourcetest" 
  from="testcontroller@xmpphost.clayster.com/controllertest" 
  type="set" 
  id="79aa6dcc-4115-4f44-beee-cb62f92df316">
  <subscribe xmlns="urn:clayster:lwtsd" 
    subscriptionid="2b71a032-5694-4808-9e2f-4c0800dc7cfc">
    <accesstoken name="urn:clayster:cdo:sessionid">dummysession</accesstoken>
    <trigger onresource="thermometers/temp2"/>
    <trigger onresource="writables/item1"/>
    <trigger onresource="writables/item0"/>
    <trigger onresource="writables/item2"/>
    <trigger onresource="thermometers/temp0"/>
    <trigger onresource="thermometers/temp1"/>
  </subscribe>
</iq>

Example response

<iq xml:lang="en" to="testsource@xmpphost.clayster.com/sourcetest" 
  from="testcontroller@xmpphost.clayster.com/controllertest" 
  type="set" id="79aa6dcc-4115-4f44-beee-cb62f92df316">
  <subscribe xmlns="urn:clayster:lwtsd" 
  subscriptionid="2b71a032-5694-4808-9e2f-4c0800dc7cfc">
    <trigger onresource="thermometers/temp2"/>
    <trigger onresource="writables/item1"/>
    <trigger onresource="writables/item0"/>
    <trigger onresource="writables/item2"/>
    <trigger onresource="thermometers/temp0"/>
    <trigger onresource="thermometers/temp1"/>
  </subscribe>
</iq>

Subscription triggered examples

Example response

<message xml:lang="en" to="testcontroller@xmpphost.clayster.com/controllertest" 
  from="testsource@xmpphost.clayster.com/sourcetest" 
  id="c8518eac-da16-4f6b-a338-c95b213ea8c2">
  <subscription-triggered xmlns="urn:clayster:lwtsd" 
    subscriptionid="2b71a032-5694-4808-9e2f-4c0800dc7cfc"/>
</message>

Re-subscription examples

Example request

<iq xml:lang="en" to="testsource@xmpphost.clayster.com/sourcetest" 
  from="testcontroller@xmpphost.clayster.com/controllertest" 
  type="get" 
  id="d3f0ec2d-9834-4916-be9f-67b421c52173">
  <read-data xmlns="urn:clayster:lwtsd" maxpoints="500" 
    startindex="0" 
    relativetimeout="10">
    <accesstoken name="urn:clayster:cdo:sessionid">dummysession</accesstoken>
    <re-subscribe subscriptionid="2b71a032-5694-4808-9e2f-4c0800dc7cfc"/>
    <read resource="thermometers/temp2" maxpoints="1"/>
    <read resource="writables/item1" maxpoints="1"/>
    <read resource="writables/item0" maxpoints="1"/>
    <read resource="writables/item2" maxpoints="1"/>
    <read resource="thermometers/temp0" maxpoints="1"/>
    <read resource="thermometers/temp1" maxpoints="1"/>
  </read-data>
</iq>

Example response

<iq lang="en" to="testcontroller@xmpphost.clayster.com/controllertest" 
  from="testsource@xmpphost.clayster.com/sourcetest" 
  type="result" 
  id="d3f0ec2d-9834-4916-be9f-67b421c52173">
  <data schemaversion="455D046E" 
    returnedpoints="6" 
    totalpoints="6" 
    xmlns="urn:clayster:lwtsd">
    <resource path="thermometers/temp2" returnedpoints="1" totalpoints="1">
      <point timestamp="2017-10-23T18:01:03.497037Z">22</point>
    </resource>
    <resource path="writables/item1" returnedpoints="1" totalpoints="1">
      <point timestamp="2017-10-23T18:01:03.931589Z">3</point>
    </resource>
    <resource path="writables/item0" returnedpoints="1" totalpoints="1">
      <point timestamp="2017-10-23T18:01:03.497052Z">1</point>
    </resource>
    <resource path="writables/item2" returnedpoints="1" totalpoints="1">
      <point timestamp="2017-10-23T18:01:03.497114Z">3</point>
    </resource>
    <resource path="thermometers/temp0" returnedpoints="1" totalpoints="1">
      <point timestamp="2017-10-23T18:01:03.494067Z">20</point>
    </resource>
    <resource path="thermometers/temp1" returnedpoints="1" totalpoints="1">
      <point timestamp="2017-10-23T18:01:03.497028Z">21</point>
    </resource>
  </data>
</iq>