maximkulkin / esp-homekit

Apple HomeKit accessory server library for ESP-OPEN-RTOS
MIT License
1.1k stars 168 forks source link

Higher battery drain due to homekit #186

Closed haecksenwerk closed 3 years ago

haecksenwerk commented 3 years ago

I have built some 12 devices based on esp-homekit. No cameras, just sonSoff switches, some door-sensors, and a garage-door opener. With all devices included in the network, my iPad and especially my first-gen iPhone SE's battery is almost drained empty overnight.

When looking into the traffic with Wireshark, I can see the iPad, as well as the iPhone, cranking out a bunch of mdns queries with "QU" and "QM" questions to each homekit device every minute.

I wonder if this is expected behavior according to the homekit protocol, or if this is something that I need to look closer into?

maccoylton commented 3 years ago

I belie thus us expected behaviour. Wifi is not really designed for batter powered devices. Most commercial accessories use bluetooth or some of the newer ones are now using thread. This library is Wifi only.

maximkulkin commented 3 years ago

That, and also: iOS devices go to sleep after some periods of no-use, so I'm not sure what do we have here. @haecksenwerk are you claiming that your devices did not go to sleep?

haecksenwerk commented 3 years ago

@maccoylton maccoylton No Bluetooth devices are involved. These are mains powered devices, running more or less the homekit-examples code. @maximkulkin sniffing with Wireshark, the iOS devices happily respond to mdns broadcasts and even send mdns requests while one would think that they should be in sleep mode.

maccoylton commented 3 years ago

So none of the homekit accessories are battery powered?

haecksenwerk commented 3 years ago

No battery-operated accessories. And in the application layer of the device's software, everything is event-driven.

maccoylton commented 3 years ago

ok .. so your theory is the mdns requests are contributing to battery drain on you phone ?

haecksenwerk commented 3 years ago

This is my assumption right now. The battery drain occurred after the installation of the accessories. Seeing the mdns related traffic to/from my phone's ip while the phone should be in sleep mode isn't a good sign. So, when I disable the phone's wifi, the battery consumption goes back to normal. These are my rough findings. I think that I need to dive a bit deeper into the homekit/mdns protocol stuff to get a better picture of what is happening here.

maccoylton commented 3 years ago

Do you have any commercial accessories to do a comparison with, otherwise if you give a little more info I can take a look as I have a mix of commercial and eps-homekit accessories.

d4rkmen commented 3 years ago

When looking into the traffic with Wireshark, I can see the iPad, as well as the iPhone, cranking out a bunch of mdns queries with "QU" and "QM" questions to each homekit device every minute.

This is the way controller (iOS device) cheks accessory online/offline. A minute interval probably related to HAP spec: there is 60 sec idle connection timeout, then it should be closed. Also home automation hub is always online (like ipad or appletv) and may ping accessories this way. There is also notification subscription (notify on this iphone when sensor breached) may cause this traffic

d4rkmen commented 3 years ago

No battery-operated accessories

There are battery driven BT accessories offcourse.

everything is event-driven.

Except the discovery service, which is UDP-based question >> answer style

haecksenwerk commented 3 years ago

This is the way controller (iOS device) cheks accessory online/offline. A minute interval probably related to HAP spec: there is 60 sec idle connection timeout, then it should be closed. Also home automation hub is always online (like ipad or appletv) and may ping accessories this way.

I have an apple tv set up as a homekit hub. While the iPad is not. So, yes, it makes sense that the apple tv frequently pings the accessories to check their status. But why would an iphone respond to or send frequently unsolicited mdns requests while in sleep mode?

There are battery driven BT accessories offcourse.

right, but I'm not using any

Except the discovery service, which is UDP-based question >> answer style

good hint

AramVartanyan commented 3 years ago

Do you have any commercial accessories to do a comparison with, otherwise if you give a little more info I can take a look as I have a mix of commercial and eps-homekit accessories.

Actually for example I have similar issues with Eufy (Anker) camera, when the Face recognition function is allowed. (Using it with Home app only.) It drains my iPhone and iPad (not set as hub) batteries three times faster compared to this function disabled. However I am not sure if it is related to queries, data transfer or if the processing is on the iOS device side. Also another example is that my old 6s device was turned into a second phone, with Home app removed. The total battery drain time is changed from ~12 hours to 48 hours, with similar daily usage time. So the HomeKit functions definitely keeping the iOS controller busy and causing faster battery drain.

haecksenwerk commented 3 years ago

I will close this issue since it isn't caused by esp-homekit. I need to learn more about the mdns and HK specifications and some router related stuff like IGMP snooping. Thanks all for sharing your thoughts and experiences on that matter.