NDU API reference

Device connectivity and server-side APIs.

MQTT Gateway API Reference

Introduction

The Gateway is a special type of device in NDU that is able to act as a bridge between external devices connected to different systems and NDU. Gateway API provides the ability to exchange data between multiple devices and the platform using single MQTT connection. The Gateway also acts as a NDU device and can leverage existing MQTT Device API to report stats, receive configuration updates and much more.

Basic MQTT API

Please refer to generic MQTT Device API to get information about data format, authentication options, etc.

Device Connect API

In order to inform NDU that device is connected to the Gateway, one needs to publish following message:

1
2
Topic: v1/gateway/connect
Message: {"device":"Device A"}

where Device A is your device name.

Once received, NDU will lookup or create a device with the name specified. Also, NDU will publish messages about new attribute updates and RPC commands for a particular device to this Gateway.

Device Disconnect API

In order to inform NDU that device is disconnected from the Gateway, one needs to publish following message:

1
2
Topic: v1/gateway/disconnect
Message: {"device":"Device A"}

where Device A is your device name.

Once received, NDU will no longer publish updates for this particular device to this Gateway.

Attributes API

NDU attributes API allows devices to

Publish attribute update to the server

In order to publish client-side device attributes to NDU server node, send PUBLISH message to the following topic:

1
2
Topic: v1/gateway/attributes
Message: {"Device A":{"attribute1":"value1", "attribute2": 42}, "Device B":{"attribute1":"value1", "attribute2": 42}}

where Device A and Device B are your device names, attribute1 and attribute2 are attribute keys.

Request attribute values from the server

In order to request client-side or shared device attributes to NDU server node, send PUBLISH message to the following topic:

1
2
Topic: v1/gateway/attributes/request
Message: {"id": $request_id, "device": "Device A", "client": true, "key": "attribute1"}

where $request_id is your integer request identifier, Device A is your device name, client identifies a client or shared attribute scope and key is the attribute key.

Before sending PUBLISH message with the request, client need to subscribe to

1
Topic: v1/gateway/attributes/response

and expect messages with result in the following format:

1
Message: {"id": $request_id, "device": "Device A", "value": "value1"}
Subscribe to attribute updates from the server

In order to subscribe to shared device attribute changes, send SUBSCRIBE message to the following topic:

1
v1/gateway/attributes

and expect messages with result in the following format:

1
Message: {"device": "Device A", "data": {"attribute1": "value1", "attribute2": 42}}

Telemetry upload API

In order to publish device telemetry to NDU server node, send PUBLISH message to the following topic:

1
Topic: v1/gateway/telemetry

Message:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
{
  "Device A": [
    {
      "ts": 1483228800000,
      "values": {
        "temperature": 42,
        "humidity": 80
      }
    },
    {
      "ts": 1483228801000,
      "values": {
        "temperature": 43,
        "humidity": 82
      }
    }
  ],
  "Device B": [
    {
      "ts": 1483228800000,
      "values": {
        "temperature": 42,
        "humidity": 80
      }
    }
  ]
}

where Device A and Device B are your device names, temperature and humidity are telemetry keys and ts is unix timestamp in milliseconds.

RPC API

Server-side RPC

In order to subscribe to RPC commands from the server, send SUBSCRIBE message to the following topic:

1
v1/gateway/rpc

and expect messages with individual commands in the following format:

1
{"device": "Device A", "data": {"id": $request_id, "method": "toggle_gpio", "params": {"pin":1}}}

Once command is processed by device, gateway can send commands back using following format:

1
{"device": "Device A", "id": $request_id, "data": {"success": true}}

where $request_id is your integer request identifier, Device A is your device name and method is your RPC method name.

Claiming devices API

In order to initiate claiming device, send PUBLISH message to the following topic:

1
Topic: v1/gateway/claim

Message:

1
2
3
4
5
6
7
8
9
10
{
  "Device A": {
    "secretKey": "value_A",
    "durationMs": 60000
  },
  "Device B": {
    "secretKey": "value_B",
    "durationMs": 60000
  }
}

where Device A and Device B are your device names, secretKey and durationMs are optional keys. In case the secretKey is not specified, the empty string as a default value is used. In case the durationMs is not specified, the system parameter device.claim.duration is used.