-
Notifications
You must be signed in to change notification settings - Fork 3
Protocol specification (v1.0.0)
This document specifies the KNoT Cloud WebSocket protocol.
All messages (requests or responses) are stringified JSON objects in the following format:
-
typeString Message type name -
dataAny (Optional) Message-defined data
{
"type": "register",
"data": {
"type": "gateway",
"name": "Home gateway",
"active": false
}
}Identifies with the server. It establishes a session that is needed to send any other message.
Object in the following format:
-
idString Device ID. -
tokenString Device token.
Replies with ready when successful or error otherwise.
{
"type": "identity"
"data": {
"id": "78159106-41ca-4022-95e8-2511695ce64c",
"token": "d5265dbc4576a88f8654a8fc2c4d46a6d7b85574"
}
}
Registers a device on the cloud. This operation can only be performed by users or devices of type 'gateway'.
Object in the following format:
-
typeString Device type. One of:'thing','gateway'or'app'. -
idString (Optional, mandatory whentypeis'thing') KNoT ID. Will be used as device ID. -
nameString (Optional) Device name. -
activeBoolean (Optional) Defines whether the'gateway'being created is active or not.
Replies with registered when successful or error otherwise.
Triggers registered event.
{
"type": "register",
"data": {
"type": "gateway",
"name": "Home gateway",
"active": false
}
}
Unregisters a device from the cloud. This operation can only be performed by users or devices of type 'gateway'.
Object in the following format:
-
idString Device ID.
Replies with unregistered when successful or error otherwise.
Triggers unregistered event.
{
"type": "unregister",
"data": {
"id": "78159106-41ca-4022-95e8-2511695ce64c"
}
}
Search registered devices.
Object in the following format:
-
queryObject (Optional) Object specifying filters for device's properties.
Replies with devices when successful or error otherwise.
{
"type": "devices",
"data": {
"query": {
"type": "gateway"
}
}
}
Creates a new session token for a device. The authenticated device must have permission to create a token for the target device.
Object in the following format:
-
idString Target device ID.
Replies with created when successful or error otherwise.
{
"type": "token",
"data": {
"id": "78159106-41ca-4022-95e8-2511695ce64c"
}
}
Revokes a token for a device. The authenticated device must have permission to revoke a token for the target device.
Object in the following format:
-
idString Target device ID. -
tokenString Token to be revoked.
Replies with revoked when successful or error otherwise.
{
"type": "revoke",
"data": {
"id": "78159106-41ca-4022-95e8-2511695ce64c",
"token": "d5265dbc4576a88f8654a8fc2c4d46a6d7b85574"
}
}
Updates the device schema. This operation can only be performed by devices of type 'thing'.
Object in the following format:
-
schemaArray Set of properties (associated to KNoT semantic) with details about sensors/actuators.-
sensorIdNumber Sensor id between 0 and the maximum number of sensors defined for that thing. -
typeIdNumber Sensor type, e.g. whether it is a presence sensor or distance sensor. -
valueTypeNumber Value type, e.g. whether it is an integer, a floating-point number, etc. -
unitNumber Sensor unit. -
nameString Sensor name.
-
Replies with updated when successful or error otherwise.
{
"type": "schema",
"data": {
"schema": [
{
"sensorId": 251,
"valueType": 2,
"unit": 1,
"typeId": 13,
"name": "Tank Volume"
},
{
"sensorId": 252,
"valueType": 1,
"unit": 1 ,
"typeId": 5,
"name": "Outdoor Temperature"
},
{
"sensorId": 253,
"valueType": 3,
"unit": 0,
"typeId": 65521,
"name": "Lamp Status"
}
]
}
}
Activates a gateway. This operation can only be performed on devices of type 'gateway'. The authenticated device must have permission to edit the target device.
Object in the following format:
-
idString Target device ID.
Replies with activated when successful or error otherwise.
{
"type": "schema",
"data": {
"id": "78159106-41ca-4022-95e8-2511695ce64c"
}
}
Updates a device's metadata. Only the specified properties will be updated. The authenticated device must have permission to edit the target device.
Object in the following format:
-
idString Target device ID. -
metadataObject An object containing the properties to be updated.
Replies with updated when successful or error otherwise.
{
"type": "metadata",
"data": {
"id": "78159106-41ca-4022-95e8-2511695ce64c",
"metadata": {
"name": "New gateway"
}
}
}
Publishes data. This operation can only be performed by device of type 'thing'.
Object in the following format:
-
sensorIdNumber Sensor id between 0 and the maximum number of sensors defined for that thing. -
valueString|Boolean|Number Sensor value. Strings must be Base64 encoded.
Replies with published when successful or error otherwise.
Triggers data event.
{
"type": "data",
"data": {
"sensorId": 1,
"value": 10.57
}
}
Request the thing to send its current data items values. This operation can only be performed by device of type 'app'.
Object in the following format:
-
idString Device ID. -
sensorIdsArray List of sensor IDs to be sent, each one is a Number.
Replies with sent when successful or error otherwise.
Triggers command event.
{
"type": "getData",
"data": {
"id": 1,
"sensorIds": [2, 3]
}
}
Request the thing to update its data items with the values that are being sent. This operation can only be performed by device of type 'app'.
Object in the following format:
-
idString Device ID.
-
dataArray Data items to be sent, each one formed by:-
sensorIdNumber Sensor ID. -
valueString|Boolean|Number Sensor value. Strings must be Base64 encoded.
-
Replies with sent when successful or error otherwise.
Triggers command event.
{
"type": "setData",
"data": {
"id": 1,
"data": [
{ "sensorId": 2, "value": 7 },
{ "sensorId": 3, "value": true }
]
}
}
Possible response of multiple messages sent in case of error.
Object in the following format:
-
codeNumber Error code (HTTP status is being used). -
messageString (Optional) Message describing the error.
{
"type": "error",
"data": {
"code": 403,
"message": "Forbidden"
}
}
Response of identity when the authentication succeeds.
{
"type": "ready"
}
Response of register when the registration succeeds.
An Object containing the registered device.
{
"type": "registered",
"data": {
"id": "35da7919-c9d1-4d39-ab4c-c3f2956771d7"
"token": "c2473601230d87662118916e9a8882f13f27f078"
"type": "gateway",
"metadata": {
"name": "My gateway"
},
"knot": {
"active": false
}
}
}
Response of unregister when the unregistration succeeds.
{
"type": "unregistered"
}
Response of devices when the query succeeds.
An Array containing Objects representing devices.
{
"type": "devices",
"data": [
{
"id": "35da7919-c9d1-4d39-ab4c-c3f2956771d7"
"type": "gateway",
"metadata": {
"name": "My gateway"
},
"knot": {
"active": false
}
}
]
}
Response of token when the creation succeeds.
The new token as a String.
{
"type": "created",
"data": "c2473601230d87662118916e9a8882f13f27f078"
}
Response of revoke when it succeeds.
{
"type": "revoked"
}
Response of schema or 'metadata' when it succeeds.
{
"type": "updated"
}
Response of activate when it succeeds.
{
"type": "activated"
}
Response of data when it succeeds.
{
"type": "published"
}
Response of getData or setData when it succeeds.
{
"type": "sent"
}
Similar to register's response, triggered when a new device is registered on the cloud.
Device of type 'app'.
An Object containing the registered device.
{
"type": "registered",
"data": {
"id": "35da7919-c9d1-4d39-ab4c-c3f2956771d7"
"token": "c2473601230d87662118916e9a8882f13f27f078"
"type": "gateway",
"metadata": {
"name": "My gateway"
},
"knot": {
"active": false
}
}
}
Similar to unregister's response, triggered when a new device is unregistered from the cloud.
Device of type 'app'.
An Object in following format:
-
idString Device ID.
{
"type": "unregistered",
"data": {
"id": "35da7919-c9d1-4d39-ab4c-c3f2956771d7"
}
}
Similar to data command, triggered when a device published data to the cloud.
Device of type 'app'.
An Object in the following format:
-
idString Device ID. -
sensorIdNumber Sensor id between 0 and the maximum number of sensors defined for that thing. -
valueString|Boolean|Number Sensor value. Strings must be Base64 encoded.
{
"type": "data",
"data": {
"id": "35da7919-c9d1-4d39-ab4c-c3f2956771d7",
"sensorId": 1,
"value": 10.57
}
}
Triggered when a device of type 'app' sends a command. Currently supported commands are getData and setData.
Device of type 'thing'.
An object in the following format:
-
nameString Command name. -
argsAny (Optional) Command-defined arguments.
{
"type": "command",
"data": {
"name": "getData",
"args": {
"id": 1,
"sensorIds": [2, 3]
}
}
}