Skip to content
thingweb.node-wot
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.vscode
examples
packages
.editorconfig
.gitattributes
.gitignore
.travis.yml
API.md
CONTRIBUTING.md
LICENSE.md
NOTICE.md
README.md
lerna.json
package.json
tsconfig.json

README.md

Eclipse Thingweb node-wot

W3C Web of Things implementation on NodeJS

Build Status

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.

Prerequisites

All systems require:

  • NodeJS version 10+ (e.g., 10.13.0 LTS)

Linux

Meet the node-gyp requirements:

  • Python 2.7 (v3.x.x is not supported)
  • 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

Mac OS

Meet the node-gyp requirements:

xcode-select --install

How to get ready for coding

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 and lerna):

npm install 

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

Link Packages

Make all packages available on your local machine (as symlinks). You can then use each paket 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):

  • yarn init
  • yarn add [packages]
  • npm run build
  • lerna init
  • lerna exec 'npm prune --production'

Trouble shooting

  • Build error around node-aead-crypto
    • node-gyp has been seen failing on MacOS
    • try node 10+, which does not require the crypto polyfill
  • 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

No time for explanations - I want to start from something running!

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 examples\scripts\counter-client.js

How to use the library

This library implements the WoT Scripting API:

You can also see examples/scripts to have a feeling of how to script a Thing.

Protocol Support

  • HTTP ✔️
  • HTTPS ✔️
  • CoAP ✔️
  • CoAPS ✔️
  • Websocket (server only)
  • MQTT (in dev branch)

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

MediaType Support

  • JSON ✔️
  • Plain text ✔️
  • CBOR ✖️

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

Logging

We used to have a node-wot-logger package to allow fine-grained logging (by means of Winston). It turned out though that depending on the actual use-case other logging libraries might be better suited. Hence we do not want to prescribe which logging library to use. Having said that, we use console statements which can be easily overriden to use the prefered logging library if needed (see here).

You can’t perform that action at this time.