Disable TCP keepalives explicitly

It looks like Go has adopted 15s TCP keepalives as a default for _all_
TCP connections, which is quite dumb if you ask me.
https://github.com/golang/go/issues/48622

For the HAP server's side, it degrades iOS battery life significantly by
waking the device every 15s to respond to these packets. In the case as
a normal MQTT client, it increases traffic on top of the 60s keepalive
we've already set at the application layer. In both cases, the solution
is to just explicitly disable TCP keepalives.

Upgrade hap to the latest version that contains the fix brutella/hap#36.
This commit is contained in:
Darell Tan
2023-08-09 01:38:50 +08:00
parent 4eac1ba2a9
commit fe5d0ce14c
3 changed files with 5 additions and 3 deletions

View File

@@ -15,6 +15,7 @@ import (
"encoding/json"
"fmt"
"log"
"net"
"net/http"
"reflect"
"strings"
@@ -163,6 +164,7 @@ func (br *Bridge) ConnectMQTT() error {
SetUsername(br.Username).
SetPassword(br.Password).
SetClientID("hap-z2m").
SetDialer(&net.Dialer{KeepAlive: -1}).
SetKeepAlive(60 * time.Second).
SetPingTimeout(2 * time.Second).
SetConnectRetry(true)