drndos / mikettle

Xiaomi Mi Kettle Bluetooth Library
MIT License
54 stars 23 forks source link

How does one figure out a product ID? #4

Closed mgedmin closed 4 years ago

mgedmin commented 4 years ago

Hi!

I've a Viomi Smart Kettle SK-152A that integrates with the Xiaomi Mi Home app. It shows up on htmgmt find as "MiKettle" (MAC B8:7C:6F:xx:xx:xx). Attempts to talk to it using the known Xiaomi MiKettle product IDs (275 or 131) fail with Exception: Authentication failed when I run python demo.py connect $MAC $PID.

Now I'm not 100% sure it uses the same protocol (although the "MiKettle" name is very telling), but if it is, how would I go about figuring out the right product ID to use? Random guessing doesn't seem very productive.

Hypfer commented 4 years ago

You iterate over a lot of them until it starts working.

Try 1116

mgedmin commented 4 years ago

1116 makes it beep before I get a

bluepy.btle.BTLEDisconnectError: Failed to connect to peripheral B8:7C:6F:xx:xx:xx, addr type: public

error, which is very interesting. (It doesn't always beep, sometimes I just get the disconnect error.)

Hypfer commented 4 years ago

Beeping means that the handshake was successful so the remaining connectivity issues are most likely not caused by a wrong productId

mgedmin commented 4 years ago

I only just now noticed that not only does it beep, it also manages to report the firmware version:

FW: 7.5.10

before disconnecting.

mgedmin commented 4 years ago

Ooh, if I comment out the firmware_version() call, then the name() call succeeds

Name: yunmi.kettle.v7

And if I comment out both, then kettle.parameter_value(MI_CURRENT_TEMPERATURE) succeeds:

DEBUG:mikettle.mikettle:Init Mikettle with mac B8:7C:6F:xx:xx:xx and pid 1116
Authenticating
Getting data from mi Kettle
DEBUG:mikettle.mikettle:Filling cache with new sensor data.
DEBUG:mikettle.mikettle:Connect
DEBUG:mikettle.mikettle:Auth
DEBUG:mikettle.mikettle:Subscribe
DEBUG:mikettle.mikettle:Wait for data
DEBUG:mikettle.mikettle:Status update:
DEBUG:mikettle.mikettle:Parse data: b'\x00\xff\x00\x00PN\x00\x00\x00\x01\x18\x00'
DEBUG:mikettle.mikettle:data parsed {'action': 'idle', 'mode': 'none', 'set temperature': 80, 'current temperature': 78, 'keep warm type': 'warm up', 'keep warm time': 0}
Current temperature: 78
Hypfer commented 4 years ago

v7 🤔

Any idea if there is more functionality in the app now?

There seems to be a preset function which you can use by just interacting with the kettle and pushing the "WARM" button a few times. I wonder if we could program those and/or see them in the current state

mgedmin commented 4 years ago

TBH I'm not sure what the app allows since it wants me to create an account or something silly like that. A coworker did that (this is an office kettle) but they already left so I can't ask.

The instruction manual mentions four preset modes (50/70/80/90 deg C) that you can choose by repeatedly pressing the Warm button.

A github search on yunmi.kettle.v7 leads me to https://github.com/liguobingh/com.viomi.kettlepro/blob/d69a5de3978c6902f20c6404d6d62b3696c86706/src/main/java/com/viomi/kettlepro/UMGlobalParam.java, but there don't seem to be any checks that distinguish MODEL_KETTLE_V7 from other versions in that codebase.

mgedmin commented 4 years ago

I've fixed the issues with disconnections: it seems that every helper method was re-connecting and re-authenticating, and my kettle doesn't appear to like that. I've created #5 for this.

I'm going to close this issue because my question was answered in https://github.com/drndos/mikettle/issues/4#issuecomment-572125171.