Coder Social home page Coder Social logo

dart_wot's Introduction

pub package Build codecov style: lint

Thingweb dart_wot logo

dart_wot

dart_wot is an implementation of the Web of Things Scripting API modelled after the WoT reference implementation node-wot. At the moment, it supports interacting with Things using the Constrained Application Protocol (CoAP), the Hypertext Transfer Protocol (HTTP), and the MQTT protocol.

Features

You can consume Thing Descriptions and interact with a Thing based on its exposed Properties, Actions, and Events. Discovery support is currently limited to the "direct" method (i.e. fetching a TD using a single URL). Exposing Things is not yet supported but will be added in future versions.

Using the Protocol Interfaces in the core package, you can add support for additional protocols in your own application or library. The main requirement for this to work is the existence of a URI scheme for the given protocol.

Getting started

To get started, you first need to install the package by adding it to your pubspec.yaml file. You can use dart pub add dart_wot (for a Dart project) or flutter pub add dart_wot (for a Flutter project) to do so.

You can then use the package in your project by adding import 'package:dart_wot/dart_wot.dart' to your source files.

Usage

Below you can find a basic example for incrementing and reading the value of a counter Thing, which is part of the Thingweb Online Things.

In the example, we first create a WoT runtime using a Servient with CoAP and HTTP support. With the runtime, we then retrieve a TD (using the requestThingDescription() method) and consume it (using the consume() method), creating a ConsumedThing object, Afterward, the actual interactions with the counter are performed by calling the invokeAction() and readProperty() methods on the ConsumedThing.

import "package:dart_wot/binding_coap.dart";
import "package:dart_wot/binding_http.dart";
import "package:dart_wot/core.dart";

Future<void> main(List<String> args) async {
  final servient = Servient.create(
    clientFactories: [
      CoapClientFactory(),
      HttpClientFactory(),
    ],
  );
  final wot = await servient.start();

  final url = Uri.parse("coap://plugfest.thingweb.io/counter");
  print("Requesting TD from $url ...");
  final thingDescription = await wot.requestThingDescription(url);

  final consumedThing = await wot.consume(thingDescription);
  print(
    "Successfully retrieved and consumed TD with title "
    '"${thingDescription.title}"!',
  );

  print(consumedThing.thingDescription.events);
  final subscription = await consumedThing.subscribeEvent("change", print);

  print("Incrementing counter ...");
  await consumedThing.invokeAction("increment");

  final status = await consumedThing.readProperty("count");
  final value = await status.value();
  print("New counter value: $value");

  await subscription.stop();
}

More complex examples can be found in the example directory.

License

dart_wot is licensed under the 3-Clause BSD License. See the LICENSE file for more information.

SPDX-License-Identifier: BSD-3-Clause

Acknowledgements

dart_wot was inspired by Eclipse Thingweb node-wot, a W3C Web of Things implementation for the Node.js ecosystem.

Contribution

Please refer to our contribution guidelines for more details.

Maintainers

This project is currently maintained by the following developers:

Name Email Address GitHub Username
Jan Romann [email protected] JKRhb

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.