Publisher

The publisher is a service inside of Yggio that pushes data to external services, informing them about iotnode updates. The data will can currently be sent through either HTTP or MQTT.

To receive updates from an iotnode you have to create a channel. The channel is a description of where updates to the iotnode should be sent. See the figure below.

channel

HTTP data will be sent through a POST request to the channel url.
MQTT data will be sent through the Yggio MQTT broker to the channel topic.

The request body will be of the following format:

{
  iotnode: Iotnode,
  diff: Object,
  event: Object
}

iotnode is the iotnode entity that has been updated.
diff contains the attributes that was changed in the update.
event contains the attributes that triggered the update.

Setting up a channel

Creating a channel is done by a simple POST request to our REST API, details can be found on Swagger.
Requirements for HTTP and MQTT channels differ and can be found below

HTTP

Creating an HTTP channel requires an iotnode and a URL. The URL will not be changed in any way in Yggio, so make sure it matches your server exactly. This means including http/https if required. Updates for the iotnode will be POSTed to the URL with header content-type: application/json i.e. it will be POSTed as JSON.

MQTT

MQTT channels work a bit differently, since the MQTT protocol requires you to connect to the Yggio MQTT broker. For information on how to connect, please refer to MQTT Broker

Creating an MQTT channel requires an iotnode and a topic.

The topic is required to consist of three parts:
publish is a constant string, it must always be publish.
iotnodeId is the iotnode _id, must be the same as the iotnode.
uniqueKey is an arbitrary string which must include only valid topic characters.

The topic is required to be on the following formats:
publish/<iotnodeId>/<uniqueKey>.
An alternative format replaces the slashes with dots:
publish.<iotnodeId>.<uniqueKey>.

The <iotnodeId> part can be omitted and is then automatically added:
If the iotnode in the request is 53cb6b9b4f4ddef1ad47f943, the request topic publish/uniqueKey will parse to publish/53cb6b9b4f4ddef1ad47f943/uniqueKey.

The unique key may include additional delimiters.
For instance, the topic publish.storage.outside.temperatures is valid and will parse to publish.<iotnodeId>.storage.outside.temperatures

A quick way to validate your topic is to match it with this regular expression:
/^publish(?!.*(\*|\+|#))(((?!.*(\.|\/{2,}))(\/*.+[^/]$))|((?!.*(\/|\.{2,}))(\.*.+[^.]$)))/