From 1576280074298e009c9be4f2a7474898e5ae885a Mon Sep 17 00:00:00 2001 From: Jan Romann Date: Thu, 4 Jan 2024 03:37:43 +0100 Subject: [PATCH] fix: update examples --- example/coaps_readproperty.dart | 2 +- example/complex_example.dart | 2 +- example/core_link_format_discovery.dart | 25 +++++++++++++++---------- example/mqtt_example.dart | 4 +++- 4 files changed, 20 insertions(+), 13 deletions(-) diff --git a/example/coaps_readproperty.dart b/example/coaps_readproperty.dart index 3083be29..4bea01b9 100644 --- a/example/coaps_readproperty.dart +++ b/example/coaps_readproperty.dart @@ -45,7 +45,7 @@ Future main(List args) async { final wot = await servient.start(); const thingDescriptionJson = { - "@context": "http://www.w3.org/ns/td", + "@context": "https://www.w3.org/2022/wot/td/v1.1", "title": "Test Thing", "base": "coaps://californium.eclipseprojects.io", "security": ["psk_sc"], diff --git a/example/complex_example.dart b/example/complex_example.dart index 76d017c6..22b17d41 100644 --- a/example/complex_example.dart +++ b/example/complex_example.dart @@ -10,7 +10,7 @@ import "package:dart_wot/dart_wot.dart"; const thingDescriptionJson = { "@context": [ - "http://www.w3.org/ns/td", + "https://www.w3.org/2022/wot/td/v1.1", {"@language": "de", "coap": "http://www.example.org/coap-binding#"}, ], "title": "Test Thing", diff --git a/example/core_link_format_discovery.dart b/example/core_link_format_discovery.dart index 11edf59a..8452f596 100644 --- a/example/core_link_format_discovery.dart +++ b/example/core_link_format_discovery.dart @@ -8,30 +8,35 @@ import "package:dart_wot/dart_wot.dart"; -const propertyName = "status"; -const actionName = "toggle"; - Future main(List args) async { final servient = Servient(clientFactories: [CoapClientFactory()]); final wot = await servient.start(); - // TODO(JKRhb): Replace with an endpoint providing CoRE Format Links pointing - // to TDs. At the moment, this URI is just for illustrative - // purpose and will not return actual Thing Description links. - final discoveryUri = Uri.parse("coap://coap.me/.well-known/core"); + final discoveryUri = + Uri.parse("coap://plugfest.thingweb.io/.well-known/core"); await for (final thingDescription in wot.discover(discoveryUri, method: DiscoveryMethod.coreLinkFormat)) { + print(thingDescription.title); + + if (thingDescription.title != "Smart-Coffee-Machine") { + continue; + } + final consumedThing = await wot.consume(thingDescription); try { - final statusBefore = await consumedThing.readProperty(propertyName); + final statusBefore = + await consumedThing.readProperty("allAvailableResources"); print(await statusBefore.value()); - await consumedThing.invokeAction(actionName); + final result = await consumedThing.invokeAction("makeDrink"); + + print(await result.value()); - final statusAfter = await consumedThing.readProperty(propertyName); + final statusAfter = + await consumedThing.readProperty("allAvailableResources"); print(await statusAfter.value()); } on Exception catch (e) { print(e); diff --git a/example/mqtt_example.dart b/example/mqtt_example.dart index 0ed4919a..21d34cc6 100644 --- a/example/mqtt_example.dart +++ b/example/mqtt_example.dart @@ -87,7 +87,9 @@ Future main(List args) async { await consumedThing.invokeAction("toggle", input: actionInput); await subscription.stop(); - await consumedThing.invokeAction("toggle", input: actionInput); + final actionInput2 = "Bye World".asInteractionInput(); + + await consumedThing.invokeAction("toggle", input: actionInput2); await consumedThing.readAndPrintProperty("status"); print("Done!"); }