merdok / homebridge-miot

Homebridge plugin for devices supporting the Xiaomi miot protocol
MIT License
394 stars 63 forks source link

Hub connection #584

Closed Avamander closed 6 months ago

Avamander commented 7 months ago

Describe the bug I can't get Bluetooth device readings directly from the gateway itself. I've configured the device ID of the BT devices to match the original ones, I'm using the gateway's IP and token and I've specified the BT device's own model.

Expected behavior I'd really like for direct fetch of readings to work.

Debug log Similar errors happen with both lumi.sensor_smoke.mcn02 and cgllc.clock.dove. The token and IP seem to work for the gateway connection itself.

I've enabled detailed debug log for the cgllc.clock.dove and "user ack timeout" seems to be the bane of all BT devices.

[4/3/2024, 2:40:25 AM] [homebridge-miot] [Mi Alarm Clock] (Protocol) Start handshake x.y.z.q
[4/3/2024, 2:40:25 AM] [homebridge-miot] [Mi Alarm Clock] (Protocol)  x.y.z.q <- (0) {"method":"get_properties","params":[{"did":"blt.4.xxxxxxxxxxx","siid":2,"piid":1},{"did":"blt.4.xxxxxxxxxxx","siid":2,"piid":2}],"id":3622}
[4/3/2024, 2:40:25 AM] [homebridge-miot] [Mi Alarm Clock] (Protocol)  x.y.z.q<- !1�Z✂️s\f�
[4/3/2024, 2:40:25 AM] [homebridge-miot] [Mi Alarm Clock] (Protocol)  x.y.z.q -> Data: {"id":3522,"error":{"code":-9999,"message":"user ack timeout"},"exe_time":4000}
[4/3/2024, 2:40:25 AM] [homebridge-miot] [Mi Alarm Clock] (Protocol)  x.y.z.q -> Message: {"id":3522,"error":{"code":-9999,"message":"user ack timeout"},"exe_time":4000}

Additional context I've tried adding the hub (lumi.gateway.mgl03) to both DE and CN location alongside the Bluetooth devices, but all I end up with are still ACK errors if the hub is used. Forced connection through Mi Cloud does work, but that has been too unreliable (I'd really like to get rid of those pesky zero readings) so I'd really like to use a local direct connection.

merdok commented 7 months ago

The first question would be if you are able to connect to the hub using a local connection and read properties from it? You could try doing that with the propertyMonitor. That would confirm at least that the connection to the hub is working.

Avamander commented 7 months ago

Yes, the hub's own connection seems to work directly. It beeps when I change some of the toggles (that lack translations).

merdok commented 7 months ago

Then I guess maybe how you entered the devices in the config might be wrong? The error which you get usually comes up when the device does not respond, but that can have multiple reasons...

Avamander commented 6 months ago

@merdok

I've tried debugging it further.

The tokens seem to be correct? It never gets as far if either the IP, device ID or the token is different. The gateway is also visible and usable in the Mi Home app.

[4/27/2024, 9:28:43 PM] [homebridge-miot] [Mi Smoke Detector 2] (Protocol) Start handshake x.y.z.q
[4/27/2024, 9:28:43 PM] [homebridge-miot] [Mi Smoke Detector 2] (Protocol) Call x.y.z.q: miIO.info - {"timeout":5000,"retries":3} - {}
[4/27/2024, 9:28:43 PM] [homebridge-miot] [Mi Smoke Detector 2] (Protocol) Start handshake x.y.z.q
[4/27/2024, 9:28:43 PM] [homebridge-miot] [Mi Smoke Detector 2] (Protocol) x.y.z.q <- (2) {"method":"miIO.info","params":{"timeout":5000,"retries":3},"id":2013}
[4/27/2024, 9:28:43 PM] [homebridge-miot] [Mi Smoke Detector 2] (Protocol) x.y.z.q <- !1 ✂️r   
[4/27/2024, 9:28:43 PM] [homebridge-miot] [Mi Smoke Detector 2] (Protocol) x.y.z.q -> Data: {"id":2013,"result":{"life":13840,"uid":6188204199,"model":"lumi.gateway.mgl03","token":"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx","ipflag":1,"miio_ver":"0.0.9","uptime":13858,"mac":"xx:xx:xx:xx:xx:xx","fw_ver":"1.5.6_0001","hw_ver":"Linux","bootloader_ver":"c0271a6705c2c64d3d582abe7356fa46","miio_client_ver":"4.3.2","VmPeak":12608,"VmSize":12608,"VmRSS":1904,"MemFree":16848,"ap":{"ssid":"xxxxxxxxxx","bssid":"28:80:23:3B:AF:F0","rssi":"-38","freq":2412},"netif":{"localIp":"x.y.z.q","mask":"255.255.255.0","gw":"x.y.z.q"},"miio_times":[13839,17,8,12675]},"exe_time":1}
[4/27/2024, 9:28:43 PM] [homebridge-miot] [Mi Smoke Detector 2] (Protocol) x.y.z.q -> Message: {"id":2013,"result":{"life":13840,"uid":6188204199,"model":"lumi.gateway.mgl03","token":"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx","ipflag":1,"miio_ver":"0.0.9","uptime":13858,"mac":"xx:xx:xx:xx:xx:xx","fw_ver":"1.5.6_0001","hw_ver":"Linux","bootloader_ver":"c0271a6705c2c64d3d582abe7356fa46","miio_client_ver":"4.3.2","VmPeak":12608,"VmSize":12608,"VmRSS":1904,"MemFree":16848,"ap":{"ssid":"xxxxxxxxxx","bssid":"28:80:23:3B:AF:F0","rssi":"-38","freq":2412},"netif":{"localIp":"x.y.z.q","mask":"255.255.255.0","gw":"x.y.z.q"},"miio_times":[13839,17,8,12675]},"exe_time":1}
[4/27/2024, 9:28:43 PM] [homebridge-miot] [Mi Smoke Detector 2] Device found! Setting up miot device from local connection!
[4/27/2024, 9:28:43 PM] [homebridge-miot] [Mi Smoke Detector 2] Device firmware: 1.5.6_0001
[4/27/2024, 9:28:43 PM] [homebridge-miot] [Mi Smoke Detector 2] Full device info: 
{
  "life": 13840,
  "uid": 6188204199,
  "model": "lumi.gateway.mgl03",
  "token": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
  "ipflag": 1,
  "miio_ver": "0.0.9",
  "uptime": 13858,
  "mac": "xx:xx:xx:xx:xx:xx",
  "fw_ver": "1.5.6_0001",
  "hw_ver": "Linux",
  "bootloader_ver": "c0271a6705c2c64d3d582abe7356fa46",
  "miio_client_ver": "4.3.2",
  "VmPeak": 12608,
  "VmSize": 12608,
  "VmRSS": 1904,
  "MemFree": 16848,
  "ap": {
    "ssid": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
    "bssid": "xx:xx:xx:xx:xx:xx",
    "rssi": "-38",
    "freq": 2412
  },
  "netif": {
    "localIp": "x.y.z.q",
    "mask": "255.255.255.0",
    "gw": "x.y.z.q"
  },
  "miio_times": [
    13839,
    17,
    8,
    12675
  ]
}
[4/27/2024, 9:28:43 PM] [homebridge-miot] [Mi Smoke Detector 2] Found device model lumi.gateway.mgl03 does not match specified model lumi.sensor_smoke.mcn02! Some services might not work correctly!
[4/27/2024, 9:28:43 PM] [homebridge-miot] [Mi Smoke Detector 2] Connected to device: lumi.gateway.mgl03
[4/27/2024, 9:28:43 PM] [homebridge-miot] [Mi Smoke Detector 2] Doing initial property fetch.
[4/27/2024, 9:28:43 PM] [homebridge-miot] [Mi Smoke Detector 2] Preparing property poll!
[4/27/2024, 9:28:43 PM] [homebridge-miot] [Mi Smoke Detector 2] Splitting properties into chunks. Number of chunks: 1. Chunk size: 14
[4/27/2024, 9:28:43 PM] [homebridge-miot] [Mi Smoke Detector 2] Chunks:  [
 [
  "smoke-sensor:status",
  "battery:battery-level"
 ]
]
[4/27/2024, 9:28:43 PM] [homebridge-miot] [Mi Smoke Detector 2] (Protocol) Call x.y.z.q: get_properties - [{"did":"blt.3.xxyyzzqqxxyyy","siid":2,"piid":1},{"did":"blt.3.xxyyzzqqxxyyy","siid":3,"piid":1}] - {}
[4/27/2024, 9:28:43 PM] [homebridge-miot] [Mi Smoke Detector 2] (Protocol) Start handshake x.y.z.q
[4/27/2024, 9:28:43 PM] [homebridge-miot] [Mi Smoke Detector 2] (Protocol) x.y.z.q <- (2) {"method":"get_properties","params":[{"did":"blt.3.xxyyzzqqxxyyy","siid":2,"piid":1},{"did":"blt.3.xxyyzzqqxxyyy","siid":3,"piid":1}],"id":2014}
[4/27/2024, 9:28:43 PM] [homebridge-miot] [Mi Smoke Detector 2] (Protocol) x.y.z.q <- !1 ✂️ j
[4/27/2024, 9:28:43 PM] [homebridge-miot] [Mi Smoke Detector 2] Successfully saved device info!
[4/27/2024, 9:28:47 PM] [homebridge-miot] [Mi Smoke Detector 2] (Protocol) Start handshake x.y.z.q
[4/27/2024, 9:28:47 PM] [homebridge-miot] [Mi Smoke Detector 2] (Protocol) x.y.z.q <- (1) {"method":"get_properties","params":[{"did":"blt.3.xxyyzzqqxxyyy","siid":2,"piid":1},{"did":"blt.3.xxyyzzqqxxyyy","siid":3,"piid":1}],"id":2114}
[4/27/2024, 9:28:47 PM] [homebridge-miot] [Mi Smoke Detector 2] (Protocol) x.y.z.q <- !1✂️  $
[4/27/2024, 9:28:51 PM] [homebridge-miot] [Mi Smoke Detector 2] (Protocol) Start handshake x.y.z.q
[4/27/2024, 9:28:51 PM] [homebridge-miot] [Mi Smoke Detector 2] (Protocol) x.y.z.q <- (0) {"method":"get_properties","params":[{"did":"blt.3.xxyyzzqqxxyyy","siid":2,"piid":1},{"did":"blt.3.xxyyzzqqxxyyy","siid":3,"piid":1}],"id":2214}
[4/27/2024, 9:28:51 PM] [homebridge-miot] [Mi Smoke Detector 2] (Protocol) x.y.z.q <- !1✂️ 
[4/27/2024, 9:28:55 PM] [homebridge-miot] [Mi Smoke Detector 2] (Protocol) x.y.z.q <- Reached maximum number of retries, giving up get_properties - [{"did":"blt.3.xxyyzzqqxxyyy","siid":2,"piid":1},{"did":"blt.3.xxyyzzqqxxyyy","siid":3,"piid":1}]
[4/27/2024, 9:28:55 PM] [homebridge-miot] [Mi Smoke Detector 2] (Protocol) x.y.z.q <- Error during send! (timeout) Call to device timed out | Request: {"method":"get_properties","params":[{"did":"blt.3.xxyyzzqqxxyyy","siid":2,"piid":1},{"did":"blt.3.xxyyzzqqxxyyy","siid":3,"piid":1}],"id":2214}
[4/27/2024, 9:28:55 PM] [homebridge-miot] [Mi Smoke Detector 2] Error on initial property request! Error: Call to device timed out
[4/27/2024, 9:28:55 PM] [homebridge-miot] [Mi Smoke Detector 2] Starting property polling.
[4/27/2024, 9:29:55 PM] [homebridge-miot] [Mi Smoke Detector 2] Preparing property poll!
[4/27/2024, 9:29:55 PM] [homebridge-miot] [Mi Smoke Detector 2] Splitting properties into chunks. Number of chunks: 1. Chunk size: 14
[4/27/2024, 9:29:55 PM] [homebridge-miot] [Mi Smoke Detector 2] Chunks:  [
 [
  "smoke-sensor:status",
  "battery:battery-level"
 ]
]
[4/27/2024, 9:29:55 PM] [homebridge-miot] [Mi Smoke Detector 2] (Protocol) Call x.y.z.q: get_properties - [{"did":"blt.3.xxyyzzqqxxyyy","siid":2,"piid":1},{"did":"blt.3.xxyyzzqqxxyyy","siid":3,"piid":1}] - {}
[4/27/2024, 9:29:55 PM] [homebridge-miot] [Mi Smoke Detector 2] (Protocol) Start handshake x.y.z.q
[4/27/2024, 9:29:55 PM] [homebridge-miot] [Mi Smoke Detector 2] (Protocol) x.y.z.q <- (2) {"method":"get_properties","params":[{"did":"blt.3.xxyyzzqqxxyyy","siid":2,"piid":1},{"did":"blt.3.xxyyzzqqxxyyy","siid":3,"piid":1}],"id":2215}
[4/27/2024, 9:29:55 PM] [homebridge-miot] [Mi Smoke Detector 2] (Protocol) x.y.z.q <- !1✂️ !
[4/27/2024, 9:29:59 PM] [homebridge-miot] [Mi Smoke Detector 2] (Protocol) Start handshake x.y.z.q
[4/27/2024, 9:29:59 PM] [homebridge-miot] [Mi Smoke Detector 2] (Protocol) x.y.z.q <- (1) {"method":"get_properties","params":[{"did":"blt.3.xxyyzzqqxxyyy","siid":2,"piid":1},{"did":"blt.3.xxyyzzqqxxyyy","siid":3,"piid":1}],"id":2315}
[4/27/2024, 9:29:59 PM] [homebridge-miot] [Mi Smoke Detector 2] (Protocol) x.y.z.q <- !1✂️  ~ 
[4/27/2024, 9:30:03 PM] [homebridge-miot] [Mi Smoke Detector 2] (Protocol) Start handshake x.y.z.q
[4/27/2024, 9:30:03 PM] [homebridge-miot] [Mi Smoke Detector 2] (Protocol) x.y.z.q <- (0) {"method":"get_properties","params":[{"did":"blt.3.xxyyzzqqxxyyy","siid":2,"piid":1},{"did":"blt.3.xxyyzzqqxxyyy","siid":3,"piid":1}],"id":2415}
[4/27/2024, 9:30:03 PM] [homebridge-miot] [Mi Smoke Detector 2] (Protocol) x.y.z.q <- !1 ✂️  +
[4/27/2024, 9:30:07 PM] [homebridge-miot] [Mi Smoke Detector 2] (Protocol) x.y.z.q <- Reached maximum number of retries, giving up get_properties - [{"did":"blt.3.xxyyzzqqxxyyy","siid":2,"piid":1},{"did":"blt.3.xxyyzzqqxxyyy","siid":3,"piid":1}]
[4/27/2024, 9:30:07 PM] [homebridge-miot] [Mi Smoke Detector 2] (Protocol) x.y.z.q <- Error during send! (timeout) Call to device timed out | Request: {"method":"get_properties","params":[{"did":"blt.3.xxyyzzqqxxyyy","siid":2,"piid":1},{"did":"blt.3.xxyyzzqqxxyyy","siid":3,"piid":1}],"id":2415}
[4/27/2024, 9:30:07 PM] [homebridge-miot] [Mi Smoke Detector 2] Poll failed 1 times!
[4/27/2024, 9:30:07 PM] [homebridge-miot] [Mi Smoke Detector 2] Poll failed! Error: Call to device timed out

This behaviour seems to be consistent with BLE devices that are constantly connected and smoke detectors that only seem to periodically push updates to the gateway. The device also seems to work if I force cloud connection.

I read https://github.com/merdok/homebridge-miot/issues/202 but I think I've tried it all.

merdok commented 6 months ago

Yeah i guess that you would need to use the cloud as some devices require it, so i think that we have the case here.