merdok / homebridge-miot

Homebridge plugin for devices supporting the Xiaomi miot protocol
MIT License
390 stars 61 forks source link

Unhandled Exception Request Timeout When Getting Device ID? #159

Closed mrking closed 2 years ago

mrking commented 2 years ago

Adding more devices >20 is resulting an unhandled exception when grabbing device id. I've provided device ID in config however, it still appears to be looking the ID regardless. This causes homebridge to restart.

**[15/12/2021, 23:56:42] Error: Device has no identifier yet, handshake needed
    at DeviceInfo.enrich (/usr/local/lib/node_modules/homebridge-miot/node_modules/miio/lib/network.js:273:10)
    at Socket.<anonymous> (/usr/local/lib/node_modules/homebridge-miot/node_modules/miio/lib/network.js:165:13)
    at Socket.emit (node:events:390:28)
    at UDP.onMessage (node:dgram:931:8)**

Removing the number devices fixes the problem for the ones that end up not being able to connect, but adding others back causes those to fail to connect.

Full Log:


[15/12/2021, 23:56:42] Homebridge v1.3.8 (HAP v0.9.7) (Homebridge 1ADC) is running on port 51836.
[15/12/2021, 23:56:42] [miot] [Kitchen Floor Lights] Error: Could not connect to device, handshake timeout
[15/12/2021, 23:56:42] [miot] [Kitchen Floor Lights] Could not connect to the device! Retrying in 30 seconds!
[15/12/2021, 23:56:42] [miot] [Spare Bedroom Bed Lights] Error: Could not connect to device, handshake timeout
[15/12/2021, 23:56:42] [miot] [Spare Bedroom Bed Lights] Could not connect to the device! Retrying in 30 seconds!
[15/12/2021, 23:56:42] [miot] [Public Bathroom Bathroom Light] Error: Could not connect to device, handshake timeout
[15/12/2021, 23:56:42] [miot] [Public Bathroom Bathroom Light] Could not connect to the device! Retrying in 30 seconds!
[15/12/2021, 23:56:42] [miot] [Master Bedroom Air Filter] Error: Could not connect to device, handshake timeout
[15/12/2021, 23:56:42] [miot] [Master Bedroom Air Filter] Could not connect to the device! Retrying in 30 seconds!
[15/12/2021, 23:56:42] Error: Device has no identifier yet, handshake needed
    at DeviceInfo.enrich (/usr/local/lib/node_modules/homebridge-miot/node_modules/miio/lib/network.js:273:10)
    at Socket.<anonymous> (/usr/local/lib/node_modules/homebridge-miot/node_modules/miio/lib/network.js:165:13)
    at Socket.emit (node:events:390:28)
    at UDP.onMessage (node:dgram:931:8)
[15/12/2021, 23:56:42] Error: Device has no identifier yet, handshake needed
    at DeviceInfo.enrich (/usr/local/lib/node_modules/homebridge-miot/node_modules/miio/lib/network.js:273:10)
    at Socket.<anonymous> (/usr/local/lib/node_modules/homebridge-miot/node_modules/miio/lib/network.js:165:13)
    at Socket.emit (node:events:390:28)
    at UDP.onMessage (node:dgram:931:8)
[15/12/2021, 23:56:42] Error: Device has no identifier yet, handshake needed
    at DeviceInfo.enrich (/usr/local/lib/node_modules/homebridge-miot/node_modules/miio/lib/network.js:273:10)
    at Socket.<anonymous> (/usr/local/lib/node_modules/homebridge-miot/node_modules/miio/lib/network.js:165:13)
    at Socket.emit (node:events:390:28)
    at UDP.onMessage (node:dgram:931:8)
[15/12/2021, 23:56:42] Error: Device has no identifier yet, handshake needed
    at DeviceInfo.enrich (/usr/local/lib/node_modules/homebridge-miot/node_modules/miio/lib/network.js:273:10)
    at Socket.<anonymous> (/usr/local/lib/node_modules/homebridge-miot/node_modules/miio/lib/network.js:165:13)
    at Socket.emit (node:events:390:28)
    at UDP.onMessage (node:dgram:931:8)
[15/12/2021, 23:56:42] Error: Device has no identifier yet, handshake needed
    at DeviceInfo.enrich (/usr/local/lib/node_modules/homebridge-miot/node_modules/miio/lib/network.js:273:10)
    at Socket.<anonymous> (/usr/local/lib/node_modules/homebridge-miot/node_modules/miio/lib/network.js:165:13)
    at Socket.emit (node:events:390:28)
    at UDP.onMessage (node:dgram:931:8)
[15/12/2021, 23:56:42] Error: Device has no identifier yet, handshake needed
    at DeviceInfo.enrich (/usr/local/lib/node_modules/homebridge-miot/node_modules/miio/lib/network.js:273:10)
    at Socket.<anonymous> (/usr/local/lib/node_modules/homebridge-miot/node_modules/miio/lib/network.js:165:13)
    at Socket.emit (node:events:390:28)
    at UDP.onMessage (node:dgram:931:8)
[15/12/2021, 23:56:42] [miot] [Backyard Lights] Error: Could not connect to device, handshake timeout
[15/12/2021, 23:56:42] [miot] [Backyard Lights] Could not connect to the device! Retrying in 30 seconds!
[15/12/2021, 23:56:43] [miot] [Living Room Seat Light] Connected to device: yeelink.light.color1
[15/12/2021, 23:56:43] [miot] [Living Room Seat Light] Setting up device!
[15/12/2021, 23:56:43] [miot] [Living Room Seat Light] Fetching device info.
[15/12/2021, 23:56:43] [miot] [Living Room Seat Light] Doing device specific setup
[15/12/2021, 23:56:43] [miot] [Living Room Seat Light] Device requires MiCloud! Trying to connect!
[15/12/2021, 23:56:43] Got SIGTERM, shutting down Homebridge...
[15/12/2021, 23:56:43] [miot] [Spare Bedroom Candle Light] Error: Could not connect to device, handshake timeout
[15/12/2021, 23:56:43] [miot] [Spare Bedroom Candle Light] Could not connect to the device! Retrying in 30 seconds!
[15/12/2021, 23:56:43] [miot] [Master Bedroom Candle Light] Error: Could not connect to device, handshake timeout
[15/12/2021, 23:56:43] [miot] [Master Bedroom Candle Light] Could not connect to the device! Retrying in 30 seconds!
[15/12/2021, 23:56:43] [miot] [Living Room Seat Light] Got device info! Device firmware: 1.4.2_0076
[15/12/2021, 23:56:43] [miot] [Living Room Seat Light] Full device info: 
mrking commented 2 years ago

I can see this has been raised before #56.

mrking commented 2 years ago

Unfortunate the underlying library hasn't seen any updated since 2018.

mrking commented 2 years ago

Interestingly the error is still present with all the devices flagged with forceMiCloud? I haven't stepped through all the code yet to see where the entry point to connecting to the cloud is but thought miio library was strictly local? @merdok

I'll look further at this when I get some time.

merdok commented 2 years ago

Hi, Thanks for the info. Yeah it seems that the issue comes from the miio library and you are right, it was not updated for a long time. I am currently working on a bigger update where I remove the dependency to the miio and will write my own code for that, so maybe that will fix it.

The issue will also appear for mi cloud devices since I first check locally if the device is even responding, if it does not respond locally then there is no need to spam the mi cloud with requests.

mrking commented 2 years ago

Hi @merdok, Thanks for the reply.

I've worked around the issue on my forked and branch removing the connection check. https://github.com/mrking/homebridge-miot/tree/fix-connection-error-from-miio-library

Given you are already working on a major rewrite, I'll wait for the fix. Feel free to comment back and I'll happily retest the issue.

merdok commented 2 years ago

Yes, as soon as the update is ready I will comment here and you can retest it. It will probably just take quite some time till the update will be ready so please be patient🙂

merdok commented 2 years ago

Update 1.0.0 is now out which ditches the miio library, you can try it now.

mrking commented 2 years ago

I'll have a test of it this weekend if I get time. Thanks!