miio
miio copied to clipboard
UnhandledPromiseRejectionWarning
Hi, i've installed miio and first got this output when doing so:
npm WARN saveError ENOENT: no such file or directory, open '/root/package.json'
npm WARN enoent ENOENT: no such file or directory, open '/root/package.json'
npm WARN root No description
npm WARN root No repository field.
npm WARN root No README data
npm WARN root No license field.
Then I ran test.js to check if basic connection works:
const miio = require('miio');
miio.device({ address: '192.168.99.154' })
.then(device => console.log('Connected to', device))
.catch(err => handleErrorHere);
it failed with this output
miIO:~# node test.js
(node:568) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): ReferenceError: handleErrorHere is not defined
(node:568) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
I am running alpine linux 3.7 and my iot devices are running in a different subnet than my miio vm, is that a problem?
miIO:~# node -v
v8.9.3
Hi,
handleErrorHere
is a function that you must implement.
If you don't want to implement extra logic, just do a console.log in the catch like this:
const miio = require('miio');
miio.device({ address: '192.168.99.154' })
.then(device => console.log('Connected to', device))
.catch(err => console.log(err));
Well, I feel a little dumb right now :)
But with that, I get a timeout.
miIO:~# node test.js
{ Error: Could not connect to device, handshake timeout
at Timeout.handshakeTimeout.setTimeout [as _onTimeout] (/root/node_modules/miio/lib/network.js:432:17)
at ontimeout (timers.js:475:11)
at tryOnTimeout (timers.js:310:5)
at Timer.listOnTimeout (timers.js:270:5) code: 'timeout', device: null }
ping works just fine
miIO:~# ping 192.168.99.154
PING 192.168.99.154 (192.168.99.154): 56 data bytes
64 bytes from 192.168.99.154: seq=0 ttl=252 time=20.202 ms
64 bytes from 192.168.99.154: seq=1 ttl=252 time=25.884 ms
64 bytes from 192.168.99.154: seq=2 ttl=252 time=22.384 ms
64 bytes from 192.168.99.154: seq=3 ttl=252 time=20.442 ms
Getting handshake timeout, too. My devices are also in aother subnet.