You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+109-9Lines changed: 109 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3,20 +3,22 @@
3
3
**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.
4
4
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.
5
5
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.
6
7
7
8
## Web of Things Principles in a Nutshell
8
9
9
10
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.
10
11
11
12
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:
12
13
14
+
- Metadata about the Thing
13
15
- The Thing’s **capabilities** (properties, actions, and events)
14
16
- Its network services (APIs)
15
-
- Security requirements
17
+
- Security definitions
18
+
- Web links to related Things or resources
16
19
17
20
The **Thing Description** serves as the foundation of the Web of Things architecture.
18
21
19
-
20
22
## Thing Description (TD)
21
23
22
24
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:
43
45
- A **chatbot** might emit an event `conversationEnded` when the user ends the chat session.
44
46
- An **AI monitoring system** might trigger an event `anomalyDetected` when it identifies unusual behavior in a monitored system.
45
47
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.
"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
+
46
135
## Advantages of Kotlin-WoT
47
136
48
137
1.**Native Kotlin Implementation:**
@@ -52,11 +141,11 @@ An **event** is a notification triggered by a specific occurrence. For example:
52
141
3.**Standards-Compliant:**
53
142
- Fully adheres to the W3C WoT specifications, ensuring interoperability and reusability.
54
143
4.**Extensibility:**
55
-
- Easy to extend and customize to fit specific IoT requirements.
144
+
- Easy to extend to support more protocols
56
145
57
146
## Example Thing
58
147
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.
60
149
61
150
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.
62
151
@@ -163,7 +252,6 @@ Example:
163
252
```kotlin
164
253
// Create the WoT object which can make use of HTTP. You can also add other protocols.
165
254
val wot =Wot.create(Servient(clientFactories =listOf(HttpProtocolClientFactory())))
166
-
167
255
```
168
256
169
257
### **Obtain the Thing Description**
@@ -190,7 +278,7 @@ Example:
190
278
191
279
Example:
192
280
```kotlin
193
-
val readProperty = consumedThing.readProperty("property_name")
281
+
val readProperty = consumedThing.readProperty("mutableProperty")
194
282
```
195
283
196
284
### **Write to a Property**
@@ -199,7 +287,7 @@ Example:
199
287
200
288
Example:
201
289
```kotlin
202
-
consumedThing.writeProperty("property_name", 20.toInteractionInputValue()) // Update the property value
290
+
consumedThing.writeProperty("mutableProperty", 20.toInteractionInputValue()) // Update the property value
203
291
```
204
292
205
293
### **Invoke an Action**
@@ -208,7 +296,7 @@ Example:
208
296
209
297
Example:
210
298
```kotlin
211
-
val output = consumedThing.invokeAction(ACTION_NAME, "actionInput".toInteractionInputValue(), null)
299
+
val output = consumedThing.invokeAction("inOutAction", "actionInput".toInteractionInputValue())
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:
232
332
233
333
For more details, refer to the official [W3C Web of Things](https://www.w3.org/WoT/) website.
0 commit comments