Skip to content

Commit 7009aad

Browse files
docs: fix that WoT needs to be generated/started first
1 parent 598140c commit 7009aad

1 file changed

Lines changed: 8 additions & 13 deletions

File tree

README.md

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -186,20 +186,15 @@ const { HttpClientFactory } = require('@node-wot/binding-http');
186186
const servient = new Servient();
187187
servient.addClientFactory(new HttpClientFactory(null));
188188

189-
WoT.requestThingDescription("http://localhost:8080/counter").then(async (td) => {
190-
try {
191-
const WoT = await servient.start();
192-
// Then from here on you can consume the thing
193-
let thing = await WoT.consume(td);
194-
thing.observeProperty("count", async (data) => { console.log("count:", await data.value()); });
195-
for (let i = 0; i < 5; i++) {
196-
await thing.invokeAction("increment");
197-
}
198-
}
199-
catch (err) {
200-
console.error("Script error:", err);
189+
servient.start().then(async (WoT) => {
190+
const td = await WoT.requestThingDescription("http://localhost:8080/counter");
191+
// Then from here on you can consume the thing
192+
let thing = await WoT.consume(td);
193+
thing.observeProperty("count", async (data) => { console.log("count:", await data.value()); });
194+
for (let i = 0; i < 5; i++) {
195+
await thing.invokeAction("increment");
201196
}
202-
}).catch((err) => { console.error("Fetch error:", err); });
197+
}).catch((err) => { console.error("Error:", err); });
203198
```
204199

205200
If you execute both scripts you will see `count: ${count}` printed 5 times. We host a more complex version of this example at [http://plugfest.thingweb.io/examples/counter.html](http://plugfest.thingweb.io/examples/counter.html) and you can find the source code in the [counter example](./examples/browser) folder. You can also find more examples in the [examples folder](./examples/scripts) for JavaScript and in the [examples folder](./packages/examples/) for TypeScript. Finally, for your convenience, we host a set of online Things that you can use to test your applications. You can find more information about them in the [Online Things](#online-things) section.

0 commit comments

Comments
 (0)