Comments (4)
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.
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.
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.
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)
- Not enough non-option arguments: got 0, need at least 1 error Command failed with exit code 1.
- Xiaomi Air Monitor cgllc.airm.cgdn1
- yeelight strip plus is supported?
- Canβt find Hub / Temperature-Sensors
- yeelink.light.color5 HOT 1
- Mi Smart LED Bulb (B22) - Support
- yeelink.light.mono6 HOT 1
- [add device request] yeelink.light.ceilb
- [add device request] yeelink.light.colorb
- -Bash: miio: command not found HOT 1
- doesn't work on Firmware version: 3.2.10
- Cannot connect to light after configuring wireless network HOT 1
- yeelink.light.bslamp2 HOT 2
- Create device with lib version >= 0.15.0
- Which devices can get tokens by "miio discover" or "mirobo discover --handshake 1"?
- Does this packge still getting maintained?
- Roborock S6 - 3.5.8._2902 - unsupported device
- colorTemperature2rgbUsingTH is not defined
- Device support [Vacum mop 2 ultra]
- Error connecting to device: Error: Call to device timed out
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from miio.