tlyakhov / fellow-stagg-ekg-plus

WiFi & Google Assistant Bridge for Fellow Stagg EKG+ electric kettle
36 stars 1 forks source link

Homebridge Collaboration? #1

Open nehayward opened 4 years ago

nehayward commented 4 years ago

Nice work @tlyakhov! I've been trying to reverse engineer the Stagg EKG the last couple days, I'm working on bringing support to home bridge. Maybe we could collaborate?

tlyakhov commented 4 years ago

Sure, I can help! This codebase has 90% of the kettle protocol figured out. Only things missing are the C/F selector state and Hold+ selector state. What are you having trouble with?

nehayward commented 4 years ago

The code base alone should be a lot of help. I'm just getting into reverse engineer the bluetooth packets. Maybe I can help with the C/F selector I'm using Wireshark and bluetooth packet logger. Is this how you figured out the protocol?

tlyakhov commented 4 years ago

I'm almost sure the missing selector states are the "unknown" data types in this method: https://github.com/tlyakhov/fellow-stagg-ekg-plus/blob/master/src/StaggKettle.cc#L167, I just haven't bothered to experiment yet heh

I used iOS bluetooth sysdiagnose + Wireshark to get the original packet snooping.

nehayward commented 4 years ago

Okay is that the bluetooth packet logger? I'm using that and I'm still trying to figure out how read the logs. I can get the logs for switching the C/F, I just would need help reading them.

Send Off Wireshark Logs
tlyakhov commented 4 years ago

Reading the logs like that is extremely confusing - since the actual data frames will be split amongst multiple packets. That said your screenshot has the following kettle command in it: 0xef 0xdd 0x0a 0x0a 0x00 0x01 0x0b 00 Which means: 0xef 0xdd = frame separator, magic number 0x0a = command 0x0a = sequence number, increases every time your app sends a command 0x00 = power command type 0x01 = on (would be 0x00 if it the command was for off) 0x0b = sequence + previous data byte, so 0x0a + 0x01 = 0x0b 0x00 = same value as command type, so 0x00 as above.

tlyakhov commented 4 years ago

See this method in the code: https://github.com/tlyakhov/fellow-stagg-ekg-plus/blob/master/src/StaggKettle.cc#L267

nehayward commented 4 years ago

Okay sweet that's what I was looking at. So is the sequence somewhat arbitrary. You just have to increment it each time. This helps a lot! Thanks Tim.

tlyakhov commented 4 years ago

Also don't forget, once you have a BLE connection to the kettle from your dev environment, send the magic "init" command for the kettle to listen to you This line in the code sends the init as soon as my code connects, and here are the magic numbers.

nehayward commented 4 years ago

Thanks Tim. This gives me a great starting point. I'll keep you updated on my progress and hopefully I can help finish the code coverage on the kettle protocol.

nehayward commented 4 years ago

Hey figured I'd keep you updated.

Currently working on writing a homebridge plugin. I tried using noble in node for BLE communication but it doesn't currently work on my raspberry pi or macOS Catalina. However I think I can use the gatttool for communication. So I'm exploring that now.

tlyakhov commented 4 years ago

Have any code up on github? I'd be curious to take a peek.

nehayward commented 4 years ago

As soon as I have something working I'll share it.

nehayward commented 4 years ago

Still a work in progress but I was able to setup small script to control the kettle.

https://gist.github.com/nehayward/28e5f4e3d22b2104b1f0203ee225fb2a

tlyakhov commented 4 years ago

p.s. see my recent commits for improvements and more comments/documentation.

nehayward commented 4 years ago

Yeah nice work on updating the docs! Looks good!

nehayward commented 4 years ago

Thanks again for all the help. I think we can close this issue now. I have a working plugin for homebridge now 😄 https://github.com/nehayward/homebridge-stagg-ekg-kettle