brutella / hc

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

Cannot Create Thermostat Accessory #126

Closed jtsiros closed 4 years ago

jtsiros commented 6 years ago

Hello,

I'm attempting to create a thermostat accessory, and for some reason, The Home app returns "Couldn't connect to this accessory." error.

here is my initialization code:

info := accessory.Info{
        Name:         "Nest",
        Manufacturer: "Nest Labs Inc",
    }
    acc := accessory.NewThermostat(
        info,
        75.0,
        75.0,
        75.0,
        1.0,
    )
    config := hc.Config{Pin: *pin, Port: *port}
    tp, err := hc.NewIPTransport(config, acc.Accessory)
    if err != nil {
        log.Info.Panicln(err.Error())
    }
    hc.OnTermination(func() {
        <-tp.Stop()
    })
    tp.Start()

Here is an excerpt from the logs:

DEBUG 2018/08/23 20:19:48 signature is valid
DEBUG 2018/08/23 20:19:48 Setup secure session
DEBUG 2018/08/23 20:19:48 192.168.7.28:64933 GET /accessories
DEBUG 2018/08/23 20:19:48 {"accessories":[{"aid":1,"services":[{"iid":1,"type":"3E","characteristics":[{"iid":2,"type":"14","perms":["pw"],"format":"bool"},{"iid":3,"type":"20","perms":["pr"],"value":"Nest Labs Inc","format":"string"},{"iid":4,"type":"21","perms":["pr"],"value":"undefined","format":"string"},{"iid":5,"type":"23","perms":["pr"],"value":"Nest","format":"string"},{"iid":6,"type":"30","perms":["pr"],"value":"undefined","format":"string"},{"iid":7,"type":"52","perms":["pr"],"value":"","format":"string"}]},{"iid":8,"type":"4A","characteristics":[{"iid":9,"type":"F","perms":["pr","ev"],"value":0,"format":"uint8"},{"iid":10,"type":"33","perms":["pr","pw","ev"],"value":0,"format":"uint8"},{"iid":11,"type":"11","perms":["pr","ev"],"value":0,"format":"float","unit":"celsius","maxValue":0,"minValue":0,"minStep":1},{"iid":12,"type":"35","perms":["pr","pw","ev"],"value":10,"format":"float","unit":"celsius","maxValue":0,"minValue":0,"minStep":1},{"iid":13,"type":"36","perms":["pr","pw","ev"],"value":0,"format":"uint8"}]}]}]}
DEBUG 2018/08/23 20:19:48 192.168.7.28:64933 POST /pairings
DEBUG 2018/08/23 20:19:48 ->     Method: Delete
DEBUG 2018/08/23 20:19:48 -> Permission: 0
DEBUG 2018/08/23 20:19:48 ->   Username: 1A9D0022-5D0F-4812-9514-7F1DE6DC2DFB
DEBUG 2018/08/23 20:19:48 ->       LTPK: []
DEBUG 2018/08/23 20:19:48 Remove LTPK for client '1A9D0022-5D0F-4812-9514-7F1DE6DC2DFB'
DEBUG 2018/08/23 20:19:48 Event: unpaired with device
DEBUG 2018/08/23 20:19:49 Close connection and remove session

I've been able to successfully run a LightSwitch accessory without any issues.

rcarmo commented 6 years ago

I'm also looking into something similar, and wondering if the (as yet un-merged) #118 might help.

brutella commented 6 years ago

From the log I can see that the client successfully connected and paired with the accessories. But then it immediately unpairs with the accessories. Probably the data of the accessory is invalid.

Maybe a min and max temperature of 75° is invalid. Have you tried to use 70° for min and 75° for max?

jtsiros commented 6 years ago

@brutella Yes, I've tried 70 for min and 80 for max. Same result (logs):

DEBUG 2018/08/27 23:46:33 signature is valid
DEBUG 2018/08/27 23:46:33 Setup secure session
DEBUG 2018/08/27 23:46:33 192.168.7.28:53979 GET /accessories
DEBUG 2018/08/27 23:46:33 {"accessories":[{"aid":1,"services":[{"iid":1,"type":"3E","characteristics":[{"iid":2,"type":"14","perms":["pw"],"format":"bool"},{"iid":3,"type":"20","perms":["pr"],"value":"Nest Labs Inc","format":"string"},{"iid":4,"type":"21","perms":["pr"],"value":"undefined","format":"string"},{"iid":5,"type":"23","perms":["pr"],"value":"Nest","format":"string"},{"iid":6,"type":"30","perms":["pr"],"value":"undefined","format":"string"},{"iid":7,"type":"52","perms":["pr"],"value":"","format":"string"}]},{"iid":8,"type":"4A","characteristics":[{"iid":9,"type":"F","perms":["pr","ev"],"value":0,"format":"uint8"},{"iid":10,"type":"33","perms":["pr","pw","ev"],"value":0,"format":"uint8"},{"iid":11,"type":"11","perms":["pr","ev"],"value":75,"format":"float","unit":"celsius","maxValue":80,"minValue":70,"minStep":1},{"iid":12,"type":"35","perms":["pr","pw","ev"],"value":38,"format":"float","unit":"celsius","maxValue":80,"minValue":70,"minStep":1},{"iid":13,"type":"36","perms":["pr","pw","ev"],"value":0,"format":"uint8"}]}]}]}
DEBUG 2018/08/27 23:46:33 192.168.7.28:53979 POST /pairings
DEBUG 2018/08/27 23:46:33 ->     Method: Delete
DEBUG 2018/08/27 23:46:33 -> Permission: 0
DEBUG 2018/08/27 23:46:33 ->   Username: 1A9D0022-5D0F-4812-9514-7F1DE6DC2DFB
DEBUG 2018/08/27 23:46:33 ->       LTPK: []
DEBUG 2018/08/27 23:46:33 Remove LTPK for client '1A9D0022-5D0F-4812-9514-7F1DE6DC2DFB'
DEBUG 2018/08/27 23:46:33 Event: unpaired with device
DEBUG 2018/08/27 23:46:34 Close connection and remove session
jtsiros commented 5 years ago

Any suggestions on what the issue could be?

brutella commented 5 years ago

Can somebody please try with hc v1.1.0?

bjanders commented 5 years ago

I just tried it, and it works without issues.

@jtsiros, note that the units are degrees Celsius (according to the HAP specs).