You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Here, an object named `thing` is produced. At this stage, it has only a name and a description for humans to read.
98
+
Here, an object named `thing` is produced. At this stage, it has only a title and a description for humans to read.
78
99
`thing.expose();` exposes/starts the exposed Thing in order to process external requests. This also creates a Thing Description that describes the interfaces of the `counter` thing.
79
100
80
101
##### Add a Property definition to the Thing
@@ -85,20 +106,22 @@ They are added as part of the `WoT.produce` invocation, like so:
85
106
86
107
```javascript
87
108
WoT.produce({
88
-
title:"property",
109
+
title:"counter",
110
+
description:"counter example thing",
89
111
properties: {
90
-
counter: {
112
+
count: {
91
113
type:"integer",
92
114
description:"current counter value",
93
-
observable:false,
94
115
},
95
116
},
117
+
}).then((thing) => {
118
+
// thing.setPropertyReadHandler(...);
119
+
// thing.setPropertyWriteHandler(...);
120
+
// thing.expose().then(() => { ...});
96
121
});
97
122
```
98
123
99
-
This creates a Property.
100
-
Its value can be initializes by calling `writeProperty`, otherwise it reads as `null`.
101
-
After being written to, the value can be read by other Things.
124
+
This creates a property `count`.
102
125
103
126
You can create a Property that has a more complex type, such as an object. This is shown in the following:
You can specify if the Thing needs do to something in case of a property write.
148
-
Here, the value written is used to set the brightness of an LED that requires a specific function (`setBrightness()`) to do that.
149
-
The property value becomes the value passed to `resolve()`, which in this case would mean the number modulo 2.
193
+
You can specify if the thing needs do to something in case of a property write.
194
+
Here, the value is used to set the `count` value.
150
195
151
196
##### Add an Action definition to the Thing
152
197
153
-
Actions offer functions of the Thing.
154
-
These functions may manipulate the interal state of a Thing in a way that is not possible through setting Properties.
155
-
Examples are changing internal state that is not exposed as a Property, changing multiple Properties, changing Properties over time or with a process that shall not be disclosed.
198
+
Actions offer functions of the thing.
199
+
These functions may manipulate the interal state of a thing in a way that is not possible through setting properties.
200
+
Examples are changing internal state that is not exposed as a property, changing multiple properties, changing properties over time or with a process that shall not be disclosed.
156
201
Actions may also be pure functions, that is, they do not use any internal state at all, e.g. for processing input data and returning the result directly.
157
202
158
-
Just like Properties above, adding Actions is done as part of a WoT.produce() call.
203
+
Just like properties above, adding actions is done as part of a WoT.produce() call.
159
204
160
205
```javascript
161
206
WoT.produce({
162
-
title:"action",
163
-
actions: {
164
-
echo: {
165
-
description:"Returns what it gets passed. Subject to SLA. Will probably terminate at null-bytes, because it treats input as strings."
166
-
input: { type:"string" },
167
-
output: { type:"string" }
168
-
}
169
-
}
170
-
})
207
+
title:"counter",
208
+
actions: {
209
+
increment: {
210
+
title:"increment",
211
+
},
212
+
},
213
+
});
171
214
```
172
215
173
-
As can be seen above,`input` and `output` data types can be specified, similar to how property types are described in TDs.
216
+
Note:`input` and `output` data types can be specified, similar to how property types are described in TDs.
174
217
175
-
##### Add an Action invoke handler
218
+
##### Add an Action handler
176
219
177
-
You need to write what will happen if an Action is invoked. This is done by setting an Action Handler:
220
+
You need to code what will happen if an action is invoked. This is done by setting an action handler:
0 commit comments