forty2 / hap-client

Control HomeKit-enabled devices with Node
MIT License
27 stars 13 forks source link

Add support for HAP over BLE #1

Open forty2 opened 7 years ago

forty2 commented 7 years ago

It should be possible to pair with and talk to HomeKit devices that only support BLE.

david-spaeth commented 6 years ago

Hey, I am interested in the ability to communicate with HomeKit BLE devices to integrate my Elgato device in a Domoticz server.

When do you think you'll put this in place ?

forty2 commented 6 years ago

Unfortunately this has turned out to be quite difficult, so I'm not sure when (or at this point even if) I'll be able to get this working.

It turns out there are actually two versions of the HAP-over-BLE protocol. The older version works almost exactly like HAP-over-HTTP, but of course with a different communication layer, and should in theory be easy to add support for. Having said that, I don't know of any devices still using the old version -- certainly the Elgato device and the August smart lock I have use the newer protocol.

The newer protocol changes things up quite a bit. I believe (though I can't confirm) that it's a fundamentally similar process, but I think there's some extra authentication or maybe some kind of out-of-band communication going on. I've tried using a Bluetooth sniffer to observe the pairing process with an iPod touch, and although little bits and pieces of the traffic look familiar, the actual pairing steps seem to be missing from the captures.

Long story short, I haven't been able to find any documentation or examples using the new protocol, and I've tried unsuccessfully to work it out myself by capturing traffic from "official" devices. I haven't given up yet -- this is still a feature I'd really like to support -- but I'm running out of ideas on how to get there from here.

david-spaeth commented 6 years ago

Thank you for your reply. I can imagine how difficult it is to solve. Apple recently released the Accessory Specification protocol (https://developer.apple.com/support/homekit-accessory-protocol/). It might contain a hint to solve this issue ?

forty2 commented 6 years ago

I would dearly love to get a look at that spec, but unfortunately the license agreement that goes with it explicitly disallows using it to create software (as opposed to hardware accessories), and even further disallows distributing anything created using it to any third party (meaning even if I could use it to add BLE functionality to this module, I wouldn't be allowed to share it with anyone). So unless they change the agreement, I don't see how I can read the spec and add this feature without breaking the rules. I don't plan to give up, but it will probably take a while.

Interestingly, the prohibition against distribution applies to hardware accessories as well, so if, for instance, I were to create some interesting gizmo, it would be a violation for me to teach you how to make one. I can understand why they don't want people selling lots of gadgets without getting them certified, but this seems a bit heavy-handed if you ask me.