• Stars
    star
    130
  • Rank 277,575 (Top 6 %)
  • Language
    TypeScript
  • License
    Other
  • Created over 6 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

thingweb.node-wot

Default CI Pipeline npm codecov Telegram Group Discord

Eclipse Thingweb node-wot

W3C Web of Things implementation on NodeJS.

Visit http://www.thingweb.io for a practical node-wot API usage, hands-on tutorials or additional information.

Useful labels: question | good first issue

Table of Contents

License

Dual-licensed under both

Pick one of these two licenses that fits your needs. Please also see the additional notices and how to contribute.

Implemented/supported features

Protocol Support

Note: More protocols can be easily added by implementing ProtocolClient, ProtocolClientFactory, and ProtocolServer interface.

Note: the bindings for binding-fujitsu and binding-oracle were removed after v0.7.x due to lack of maintainers.

MediaType Support

  • JSON โœ”๏ธ
  • Text (HTML, CSS, XML, SVG) โœ”๏ธ
  • Base64 (PNG, JPEG, GIF) โœ”๏ธ
  • Octet stream โœ”๏ธ
  • CBOR โœ”๏ธ
  • EXI โฒ๏ธ

Note: More mediaTypes can be easily added by implementing ContentCodec interface.

const ContentSerdes = require('@node-wot/core').ContentSerdes
const JsonCodec = require('@node-wot/core').JsonCodec

// e.g., assign built-in codec for *new* contentType
let cs = ContentSerdes.get();
cs.addCodec(new JsonCodec("application/calendar+json"));

// e.g., assign *own* MyCodec implementation (implementing ContentCodec interface)
cs.addCodec(new MyCodec("application/myType"));

Prerequisites

To use with Node.js

All systems require:

Linux

Meet the node-gyp requirements:

  • Python v3.6, v3.7, or v3.8
  • make
  • A proper C/C++ compiler toolchain, like GCC

Windows

Install the Windows build tools through a CMD shell as administrator:

npm install -g --production windows-build-tools

WSL: Windows Services for Linux should follow Linux instructions.

Mac OS

Meet the node-gyp requirements:

xcode-select --install

To use in a browser

To use node-wot as a browser-side JavaScript Library, the browser needs to support ECMAScript 2015. Supported browsers include:

  • Microsoft Edge 15 and later
  • Firefox 54 and later
  • Chrome 58 and later
  • Safari 10 and later

Using a browser with only ES5 support (eg. IE 11) might be possible if you add polyfills.

How to get the library

As a Node.js dependency

You can install node-wot in the following ways:

  1. As a normal dependency (i.e., like loadsh). In this case, you are embedding a servient inside your application.
  2. As a CLI to run scripts. In this case, your application is running inside the default servient.

Normal Dependency

If you want to use node-wot as a library in your Node.js application, you can use npm to install the node-wot packages that you need. To do so, cd inside you application folder, and run:

npm i @node-wot/core @node-wot/binding-http --save

Now, you can implement a thing as follows:

// server.js
// Required steps to create a servient for creating a thing
const Servient = require('@node-wot/core').Servient;
const HttpServer = require('@node-wot/binding-http').HttpServer;

const servient = new Servient();
servient.addServer(new HttpServer());

servient.start().then((WoT) => {
    // Then from here on you can use the WoT object to produce the thing
    // i.e WoT.produce({.....})
});

A client consuming a thing can be implemented like this:

// client.js
// Required steps to create a servient for a client
const { Servient, Helpers } = require("@node-wot/core");
const { HttpClientFactory } = require('@node-wot/binding-http');

const servient = new Servient();
servient.addClientFactory(new HttpClientFactory(null));
const WoTHelpers = new Helpers(servient);

WoTHelpers.fetch("http://localhost:8080/example").then(async (td) => {
    try {
        servient.start().then(async (WoT) => {
            // Then from here on you can consume the thing
            // i.e let thing = await WoT.consume(td) ...
        });
    }
    catch (err) {
        console.error("Script error:", err);
    }
}).catch((err) => { console.error("Fetch error:", err); });

You can then start the applications with node by running node server.js and node client.js.

CLI Tool

You can alternatively use node-wot via its command line interface (CLI). Please visit the CLI tool's Readme to find out more.

As a standalone application

Clone and build

Clone the repository:

git clone https://github.com/eclipse-thingweb/node-wot

Go into the repository:

cd thingweb.node-wot

Install root dependencies (locally installs tools such as typescript):

npm ci

Use tsc to transcompile TS code to JS in dist directory for each package: Note: This step automatically calls npm run bootstrap.

npm run build

Optional steps

Link Packages

Make all packages available on your local machine (as symlinks). You can then use each package in its local version via npm link <module> instead of npm install <module> (see also https://docs.npmjs.com/cli/link).

sudo npm run link

(On Windows omit sudo)

Link Local wot-typescript-definitions

To evolve the Scripting API in development, you need to use a locally changed version of the wot-typescript-definitions. Use npm link for this as well:

git clone https://github.com/w3c/wot-scripting-api/
cd wot-scripting-api/typescript/
sudo npm link

(On Windows omit sudo)

In each node-wot package, link the local version made available in the previous step:

sudo npm link wot-typescript-definitions

(On Windows omit sudo)

Optimization

To reduce the size of the installation from about 800 MByte down to about 200 MByte, you can run the following commands (currently only tested on Linux): npm prune --production

Trouble shooting

  • Build error about No matching version found for @node-wot/... or something about match
    • try npm run unlock from project root before building
  • sudo npm run link does not work
    • try npm run unlock from project root before calling [sudo] npm run link
    • try npm link in each package directory in this order: td-tools, core, binding-*, cli, demo-servients
  • Error mesage for npm link @node-wot/<module> ELOOP: too many symbolic links encountered, stat '/usr/lib/node_modules/@node-wot/<module>
    1. Run npm run link in thingweb.node-wot again
    2. Remove node_modules in the targeted project
    3. Remove all @node-wot/<module> dependencies in your package.json
    4. Run npm i again
    5. Install the packages with npm link @node-wot/<module>
  • Build error around prebuild: npm run bootstrap
    • This has been seen failing on WSL. Try using a more recent NodeJS version

As a Docker image

Alternatively, node-wot can be built as a Docker image with the Dockerfile.

Make sure you are under linux or under WSL if you are running on Windows.

Clone the repository:

git clone https://github.com/eclipse-thingweb/node-wot

Go into the repository:

cd thingweb.node-wot

Build the Docker image named wot-servient from the Dockerfile:

npm run build:docker

Run the wot-servient as a container:

docker run --rm wot-servient -h

As a browser library

node-wot can also be imported as browser-side library. To do so, include the following script tag in your html:

<script src="https://cdn.jsdelivr.net/npm/@node-wot/browser-bundle@latest/dist/wot-bundle.min.js"></script>

In the browser, node wot only works in client mode with limited binding support. Supported bindings: HTTP / HTTPS / WebSockets You can access all node-wot functionality through the "Wot" global object:

var servient = new Wot.Core.Servient();
var client = new Wot.Http.HttpClient();

No time for explanations - show me a running example!

Using Node.js

Run all the steps above including "Link Packages" and then run this:

wot-servient -h
cd examples/scripts
wot-servient

Without the "Link Packages" step, the wot-servient command is not available and node needs to be used (e.g., Windows CMD shell):

# expose
node packages\cli\dist\cli.js examples\scripts\counter.js
# consume
node packages\cli\dist\cli.js --client-only examples\scripts\counter-client.js

Using Docker

First build the docker image and then run the counter example:

# expose
docker run -it --init -p 8080:8080/tcp -p 5683:5683/udp -v "$(pwd)"/examples:/srv/examples --rm wot-servient /srv/examples/scripts/counter.js
# consume
docker run -it --init -v "$(pwd)"/examples:/srv/examples --rm --net=host wot-servient /srv/examples/scripts/counter-client.js --client-only
  • The counter exposes the HTTP endpoint at 8080/tcp and the CoAP endpoint at 5683/udp and they are bound to the host machine (with -p 8080:8080/tcp -p 5683:5683/udp).
  • The counter-client binds the network of the host machine (--net=host) so that it can access the counter thing's endpoints.
  • --init allows the containers to be killed with SIGINT (e.g., Ctrl+c)
  • -v "$(pwd)"/examples:/srv/examples mounts the examples directory to /srv/examples on the container so that the node inside the container can read the example scripts.

Using a browser

An example of how to use node-wot as a browser-side library can be found under examples/browser/index.html. To run it, open examples/browser/index.html in a modern browser, and consume the test Thing available under http://plugfest.thingweb.io:8083/testthing to interact with it.

The JavaScript code that uses node-wot as a library to power this application can be found under: examples/browser/index.js

Online Things

We offer online simulated Things that are available to be used by anyone.

Their TDs are available at the following links:

All of them require no security mechanism to be communicated with and have same behavior from CoAP or HTTP endpoints. Below are small explanations on what they can be used for:

  • Counter: It has a count property that can be read or observed and can be incremented or decremented via separate actions. It is also possible to reset the count the value, obtain when the last change occured, subscribe to a change in the count value or get the count value as an image.
  • TestThing: This Thing exists primarily for testing different data schemas and payload formats. It also has events attached to affordances that notify when a value changes.
  • Smart Coffee Machine: This is a simulation of a coffee machine that also has a simple user interface that displays the values of properties. In addition to proving a real life device example, it can be used for testing uriVariables. You can ask it to brew different coffees and monitor the available resource level.

How to use the library

The API

This library implements the WoT Scripting API:

Additionally, you can have a look at our API Documentation.

To learn by examples, see examples/scripts to have a feeling of how to script a Thing or a Consumer.

TD Tooling

The package td-tools provides utilties around ThingDescription (TD) tooling:

Logging

Logging in node-wot is implemented via the debug package. This allows users to enable log messages for specific logging levels (info, debug, warn, or error) or packages. Which log messages are emitted is controlled by the DEBUG environment variable.

In the following, we will show a couple of examples for its usage using wildcard characters (*). Note, however, that the syntax for setting an environment variable depends on your operating system and the terminal you use. See the debug documentation for more details on platform-specific differences.

First, you can enable all log messages by setting DEBUG to a wildcard like so:

DEBUG=* npm start

To only show node-wot-specific logging messages, prefix the wildcard with node-wot:

DEBUG=node-wot* npm start

To only show a specific log level, use one of info, debug, warn, or error as the suffix. Note in this context that you can provide multiple values for DEBUG. For example, if you want to show only debug and info messages, you can use the following:

DEBUG='*debug,*info' npm start

Finally, you can choose to only display log messages from a specific node-wot package. For example, if you only want to see log messages for the core package, use the following:

DEBUG=node-wot:core* npm start

Using the log levels above, you can also apply more fine-grained parameters for logging. For instance, if you only want to see error messages from the binding-coap package, use this:

DEBUG=node-wot:binding-coap*error npm start

Install new/different versions of NodeJS

Using NPM, you can install NodeJS independent from the usually outdated package managers such as apt. This is nicely done by n:

sudo npm cache clean -f
sudo npm install -g n

To get the "stable" version:

sudo n stable

To get the "latest" version:

sudo n latest

Finally, make the node command available through:

sudo ln -sf /usr/local/n/versions/node/<VERSION>/bin/node /usr/bin/node

Development Internals

details

Publishing on NPM

Run npm publish --workspaces in root node-wot folder.

Regenerating package-lock.json

  1. Delete package-lock.json file
  2. Delete any local cache (like node_modules folders etc.)
  3. Run npm install
  4. Run npm dedupe (see #765 (comment))

More Repositories

1

mosquitto

Eclipse Mosquitto - An open source MQTT broker
C
7,649
star
2

che

Kubernetes based Cloud Development Environments for Enterprise Teams
TypeScript
6,868
star
3

jetty.project

Eclipse Jettyยฎ - Web Container & Clients - supports HTTP/2, HTTP/1.1, HTTP/1.0, websocket, servlets, and more
Java
3,655
star
4

paho.mqtt.android

MQTT Android
Java
2,708
star
5

paho.mqtt.golang

Go
2,381
star
6

eclipse-collections

Eclipse Collections is a collections framework for Java with optimized data structures and a rich, functional and fluent API.
Java
2,283
star
7

paho.mqtt.java

Eclipse Paho Java MQTT client library. Paho is an Eclipse IoT project.
Java
2,095
star
8

paho.mqtt.python

paho.mqtt.python
Python
1,946
star
9

sumo

Eclipse SUMO is an open source, highly portable, microscopic and continuous traffic simulation package designed to handle large networks. It allows for intermodal simulation including pedestrians and comes with a large set of tools for scenario creation.
1,902
star
10

paho.mqtt.c

An Eclipse Paho C client library for MQTT for Windows, Linux and MacOS. API documentation: https://eclipse.github.io/paho.mqtt.c/
C
1,736
star
11

eclipse.jdt.ls

Java language server
Java
1,410
star
12

mraa

Linux Library for low speed IO Communication in C with bindings for C++, Python, Node.js & Java. Supports generic io platforms, as well as Intel Edison, Intel Joule, Raspberry Pi and many more.
C
1,349
star
13

paho.mqtt.embedded-c

Paho MQTT C client library for embedded systems. Paho is an Eclipse IoT project (https://iot.eclipse.org/)
C
1,307
star
14

openvsx

An open-source registry for VS Code extensions
Java
1,181
star
15

paho.mqtt.javascript

paho.mqtt.javascript
JavaScript
1,145
star
16

paho.mqtt.cpp

C++
976
star
17

milo

Eclipse Miloโ„ข - an open source implementation of OPC UA (IEC 62541).
Java
976
star
18

omr

Eclipse OMRโ„ข Cross platform components for building reliable, high performance language runtimes
C++
917
star
19

xtext

Eclipse Xtextโ„ข is a language development framework
Java
715
star
20

upm

UPM is a high level repository that provides software drivers for a wide variety of commonly used sensors and actuators. These software drivers interact with the underlying hardware platform through calls to MRAA APIs.
C++
651
star
21

microprofile

Repository for important documentation - the index to the project / community
Java
635
star
22

californium

CoAP/DTLS Java Implementation
Java
620
star
23

leshan

Java Library for LWM2M
Java
614
star
24

paho.mqtt-spy

mqtt-spy is an open source desktop & command line utility intended to help you with monitoring activity on MQTT topics
Java
605
star
25

steady

Analyses your Java applications for open-source dependencies with known vulnerabilities, using both static analysis and testing to determine code context and usage for greater accuracy. https://eclipse.github.io/steady/
Java
518
star
26

sprotty

A diagramming framework for the web
TypeScript
514
star
27

paho.mqtt.m2mqtt

C#
513
star
28

jifa

๐Ÿ”ฌ Online Heap Dump, GC Log, Thread Dump & JFR File Analyzer.
Java
509
star
29

buildship

The Eclipse Plug-ins for Gradle project.
Java
507
star
30

lsp4j

A Java implementation of the language server protocol intended to be consumed by tools and language servers implemented in Java.
Java
473
star
31

kura

Eclipse Kuraโ„ข project
Java
469
star
32

wakaama

Eclipse Wakaama is a C implementation of the Open Mobile Alliance's LightWeight M2M protocol (LWM2M).
C
465
star
33

streamsheets

An open-source tool for processing stream data using a spreadsheet-like interface.
JavaScript
449
star
34

paho.mqtt.rust

paho.mqtt.rust
Rust
422
star
35

hawkbit

Eclipse hawkBitโ„ข
Java
416
star
36

eclipse-collections-kata

Eclipse Collections Katas
Java
411
star
37

hono

Eclipse Honoโ„ข Project
Java
378
star
38

repairnator

Software development bots for Github. Join the bot revolution! ๐ŸŒŸ๐Ÿค–๐ŸŒŸ๐Ÿ’ž
Java
370
star
39

ponte

Ponte Project
JavaScript
360
star
40

birt

Eclipse BIRTโ„ข The open source reporting and data visualization project.
Java
355
star
41

paho.golang

Go libraries
Go
324
star
42

rdf4j

Eclipse RDF4J: scalable RDF for Java
Java
323
star
43

paho.mqtt-sn.embedded-c

Paho C MQTT-SN gateway and libraries for embedded systems. Paho is an Eclipse IoT project.
C++
313
star
44

lemminx

XML Language Server
Java
255
star
45

vorto

Vorto Project
Java
221
star
46

tahu

Eclipse Tahu addresses the existence of legacy SCADA/DCS/ICS protocols and infrastructures and provides a much-needed definition of how best to apply MQTT into these existing industrial operational environments.
Java
220
star
47

kapua

Java
218
star
48

elk

Eclipse Layout Kernel - Automatic layout for Java applications.
Java
211
star
49

jnosql

Eclipse JNoSQL is a framework which has the goal to help Java developers to create Jakarta EE applications with NoSQL.
Java
210
star
50

corrosion

Eclipse Corrosion - Rust edition in Eclipse IDE
Java
199
star
51

capella

Open Source Solution for Model-Based Systems Engineering
Java
197
star
52

dirigible

Eclipse Dirigibleโ„ข Project
JavaScript
196
star
53

microprofile-config

MicroProfile Configuration Feature
Java
182
star
54

wildwebdeveloper

Simple and productive Web Development Tools in the Eclipse IDE
Java
181
star
55

pdt

PHP Development Tools project (PDT)
PHP
178
star
56

org.aspectj

Java
172
star
57

xacc

XACC - eXtreme-scale Accelerator programming framework
C++
137
star
58

microprofile-rest-client

MicroProfile Rest Client
Java
124
star
59

tycho

Tycho project repository (tycho)
Java
119
star
60

microprofile-conference

Microprofile.io Demo Code - Web Services Conference Application
Java
117
star
61

microprofile-fault-tolerance

microprofile fault tolerance
Java
115
star
62

microprofile-samples

Micro Profile Samples
Java
115
star
63

xtext-core

xtext-core
Java
114
star
64

microprofile-open-api

Microprofile open api
Java
112
star
65

jbom

Java
111
star
66

gef

Eclipse GEFโ„ข
Java
111
star
67

transformer

Eclipse Transformer provides tools and runtime components that transform Java binaries, such as individual class files and complete JARs and WARs, mapping changes to Java packages, type names, and related resource names.
Java
108
star
68

paho.mqtt.testing

An Eclipse Paho project - a Python broker for testing
Python
104
star
69

tinydtls

Eclipse tinydtls
C
102
star
70

xtext-xtend

xtext-xtend
Java
100
star
71

microprofile-graphql

microprofile-graphql
Java
98
star
72

microprofile-lra

microprofile-lra
Java
97
star
73

microprofile-health

microprofile-health
Java
95
star
74

microprofile-metrics

microprofile-metrics
Java
94
star
75

kuksa.val

kuksa.val
C++
93
star
76

sw360

SW360 project
Java
92
star
77

microprofile-jwt-auth

Java
92
star
78

mosaic

Eclipse MOSAIC is a Multi-Domain and Multi-Scale Simulation Framework for Automated and Connected Mobility Scenarios.
Java
88
star
79

nebula

Nebula Project
Java
84
star
80

microprofile-reactive-streams-operators

Microprofile project
Java
79
star
81

mosquitto.rsmb

Mosquitto rsmb
C
75
star
82

microprofile-starter

MicroProfile project generator source code
Java
69
star
83

aCute

Eclipse aCute - C# edition in Eclipse IDE
Java
65
star
84

ditto-examples

Eclipse Dittoโ„ข: Digital Twin framework - Examples
Java
63
star
85

epsilon

Epsilon is a family of Java-based scripting languages for automating common model-based software engineering tasks, such as code generation, model-to-model transformation and model validation, that work out of the box with EMF (including Xtext and Sirius), UML (including Cameo/MagicDraw), Simulink, XML and other types of models.
Java
61
star
86

lsp4e

Language Server Protocol support in Eclipse IDE
Java
60
star
87

tm4e

TextMate support in Eclipse IDE
Java
60
star
88

californium.tools

Californium project
Java
59
star
89

microprofile-reactive-messaging

Java
59
star
90

microprofile-opentracing

microprofile-opentracing
Java
57
star
91

eclemma

๐ŸŒ˜ใ€€Java Code Coverage for Eclipse IDE
Java
57
star
92

texlipse

Eclipse Texlipse
Java
56
star
93

mita

mita
Xtend
55
star
94

dartboard

Dart Plugin for Eclipse
Java
55
star
95

jnosql-databases

This project contains Eclipse JNoSQL databases
Java
54
star
96

windowbuilder

Eclipse Windowbuilder
Java
54
star
97

xtext-eclipse

xtext-eclipse
Java
49
star
98

adore

Eclipse ADORe is a ROS based modular software library and toolkit for decision making, planning, control and simulation of automated vehicles supporting CARLA and SUMO.
Makefile
48
star
99

packages

IoT Packages project
Smarty
46
star
100

amlen

Message Broker for IoT/Mobile/Web. Mainly uses MQTT v3.x and v5. Aims to be easy to use, scalable and reliable
C
46
star