dnandha / miauth

Authenticate and interact with Xiaomi devices over BLE
GNU Affero General Public License v3.0
28 stars 10 forks source link

Trying to connnect to XM365 give "recovering key"? error #13

Closed n3rd4i closed 1 year ago

n3rd4i commented 1 year ago

The output of the command miauth -m -d -s -v -r AA:BB:CC:DD:EE:FF

user@home:~/bluez$ miauth -m -d -s -v -r AA:BB:CC:DD:EE:FF
Namespace(command=None, debug=True, m365=True, mac='AA:BB:CC:DD:EE:FF', nb=False, register=True, serial=True, token_file='./mi_token', version=True)
Connecting
enabling notifications for: 6e400003-b5a3-f393-e0a9-e50e24dcca9e
enabling notifications for: None
found old 55ab encryption -> recovering key
Traceback (most recent call last):
  File "/home/user/.local/bin/miauth", line 8, in <module>
    sys.exit(main())
  File "/home/user/.local/lib/python3.8/site-packages/miauth/cli.py", line 151, in main
    m365_main(ble)
  File "/home/user/.local/lib/python3.8/site-packages/miauth/cli.py", line 79, in m365_main
    mc.recover_key()
  File "/home/user/.local/lib/python3.8/site-packages/miauth/mi/m365client.py", line 73, in recover_key
    self.key = self.ch_key[0].read()
TypeError: 'NoneType' object is not subscriptable
n3rd4i commented 1 year ago

I suspect this might have to do with some missing python dependency ?

user@home:~/bluez$ pip freeze | grep miauth
miauth==0.9.6
n3rd4i commented 1 year ago

I forgot to mention that I had to upgrade my dashboard from M365 to M365 PRO variant. This is a clone dashboard (for a XM365 PRO). It implements Nordic's NUS.

dnandha commented 1 year ago

@n3rd4i Sorry for the late reply. The pip package did not contain the latest repo code. I have pushed a new pip version, please upgrade your miauth package with pip install -U miauth to version 0.9.7 and check if the issue still exists. Thanks!

n3rd4i commented 1 year ago

Ok, with version 0.9.7 I've tried (kind of works now), command:

When success I get:

Namespace(command=None, fwver=True, m365=True, mac='AA:BB:CC:DD:EE:FF', nb=False, register=False, register_did=None, serial=True, token_file='./mi_token', verbose=False)
Connecting
enabling notifications for: 6e400003-b5a3-f393-e0a9-e50e24dcca9e
enabling notifications for: None
found old 55ab encryption -> recovering key
Retrieving serial number
Serial no.: 12345/12345678
Retrieving firmware version
Firmware version: 85.5
Disconnecting

Sometimes I get:

Namespace(command=None, fwver=True, m365=True, mac='AA:BB:CC:DD:EE:FF', nb=False, register=False, register_did=None, serial=True, token_file='./mi_token', verbose=False)
Connecting
enabling notifications for: 6e400003-b5a3-f393-e0a9-e50e24dcca9e
enabling notifications for: None
found old 55ab encryption -> recovering key
Retrieving serial number
Traceback (most recent call last):
  File "/home/user/.local/bin/miauth", line 8, in <module>
    sys.exit(main())
  File "/home/user/.local/lib/python3.8/site-packages/miauth/cli.py", line 152, in main
    m365_main(ble)
  File "/home/user/.local/lib/python3.8/site-packages/miauth/cli.py", line 89, in m365_main
    resp = mc.comm("55aa032001100e")
  File "/home/user/.local/lib/python3.8/site-packages/miauth/mi/m365client.py", line 104, in comm
    raise Exception("Checksum mismatch in response")
Exception: Checksum mismatch in response
n3rd4i commented 1 year ago

I don't know if this the above is a problem or not, but the whole idea is to get battery SOC so I can shutoff charging if is 80%.

I'm thinking I need, -c but I've no clue what COMMAND actually is, where can I find docs about it?

  -c COMMAND, --command COMMAND
                        send command (w/o checksum) to uart and print reply