一个快速、可扩展的框架,可将任何设备与浏览器和后端应用程序连接起来
A fast and extensible framework to connect any device with your application The Eclipse Thingweb node-wot is a framework for implementing Web of Things servers and clients in Node.js. It is written from the ground up with Typescript with the goal of providing a fast and extensible framework for IoT applications. Node-wot wants to give developers the ability to create complex business logic without worrying about protocol and low-level details leveraging on a standard metadata format, the Thing Description (TD). Thanks to the TD abstraction developers can find a set of satellite tools to create their applications in a fast and easy way.
The Web of Things (WoT) tackles IoT fragmentation by extending standardized web technologies. It simplifies IoT application development, promoting flexibility and interoperability. WoT preserves existing IoT standards, ensuring reuse, and provides an adaptable, abstract architecture based on real-world use cases across domains. In essence, WoT paves the way for seamless IoT integration by defining an information model capable of describing Things and Services and how to interact with them. This information model is called the Thing Description (TD) and it is a JSON-LD document that describes the Thing and its capabilities, including its network services (APIs), its network interactions, and security requirements. The TD is the cornerstone of the Web of Things architecture and it is the main abstraction that node-wot uses to implement its functionalities. Every Thing has the following capabilities or "affordances":
For further information please refer to the official W3C Web of Things website.
The framework is composed by different packages that users can use as they please. The core package is @node-wot/core and it is the only mandatory package to install. The other packages are bindings that allow the framework to communicate with different protocols.
[!WARNING] We no longer actively support Node.js version 18 and lower.
Platforms specific prerequisites:
npm install -g --production windows-build-toolsxcode-select --installIf 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.
Todo so, cd inside your application folder and install at least the mandatory core package:
npm i @node-wot/coreUsually, your application needs at least one protocol binding to commmunicate, e.g.,:
npm i @node-wot/binding-httpIn case the application shall consume Thing Descriptions that are stored locally, you would also need the file binding:
npm i @node-wot/binding-fileYou see other available bindings in the packages folder, which you can install via npm i @node-wot/.
To use node-wot as JavaScript library insde the Web browser, it needs to support ECMAScript 2015+. Using a browser with only ES5 support (e.g., IE 11) might be possible if you add polyfills.
If you want to use node-wot as a library in your browser application,cd inside your application folder and install the browser bundle:
npm i @node-wot/browser-bundleYou can find more (non-)installation options in the specific package README.
You can alternatively use node-wot via its command line interface (CLI). Please visit the CLI tool README to find out more.
To make the node-wot command available on your machine, install the CLI tool in the global scope:
npm i @node-wot/cli -gAnother option is to use node-wot inside a docker image. 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-wotGo into the repository:
cd node-wotBuild the Docker image named node-wot from the Dockerfile:
npm run build:dockerRun the node-wot as a container:
docker run --rm node-wot -hWith node-wot you can create server-side Things, in WoT jargon we call this operation "expose a Thing" or you can create client-side Things, in WoT jargon we call this operation "consume a Thing". An exposed Thing allows you to bring your device or services to the Web with just a few lines of code. On the other hand, with a consumed Thing, you have a fixed interface to interact with devices, potentially using different protocols/frameworks. In the following section, we will show how to create a simple counter Thing and how to consume it. Assuming you have installed and configured node-wot as a library, you can create and expose a counter Thing as follows:
…Now supposing you want to interact with the device, you have to consume its Thing Description as follows:
…If you execute both scripts you will see count: ${count} printed 5 times. We host a more complex version of this example at http://plugfest.thingweb.io/examples/counter.html and you can find the source code in the counter example folder. You can also find more examples in the examples folder for JavaScript and in the examples folder for TypeScript. Finally, for your convenience, we host a set of online Things that you can use to test your applications. You can find more information about them in the Online Things section.
[!NOTE] More protocols can be easily added by implementing
ProtocolClient,ProtocolClientFactory, andProtocolServerinterface.
Can't find your preferred MediaType? More codecs can be easily added by implementing ContentCodec interface. Read more in the Documentation section.
Run all the steps above including "Link Packages" and then run this:
node-wot -h
cd examples/scripts
node-wotWithout the "Link Packages" step, the node-wot 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.jsexamples/scripts/counter.jsFirst 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 node-wot /srv/examples/scripts/counter.js
# consume
docker run -it --init -v "$(pwd)"/examples:/srv/examples --rm --net=host node-wot /srv/examples/scripts/counter-client.js --client-only-p 8080:8080/tcp -p 5683:5683/udp).--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.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
暂无开放 Issues,或尚未同步最近议题。