This document defines a WebSocket sub-protocol called the Web Thing Protocol, for monitoring and controlling connected devices over the World Wide Web. The Web Thing Protocol is intended as a dedicated real-time protocol for the Web of Things, to enable a WoT Consumer to communicate with one or more WoT Things over a WebSocket connection.
This document defines a WebSocket [[WEBSOCKETS-PROTOCOL]] sub-protocol for monitoring and controlling connected devices over the Web.
The Web of Things (WoT) is a collection of standardised technology building blocks that help provide interoperability on the Internet of Things (IoT). The WoT Thing Description specification [[wot-thing-description11]] defines a metadata format for describing the capabilities of "Things" (connected devices) on the Web. The WoT Discovery specification [[wot-discovery]] defines mechanisms for discovering Things on the Web. This specification complements those building blocks by defining a dedicated real-time protocol for communicating with Things over the Web.
WebSockets [[WEBSOCKETS-PROTOCOL]] provide a way to upgrade a standard HTTP [[HTTP11]] request to a full-duplex, persistent, real-time communication channel over a single TCP connection. This can be used to create a versatile and efficient two-way channel with which a WoT Consumer can communicate with one or more Things [[wot-architecture11]] to carry out the full set of WoT operations. However, since a WebSocket is essentially just a raw TCP socket with no semantics of its own, a sub-protocol needs to be defined in order for a Consumer and Thing to communicate.
Whilst many other WebSocket sub-protocols exist, what makes the Web Thing Protocol unique is that it is specifically designed around the Web of Things information model and set of operations [[wot-thing-description11]], as well as being targeted specifically at Web of Things use cases [[wot-usecases]]. It can therefore be thought of as being native to the Web of Things.
The sub-protocol defines message payload formats for each of the well-known operation types defined in the WoT interaction model [[wot-architecture11]], and other messages needed for WebSocket communication.
This specification is intended to complement deliverables of the WoT Working Group, including WoT Architecture [[wot-architecture11]], WoT Thing Description [[wot-thing-description11]], WoT Discovery [[wot-discovery]], WoT Binding Templates [[wot-binding-templates]] and WoT Profile [[wot-profile]]. It is intended to implement use cases and requirements defined in the Web Thing Protocol Use Cases & Requirements community report.
Whilst this document is not on a standards track, the Web Thing Protocol is intended to eventually join a standards track at the W3C or another standards body such as the IETF.
Fundamental WoT terminology such as Thing or Web Thing, Consumer or WoT Consumer, WoT Thing Description or Thing Description, Interaction Model, Interaction Affordance, Property, Action and Event are defined in the Terminology section of the WoT Architecture specification [[wot-architecture11]].
In order to communicate with a Web Thing, a WoT Consumer [[wot-architecture11]] MUST locate one or more WebSocket [[WEBSOCKETS-PROTOCOL]] endpoints provided by the Thing for a given set of Interaction Affordances [[wot-thing-description11]].
The URL of a WebSocket endpoint to be used for a given interaction MUST be obtained from a Thing Description [[wot-architecture11]] by locating a Form inside the corresponding Interaction Affordance for which:
base
URL
[[wot-thing-description11]] where applicable, the URI scheme [[RFC3986]] of the value of its href
member
[[wot-thing-description11]] is "ws"
or &"wss"
subprotocol
member has a value of "webthingprotocol"
To open a WebSocket on a Thing, an HTTP GET
request [[RFC9110]] MUST be upgraded to
a WebSocket connection using a standard WebSocket protocol handshake [[WEBSOCKETS-PROTOCOL]],
specifying the "webthingprotocol" sub-protocol.
GET wss://mythingserver.com/things/robot Host: mythingserver.com Origin: https://mythingserver.com Upgrade: websocket Connection: Upgrade Sec-WebSocket-Key: x3JJHMbDL1EzLkh9GBhXDw== Sec-WebSocket-Protocol: webthingprotocol Sec-WebSocket-Version: 13
HTTP/1.1 101 Switching Protocols Upgrade: websocket Connection: Upgrade Sec-WebSocket-Accept: HSmrc0sMlYUkAGmm5OPpG2HaGWk= Sec-WebSocket-Protocol: webthingprotocol
Sub-protocol name to be confirmed, see IANA Considerations.
A WebSocket can be opened from a web page using the JavaScript WebSocket API [[WEBSOCKETS-API]] which will take care of the handshake detailed above and allow messages to be sent and received.
const socket = new WebSocket('wss://mywebthingserver/things/robot', 'webthingprotocol');
A single WebSocket [[WEBSOCKETS-PROTOCOL]] connection from a WoT Consumer MAY be shared between multiple Interaction Affordances of a Thing. A single WebSocket connection from a WoT Consumer MAY also be shared between multiple Things.
Before opening a new WebSocket connection, a WoT Consumer SHOULD check whether it already has an open connection to the same WebSocket endpoint URL.
If an existing connection to the same WebSocket endpoint URL exists, then that connection SHOULD be re-used rather than opening an additional socket.
If an existing connection to the same WebSocket endpoint URL exists but is using a different set of credentials
for its given SecurityScheme
[[wot-thing-description11]] (e.g. a different Bearer Token), then the WoT Consumer MUST NOT re-use the
connection.
All messages MUST be a JSON object [[JSON]].
Member | Type | Assignment | Description |
---|---|---|---|
thingID |
string | Mandatory | The ID (URI) of the Thing to which the message relates. |
messageID |
string | Mandatory | A unique identifier (UUID) for the current message. |
messageType |
string | Mandatory | A string which denotes the type of message (one of request , response or
notification ).
|
operation |
string | Mandatory | A string which denotes the type of WoT operation
[[wot-thing-description11]] to which the message relates (one of
readproperty , writeproperty , observeproperty ,
unobserveproperty , invokeaction , queryaction ,
cancelaction , subscribeevent , unsubscribeevent ,
readallproperties , writeallproperties , readmultipleproperties ,
writemultipleproperties , observeallproperties ,
unobserveallproperties , subscribeallevents , unsubscribeallevents , or
queryallactions ).
|
correlationID |
string | Optional | A unique identifer (UUID) which is shared between messages corresponding to the same operation, e.g. a request and a response. |
The top level JSON object MUST contain a thingID
member with the value set to a unique identifier of
the Web Thing to which the message relates.
If the Thing Description of the Web Thing contains an id
member then the value of that
id
member MUST be used as the unique identifier assigned to thingID
.
If the Thing Description of the Web Thing does not contain an id
member then the URL
[[URL]] from which the Thing Description was retrieved MAY be used as the thingID
value
instead. The value of the thingID
member MUST be a valid URI [[URI]] serialised as a string.
The top level JSON object MUST contain a messageID
member with the value set to a unique identifier
for the current message in UUIDv4 format [[rfc9562]].
The top level JSON object MUST contain a messageType
member, with its value set to one of
request
, response
or notification
.
Message type | Direction | Description |
---|---|---|
request |
Consumer ➡ Thing | A message sent from a Consumer to a Thing (e.g. to request a reading of a property, invoke an action or subscribe to an event) |
response |
Thing ➡ Consumer | A message sent from a Thing to a Consumer in response to a request (e.g. to respond with a property reading, provide the final response to an action or confirm a subscription to an event) |
notification |
Thing ➡ Consumer | A message pushed from a Thing to a Consumer (e.g. an event, change in property value, or change in action state) |
The top level JSON object MUST contain an operation
member, with its value set to one of the
well-known WoT operation names from
the Thing Description specification [[wot-thing-description11]].
The lifecycle of an operation consists of a series of messages in a sequence (e.g. a request followed by a response, or a request followed by a response then one or more notifications). Each type of operation follows a particular sequence of message types, outlined in the table below:
Operation | Lifecycle |
---|---|
readproperty |
request, response |
writeproperty |
request, response |
readallproperties |
request, response |
readmultipleproperties |
request, response |
The top level JSON object MAY contain a correlationID
member which provides a unique identifier in
UUIDv4 format [[rfc9562]] which is shared between messages corresponding to the same WoT operation (e.g. a
property read request and response, or an event subscription request and event notification). If a request message
contains a correlatonID
member then any response and notification messages which correspond to the
same operation MUST also include a correlationID
member with the same value.
All date and time values MUST use the date-time
format
defined in [[RFC3339]].
2025-01-15T12:08:00.42Z
In order to reduce ambiguity, RFC 3339 only permits an hour with a value between 00 and 23 (not 24), and time zones expressed as a numerical offset relative to UTC. The suffix "Z" when applied to a time denotes a UTC offset of 00:00.
readproperty
To request a property reading from a Thing, a Consumer MUST send a message to the Thing which contains the following members:
Member | Type | Assignment | Description |
---|---|---|---|
messageType |
string | "request" | A string which denotes that this message is a request sent from a Consumer to a Thing. |
operation |
string | "readproperty" | A string which denotes that this message relates to a readproperty operation. |
name |
string | Mandatory | The name of the Property to read, as per its key in the properties member of
the Thing Description.
|
{ "thingID": "https://mythingserver.com/things/mylamp1", "messageID": "c370da58-69ae-4e83-bb5a-ac6cfb2fed54", "messageType": "request", "operation": "readproperty", "name": "on", "correlationID": "5afb752f-8be0-4a3c-8108-1327a6009cbd" }
When a Thing receives a message from a Consumer with messageType
set to
request
and operation
set to readproperty
it MUST
attempt to read the value of the Property with the given name
.
Upon successfully reading the value of the requested Property, the Thing MUST send a message to the
requesting Consumer
containing the following members:
Member | Type | Assignment | Description |
---|---|---|---|
messageType |
string | "response" | A string which denotes that this message is a response sent from a Thing to a Consumer. |
operation |
string | "readproperty" | A string which denotes that this message relates to a readproperty operation.
|
name |
string | Mandatory | The name of the Property being read, as per its key in the properties member of
the
Thing Description.
|
value |
any | Mandatory | The current value of the Property being read, with a type and structure conforming to the data schema of the corresponding PropertyAffordance in the Thing Description. |
timestamp |
string | Optional | A timestamp in date-time format [[RFC3339]] set to the time the property reading took place. |
{ "thingID": "https://mythingserver.com/things/mylamp1", "messageID": "79057736-3e0e-4dc3-b139-a33051901ee2", "messageType": "response", "operation": "readproperty", "name": "on", "value": true, "timestamp": "2024-01-13T23:20:50.52Z", "correlationID": "5afb752f-8be0-4a3c-8108-1327a6009cbd" }
writeproperty
To set the value of a Property of a Thing, a Consumer MUST send a message to the Thing which contains the following members:
Member | Type | Assignment | Description |
---|---|---|---|
messageType |
string | "request" | A string which denotes that this message is a request sent from a Consumer to a Thing. |
operation |
string | "writeproperty" | A string which denotes that this message relates to a writeproperty operation. |
name |
string | Mandatory | The name of the Property whose value should be set, as per its key in the
properties member of the Thing Description.
|
value |
any | Mandatory | The desired new value of the Property, with a type and structure conforming to the data schema of the corresponding PropertyAffordance in the Thing Description. |
{ "thingID": "https://mythingserver.com/things/mylamp1", "messageID": "97d22676-6d45-4435-aef5-dd87467a0c44", "messageType": "response", "operation": "writeproperty", "name": "on", "value": true, "correlationID": "f6cf46a8-9c96-437e-8b53-925b7679a990" }
When a Thing receives a message from a Consumer with messageType
set to
request
and operation
set to writeproperty
it MUST
attempt to set the Property with the name provided in the name
member to
the value provided in the value
member.
Upon successfully submitting the value of the requested Property, the Thing MUST send a message to the
requesting Consumer
containing the following members:
Member | Type | Assignment | Description |
---|---|---|---|
messageType |
string | "response" | A string which denotes that this message is a response sent from a Thing to a Consumer. |
operation |
string | "writeproperty" | A string which denotes that this message relates to a writeproperty operation.
|
name |
string | Mandatory | The name of the Property being written, as per its key in the properties member of
the
Thing Description.
|
value |
any | Optional | The value which has been successfully assigned to the Property being written, with a type and structure conforming to the data schema of the corresponding PropertyAffordance in the Thing Description. |
timestamp |
string | Optional | A timestamp in date-time format [[RFC3339]] set to the time the property write took place. |
{ "thingID": "https://mythingserver.com/things/mylamp1", "messageID": "db25fe4f-bee8-43a7-8ff0-3a1ff6e620b0", "messageType": "response", "operation": "writeproperty", "name": "on", "value": true, "timestamp": "2024-01-13T23:20:50.52Z", "correlationID": "f6cf46a8-9c96-437e-8b53-925b7679a990" }
If the Thing can confirm that the requested value has been set successfully then the response message
to a writeproperty
request SHOULD contain a value
member with its value set to the
value which has been successfully set.
If the Thing can not confirm that the requested value has been set successfully (e.g. in the case of a
write-only property or a device that is temporarily asleep so the write has been queued) then
the response message to a writeproperty
request MUST NOT contain a
value
member.
If a Consumer attempts to set the value of a numerical Property to a value which conforms to the Property's data schema but to a level of precision the Thing does not support, (e.g. 3.14159), then the Thing MAY respond with the actual value set (e.g. 3.14).
readallproperties
To request a reading of all of a Thing's readable Properties at once, a Consumer MUST send a message to the Thing which contains the following members:
Member | Type | Assignment | Description |
---|---|---|---|
messageType |
string | "request" | A string which denotes that this message is a request sent from a Consumer to a Thing. |
operation |
string | "readallproperties" | A string which denotes that this message relates to a readallproperties operation. |
{ "thingID": "https://mythingserver.com/things/mylamp1", "messageID": "e144349c-5cd7-4002-938f-aac5adf99789", "messageType": "request", "operation": "readallproperties", "correlationID": "c08075a4-d53c-4f51-b251-a6b6922c2b1f" }
When a Thing receives a message from a Consumer with messageType
set to
request
and operation
set to readallproperties
it MUST
attempt to read the value of all of its readable Properties (i.e. all
Property Affordances where
writeOnly
[[wot-thing-description11]] is not set to true
).
Upon successfully reading the value of all of its readable Properties, the Thing MUST send a message to the requesting Consumer containing the following members:
Member | Type | Assignment | Description |
---|---|---|---|
messageType |
string | "response" | A string which denotes that this message is a response sent from a Thing to a Consumer. |
operation |
string | "readallproperties" | A string which denotes that this message relates to a readallproperties operation.
|
values |
object | Mandatory | The values of all Properties contained in an object keyed by Property name, with the value of each Property conforming to the data schema of the corresponding PropertyAffordance in the Thing Description. |
timestamp |
string | Optional | A timestamp in date-time format [[RFC3339]] set to the time the property readings took place. |
{ "thingID": "https://mythingserver.com/things/mylamp1", "messageID": "79057736-3e0e-4dc3-b139-a33051901ee2", "messageType": "response", "operation": "readallproperties", "values": { "on": true, "level": 50 }, "timestamp": "2025-05-22T17:15:35.636Z", "correlationID": "c08075a4-d53c-4f51-b251-a6b6922c2b1f" }
readmultipleproperties
To request a reading of multiple readable Properties of a Thing at once, a Consumer MUST send a message to the Thing which contains the following members:
Member | Type | Assignment | Description |
---|---|---|---|
messageType |
string | "request" | A string which denotes that this message is a request sent from a Consumer to a Thing. |
operation |
string | "readmultipleproperties" | A string which denotes that this message relates to a readmultipleproperties operation.
|
names |
array | Mandatory | An array of strings specifying the names of the Properties to read, as per their keys in the
properties member of the Thing Description.
|
{ "thingID": "https://mythingserver.com/things/mylamp1", "messageID": "dacaea0e-43c2-4fc0-bd66-5a807ca52324", "messageType": "request", "operation": "readmultipleproperties", "names": ["on", "level"], "correlationID": "c0503f71-288f-4460-b308-c4cc0009cd89" }
When a Thing receives a message from a Consumer with messageType
set to
request
and operation
set to readmultipleproperties
it MUST
attempt to read the value of all the Properties specified in the names
member of the
message.
Upon successfully reading the values of the specified Properties, the Thing MUST send a message to the requesting Consumer containing the following members:
Member | Type | Assignment | Description |
---|---|---|---|
messageType |
string | "response" | A string which denotes that this message is a response sent from a Thing to a Consumer. |
operation |
string | "readmultipleproperties" | A string which denotes that this message relates to a readmultipleproperties operation.
|
values |
object | Mandatory | The values of the read Properties contained in an object keyed by Property name, with the value of each Property conforming to the data schema of the corresponding PropertyAffordance in the Thing Description. |
timestamp |
string | Optional | A timestamp in date-time format [[RFC3339]] set to the time the property readings took place. |
{ "thingID": "https://mythingserver.com/things/mylamp1", "messageID": "695a2626-be5f-4f91-8719-105abc52aa0f", "messageType": "response", "operation": "readmultipleproperties", "values": { "on": true, "level": 50 }, "timestamp": "2025-05-22T18:04:33.531Z", "correlationID": "c0503f71-288f-4460-b308-c4cc0009cd89" }
If a Thing experiences an error when attempting to carry out an operation requested by a Consumer, it MUST send a response message to the Consumer containing the following members:
Member | Type | Assignment | Description |
---|---|---|---|
messageType |
string | "response" | A string which denotes that this message is a response sent from a Thing to a Consumer. |
error |
object | Mandatory | An object conforming to the Problem Details Format [[RFC9457]]. |
{
"thingID": "https://mythingserver.com/things/mylamp1",
"messageID": "79057736-3e0e-4dc3-b139-a33051901ee2",
"messageType": "response",
"operation": "readproperty",
"name": "on",
"error": {
"status": "404",
"type": "https://w3c.github.io/web-thing-protocol/errors#not-found",
"title": "Not Found"
"detail": "No property found with the name 'on'"
}
"timestamp": "2024-01-13T23:20:50.52Z",
"correlationID": "5afb752f-8be0-4a3c-8108-1327a6009cbd"
}
If the error experienced could be described by one of the common error types described in the following table then that error type SHOULD be used:
status |
type |
title |
Description |
---|---|---|---|
400 | https://w3c.github.io/web-thing-protocol/errors#400 | Bad Request | The request message was invalid (e.g. is missing mandatory members or contains an unknown operation type). |
403 | https://w3c.github.io/web-thing-protocol/errors#403 | Forbidden | The requesting Consumer is not have permission to carry out the requested operation. |
404 | https://w3c.github.io/web-thing-protocol/errors#404 | Not Found | The interaction affordance referenced in the request message can not be found (e.g. no Property
with the given name exists).
|
500 | https://w3c.github.io/web-thing-protocol/errors#500 | Internal Server Error | The Thing experienced an unexpected condition which prevented it from fulfilling the requested operation. |
503 | https://w3c.github.io/web-thing-protocol/errors#503 | Service Unavailable | The Thing or interaction affordance is currently not able to fulfil the requested operation (e.g. because it is overloaded or undergoing a firmware update). |
The URLs given for error types in the table above are placeholders and will be replaced in the final version of this specification.
The error
member of an error response message MAY contain a detail
member with its
value set to a string containing additional human-readable information about the specific instance of the error.
A Thing MAY use its own error types where one of the common error types above does not sufficiently
explain the error, as long as the error
member of the response message conforms to the Problem
Details Format [[RFC9457]].
{
"thingID": "https://mythingserver.com/things/teapot",
"messageID": "07de640d-1b10-4857-b1ae-0c29d62acedc",
"messageType": "response",
"operation": "invokeaction",
"name": "brewCoffee",
"error": {
"status": "418",
"type": "https://mythingserver.com/errors#418",
"title": "I'm a teapot"
"detail": "This device can not brew coffee because it is a teapot"
}
"timestamp": "2025-05-22T07:21:50.53Z",
"correlationID": "61aa2164-b1ef-4585-aa3f-626a7f4a185f"
}
This specification proposes the registration of a sub-protocol in the IANA "WebSocket Subprotocol Name Registry". The name of the sub-protocol and the published URL of its definition are to be confirmed, but currently the name "webthingprotocol" and this document are used as a placeholder and draft proposal.