Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
FadySalama authored Feb 8, 2024
1 parent df02d81 commit 486ad7f
Showing 1 changed file with 76 additions and 0 deletions.
76 changes: 76 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,82 @@ rapid development of WoT applications for devices running Windows OS, including
Our short-term goal is to implement the functionalities of a WoT Consumer, i.e. the functionalities needed to fetch a TD and consume it to interact with the entity it describes.
We will focus first on HTTP Things but aim to implement functionality for HTTPS, CoAP, CoAPS, and MQTT in the future.

## Getting Started
An example showing how to use this library
```csharp
using Newtonsoft.Json;
using WoT;
using WoT.Definitions;
using WoT.Implementation;

SimpleHTTPConsumer consumer = new SimpleHTTPConsumer();
ThingDescription td = await consumer.RequestThingDescription("http://plugfest.thingweb.io:8083/testthing");
SimpleConsumedThing consumedThing = await consumer.Consume(td) as SimpleConsumedThing;

// Read a boolean
bool boolean = await (await consumedThing.ReadProperty<bool>("bool")).Value();
Console.WriteLine("Read a boolean: " + boolean);
// Read an integer
int integer = await (await consumedThing.ReadProperty<int>("int")).Value();
Console.WriteLine("Read an integer: " + integer);
// Read a number
float number = await (await consumedThing.ReadProperty<float>("num")).Value();
Console.WriteLine("Read a number: " +number);
// Read a string
string str = await (await consumedThing.ReadProperty<string>("string")).Value();
Console.WriteLine("Read a string: " + str);
// Read an array
object[] array = await (await consumedThing.ReadProperty<object[]>("array")).Value();
Console.WriteLine("Read a string: " + JsonConvert.SerializeObject(array));
// Read an object
Dictionary<string, object> obj = await (await consumedThing.ReadProperty<Dictionary<string, object>>("object")).Value();
Console.WriteLine("Read a string: " + JsonConvert.SerializeObject(obj));


// Invoke Action with no input and no output
await consumedThing.InvokeAction("void-void");

// Invoke Action with an input and no output
await consumedThing.InvokeAction("int-void", 1);

// Invoke Action with no input but an output
int output = await (await consumedThing.InvokeAction<int>("void-int")).Value();
Console.WriteLine("Output of 'void-int' action was: " + output);

// Invoke Action with an input and an output
int output2 = await (await consumedThing.InvokeAction<int, int>("int-int", 4)).Value();
Console.WriteLine("Output of 'void-int' action was: " + output2);

if (consumedThing != null)
{

// Subscribe to Event
var sub = await consumedThing.SubscribeEvent<int>("on-int", async (output) =>
{
Console.WriteLine("Event:");
Console.WriteLine(await output.Value());
Console.WriteLine("---------------------");
});

var task = Task.Run(async () =>
{
Console.WriteLine("Here");
Console.WriteLine(consumedThing.HasActiveListeners);
while (consumedThing.HasActiveListeners) {
// Write an int
await consumedThing.WriteProperty<int>("int", 5);
await Task.Delay(TimeSpan.FromSeconds(1));
}
return;
});

Task stopTask = Task.Delay(TimeSpan.FromSeconds(10)).ContinueWith(async (task) => { await sub.Stop(); });
await task;
}
Console.WriteLine("Done");
```
For a more detailed step-by-step explanation and documentation, feel free to visit our [documentation page](https://tum-esi.github.io/WoT.Net/).

## Roadmap
- [X] TD Deserializing and Parsing
- [X] HTTP Consumer (works only with `"application\json"`, `"longpoll"` and no security)
Expand Down

0 comments on commit 486ad7f

Please sign in to comment.