|
8 | 8 |
|
9 | 9 | import "package:dart_wot/dart_wot.dart"; |
10 | 10 |
|
11 | | -const propertyName = "status"; |
12 | | -const actionName = "toggle"; |
13 | | - |
14 | 11 | Future<void> main(List<String> args) async { |
15 | 12 | final servient = Servient(clientFactories: [CoapClientFactory()]); |
16 | 13 |
|
17 | 14 | final wot = await servient.start(); |
18 | 15 |
|
19 | | - // TODO(JKRhb): Replace with an endpoint providing CoRE Format Links pointing |
20 | | - // to TDs. At the moment, this URI is just for illustrative |
21 | | - // purpose and will not return actual Thing Description links. |
22 | | - final discoveryUri = Uri.parse("coap://coap.me/.well-known/core"); |
| 16 | + final discoveryUri = |
| 17 | + Uri.parse("coap://plugfest.thingweb.io/.well-known/core"); |
23 | 18 |
|
24 | 19 | await for (final thingDescription |
25 | 20 | in wot.discover(discoveryUri, method: DiscoveryMethod.coreLinkFormat)) { |
| 21 | + print(thingDescription.title); |
| 22 | + |
| 23 | + if (thingDescription.title != "Smart-Coffee-Machine") { |
| 24 | + continue; |
| 25 | + } |
| 26 | + |
26 | 27 | final consumedThing = await wot.consume(thingDescription); |
27 | 28 |
|
28 | 29 | try { |
29 | | - final statusBefore = await consumedThing.readProperty(propertyName); |
| 30 | + final statusBefore = |
| 31 | + await consumedThing.readProperty("allAvailableResources"); |
30 | 32 | print(await statusBefore.value()); |
31 | 33 |
|
32 | | - await consumedThing.invokeAction(actionName); |
| 34 | + final result = await consumedThing.invokeAction("makeDrink"); |
| 35 | + |
| 36 | + print(await result.value()); |
33 | 37 |
|
34 | | - final statusAfter = await consumedThing.readProperty(propertyName); |
| 38 | + final statusAfter = |
| 39 | + await consumedThing.readProperty("allAvailableResources"); |
35 | 40 | print(await statusAfter.value()); |
36 | 41 | } on Exception catch (e) { |
37 | 42 | print(e); |
|
0 commit comments