-
Couldn't load subscription status.
- 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": "knot: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 'knot:gateway'.
Object in the following format:
-
typeString Device type. One of:'knot:thing','knot:gateway'or'knot:app'. -
idString (Optional, mandatory whentypeis'knot:thing') KNoT ID. Will be used as device ID. -
nameString (Optional) Device name. -
activeBoolean (Optional) Defines whether the'knot:gateway'being created is active or not.
Replies with registered when successful or error otherwise.
Triggers registered event.
{
"type": "register",
"data": {
"type": "knot:gateway",
"name": "Home gateway",
"active": false
}
}Unregisters a device from the cloud. This operation can only be performed by users or devices of type 'knot: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. Depending on the type of the authenticated device, different devices will be returned:
-
'knot:user'can see all registered devices. -
'knot:gateway'can see the'knot:thing's associated to it. -
'knot:app'can see all the'knot:thing's associated to a'knot:user'. -
'knot:thing'won't see any device.
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": "knot: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 'knot:thing'.
Object in the following format:
-
schemaArray Set of properties (associated to KNoT semantic) with details about sensors/actuators.-
sensorIdNumber Sensor ID. Value 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 'knot: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": "activate",
"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 'knot:thing'.
Object in the following format:
-
sensorIdNumber Sensor ID. Value 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 'knot: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": "78159106-41ca-4022-95e8-2511695ce64c",
"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 'knot: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": "78159106-41ca-4022-95e8-2511695ce64c",
"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": "knot: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": "knot: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"
}Events have a common format for the data field, as follows:
-
fromString ID of the device generating the event. -
payloadAny (Optional) Event-defined payload.
Similar to register's response, triggered when a new device is registered on the cloud.
Device of type 'knot:app'.
The from field contains the ID of the device that is registering the new device.
An Object containing the registered device.
{
"type": "registered",
"data": {
"from": "1b235edc-dfbe-46ea-ac01-98ad52b2f0e4",
"payload": {
"id": "35da7919-c9d1-4d39-ab4c-c3f2956771d7",
"token": "c2473601230d87662118916e9a8882f13f27f078",
"type": "knot:gateway",
"metadata": {
"name": "My gateway"
},
"knot": {
"active": false
}
}
}
}Similar to unregister's response, triggered when a device is unregistered from the cloud.
Device of type 'knot:app'.
The from field contains the ID of the device that was unregistered.
{
"type": "unregistered",
"data": {
"from": "35da7919-c9d1-4d39-ab4c-c3f2956771d7"
}
}Similar to data command, triggered when a device published data to the cloud.
Device of type 'knot:app'.
The from field contains the ID of the device that published data.
An Object in the following format:
-
sensorIdNumber Sensor ID. Value 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": {
"from": "35da7919-c9d1-4d39-ab4c-c3f2956771d7",
"payload": {
"sensorId": 1,
"value": 10.57
}
}
}Triggered when a device of type 'knot:app' sends a command. Currently supported commands are getData and setData.
Device of type 'knot:thing'.
The from field contains the ID of the device that issued the command.
An object in the following format:
-
nameString Command name. -
argsAny (Optional) Command-defined arguments.
{
"type": "command",
"data": {
"from": "35da7919-c9d1-4d39-ab4c-c3f2956771d7",
"payload": {
"name": "setData",
"args": [
{
"sensorId": 1,
"value": 100
}
]
}
}
}