hap-java / HAP-Java

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

No response from accessories intermittently #48

Closed joenicorata closed 5 years ago

joenicorata commented 5 years ago

Hello and thank you for this library.

I have built a java application implementing this server. I have an issue where all of my accessories go from working perfectly to "No response" after a random amount of time. Sometimes it can stay running for 1-2 hours, other times it fails within 10 minutes of launching.

I have implemented "hasUser()" in authinfo to return true, i have removed my apple tv 4 from home as a hub, and i have removed all of my accessories one-by-one to see if one is causing bad values. none of the above fix the issue.

oddly enough the homekit accessories come back online on their own without restarting the server, but then will go unavailable again a short time later.

thank you in advance for your time

joenicorata commented 5 years ago

I am still hung up on this one, here is what i have tried since my last post:

Thank you

joenicorata commented 5 years ago

A week later I am still really struggling, here is where I am at:

still i get "no response" from my accessories after random amounts of time from the bridge starting.

My next attempt will be to write a watchdog process that reboots the bridge every 5 minutes so I can move onto the next part of the project for now

Any comments or insight would be greatly appreciated

Thank You Joe

joenicorata commented 5 years ago

Beowulfe, any advice for me? I have hit a wall on this and can't seem to figure it out. I can paste code samples here, but don't want to clutter up the thread unless requested. Thanks

joenicorata commented 5 years ago

Still stuck on this, I have narrowed it down to the Jmdns advertisement. Whenever the accessories are working, several bonjour discovery apps show _hap_tcp service. When accessories report "not responding", the bonjour service disappears. Restarting Jmdns services temporarily brings accessories back online

cice commented 5 years ago

I have the same problem, as many do / had in OpenHAB2 (see https://github.com/openhab/openhab2-addons/issues/3522 - but it is definitely not fixed until today. Just seems to be random enough.) Thanks for your debugging effort, i'd like to help if i can.

joenicorata commented 5 years ago

I tried creating a separate Jmdns application in java, advertising the services. I disabled all Jmdns advertising in the hap-java library with the intention of eliminating thread/locking issues. Again, same issue. The bonjour disappears after a random interval (most of the time it as about 30 min). The services return after an extended period of time, but never stay for long. This is mirrored in all bonjour browser services.

joenicorata commented 5 years ago

I have the same problem, as many do / had in OpenHAB2 (see openhab/openhab2-addons#3522 - but it is definitely not fixed until today. Just seems to be random enough.) Thanks for your debugging effort, i'd like to help if i can.

I havent really looked at OpenHab that much yet, but the underlying common attributes between my implementation and OpenHab's are: Java, Hap-Java, and the high probability that other UPNP and multicast services are being run on the same platform/interface. Sonos is an example of a UPNP intensive plugin I wrote for my system.

What other plugins are you loading/using in openhab?

cice commented 5 years ago

I am using the zwave and the hue binding, both of them should not use bonjour i think, but i'll try to gather some details about mdns services in my network and on the openhab device in particular

watta90 commented 5 years ago

I will join this thread even though it might not be the exact same problem. I also have problem with the bridge showing "No response" after some days but I'm able to reconnect again without rebooting the bridge, and the bridge is still publishing the bonjour service. I'm also able to connect new homekit users while the previous are showing "No response".

When homekit is in state "No response" then it doesn't try to reconnect, even if I force close the app. I don't receive any connection requests on my bridge nor can I see anything in Wireshark which has to do with homekit trying to connect to the bridge. Somehow it looks like homekit has given up the connection to the bridge and will not try any longer, the only solution is to remove the bridge and add it again.

Is this the same experience that you've had?

joenicorata commented 5 years ago

I think I have discovered the cause of THIS issue. My operating system was syncing the OS time to the hardware clock time every hour, starting exactly one hour after bootup. My OS time momentarily shifted back by 6 hours (GMT-6 for CST) once an hour. Within 45 seconds of the time shifting, it corrects itself using the Windows defined time zone. It is during this period that all Jmdns advertising goes silent.

Due to the hourly scheduled nature of the OS time sync, the duration of a working Jmdns implementation varied from 1-59 minutes, depending on when i started the server in relation to the last windows time sync. This explains the "randomness" in outages.

My architecture is unique. App/JVM via Eclipse, running on Windows, run in Boot Camp, booted through parallels over MacOS on a Mac Pro. Disabling the time sync between parallels and guest os solved hourly synchronization. This solved my mDNS advertisement issues and now the service displays constantly.


Since resolving this, I have run into the same issue as watta90 once now:

This has only happened once so far. I have had the bridge running for 12 hours now with no interruption, I will post back with more results as I test

watta90 commented 5 years ago

@joenicorata great that you solved that one! I think there are a lot of people having the same issue. We can continue in another issue for the other problem and keep this clean so people find it easily?

joenicorata commented 5 years ago

Sounds good, i am closing this issue