Skip to content

Commit 8b5812c

Browse files
author
Robert Winkler
committed
Modified a readme
1 parent 7f115c2 commit 8b5812c

File tree

1 file changed

+109
-9
lines changed

1 file changed

+109
-9
lines changed

README.md

Lines changed: 109 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,22 @@
33
**kotlin-wot** is a framework designed to enable developers to implement [**Web of Things (WoT)**](https://www.w3.org/WoT/) servers and clients in Kotlin. Built from the ground up with Kotlin and leveraging modern coroutine-based architecture, it aims to provide a **fast, reliable, and extensible framework** for AI or IoT applications. By abstracting low-level details and protocols through the use of [**Thing Descriptions (TDs)**](https://www.w3.org/TR/wot-thing-description11/), Kotlin-WoT empowers developers to focus on creating complex business logic with ease.
44
Thing Descriptions provide an excellent alternative to OpenAPI or AsyncAPI. Unlike these formats, Thing Descriptions are protocol-agnostic and utilize forms to remain independent of specific transport protocols, enabling greater flexibility and interoperability across diverse ecosystems.
55

6+
The implementation was inspired by the awesome [Eclipse Thingweb](https://thingweb.io/) and [node-wot](https://github.com/eclipse-thingweb/node-wot). There are also open-source implementations available for TypeScript, Dart, Rust and Python.
67

78
## Web of Things Principles in a Nutshell
89

910
The [**Web of Things (WoT)**](https://www.w3.org/WoT/) addresses the fragmentation in AI and IoT by extending standardized web technologies. WoT builds on existing web standards, ensuring reuse, and introduces an abstract, adaptable architecture tailored to real-world use cases across various domains.
1011

1112
At its core, the WoT defines an **information model** for describing Things and Services, including how to interact with them. This model is encapsulated in the **Thing Description (TD)**, a JSON-LD document that outlines the following:
1213

14+
- Metadata about the Thing
1315
- The Thing’s **capabilities** (properties, actions, and events)
1416
- Its network services (APIs)
15-
- Security requirements
17+
- Security definitions
18+
- Web links to related Things or resources
1619

1720
The **Thing Description** serves as the foundation of the Web of Things architecture.
1821

19-
2022
## Thing Description (TD)
2123

2224
The [**Thing Description (TD)**](https://www.w3.org/TR/wot-thing-description11/) is a standardized metadata format used to describe a Thing’s structure and interactions. Each TD is a machine-readable document that defines how to communicate with a Thing. Kotlin-WoT uses the TD abstraction to support developers in creating applications quickly and transport protocol-agnostic.
@@ -43,6 +45,93 @@ An **event** is a notification triggered by a specific occurrence. For example:
4345
- A **chatbot** might emit an event `conversationEnded` when the user ends the chat session.
4446
- An **AI monitoring system** might trigger an event `anomalyDetected` when it identifies unusual behavior in a monitored system.
4547

48+
### Example of a Thing Description
49+
50+
This example illustrates how a Weather Agent can be modeled using a Thing Description, with HTTP as the primary communication protocol, although alternative protocols may also be utilized. The Agent metadata describes that the agent uses the gpt-4o model from Azure and integrates with OpenWeatherMap API to provide weather information. The agent supports both text and voice interactions in English and German, adheres to GDPR compliance, and uses data anonymization. It offers a single action, "getWeather," which takes a natural language question and interaction mode as input and returns weather information in natural language. The service is secured using basic authentication and is accessed via a POST request to a specified endpoint, but other security schemes, such as OAuth2 tokens, can also be used.
51+
52+
```json
53+
{
54+
"@context": [
55+
"https://www.w3.org/2022/wot/td/v1.1",
56+
{
57+
"htv": "http://www.w3.org/2011/http#",
58+
"ex": "https://weatherai.example.com",
59+
},
60+
"https://schema.org/"
61+
],
62+
"id": "urn:uuid:6f1d3a7a-1f97-4e6b-b45f-f3c2e1c84c77",
63+
"title": "WeatherAgent",
64+
"@type": "ex:Agent",
65+
"ex:metadata": {
66+
"ex:vendor": {
67+
"ex:name": "WeatherAI Inc.",
68+
"ex:url": "https://weatherai.example.com"
69+
},
70+
"ex:model": {
71+
"ex:name": "gpt-4o",
72+
"ex:provider": "Azure"
73+
},
74+
"ex:serviceIntegration": {
75+
"ex:weatherAPI": "OpenWeatherMap",
76+
"ex:apiVersion": "v2.5",
77+
"ex:apiDocumentation": "https://openweathermap.org/api"
78+
},
79+
"ex:dataPrivacy": {
80+
"ex:dataRetentionPeriod": "30 days",
81+
"ex:anonymizationMethod": "HASHING"
82+
},
83+
"ex:interaction": {
84+
"ex:supportedLanguages": ["en_US", "de_DE"],
85+
"ex:interactionMode": ["text", "voice"]
86+
},
87+
"ex:compliance": {
88+
"ex:regulatoryCompliance": "GDPR"
89+
}
90+
},
91+
"securityDefinitions": {
92+
"basic_sc": {
93+
"scheme": "basic",
94+
"in": "header"
95+
}
96+
},
97+
"security": "basic_sc",
98+
"actions": {
99+
"getWeather": {
100+
"description": "Fetches weather information based on user input.",
101+
"safe": true, // Used to signal that there is no internal state changed when invoking the action.
102+
"idempotent": false, // Informs whether the Action can be called repeatedly with the same result.
103+
"synchronous": true,
104+
"input": {
105+
"type": "object",
106+
"properties": {
107+
"question": {
108+
"type": "string"
109+
},
110+
"interactionMode": {
111+
"type": "string",
112+
"enum": ["text", "voice"]
113+
}
114+
},
115+
"required": ["question","interactionMode"]
116+
},
117+
"output": {
118+
"type": "string",
119+
"description": "Natural language output providing weather information."
120+
},
121+
"forms": [
122+
{
123+
"op": "invokeaction",
124+
"href": "https://weatherai.example.com/weather",
125+
"contentType": "application/json",
126+
"htv:methodName":"POST"
127+
}
128+
]
129+
}
130+
}
131+
}
132+
133+
```
134+
46135
## Advantages of Kotlin-WoT
47136

48137
1. **Native Kotlin Implementation:**
@@ -52,11 +141,11 @@ An **event** is a notification triggered by a specific occurrence. For example:
52141
3. **Standards-Compliant:**
53142
- Fully adheres to the W3C WoT specifications, ensuring interoperability and reusability.
54143
4. **Extensibility:**
55-
- Easy to extend and customize to fit specific IoT requirements.
144+
- Easy to extend to support more protocols
56145

57146
## Example Thing
58147

59-
The `SimpleThing` class defines a Web of Things (WoT) model with properties, actions, and events using annotations. This structure allows external systems to interact with the Thing's state, invoke functionality, and subscribe to real-time notifications, all described in a Thing Description (TD), making it a flexible and extensible component for IoT applications.
148+
The `SimpleThing` class defines a Web of Things (WoT) model with properties, actions, and events using annotations. This structure allows external systems to interact with the Thing's state, invoke functionality, and subscribe to real-time notifications, all described in a Thing Description (TD), making it a flexible and extensible component for AI/IoT applications.
60149

61150
One of the key benefits of the Web of Things (WoT) framework is that developers can focus on building the core functionality of their applications without needing to delve into the low-level details of communication protocols like MQTT, WebSockets, or AMQP. By abstracting these protocols, kotlin-wot allows developers to use higher-level constructs such as coroutines and flows for managing asynchronous behavior and real-time interactions. With coroutines, developers can write non-blocking, concurrent code in a sequential and readable manner, simplifying the development of complex workflows. Flows, on the other hand, provide a powerful way to handle streams of data that can be emitted over time, making it easier to work with dynamic or event-driven environments. This abstraction minimizes the need for developers to manage protocol-specific intricacies and allows them to focus on implementing the logic and behavior of Things, enabling faster and more intuitive development.
62151

@@ -163,7 +252,6 @@ Example:
163252
```kotlin
164253
// Create the WoT object which can make use of HTTP. You can also add other protocols.
165254
val wot = Wot.create(Servient(clientFactories = listOf(HttpProtocolClientFactory())))
166-
167255
```
168256

169257
### **Obtain the Thing Description**
@@ -190,7 +278,7 @@ Example:
190278

191279
Example:
192280
```kotlin
193-
val readProperty = consumedThing.readProperty("property_name")
281+
val readProperty = consumedThing.readProperty("mutableProperty")
194282
```
195283

196284
### **Write to a Property**
@@ -199,7 +287,7 @@ Example:
199287

200288
Example:
201289
```kotlin
202-
consumedThing.writeProperty("property_name", 20.toInteractionInputValue()) // Update the property value
290+
consumedThing.writeProperty("mutableProperty", 20.toInteractionInputValue()) // Update the property value
203291
```
204292

205293
### **Invoke an Action**
@@ -208,7 +296,7 @@ Example:
208296

209297
Example:
210298
```kotlin
211-
val output = consumedThing.invokeAction(ACTION_NAME, "actionInput".toInteractionInputValue(), null)
299+
val output = consumedThing.invokeAction("inOutAction", "actionInput".toInteractionInputValue())
212300
```
213301

214302
### **Read All Properties**
@@ -226,9 +314,21 @@ Example:
226314

227315
Example:
228316
```kotlin
229-
consumedThing.observeProperty(PROPERTY_NAME, listener = { println("Property observed: $it") })
317+
consumedThing.observeProperty("observableProperty", listener = { println("Property observed: $it") })
230318
```
231319

320+
### **Subscribe to Events**
321+
- If the Thing supports event subscription, you can use the `subscribeEvent` method to listen for events.
322+
- When an event is emitted, the listener will be triggered with the new value.
323+
324+
Example:
325+
```kotlin
326+
consumedThing.subscribeEvent("statusUpdated", listener = { println("Event received: $it") })
327+
```
328+
329+
## Thing Description Discovery
330+
331+
W3C Web of Things (WoT) offers a mechanism that things can propagate metadata using protocols like mDNS for local discovery and/or can register themselves on centralized directories for broader access. [W3C Web of Things (WoT) Discovery](https://www.w3.org/TR/wot-discovery/#architecture) describes how things can register themselves in a central directory, known as a Thing Description Directory (TDD), through a process that involves several steps:
232332

233333
For more details, refer to the official [W3C Web of Things](https://www.w3.org/WoT/) website.
234334

0 commit comments

Comments
 (0)