Using a bridge causes the state of the device in the Apple home app to be out of sync
Using the bridge, the device status in the Apple home app is no longer synchronized after the state changes several times, and it needs to be controlled before it will be synchronized。
func main() {
a := accessory.NewBridge(accessory.Info{
Name: "Bridge",
})
b := accessory.NewSwitch(accessory.Info{
Name: "Lamp",
})
d := accessory.NewSwitch(accessory.Info{
Name: "Lamp1",
})
s, err := hap.NewServer(hap.NewFsStore("./db"), a.A, b.A, d.A)
if err != nil {
log.Panic(err)
}
// Log to console when client (e.g. iOS app) changes the value of the on characteristic
b.Switch.On.OnValueRemoteUpdate(func(on bool) {
if on {
log.Println("Client changed switch to on")
} else {
log.Println("Client changed switch to off")
}
})
s.Pin = "34679023"
// Periodically toggle the switch's on characteristic
go func() {
for {
on := !b.Switch.On.Value()
if on {
log.Println("Switch is on")
} else {
log.Println("Switch is off")
}
b.Switch.On.SetValue(on)
time.Sleep(5 * time.Second)
}
}()
c := make(chan os.Signal)
signal.Notify(c, os.Interrupt)
signal.Notify(c, syscall.SIGTERM)
ctx, cancel := context.WithCancel(context.Background())
go func() {
<-c
signal.Stop(c)
cancel()
}()
s.ListenAndServe(ctx)
}
Remove the first bridge a, then the status in the Apple home app is synchronized no matter how the value is set
What causes this?
Im having the same issue
This issue sounds like a network issue, where the Apple Home app cannot find the bridge anymore.
Are you using the latest version of this library? There were several improvements in the last months, especially in the used dnssd library.
This issue sounds like a network issue, where the Apple Home app cannot find the bridge anymore.
Are you using the latest version of this library? There were several improvements in the last months, especially in the used dnssd library.
I used the latest one,and it's still the same problem.You can try it,it's a must-see question.
Hey @brutella ,
I've just hit this issue whilst building out a custom HomeKit Bridge on the library. It doesn't seem to be directly related to dnssd as the issue is resolved by closing and opening the HomeKit app (presumably refetching the state under the hood). I assume this is some kind of realtime issue but don't know enough about the spec to fully investigate.
Could you give some pointers about where I should look or what information I can provide to help investigate?
@AJCStriker What network configuration do you have to connect from your HomeKit client (e.g. Home app on iOS) to the HomeKit bridge? Are both on the same network? Is the computer, on which the HomeKit bridge is running, connected to the network via multiple interfaces (WiFi and Ethernet).
In my experience, if a HomeKit bridge publishes multiple IP addresses, the HomeKit client on your iOS device sometimes uses the wrong path and ends up with no connection. It helps if the HomeKit bridge only uses one network interface to communicate to the client.
Hey @brutella ,
Apologies for the slow reply!
What network configuration do you have to connect from your HomeKit client (e.g. Home app on iOS) to the HomeKit bridge? I am running the bridge app on a M4 Mac machine with a single wifi connection active. The iOS device is on the same wifi network.
Is the computer, on which the HomeKit bridge is running, connected to the network via multiple interfaces (WiFi and Ethernet).
No - it only has one active Wifi connection.
In my experience, if a HomeKit bridge publishes multiple IP addresses, the HomeKit client on your iOS device sometimes uses the wrong path and ends up with no connection.
The issue doesn't appear to occur when listing appliances directly, only when sent via a bridge