hap-java / HAP-Java

Java implementation of the HomeKit Accessory Protocol
MIT License
152 stars 83 forks source link

Accessories show "no response" in home app after restart of Java application #139

Closed dfrommi closed 3 years ago

dfrommi commented 3 years ago

Hello,

I'm facing a very strange problem with HAP-Java now... Whenever I restart the app that's using HAP-Java, the Home app on iPhone shows "no response" for all accessories managed by HAP-Java. When I re-pair the bridge, everything is working fine. But as soon as I restart the app, "no response" is shown again and I have to pair again.

TRACE-log is enabled and while I see a lot of communication going on during the pairing process, I hardly see anything after restart.

The latest log statements related to HAP-Java after restart are

2021-02-11 20:51:24.776  INFO 2640 --- [ntLoopGroup-2-1] io.netty.handler.logging.LoggingHandler  : [id: 0x8823f8cc] REGISTERED
2021-02-11 20:51:24.787  INFO 2640 --- [ntLoopGroup-2-1] io.netty.handler.logging.LoggingHandler  : [id: 0x8823f8cc] BIND: home/192.168.1.10:9123
2021-02-11 20:51:24.794 TRACE 2640 --- [ntLoopGroup-2-1] i.g.h.s.i.h.i.NettyHomekitHttpService    : Bound homekit listener to /192.168.1.10:9123
2021-02-11 20:51:25.077 TRACE 2640 --- [ntLoopGroup-2-1] i.g.h.s.i.jmdns.JmdnsHomekitAdvertiser   : Advertising accessory Smart Home Bridge
2021-02-11 20:51:25.078  INFO 2640 --- [ntLoopGroup-2-1] i.g.h.s.i.jmdns.JmdnsHomekitAdvertiser   : Registering _hap._tcp.local. on port 9123
2021-02-11 20:51:25.078 TRACE 2640 --- [ntLoopGroup-2-1] i.g.h.s.i.jmdns.JmdnsHomekitAdvertiser   : MAC:c2:9b:ab:62:f:9 Setup Id:BOQ3
2021-02-11 20:51:25.132  INFO 2640 --- [ntLoopGroup-2-1] io.netty.handler.logging.LoggingHandler  : [id: 0x8823f8cc, L:/192.168.1.10:9123] ACTIVE

Then nothing HAP-related anymore.

I first thought that reading the configuration from my homekit.json file is the issue, but the mac-address matches the value from the json-file.

It looks to me like the iPhone wouldn't even try to connect. So maybe something related to advertising? But I have no clue how to debug that, so help would be very much appreciated.

I have the same issue with HAP-Java version 87bab73be807fec98b4f51b4a97326e3fd21045a as well as 45d9403dac182aae4e9de6c171b16b97b89f3e1c, just to rule out that the jmDNS change has caused the issue.

Not sure what else could be useful, so please let me know what info I should provide.

Thanks a lot already and I hope very much someone can point me in the right direction.

andylintner commented 3 years ago

I'd expect exactly what you're describing if you didn't correctly implement HomekitAuthInfo.

jrburk commented 3 years ago

I'd expect exactly what you're describing if you didn't correctly implement HomekitAuthInfo.

I have the same problem since a few months.

I added now debug code to my AuthInfo implementation. After restarting only getMac() is called, even if I restart the Home app on my iPad. getMac returns the correct ipv4 mac in XX:XX:XX:XX:XX.XX format.

I don't think AuthInfo is causing this, except it's related to the MAC address. Is the problem related to ipv4/ipv6?

yfre commented 3 years ago

public boolean hasUser() from AuthInfo should be called as well. depending on returned value Java-HAP decide to advertise or not the bridge for pairing. hasUser = true means the bridge is paired already and cannot be paired anymore hasUser = false mains the bridge is not paired and be advertised via mDNS as ready for pairing

jrburk commented 3 years ago

public boolean hasUser() from AuthInfo should be called as well. depending on returned value Java-HAP decide to advertise or not the bridge for pairing. hasUser = true means the bridge is paired already and cannot be paired anymore hasUser = false mains the bridge is not paired and be advertised via mDNS as ready for pairing

Thank's for pointing that out. I missed that change in the interface because it has a default implementation.

I started fresh on my iPad and repaired. During that process createUser was called (as expected).

12:50:50.291 HAP0: HomekitAuthInfo: createUser

however 10 seconds laster

12:51:00.088 HAP0: HomekitAuthInfo: removeUser

Then I rebooted the iPad and it couldn't connect anymore. I commented out the removeUser implementation and paired again and now it works as expected.

Any thoughts on this?

jrburk commented 3 years ago

Can I change public boolean hasUser() at runtine from true to false and the system will become discoverable again?

yfre commented 3 years ago

the only place where "removeUser" is called in java-hap is PairingUpdateController that calls this function on "remove pairing" message from client / home. if you dont have anywhere in your code "removeUser" then it is your ipad that request unpairing

if you change the hasUser to true you need to call "HomekitRoot.refreshAuthInfo()" to discoverability

dfrommi commented 3 years ago

@yfre Thank you so much for pointing to the hasUser method. That was also the reason for my "no response" issue.

It might, however, be a good idea to remove the default implementation. There's - as far as I understand - no scenario where the default implementation would be sufficient. For a working integration, it always has to be overridden and return different values depending on the state.

dfrommi commented 3 years ago

Issue resolved by implementing HomekitAuthInfo.hasUser()