miio icon indicating copy to clipboard operation
miio copied to clipboard

UnhandledPromiseRejectionWarning

Open lug-gh opened this issue 5 years ago • 3 comments

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

lug-gh avatar Jan 19 '19 12:01 lug-gh

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));

floviolleau avatar Jan 28 '19 15:01 floviolleau

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

lug-gh avatar Feb 03 '19 14:02 lug-gh

Getting handshake timeout, too. My devices are also in aother subnet.

EnixCoda avatar Jul 05 '21 13:07 EnixCoda