Skip to content

Commit

Permalink
Merge pull request #101 from eclipse-thingweb/adjust-example
Browse files Browse the repository at this point in the history
chore: adjust main example
  • Loading branch information
JKRhb authored Apr 28, 2024
2 parents 0e98ff9 + e4ededb commit b869322
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
11 changes: 9 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ Below you can find a basic example for incrementing and reading the value of a
counter Thing, which is part of the
[Thingweb Online Things](https://www.thingweb.io/services).

In the example, we first create a WoT runtime using a `Servient` with CoAP
support.
In the example, we first create a WoT runtime using a `Servient` with CoAP and
HTTP support.
With the runtime, we then retrieve a TD (using the `requestThingDescription()`
method) and consume it (using the `consume()` method), creating a
`ConsumedThing` object,
Expand All @@ -56,12 +56,14 @@ Afterward, the actual interactions with the counter are performed by calling the

```dart
import "package:dart_wot/binding_coap.dart";
import "package:dart_wot/binding_http.dart";
import "package:dart_wot/core.dart";
Future<void> main(List<String> args) async {
final servient = Servient(
clientFactories: [
CoapClientFactory(),
HttpClientFactory(),
],
);
final wot = await servient.start();
Expand All @@ -76,12 +78,17 @@ Future<void> main(List<String> args) async {
'"${thingDescription.title}"!',
);
print(consumedThing.thingDescription.events);
final subscription = await consumedThing.subscribeEvent("change", print);
print("Incrementing counter ...");
await consumedThing.invokeAction("increment");
final status = await consumedThing.readProperty("count");
final value = await status.value();
print("New counter value: $value");
await subscription.stop();
}
```

Expand Down
7 changes: 7 additions & 0 deletions example/example.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@
// ignore_for_file: avoid_print

import "package:dart_wot/binding_coap.dart";
import "package:dart_wot/binding_http.dart";
import "package:dart_wot/core.dart";

Future<void> main(List<String> args) async {
final servient = Servient(
clientFactories: [
CoapClientFactory(),
HttpClientFactory(),
],
);
final wot = await servient.start();
Expand All @@ -27,10 +29,15 @@ Future<void> main(List<String> args) async {
'"${thingDescription.title}"!',
);

print(consumedThing.thingDescription.events);
final subscription = await consumedThing.subscribeEvent("change", print);

print("Incrementing counter ...");
await consumedThing.invokeAction("increment");

final status = await consumedThing.readProperty("count");
final value = await status.value();
print("New counter value: $value");

await subscription.stop();
}

0 comments on commit b869322

Please sign in to comment.