GithubHelp home page GithubHelp logo

webthingsio / webthing-node Goto Github PK

View Code? Open in Web Editor NEW
233.0 18.0 48.0 523 KB

Node.js implementation of a Web Thing server

License: Mozilla Public License 2.0

JavaScript 38.63% Shell 0.57% Dockerfile 0.93% Makefile 5.82% TypeScript 54.04%

webthing-node's Introduction

webthing

Build Status NPM license

Implementation of an HTTP Web Thing.

Installation

webthing can be installed via npm, as such:

$ npm install webthing

Example

In this example we will set up a dimmable light and a humidity sensor (both using fake data, of course). Both working examples can be found in here.

Dimmable Light

Imagine you have a dimmable light that you want to expose via the web of things API. The light can be turned on/off and the brightness can be set from 0% to 100%. Besides the name, description, and type, a Light is required to expose two properties:

  • on: the state of the light, whether it is turned on or off
    • Setting this property via a PUT {"on": true/false} call to the REST API toggles the light.
  • brightness: the brightness level of the light from 0-100%
    • Setting this property via a PUT call to the REST API sets the brightness level of this light.

First we create a new Thing:

const light = new Thing('urn:dev:ops:my-lamp-1234',
                        'My Lamp',
                        ['OnOffSwitch', 'Light'],
                        'A web connected lamp');

Now we can add the required properties.

The on property reports and sets the on/off state of the light. For this, we need to have a Value object which holds the actual state and also a method to turn the light on/off. For our purposes, we just want to log the new state if the light is switched on/off.

light.addProperty(
  new Property(
    light,
    'on',
    new Value(true, (v) => console.log('On-State is now', v)),
    {
      '@type': 'OnOffProperty',
      title: 'On/Off',
      type: 'boolean',
      description: 'Whether the lamp is turned on',
    }));

The brightness property reports the brightness level of the light and sets the level. Like before, instead of actually setting the level of a light, we just log the level.

light.addProperty(
  new Property(
    light,
    'brightness',
    new Value(50, v => console.log('Brightness is now', v)),
    {
      '@type': 'BrightnessProperty',
      title: 'Brightness',
      type: 'number',
      description: 'The level of light from 0-100',
      minimum: 0,
      maximum: 100,
      unit: 'percent',
    }));

Now we can add our newly created thing to the server and start it:

// If adding more than one thing, use MultipleThings() with a name.
// In the single thing case, the thing's name will be broadcast.
const server = new WebThingServer(SingleThing(light), 8888);

process.on('SIGINT', () => {
  server.stop().then(() => process.exit()).catch(() => process.exit());
});

server.start().catch(console.error);

This will start the server, making the light available via the WoT REST API and announcing it as a discoverable resource on your local network via mDNS.

Sensor

Let's now also connect a humidity sensor to the server we set up for our light.

A MultiLevelSensor (a sensor that returns a level instead of just on/off) has one required property (besides the name, type, and optional description): level. We want to monitor this property and get notified if the value changes.

First we create a new Thing:

const sensor = new Thing('urn:dev:ops:my-humidity-sensor-1234',
                         'My Humidity Sensor',
                         ['MultiLevelSensor'],
                         'A web connected humidity sensor');

Then we create and add the appropriate property:

  • level: tells us what the sensor is actually reading

    • Contrary to the light, the value cannot be set via an API call, as it wouldn't make much sense, to SET what a sensor is reading. Therefore, we are creating a readOnly property.
    const level = new Value(0.0);
    
    sensor.addProperty(
      new Property(
        sensor,
        'level',
        level,
        {
          '@type': 'LevelProperty',
          title: 'Humidity',
          type: 'number',
          description: 'The current humidity in %',
          minimum: 0,
          maximum: 100,
          unit: 'percent',
          readOnly: true,
        }));

Now we have a sensor that constantly reports 0%. To make it usable, we need a thread or some kind of input when the sensor has a new reading available. For this purpose we start a thread that queries the physical sensor every few seconds. For our purposes, it just calls a fake method.

// Poll the sensor reading every 3 seconds
setInterval(() => {
  // Update the underlying value, which in turn notifies all listeners
  level.notifyOfExternalUpdate(readFromGPIO());
}, 3000);

This will update our Value object with the sensor readings via the this.level.notifyOfExternalUpdate(readFromGPIO()); call. The Value object now notifies the property and the thing that the value has changed, which in turn notifies all websocket listeners.

Adding to Gateway

To add your web thing to the WebThings Gateway, install the "Web Thing" add-on and follow the instructions here.

Resources

webthing-node's People

Contributors

autonome avatar dravenk avatar hobinjk avatar mozilla-github-standards avatar mrstegeman avatar notwoods avatar rzr avatar tim-hellhake avatar vkuzmichev avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

webthing-node's Issues

Node does not exit after server.stop()

Code to reproduce

I am using Node v10.11.0.

const { SingleThing, Thing, WebThingServer } = require('webthing');

async function test() {
  const thing = new Thing();
  const server = new WebThingServer(new SingleThing(thing), 8000);
  console.log('starting...');
  await server.start();
  console.log('started');
  console.log('stopping...');
  server.stop();
  console.log('stopped');
}

test().catch(console.error);

After completing tests in a repository of mine Jest has to be force exited for the process to quit.

git clone [email protected]:webthings/all-webthings.git
cd all-webthings
git checkout cf92a899d376ca48411b56f04ca0c2915a41d2ba
npm test -- --detectOpenHandles

This output the following on my machine:

Ran all test suites.

Jest has detected the following 1 open handle potentially keeping Jest from exiting:

  ●  Timeout

      at Object.<anonymous> (node_modules/dnssd/lib/sleep.js:14:16)
      at Object.<anonymous> (node_modules/dnssd/lib/Advertisement.js:14:13)

Because I assume that this is an issue more related to dnssd I filed it in that repository as well: DeMille/dnssd.js#10.

Disable discovery and server?

Hi, just getting started and please forgive my ignorance if the question doesn't make sense.

webthing-node starts a server that can be discovered and connected to. However there are a few reasons why this is not always desirable:

  1. No centralized permission management. Permissions need to be set per instance.
  2. A network with VLANs doesn't allow for discovery
  3. The current approach only works on fully trusted networks. In case of remote IoT devices such a network might not be available.
  4. Security concerns. Minimizing attack footprint by only allowing access to a gateway.

In theory, is it possible to turn off the server completely and configure it to push the discovery and status updates to a gateway?
(even if it requires an update to the gateway). This allows a single point for contact and authentication for all instances by the end user.
Thanks

WebThingServer fails to start if there is no network connection

This issue has the same bedrock as WebThingsIO/gateway#1401.

Steps to reproduce

  1. Disconnect from all networks.
  2. Start a WebThingServer

Actual

The process crashes while starting the advertisement service dnssd.

Error: send ENETUNREACH 224.0.0.251:5353
    at SendWrap.afterSend [as oncomplete] (dgram.js:467:11)
Emitted 'error' event at:
    at Advertisement._onError (/home/jaller94/Git/webthings/all-webthings/node_modules/dnssd/lib/Advertisement.js:221:8)
    at Object.onceWrapper (events.js:273:13)
    at NetworkInterface.emit (events.js:182:13)
    at NetworkInterface._onError (/home/jaller94/Git/webthings/all-webthings/node_modules/dnssd/lib/NetworkInterface.js:438:8)
    at SendWrap.callback (/home/jaller94/Git/webthings/all-webthings/node_modules/dnssd/lib/NetworkInterface.js:393:50)
    at SendWrap.afterSend [as oncomplete] (dgram.js:472:8)

Expected

If the web server starts successfully, the process stays alive. It might try to start the dnssd advertisement in a set time interval, hoping for a better network condition.

Minimal code to reproduce

const { SingleThing, Thing, WebThingServer } = require('webthing');

async function test() {
  const thing = new Thing();
  const server = new WebThingServer(new SingleThing(thing), 8000);
  console.log('starting...');
  await server.start();
  console.log('started');
}

test().catch(console.error);

Unhandled promise in start() of WebThingServer

The error case of every promise needs to be handled, otherwise Node 10 might kill the process.

Code location of an unhandled promise:
https://github.com/mozilla-iot/webthing-node/blob/aed7d52ba8f80d7acf14216e1edd4484cefef265/lib/server.js#L754-L766

Add .catch(console.error); to the last line of the code location above to make it debuggable.

Steps to reproduce

const {SingleThing, Thing, WebThingServer} = require('webthing');

class TestThing extends Thing {}

const thing = new TestThing();
const server = new WebThingServer(new SingleThing(thing), 100000);
server.start();

Expected

The server fails to start. In this case it’s because the port is outside the valid TCP range. It could also fail because of the port being taken or other network configuration issues.

Actual

With Node 10.9.0 no error is shown and the application quits.

Types for Typescript

Typescript types would make this library easier to use from Typescript. I'd be happy to create a PR to add types to this repo if it's welcome. Otherwise, I can maintained them locally or submit them to DefinitelyTyped.

CODE_OF_CONDUCT.md file missing

As of January 1 2019, Mozilla requires that all GitHub projects include this CODE_OF_CONDUCT.md file in the project root. The file has two parts:

  1. Required Text - All text under the headings Community Participation Guidelines and How to Report, are required, and should not be altered.
  2. Optional Text - The Project Specific Etiquette heading provides a space to speak more specifically about ways people can work effectively and inclusively together. Some examples of those can be found on the Firefox Debugger project, and Common Voice. (The optional part is commented out in the raw template file, and will not be visible until you modify and uncomment that part.)

If you have any questions about this file, or Code of Conduct policies and procedures, please reach out to [email protected].

(Message COC001)

Fail to find "webthing" Node module

Hi all,
After I installed the webthing module via npm as instructued, I tried to run the command node single-thing.js. This is when I was confronted with the following error:

internal/modules/cjs/loader.js:583
    throw err;
    ^

Error: Cannot find module 'webthing'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:581:15)
    at Function.Module._load (internal/modules/cjs/loader.js:507:25)
    at Module.require (internal/modules/cjs/loader.js:637:17)
    at require (internal/modules/cjs/helpers.js:20:18)
    at Object.<anonymous> (/media/nuwan/7528bf5e-4c32-448c-8c6c-0c40f3d39dc0/nuwan/Desktop/Projects/personal/mozilla-web-things/webthing-node/example/multiple-things.js:9:5)
    at Module._compile (internal/modules/cjs/loader.js:689:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
    at Module.load (internal/modules/cjs/loader.js:599:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
    at Function.Module._load (internal/modules/cjs/loader.js:530:3)

Believing it was a problem with the module not being installed properly I did a search and confirmed that it had indeed installed globally.

nuwan@nuwan-Aspire-E5-573G:~$ npm search webthing
NAME                      | DESCRIPTION          | AUTHOR          | DATE       | VERSION  | KEYWORDS                      
webthing                  | HTTP Web Thing…      | =mozilla-iot    | 2018-10-12 | 0.8.3    | mozilla iot web thing webthing

After deleting the local node_modules folder within the webthing-node directory I did a npm install but still the issue persists.
Although when searched I could not find a webthing module inside the local node_modules directory.

Running Ubuntu 18.04 on Node v10.6.0 installed via nvm

Are more stringent schema validation methods supported?

I use https://github.com/xeipuuv/gojsonschema as the validation scheme package. It failed because the running case name capitalization was inconsistent with the test script. https://github.com/dravenk/webthing-go/runs/5960961634?check_suite_focus=true#step:6:143
Should the default Scheme validation method be more stringent or lax?

https://github.com/WebThingsIO/webthing-tester/blob/551388e7fa15b92f58ee644c480e9e049cbc403a/test-client.py#L241

Port stays in use after server.stop()

Steps to reproduce

Run the following script with any WebThing in ./webthing.js.

const {
  SingleThing,
  WebThingServer,
} = require('webthing');
const WebThing = require('./webthing.js');

async function test() {
  const PORT = 8000;
  const thing = new WebThing();
  const server = new WebThingServer(new SingleThing(thing), PORT);
  console.log('start 1');
  await server.start();
  server.stop();
  console.log('start 2');
  await server.start();
  server.stop();
}

test().catch(console.error);

Actual

The server fails to start after it got stopped, because the port is still in use. Output:

start 1
start 2
Error [ERR_SERVER_ALREADY_LISTEN]: Listen method has been called more than once without closing.
    at Server.listen (net.js:1372:11)
    at ipPromise.then (/home/jaller94/Git/webthings/webthing-add/node_modules/webthing/lib/server.js:765:19)
    at process._tickCallback (internal/process/next_tick.js:68:7)

Expected

The server starts and stops two times without a problem.

Cannot find module 'uuid/v4'

Hello,
while running $ node single-thing.js i get this error:

module.js:549
    throw err;
    ^

Error: Cannot find module 'uuid/v4'
    at Function.Module._resolveFilename (module.js:547:15)
    at Function.Module._load (module.js:474:25)
    at Module.require (module.js:596:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (/home/pi/webthing/node_modules/webthing/example/single-thing.js:10:16)
    at Module._compile (module.js:652:30)
    at Object.Module._extensions..js (module.js:663:10)
    at Module.load (module.js:565:32)
    at tryModuleLoad (module.js:505:12)
    at Function.Module._load (module.js:497:3)

OS:
Raspbian Version:June 2018
Release date:2018-06-27
Kernel version:4.14
npm version 1.4.21
node version 8.11.1

How to handle action response and error running actions?

I need some help. How to deal with actions that have any kind of response? And how to deal with action when it returns an error?

Seen the code, it seems that start method calls always finish, even if there is an error. And it not pass the response from performAction to finish method.

There is any way to handle with these problems? Thank you!

Nested properties

Is it possible to nest properties? I think that the Web Thing API does not mention it. For example, I want a property gas such as:

{
  "gas": {
    "eco2": 400
    "tvoc": 1000
  }
}

It would be neat to access nested properties using either /properties/gas/eco2 and /properties/gas/tvoc or using /properties/gas and get both values.

One other possible case would be reusing of Web Thing Types, e.g. a composite Thing with a built-in RGB LED:

"properties": {
  "led": {
    "type": "onOffColorLight",
    "properties": {
      "on": {"type": "boolean"},
      "color": {"type": "string"}
    }
  }
}

Exposing multiple Things on the same ThingServer

I want to expose multiple Things on the same port. Is it possible to create a ThingServer with multiple Things (similarly to the Things Gateway where things are accessed using /things/{thing_id} URI)?

Maybe writing an adapter for the Things Gateway is a better option in this case. For reference, I am experimenting with a Thingy:52 to create a simple Web Thingy.

Don't know which files to edit

Hi;

I have looked at the readme that shows various code snippets, but it does not state what files need to be updated with this code !

I have no idea where these code snippets should be added !

MaxListenersExceededWarning: Possible EventEmitter memory leak detected

Hi,

on Windows 10 and Node v13.9.0 I do get regularly the following warning and can not close the app by "ctrl+c". Not yet tested on Linux.

The warning occurs mostly when one Websocket client is connected to just one Thing. Without any Websocket connected I can close the app by "ctrl+c".

(node:13352) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 close listeners added to [Server]. Use emitter.setMaxListeners() to increase limit
    at _addListener (events.js:396:17)
    at Server.addListener (events.js:412:10)
    at Server.once (events.js:443:8)
    at Server.close (net.js:1603:12)
    at C:\apps\webiot\node_modules\webthing\lib\server.js:862:19
    at new Promise (<anonymous>)
    at WebThingServer.stop (C:\apps\webiot\node_modules\webthing\lib\server.js:861:19)
    at process.<anonymous> (C:\apps\webiot\index.js:262:16)
    at process.emit (events.js:321:20)

Setting manually the max listener as follows results in the same error:

const server = new WebThingServer(new MultipleThings(things, "mthings"), 8888);
server.server.setMaxListeners(20);
(node:10676) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 21 close listeners added to [Server]. Use emitter.setMaxListeners() to increase limit
    at _addListener (events.js:396:17)
    at Server.addListener (events.js:412:10)
    at Server.once (events.js:443:8)
    at Server.close (net.js:1603:12)
    at C:\apps\webiot\node_modules\webthing\lib\server.js:862:19
    at new Promise (<anonymous>)
    at WebThingServer.stop (C:\apps\webiot\node_modules\webthing\lib\server.js:861:19)
    at process.<anonymous> (C:\apps\webiot\index.js:262:16)
    at process.emit (events.js:321:20)

Any ideas how to close the app in Windows wihout any problems?

'OnOffSwitch', 'Light'

Why does every light in the examples also have the type 'OnOffSwitch' ?
I thought the light itself already has an OnOffProperty.

"links" si no more allowed as PropertyMetadata

Hello,

I created some Things for my Raspberry and every was working fine with version 0.13.0.
I just updated to 0.15.0 and I get the following:

/home/pi/webthing-home/node_modules/ajv/dist/compile/index.js:119
        throw e;
        ^

Error: strict mode: unknown keyword: "links"
    at Object.checkStrictMode (/home/pi/webthing-home/node_modules/ajv/dist/compile/validate/index.js:183:15)
    at Object.checkUnknownRules (/home/pi/webthing-home/node_modules/ajv/dist/compile/util.js:32:24)
    at checkKeywords (/home/pi/webthing-home/node_modules/ajv/dist/compile/validate/index.js:118:12)
    at Object.validateFunctionCode (/home/pi/webthing-home/node_modules/ajv/dist/compile/validate/index.js:14:9)
    at Ajv.compileSchema (/home/pi/webthing-home/node_modules/ajv/dist/compile/index.js:79:20)
    at Ajv._compileSchemaEnv (/home/pi/webthing-home/node_modules/ajv/dist/core.js:446:37)
    at Ajv.compile (/home/pi/webthing-home/node_modules/ajv/dist/core.js:141:38)
    at new Property (/home/pi/webthing-home/node_modules/webthing/lib/property.js:30:29)
    at makeVideoCameraHLS (/home/pi/webthing-home/src/lib/video-camera.js:78:5)
    at createServer (/home/pi/webthing-home/src/raspi-1-server.js:19:39)

The code that raises the error is the following:

  const imageValue = new Value(null)
  thing.addProperty(
    new Property(thing, 'image', imageValue, {
      '@type': 'ImageProperty',
      title: 'Snapshot',
      links: [{ rel: 'alternate', mediaType: 'image/jpeg', href: `/media/${imageFilename}` }],
      readOnly: true
    }))

I read the lib code and I notice that there is a ajv validation of metadata ( https://github.com/WebThingsIO/webthing-node/blob/master/lib/property.ts#L55 ) and some attributes are deleted and never read ( https://github.com/WebThingsIO/webthing-node/blob/master/lib/property.ts#L54 ), why?

I can't understand: PropertyMetadata interface let you write links field ( https://github.com/WebThingsIO/webthing-node/blob/master/lib/property.ts#L172 ).
Metadata must be a JSONSchema or a PropertyMetadata object? How can I set links property for my Raspberry camera?

( My complete code here https://github.com/cescobaz/webthing-home )

Many thanks

Questions about contributing

Hi,

I'd like to contribute to this project, as I use it in my own home system (with some self-made things, which I plan to release as free open source hardware + software as soon as I got a complete breakthrough).

I already provided a small pull request an hour ago. There are some things, which I'd like to discuss, before taking the effort.

What I noticed is for example, that the target files js/map/d.ts are transpiled/generated directly into the same location where the source files are. This makes navigation in code harder. Is this by intention? Would a PR be accepted, which puts the generated files into a bin folder (or whatever name you prefer?) instead?

Also I'd suggest to extract the SingleThing / MultipleThings classes into separate files to make server.ts easier to grasp. Handlers may be extracted e.g. into a folder lib/handlers if accepted.

I noticed that it is rather hard to integrate things with any kind of subscriber pattern. Those things would:

  • only notify about events when subscribed
  • as a special case of event: only notify about property changes when there is a subscriber - if they support this kind of notification at all -> read back from the thing itself in case of a get is often required.
    While the latter is an implementation thing of the webthings-node, for which I'd like to file a PR, which introduces a get callback function returning a promise on Value, the first one would need an extension on the WebThings specification: There is no addEventSubscription on the REST API (adding this would imply a session handling of course). The event description should contain an information on whether the event requires a subscription or if it just works. Also in general I am missing a removeEventSubscription in the WebSocket API. Where would be the best place for suggestions towards the WebThings specification?

My "workaround" to integrate those devices will be, that my webthings bridge subscribes on all events when adding a thing, which however may overcrowd the limited bandwidth of the local CAN bus in cases where there are many things with many events. Another workaround would be to add an additional property for each event to be able to turn it on/off.

I know that's much information. I am willing to split this ticket up and rename it and also provide PRs depending on your feedback.

Thank you, Michael

Unhandled promise in WebThingServer constructor

I am not yet sure how to make my local issues reproducible, but I want to highlight the issue of multiple uncaught Promises in this framework.

Most recently my server got silently killed by Node 10.9.0 when running npm start of my project webthing-add.

Link to the Promise:
https://github.com/mozilla-iot/webthing-node/blob/aed7d52ba8f80d7acf14216e1edd4484cefef265/lib/server.js#L624-L645

Logged error when adding .catch(console.error):

{ Error: spawn netstat ENOENT
    at Process.ChildProcess._handle.onexit (internal/child_process.js:231:19)
    at onErrorNT (internal/child_process.js:406:16)
    at process._tickCallback (internal/process/next_tick.js:63:19)
    at Function.Module.runMain (internal/modules/cjs/loader.js:745:11)
    at startup (internal/bootstrap/node.js:266:19)
    at bootstrapNodeJSCore (internal/bootstrap/node.js:596:3)
  errno: 'ENOENT',
  code: 'ENOENT',
  syscall: 'spawn netstat',
  path: 'netstat',
  spawnargs: [ '-r', '-n', '-A', 'inet' ],
  cmd: 'netstat -r -n -A inet' }

this.router.ws is not a function when trying to run any Example

Hello, when I try to run any of the example scripts I get the error as title, the result follows:

C:\Users\david\Downloads\iot3>node simplest-thing.js 8888
Usage:

C:\Program Files\nodejs\node.exe C:\Users\david\Downloads\iot3\simplest-thing.js [port]

Try:
curl -X PUT -H 'Content-Type: application/json' --data '{"on": true }' http://localhost:8888/properties/on

C:\Users\david\Downloads\iot3\node_modules\webthing\lib\server.js:747
      this.router.ws('/', (ws, req) => thingHandler.ws(ws, req));
                  ^

TypeError: this.router.ws is not a function
    at new WebThingServer (C:\Users\david\Downloads\iot3\node_modules\webthing\lib\server.js:747:19)
    at runServer (C:\Users\david\Downloads\iot3\simplest-thing.js:49:18)
    at Object.<anonymous> (C:\Users\david\Downloads\iot3\simplest-thing.js:56:1)
    at Module._compile (module.js:653:30)
    at Object.Module._extensions..js (module.js:664:10)
    at Module.load (module.js:566:32)
    at tryModuleLoad (module.js:506:12)
    at Function.Module._load (module.js:498:3)
    at Function.Module.runMain (module.js:694:10)
    at startup (bootstrap_node.js:204:16)

What's wrong?

How to create a push button

I try to create a push button but I can't figure out how it work:

function makeThing() {
    const thing = new Thing(
        'urn:dev:ops:my-switchbot-1234',
        'Switchbot',
        ['PushButton'],
        'Trigger Switchbot',
    );

    thing.addProperty(
        new Property(
            thing,
            'pushed',
            new Value(true, (update) => {
                console.log(`change: ${update}`);
                if (update === 'pushed') {
                    switchbot.press();
                }
            }),
            {
                '@type': 'PushedProperty',
                title: 'Switchbot',
                type: 'boolean',
                description: 'Press switchbot',
            },
        ),
    );
    return thing;
}

Right now, I get:
image

But clicking on the icon doesn't trigger any event... I just need a sinple push button, with a sinle press (no on/off).

How can fix this? Is there some example somewhere? Is there better documentation than https://iot.mozilla.org/schemas/ ?

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.