GithubHelp home page GithubHelp logo

Comments (4)

aholstenson avatar aholstenson commented on May 26, 2024

Thanks! The closest that exists right now is the miio.devices() method that discovers all devices on the local network and connects to them (if the token is available either via auto-token or manually set via miio command). It emits events for when a device is found or when it is no longer available on the network. You can safely keep the handle of a device received in the available event.

Does that come close to what you need?

from miio.

jghaanstra avatar jghaanstra commented on May 26, 2024

It might but I lack the programming skills to create a working example. I used the miio.devices() example code form the README (which contains a little error where it is declared as miio.devices but uses browser.on etc.) but cant get it to resolve my vacuum cleaner as it hides it's token. I dont know how to use the miio.devices() method while manually setting the token.

I did fiddle with the miio.createDevice() method and resolve my cleaner twice under it's own device name. This comes close in allowing me to create multiple devices manually upon initializing my own app based on the devices settings previously saved within my own app. Problem here is that I dont see a way to dynamically name the devices so I can refer to them later on. But the following example code with hardcoded names works, I did not even have to manually initialize the device for the find command to be fired twice. I'll just mess around some more and learn a thing or two.

const miio = require('./lib');

const device1 = miio.createDevice({
	address: '192.168.0.133',
	token: '69..removed..64',
	model: 'rockrobo.vacuum.v1'
});

device1.find();

const device2 = miio.createDevice({
	address: '192.168.0.133',
	token: '69..removed..64',
	model: 'rockrobo.vacuum.v1'
});

device2.find();

from miio.

aholstenson avatar aholstenson commented on May 26, 2024

miio.devices() pulls its token from the token storage, so if you have a device that does not have a token you should update the token via the miio command line app: Setting the token of a device

That will only work if you can actually run the miio app on the device though, which might not work in your case. I'm thinking it would be nice to have a way to give miio.devices() a set of tokens to fallback on.

Something like this:

miio.devices({
  tokens: {
    'device-id': 'token-as-hex'
  }
});

And yes, createDevice is what is used internally, but there are a few things you need to think about:

  • Call init() on the device for everything to work properly. Properties such as if your vacuum is running or not wont be available otherwise.
  • It's good practice to keep only one device handle around, create it and store it somewhere if you can.
  • When you do not need a device handle anymore call destroy() on it, otherwise the socket used for communication just lies around eating up more and more resource the more device handles you create.

from miio.

jghaanstra avatar jghaanstra commented on May 26, 2024

Ok, thanx for the information. Running the miio app on the domotica controller is indeed not possible.

Feeding tokens to the miio.devices() method and manually setting device handles for these tokens would enable me to create one device handle for every user added device upon initialization of my own app and keep things clean. But for now I'll go with creating a new device handle for every new command or status request and destroy() this handle afterwards. If you could add this some time in the future it would be great though.

Thanx again for this great library.

from miio.

Related Issues (20)

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.