Comments (14)
@Brawrdon , since reachability of HomeKit accessories depends on mDNS, which is a UDP based protocol, there is indeed a high chance of accessory seeming unreachable just because of a few missed packets in a noisy environment. The solution you have mentioned could indeed work. However, Apple's Bonjour Conformance Test does not allow unsolicited mDNS announcements. In fact there is a specific test just to ensure that the accessory does not make any mDNS announcements for at least a couple of hours, if there is no query. Of course, the solution could still be fine for hobby projects, but not something we can add ourselves, since we want to keep this SDK in sync with the MFi variant of the SDK.
Meanwhile, the purpose of state number (s#) is to let controllers in the network know that something has changed on the accessory. This triggers a GET request from the controllers or a session re-establishment (in case it was broken for some reason).
from esp-homekit-sdk.
I think I've solved it! Tldr: I had to reboot my router... 😖
Basically, whilst trying to setup Wireshark to sniff packets between my ESP32, I noticed that I couldn't access machines in my LAN when connected to certain SSIDs (I have multiple SSIDs on one router to separate my IoT stuff). I have no idea why but certain hosts, such as when trying to access my Raspberry Pi, weren't being forwarded. I assume that included ones to my ESP32, which probably caused my devices to go "well I can't see this host guess I'll shut it off". Simply rebooting my router to fix whatever went astray has stopped the ESP32 from disconnected even with multiple devices connected via iCloud.
I'm gonna close this issue now, thanks for the support guys! Moral of the story, always try turning things off and on again 😅
from esp-homekit-sdk.
@Brawrdon , can you give some more information about your network, specifically with regards to number of iOS devices linked to the same Apple account? I see multiple socket fd numbers in the log (51, 52, 53) and so was wondering which session is getting closed. Please also apply this small patch which would also indicate the session being closed and check again
diff --git a/components/homekit/esp_hap_core/src/esp_hap_network_io.c b/components/homekit/esp_hap_core/src/esp_hap_network_io.c
index a2724ab..42b7d6b 100644
--- a/components/homekit/esp_hap_core/src/esp_hap_network_io.c
+++ b/components/homekit/esp_hap_core/src/esp_hap_network_io.c
@@ -97,8 +97,8 @@ int hap_encrypt_data(hap_encrypt_frame_t *frame, hap_secure_session_t *session,
int hap_decrypt_error(hap_secure_session_t *session)
{
- ESP_MFI_DEBUG(ESP_MFI_DEBUG_INFO, "Decryption error/Connection lost. Marking session as invalid");
if (session) {
+ ESP_MFI_DEBUG(ESP_MFI_DEBUG_INFO, "Decryption error/Connection lost. Marking session %d as invalid", session->conn_identifier);
session->state = STATE_INVALID;
hap_close_ctrl_sessions(session->ctrl);
}
from esp-homekit-sdk.
@shahpiyushv I currently have four which are signed into my account with access to Home. When I pair it with my iPhone it sends: Socket fd: 51; HTTP Request POST /pair-setup
and then the same for socket 52, 53 and 54 which I guess is iCloud doing its thing. I'm assuming 51 is the iPhone. The first socket to be marked as invalid is 53 which destroys all four sessions. 51 is marked as invalid again slightly after, it manages to successfully send a GET request just before hand even though it seems all sessions were terminated.
I've attached the full log.
from esp-homekit-sdk.
If I disconnect every other device and just have my iPhone connected it appears to work (doesn't go unresponsive after about a minute). It does however, throw the error the minute I reconnect any other device to the network. There's no log of the second device pairing or creating a socket session, just Decryption error/Connection lost. Marking session 51 as invalid
.
from esp-homekit-sdk.
@Brawrdon , thanks for the additional information. I will check at my end and see if I can find the root cause. Note that this does not seem related to #4 as that issue was specific to ESP8266, that too for only float values.
Meanwhile, can you try commenting out this line and see what happens?
from esp-homekit-sdk.
@shahpiyushv Thanks for the help!
Meanwhile, can you try commenting out this line and see what happens?
Nothing seems to change, the error still occurs when I have multiple devices connected.
from esp-homekit-sdk.
I think I discovered the issue and a potential solution! I stumbled upon an issue with a HomeKit library for the ESP8266 (Mixiaoxiao/Arduino-HomeKit-ESP8266#9) that seemed to be identical to mine; the mDNS services were being removed just before the device disconnects. I hacked in the solution proposed on the issue, which was to re-announce the mDNS service every five seconds, by calling hap_mdns_announce(false);
in the hap_loop_task
function inside of esp_hap_main.c
. Every time an event occurred, specifically turning the fan on or off, the mDNS service would announce itself again and stay connected, after leaving it be for a few seconds the error appears again.
I'm assuming by adding a timed function to just call hap_mdns_announce(false);
every 5ish seconds (I think you could push that up to 15ish) would solve the problem. I'm currently looking into doing that with another task, I think my understanding of how IDF utilises them is wrong since I can't seem to get it to call every 5 seconds. The only thing with this is that the state number increases quickly, I don't know what the purpose of it is or if this would cause an issue.
I'm not that experience with mDNS or the HomeKit Accessory Protocol so I can't think as to why this is a thing... Though, the owner of the library for the ESP8266 did mention two cases they found for when the iOS device disconnects.
Mixiaoxiao/Arduino-HomeKit-ESP8266#9 (comment)
from esp-homekit-sdk.
@shahpiyushv Thanks for the explanation!
My solution seems to only slightly increase the time until the error occurs, the device lasts about half an hour before the same error shows up. Guess I'll have to leave it up to you to see if a proper solution can be found 😭
from esp-homekit-sdk.
@Brawrdon Do not forget that there is another side of the issue - iOS controller / HomeKit hub (or especially in case there is more than one hub). This side is still in evolving stage. I am pretty sure that some of the answers behind “No response” issues are hidden there.
from esp-homekit-sdk.
@Brawrdon Do not forget that there is another side of the issue - iOS controller / HomeKit hub (or especially in case there is more than one hub). This side is still in evolving stage. I am pretty sure that some of the answers behind “No response” issues are hidden there.
Which issues are you referring to exactly?
from esp-homekit-sdk.
As far as I understood “Decryption error/Connection lost” you have mentioned is followed by accessory unavailability or famous “No response” status, that has million reasons to appear.
My point is that Apple is constantly changing the way that their system works.
Also there are other variables like iOS version, kind of hub, number of controllers connected etc.
It is good idea to check your setup, for example, on an older version of iOS device (version 10 to 12) and share your experience.
I have checked the Fan example myself and it works fine for me (tested on esp32 and esp8266).
However I have troubles pairing from iPhone 11 Pro, but with 6s and 5c - don’t. The iOS controller (11 pro) sporadically sends “0” instead of the pairing information on step M3. (I will share details on this issue.) Apple’s code is not perfect, unfortunately.
from esp-homekit-sdk.
@AramVartanyan I think I've pinpointed the cause of the issue to having multiple devices connected to the ESP32 via iCloud. The demos appear to work fine when I turn all the other devices onto aeroplane mode and disconnect them from the network. Three devices are on the latest version of their respective OS whilst one isn't. I'm gonna see if it has something to do with that by disabling the device running Catalina. They may have changed something, like you said, which the Catalina device doesn't understand and so causes a panic! If that doesn't work I'm gonna try take a look at the packets via Wireshark. I've been having an issue sniffing packets from my ESP32 via my Mac but that's an entirely separate problem.
Also might be worth mentioning that I have my iPad enabled as a hub but I don't think that's an issue since the devices have always been on the same network. The main controller is an iPhone XR running iOS 14.3.
The iOS controller (11 pro) sporadically sends “0” instead of the pairing information on step M3.
I'm assuming you used Wireshark to do this or does this info show up on the logs?
from esp-homekit-sdk.
You can understand much better the issues if you just activate the debugging messages.
from esp-homekit-sdk.
Related Issues (20)
- Associated more than one accessory HOT 2
- mbedtls inclusion error, udnefined functions HOT 1
- Unable to find components to build examples for ESP8266 HOT 2
- How to cleanly add or remove accessories ? (bridge) HOT 2
- HTTPD init error HOT 2
- ESP8266无法使用
- Accessory Not Found HOT 6
- Update examples CMakeLists.txt
- hap_platform_httpd_start failing HOT 1
- Is it possible to remove nvs? HOT 2
- More than 1 accessory support without using bridge HOT 6
- How to change Homekit TCP port? HOT 2
- esp-homekit-sdk network allocation HOT 2
- Lightbulb: save status on flash HOT 3
- Change serial number without re-build source code HOT 2
- Is it possible to return the device status outside the hap_serv_set_write_cb callback function? HOT 3
- idf.py menuconfig fails for aws-iot example
- Mfi license HOT 5
- homekit bridge Decryption error/Connection lost HOT 2
- Problem with some services and features HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from esp-homekit-sdk.