Skip to content

Commit b869322

Browse files
authored
Merge pull request #101 from eclipse-thingweb/adjust-example
chore: adjust main example
2 parents 0e98ff9 + e4ededb commit b869322

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

README.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ Below you can find a basic example for incrementing and reading the value of a
4646
counter Thing, which is part of the
4747
[Thingweb Online Things](https://www.thingweb.io/services).
4848

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

5757
```dart
5858
import "package:dart_wot/binding_coap.dart";
59+
import "package:dart_wot/binding_http.dart";
5960
import "package:dart_wot/core.dart";
6061
6162
Future<void> main(List<String> args) async {
6263
final servient = Servient(
6364
clientFactories: [
6465
CoapClientFactory(),
66+
HttpClientFactory(),
6567
],
6668
);
6769
final wot = await servient.start();
@@ -76,12 +78,17 @@ Future<void> main(List<String> args) async {
7678
'"${thingDescription.title}"!',
7779
);
7880
81+
print(consumedThing.thingDescription.events);
82+
final subscription = await consumedThing.subscribeEvent("change", print);
83+
7984
print("Incrementing counter ...");
8085
await consumedThing.invokeAction("increment");
8186
8287
final status = await consumedThing.readProperty("count");
8388
final value = await status.value();
8489
print("New counter value: $value");
90+
91+
await subscription.stop();
8592
}
8693
```
8794

example/example.dart

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,14 @@
77
// ignore_for_file: avoid_print
88

99
import "package:dart_wot/binding_coap.dart";
10+
import "package:dart_wot/binding_http.dart";
1011
import "package:dart_wot/core.dart";
1112

1213
Future<void> main(List<String> args) async {
1314
final servient = Servient(
1415
clientFactories: [
1516
CoapClientFactory(),
17+
HttpClientFactory(),
1618
],
1719
);
1820
final wot = await servient.start();
@@ -27,10 +29,15 @@ Future<void> main(List<String> args) async {
2729
'"${thingDescription.title}"!',
2830
);
2931

32+
print(consumedThing.thingDescription.events);
33+
final subscription = await consumedThing.subscribeEvent("change", print);
34+
3035
print("Incrementing counter ...");
3136
await consumedThing.invokeAction("increment");
3237

3338
final status = await consumedThing.readProperty("count");
3439
final value = await status.value();
3540
print("New counter value: $value");
41+
42+
await subscription.stop();
3643
}

0 commit comments

Comments
 (0)