From 9c27e6519c7541612a5889936be6adcdbf96317f Mon Sep 17 00:00:00 2001 From: Jan Romann Date: Fri, 12 Jan 2024 23:36:06 +0100 Subject: [PATCH 1/2] chore(examples): add HTTP support to main example --- README.md | 6 ++++-- example/example.dart | 2 ++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 1816a4e6..2066c035 100644 --- a/README.md +++ b/README.md @@ -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, @@ -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 main(List args) async { final servient = Servient( clientFactories: [ CoapClientFactory(), + HttpClientFactory(), ], ); final wot = await servient.start(); diff --git a/example/example.dart b/example/example.dart index 94bc1773..ededc6cc 100644 --- a/example/example.dart +++ b/example/example.dart @@ -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 main(List args) async { final servient = Servient( clientFactories: [ CoapClientFactory(), + HttpClientFactory(), ], ); final wot = await servient.start(); From e4ededb18f112acfa088924ccc4510b311c43c6a Mon Sep 17 00:00:00 2001 From: Jan Romann Date: Fri, 12 Jan 2024 23:36:53 +0100 Subject: [PATCH 2/2] chore(examples): add event subscribing to the main example --- README.md | 5 +++++ example/example.dart | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/README.md b/README.md index 2066c035..1c40bd46 100644 --- a/README.md +++ b/README.md @@ -78,12 +78,17 @@ Future main(List 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(); } ``` diff --git a/example/example.dart b/example/example.dart index ededc6cc..edf73ef8 100644 --- a/example/example.dart +++ b/example/example.dart @@ -29,10 +29,15 @@ Future main(List 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(); }