-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathindex.html
479 lines (458 loc) · 21.1 KB
/
index.html
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Web Thing Protocol</title>
<script src="https://www.w3.org/Tools/respec/respec-w3c" class="remove" defer></script>
<script class="remove">
// All config options at https://respec.org/docs/
var respecConfig = {
specStatus: "CG-DRAFT",
editors: [{
name: "Ben Francis",
company: "Krellian",
mailto: "[email protected]",
companyURL: "https://krellian.com",
w3cid: "51527"
}],
github: "w3c/web-thing-protocol",
shortName: "web-thing-protocol",
xref: true,
group: "web-thing-protocol",
wgPublicList: "public-web-thing-protocol",
edDraftURI: "https://w3c.github.io/web-thing-protocol/",
latestVersion: "https://w3c.github.io/web-thing-protocol/"
};
</script>
</head>
<body>
<h1 id="title">Web Thing Protocol</h1>
<h2 id="subtitle">WebSocket Sub-protocol</h2>
<section id="abstract">
<p>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 <a href="https://www.w3.org/WoT/">Web of
Things</a>, to enable a WoT
<a href="https://www.w3.org/TR/wot-architecture/#dfn-consumer">Consumer</a>
to communicate with one or more WoT
<a href="https://www.w3.org/TR/wot-architecture/#dfn-web-thing">Things</a>
over a WebSocket connection.
</p>
</section>
<section id="sotd">
<aside class="ed-note" title="Empty Sections">
Please note that this document is a work in progress and contains empty
sections. For an indication of what these sections may eventually contain,
please see this
<a href="https://docs.google.com/document/d/1KWv-aQfMgsqBFg0v4rVqzcVvzzisC7y4X4CMUYGc8rE/edit?usp=sharing">strawman
proposal</a>.
</aside>
</section>
<section id="introduction" class="informative">
<h2>Introduction</h2>
<p>This document defines a WebSocket [[WEBSOCKETS-PROTOCOL]] sub-protocol for
monitoring and controlling connected devices over the Web.
</p>
<p>The <a href="https://www.w3.org/WoT/">Web of Things</a> (WoT) is a
collection of standardised technology building blocks that help provide
interoperability on the
<a href="https://en.wikipedia.org/wiki/Internet_of_things">Internet of
Things</a> (IoT). The WoT Thing Description specification
[[wot-thing-description11]] defines a metadata format for
<em>describing</em> the capabilities of "Things" (connected
devices) on the Web. The WoT Discovery specification [[wot-discovery]]
defines mechanisms for <em>discovering</em> Things on the Web. This
specification complements those building blocks by
defining a dedicated real-time protocol for <em>communicating</em> with Things over the
Web.
</p>
<p>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
<a href="https://www.w3.org/TR/wot-architecture/#dfn-consumer">Consumer</a>
can communicate with one or more
<a href="https://www.w3.org/TR/wot-architecture/#dfn-web-thing">Things</a>
[[wot-architecture11]] to carry out the full set of WoT
<a href="https://www.w3.org/TR/wot-thing-description/#table-well-known-operation-types">operations</a>.
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.
</p>
<p>Whilst many other <a href="https://www.iana.org/assignments/websocket/websocket.xml#subprotocol-name">WebSocket
sub-protocols</a> exist, what makes the Web Thing Protocol unique
is that it is specifically designed around the Web of Things
<a href="https://www.w3.org/TR/wot-thing-description11/#sec-vocabulary-definition">information
model</a> and
<a href="https://www.w3.org/TR/wot-thing-description11/#table-well-known-operation-types">set
of operations</a> [[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.
</p>
<p>
The sub-protocol defines message payload formats for each of the
well-known
<a href="https://www.w3.org/TR/wot-thing-description11/#table-well-known-operation-types">
operation types</a> defined in the WoT
<a href="https://www.w3.org/TR/wot-architecture/#sec-interaction-model">
interaction model</a> [[wot-architecture11]], and other messages needed for
WebSocket communication.
</p>
<p>
This specification is intended to complement deliverables of the
<a href="https://www.w3.org/WoT/wg/">WoT Working Group</a>, 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
<a
href="https://www.w3.org/community/reports/web-thing-protocol/CG-FINAL-web-thing-protocol-requirements-20231101/">Web
Thing Protocol Use Cases & Requirements</a> community report.
</p>
<p>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.
</p>
</section>
<section id="conformance">
</section>
<section id="terminology">
<h2>Terminology</h2>
<p>Fundamental WoT terminology such as <dfn>Thing</dfn> or <dfn>Web Thing</dfn>, <dfn>Consumer</dfn> or <dfn>WoT
Consumer</dfn>, WoT Thing Description or <dfn>Thing Description</dfn>, Interaction Model,
<dfn>Interaction Affordance</dfn>, <dfn>Property</dfn>, Action and Event are defined in
the
<a href="https://www.w3.org/TR/wot-architecture/#terminology">Terminology</a>
section of the WoT Architecture specification [[wot-architecture11]].
</p>
</section>
<section id="websocket-connection">
<h2>WebSocket Connection</h2>
<section id="protocol-handshake">
<h3>Protocol Handshake</h3>
<p>In order to communicate with a <a>Web Thing</a>,
a WoT <a>Consumer</a> [[wot-architecture11]] MUST
locate one or more WebSocket [[WEBSOCKETS-PROTOCOL]] endpoints provided by the <a>Thing</a> for a given set of
<a>Interaction Affordances</a>
[[wot-thing-description11]].
</p>
<p>The URL of a WebSocket endpoint to be used for a given interaction MUST be obtained from a <a>Thing
Description</a>
[[wot-architecture11]] by locating a <a href="https://www.w3.org/TR/wot-thing-description/#form">Form</a> inside
the corresponding <a>Interaction Affordance</a> for which:
<ul>
<li>After being resolved against a <a
href="https://www.w3.org/TR/wot-thing-description/#td-vocab-base--Thing"><code>base</code></a> URL
[[wot-thing-description11]] where applicable, the URI scheme [[RFC3986]] of the value of its <a
href="https://www.w3.org/TR/wot-thing-description/#td-vocab-href--Form"><code>href</code></a> member
[[wot-thing-description11]] is <code>"ws"</code> or &<code>"wss"</code></li>
<li>Its <a
href="https://www.w3.org/TR/wot-thing-description/#td-vocab-subprotocol--Form"><code>subprotocol</code></a>
member has a value of <code>"webthingprotocol"</code></li>
</ul>
</p>
<p>To open a WebSocket on a Thing, an HTTP <a
href="https://httpwg.org/specs/rfc9110.html#GET"><code>GET</code></a> request [[RFC9110]] MUST be upgraded to
a WebSocket connection using a standard WebSocket <a
href="https://www.rfc-editor.org/rfc/rfc6455#page-6">protocol handshake</a> [[WEBSOCKETS-PROTOCOL]],
specifying the "webthingprotocol" sub-protocol.
</p>
<pre class="example" title="WebSocket Protocol Handshake HTTP Request">
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
</pre>
<pre class="example" title="WebSocket Protocol Handshake HTTP Response">
HTTP/1.1 101 Switching Protocols
Upgrade: websocket
Connection: Upgrade
Sec-WebSocket-Accept: HSmrc0sMlYUkAGmm5OPpG2HaGWk=
Sec-WebSocket-Protocol: webthingprotocol
</pre>
<p class="ednote" title="Sub-protocol Name">
Sub-protocol name to be confirmed, see <a href="#iana-considerations">IANA Considerations</a>.
</p>
<p class="note">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.
</p>
<pre class="example" title="WebSocket Instantiation in JavaScript">
const socket = new WebSocket('wss://mywebthingserver/things/robot', 'webthingprotocol');
</pre>
</section>
<section id="websocket-reuse">
<h3>WebSocket Re-use</h3>
<p>A single WebSocket [[WEBSOCKETS-PROTOCOL]] connection from a <a>WoT Consumer</a> MAY be shared between multiple
<a>Interaction
Affordances</a> of a <a>Thing</a>. A single WebSocket connection from a <a>WoT Consumer</a> MAY also be shared
between multiple <a>Things</a>.
</p>
<p>Before opening a new WebSocket connection, a <a>WoT Consumer</a> SHOULD check whether it already has an open
connection to the same WebSocket endpoint URL.</p>
<p>If an existing connection to the same WebSocket endpoint URL exists, then that connection SHOULD be re-used
rather than opening an additional socket.</p>
<p>If an existing connection to the same WebSocket endpoint URL exists but is using a different set of credentials
for its given <a
href="https://www.w3.org/TR/wot-thing-description11/#securityscheme"><code>SecurityScheme</code></a>
[[wot-thing-description11]] (e.g. a different Bearer Token), then the <a>WoT Consumer</a> MUST NOT re-use the
connection.</p>
</section>
</section>
<section id="websocket-messages">
<h2>WebSocket Messages</h2>
<p>All messages MUST be a JSON <a href="https://www.rfc-editor.org/rfc/rfc8259#section-4">object</a> [[JSON]].</p>
<p>The top level JSON object MUST contain a <code>thingID</code> member with the value set to a unique identifier of
the <a>Web Thing</a> to which the message relates.
If the <a>Thing Description</a> of the <a>Web Thing</a> contains an <code>id</code> member then the value of that
<code>id</code> member MUST be used as the unique identifier assigned to <code>thingID</code>.
If the <a>Thing Description</a> of the <a>Web Thing</a> does not contain an <code>id</code> member then the URL
[[URL]] from which the <a>Thing Description</a> was retrieved MAY be used as the <code>thingID</code> value
instead. The value of the <code>thingID</code> member MUST be a valid URI [[URI]] serialised as a string.
</p>
<p>The top level JSON object MUST contain a <code>messageID</code> member with the value set to a unique identifier
for the current message in UUIDv4 format [[rfc9562]].</p>
<p>The top level JSON object MAY contain a <code>correlationID</code> 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).</p>
<table class="def">
<caption>Common members of all messages</caption>
<thead>
<tr>
<th>Member</th>
<th>Type</th>
<th>Assignment</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>thingID</code></td>
<td>string</td>
<td>Mandatory</td>
<td>The ID (URI) of the <a>Thing</a> to which the <a>Property</a> belongs.</td>
</tr>
<tr>
<td><code>messageID</code></td>
<td>string</td>
<td>Mandatory</td>
<td>A unique identifier (UUID) for the current message.</td>
</tr>
<tr>
<td><code>messageType</code></td>
<td>string</td>
<td>Mandatory</td>
<td>A string which denotes the type of message, with a value from the <a href="#message-types-table">WebSocket
message types</a> table below.</td>
</tr>
<tr>
<td><code>correlationID</code></td>
<td>string</td>
<td>Optional</td>
<td>A unique identifer (UUID) which is shared between messages corresponding to the same operation, e.g. a
request and a response.</td>
</tr>
</tbody>
</table>
<p>The top level JSON object MUST contain a <code>messageType</code> member, with its value set to one of the
message type strings from the following table:</p>
<table id="message-types-table" class="def">
<caption>WebSocket message types</caption>
<thead>
<tr>
<th>Message type</th>
<th>Description</th>
<th>Entity</th>
<th>Direction</th>
</tr>
</thead>
<tbody>
<tr>
<td><a href="#readProperty"><code>readProperty</code></a></td>
<td>Request a property reading from a Thing</td>
<td>PropertyAffordance</td>
<td>Consumer ➡ Thing</td>
</tr>
<tr>
<td><a href="#propertyReading"><code>propertyReading</code></a></td>
<td>A property reading from a Thing</td>
<td>PropertyAffordance</td>
<td>Thing ➡ Consumer</td>
</tr>
</tbody>
</table>
<p>All date and time values MUST use the <code>date-time</code> format
defined in [[RFC3339]].</span>
</p>
<pre class="example" title="Example timestamp">
<code>2025-01-15T12:08:00.42Z</code>
</pre>
<p class="note">
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.
</p>
<section id="properties">
<h3>Properties</h3>
<p>The following sections define WebSocket message payload formats for reading, writing and observing
<a>Properties</a> of <a>Things</a>.
</p>
<section id="readProperty">
<h4><code>readProperty</code></h4>
<p>To request a property reading from a <a>Thing</a>, a <a>Consumer</a> MUST send a <a
href="#websocket-messages">message</a> to the <a>Thing</a>
which contains the following members:</p>
<table class="def">
<caption>Members of a <code>readProperty</code> message</caption>
<thead>
<tr>
<th>Member</th>
<th>Type</th>
<th>Assignment</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>messageType</code></td>
<td>string</td>
<td>"readProperty"</td>
<td>A string which denotes that this message is requesting a <code>readproperty</code> operation.</td>
</tr>
<tr>
<td><code>name</code></td>
<td>string</td>
<td>Mandatory</td>
<td>The name of the <a>Property</a> to read, as per its key in the <code>properties</code> member of
the <a>Thing Description</a>.
</td>
</tr>
</tbody>
</table>
<pre class="example" title="Read property operation (Consumer to Thing)">
{
"thingID": "https://mythingserver.com/things/mylamp1",
"messageID": "c370da58-69ae-4e83-bb5a-ac6cfb2fed54",
"messageType": "readProperty",
"name": "on",
"correlationID": "5afb752f-8be0-4a3c-8108-1327a6009cbd"
}
</pre>
<p>When a <a>Thing</a> receives a <code>readProperty</code> message from a <a>Consumer</a>, then upon
successfully reading the value of the corresponding property it MUST send a <a
href="propertyReading"><code>propertyReading</code></a> message in response, containing its current value.
</p>
</section>
<section id="propertyReading">
<h4><code>propertyReading</code></h4>
<p>To notify a <a>Consumer</a> of the value of a <a>Property</a>, a <a>Thing</a> MUST send a
<a href="#websocket-messages">message</a> to the <a>Consumer</a> which contains the following members:
</p>
<table class="def">
<caption>Members of a <code>propertyReading</code> message</caption>
<thead>
<tr>
<th>Member</th>
<th>Type</th>
<th>Assignment</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>messageType</code></td>
<td>string</td>
<td>"propertyReading"</td>
<td>A string which denotes that this message is notifying a <a>Consumer</a> of the value of a
<a>Property</a>.
</td>
</tr>
<tr>
<td><code>name</code></td>
<td>string</td>
<td>Mandatory</td>
<td>The name of the <a>Property</a> being read, as per its key in the <code>properties</code> member of
the
<a>Thing Description</a>.
</td>
</tr>
<tr>
<td><code>value</code></td>
<td>any</td>
<td>Mandatory</td>
<td>The current value of the <a>Property</a> being read, with a format conforming to the data schema of
the
corresponding PropertyAffordance in the <a>Thing Description</a>.</td>
</tr>
<tr>
<td><code>timestamp</code></td>
<td>string</td>
<td>Optional</td>
<td>A timestamp in date-time format [[RFC3339]] set to the time the property reading took place.</td>
</tr>
</tbody>
</table>
<p>If a <code>propertyReading</code> message is sent in response to a <a
href="#readProperty"><code>readProperty</code></a>, <code>readAllProperties</code>,
<code>observeProperty</code> or <code>observeAllProperties</code> message which contained a
<code>correlatonID</code> member, then the response message SHOULD also include a <code>correlationID</code>
member with the same value.
</p>
<pre class="example" title="Property reading message (Thing to Consumer)">
{
"thingID": "https://mythingserver.com/things/mylamp1",
"messageID": "79057736-3e0e-4dc3-b139-a33051901ee2",
"messageType": "propertyReading",
"name": "on",
"value": true,
"timestamp": "2024-01-13T23:20:50.52Z",
"correlationID": "5afb752f-8be0-4a3c-8108-1327a6009cbd"
}
</pre>
</section>
</section>
<section id="actions">
<h3>Actions</h3>
</section>
<section id="events">
<h3>Events</h3>
</section>
<section id="events">
<h3>Other Messages</h3>
</section>
</section>
<section id="example-thing-descriptions">
<h2>Example Thing Descriptions</h2>
</section>
<section id="privacy-considerations">
<h2>Privacy Considerations</h2>
</section>
<section id="security-considerations">
<h2>Security Considerations</h2>
</section>
<section id="accessibility-considerations">
<h2>Accessibility Considerations</h2>
</section>
<section id="iana-considerations">
<h2>IANA Considerations</h2>
<p>This specification proposes the registration of a sub-protocol in the IANA "<a
href="https://www.iana.org/assignments/websocket/websocket.xml">WebSocket Subprotocol Name Registry</a>".
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.</p>
<dl>
<dt>Subprotocol Identifier</dt>
<dd>webthingprotocol</dd>
<dt>Subprotocol Common Name</dt>
<dd>Web Thing Protocol</dd>
<dt>Subprotocol Definition</dt>
<dd>This document.</dd>
</dl>
</section>
</body>
</html>