Skip to content

Commit

Permalink
fix: update examples
Browse files Browse the repository at this point in the history
  • Loading branch information
JKRhb committed Jan 4, 2024
1 parent 00db239 commit 1576280
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 13 deletions.
2 changes: 1 addition & 1 deletion example/coaps_readproperty.dart
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ Future<void> main(List<String> 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"],
Expand Down
2 changes: 1 addition & 1 deletion example/complex_example.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
25 changes: 15 additions & 10 deletions example/core_link_format_discovery.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,30 +8,35 @@

import "package:dart_wot/dart_wot.dart";

const propertyName = "status";
const actionName = "toggle";

Future<void> main(List<String> 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);
Expand Down
4 changes: 3 additions & 1 deletion example/mqtt_example.dart
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,9 @@ Future<void> main(List<String> 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!");
}
Expand Down

0 comments on commit 1576280

Please sign in to comment.