brutella / hc

hc is a lightweight framework to develop HomeKit accessories in Go.
Apache License 2.0
1.74k stars 189 forks source link

closed connection #165

Closed pyxiscloud closed 4 years ago

pyxiscloud commented 4 years ago

Hello I've tried this example (golang 1.13.8)

package main import ( "github.com/brutella/hc" "github.com/brutella/hc/accessory" "github.com/brutella/hc/log" "time" ) func main() { log.Debug.Enable() switchInfo := accessory.Info{ Name: "Lamp", SerialNumber: "051AC-23AAM1", Manufacturer: "Apple", Model: "AB", FirmwareRevision: "fdsa", ID: 0, } bridge := accessory.NewBridge(switchInfo) outlet := accessory.NewOutlet(accessory.Info{Name: "Outlet", ID: 2}) lightbulb := accessory.NewColoredLightbulb(accessory.Info{Name: "Light", ID: 3}) config := hc.Config{Pin: "12344321", Port: "12345", StoragePath: "./db"} t, err := hc.NewIPTransport(config, bridge.Accessory, outlet.Accessory, lightbulb.Accessory) if err != nil { log.Info.Panic(err) } // Log to console when client (e.g. iOS app) changes the value of the on characteristic outlet.Outlet.On.OnValueRemoteUpdate(func(on bool) { if on == true { log.Debug.Println("Client changed switch to on") } else { log.Debug.Println("Client changed switch to off") } }) // Periodically toggle the switch's on characteristic go func() { for { on := !outlet.Outlet.On.GetValue() if on == true { log.Debug.Println("Switch is on") } else { log.Debug.Println("Switch is off") } outlet.Outlet.On.SetValue(on) time.Sleep(5 * time.Second) } }() hc.OnTermination(func() { <-t.Stop() }) t.Start() }

somebody it fails on pairing with "DEBUG 2020/02/23 18:03:08 connection.go:112: Close connection and remove session" and after successfully paired it loose connection after some minutes and then after some minutes connect again:

DEBUG 2020/02/23 18:03:03 homekit.go:52: Switch is off DEBUG 2020/02/23 18:03:03 ip_transport.go:282: 192.168.88.246:56839 <- EVENT/1.0 200 OK Content-Length: 53 Content-Type: application/hap+json {"characteristics":[{"aid":2,"iid":9,"value":false}]} DEBUG 2020/02/23 18:03:08 homekit.go:50: Switch is on DEBUG 2020/02/23 18:03:08 ip_transport.go:282: 192.168.88.246:56839 <- EVENT/1.0 200 OK Content-Length: 52 Content-Type: application/hap+json {"characteristics":[{"aid":2,"iid":9,"value":true}]} DEBUG 2020/02/23 18:03:08 connection.go:112: Close connection and remove session DEBUG 2020/02/23 18:03:13 homekit.go:52: Switch is off DEBUG 2020/02/23 18:03:18 homekit.go:50: Switch is on DEBUG 2020/02/23 18:03:23 homekit.go:52: Switch is off DEBUG 2020/02/23 18:03:28 homekit.go:50: Switch is on DEBUG 2020/02/23 18:03:33 homekit.go:52: Switch is off DEBUG 2020/02/23 18:03:38 homekit.go:50: Switch is on DEBUG 2020/02/23 18:03:43 homekit.go:52: Switch is off DEBUG 2020/02/23 18:03:48 homekit.go:50: Switch is on DEBUG 2020/02/23 18:03:53 homekit.go:52: Switch is off DEBUG 2020/02/23 18:03:58 homekit.go:50: Switch is on DEBUG 2020/02/23 18:04:03 homekit.go:52: Switch is off DEBUG 2020/02/23 18:04:08 homekit.go:50: Switch is on DEBUG 2020/02/23 18:04:13 homekit.go:52: Switch is off DEBUG 2020/02/23 18:04:18 homekit.go:50: Switch is on DEBUG 2020/02/23 18:04:23 homekit.go:52: Switch is off DEBUG 2020/02/23 18:04:28 homekit.go:50: Switch is on DEBUG 2020/02/23 18:04:33 homekit.go:52: Switch is off DEBUG 2020/02/23 18:04:38 homekit.go:50: Switch is on DEBUG 2020/02/23 18:04:43 homekit.go:52: Switch is off DEBUG 2020/02/23 18:04:48 homekit.go:50: Switch is on DEBUG 2020/02/23 18:04:53 homekit.go:52: Switch is off DEBUG 2020/02/23 18:04:58 homekit.go:50: Switch is on DEBUG 2020/02/23 18:05:03 homekit.go:52: Switch is off DEBUG 2020/02/23 18:05:08 homekit.go:50: Switch is on DEBUG 2020/02/23 18:05:13 homekit.go:52: Switch is off DEBUG 2020/02/23 18:05:18 homekit.go:50: Switch is on DEBUG 2020/02/23 18:05:23 homekit.go:52: Switch is off DEBUG 2020/02/23 18:05:28 homekit.go:50: Switch is on DEBUG 2020/02/23 18:05:33 homekit.go:52: Switch is off DEBUG 2020/02/23 18:05:38 homekit.go:50: Switch is on DEBUG 2020/02/23 18:05:43 homekit.go:52: Switch is off DEBUG 2020/02/23 18:05:48 homekit.go:50: Switch is on DEBUG 2020/02/23 18:05:53 homekit.go:52: Switch is off DEBUG 2020/02/23 18:05:58 homekit.go:50: Switch is on DEBUG 2020/02/23 18:06:03 homekit.go:52: Switch is off DEBUG 2020/02/23 18:06:08 homekit.go:50: Switch is on DEBUG 2020/02/23 18:06:11 pair-verify.go:37: 192.168.88.246:56843 POST /pair-verify DEBUG 2020/02/23 18:06:11 pair-verify.go:44: Create new pair verify controller

pyxiscloud commented 4 years ago

Please test this code and confirm bug?

brutella commented 4 years ago

I've tried the code above, kept my iPhone running Apple Home all the time and I also got some connection closed. But Apple Home displayed the accessories correctly all the time. I never got an error messages.

Do you experience any errors?

pyxiscloud commented 4 years ago

reinstalled all and now it works without closing connections