Skip to content

Instantly share code, notes, and snippets.

@brutella
Forked from gerardbos/multiswitchtest.go
Last active November 30, 2017 13:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brutella/6e2eb0783701589d492be1592cff59ac to your computer and use it in GitHub Desktop.
Save brutella/6e2eb0783701589d492be1592cff59ac to your computer and use it in GitHub Desktop.
// Steps to get this running
// 1. Install Go: http://golang.org/doc/install
// 2. Setup Go workspace: http://golang.org/doc/code.html#Organization
// 3. Download dependencies in Terminal.app
// 3.1 Navigate to multiswitchtest.go
// 3.2 Execute `go get`
// 4. Run `go run multiswitchtest.go`
package main
import (
"strconv"
"github.com/brutella/hc"
"github.com/brutella/hc/log"
"github.com/brutella/hc/accessory"
)
func main(){
log.Debug.Enable()
accessory_cnt := 18
hc_config := hc.Config{Pin: "56781234", StoragePath: "./db"}
info := accessory.Info{
Name: "0",
SerialNumber: "0",
}
switch1 := accessory.NewSwitch(info)
var switches[] *accessory.Accessory
for i := 1; i < accessory_cnt; i++ {
info_ := accessory.Info{
Name: strconv.Itoa(i),
SerialNumber: strconv.Itoa(i),
}
s := accessory.NewSwitch(info_);
switches = append(switches, s.Accessory)
}
t, err := hc.NewIPTransport(hc_config, switch1.Accessory, switches...)
if(err != nil){
log.Info.Fatal("Error starting Transport. Error: ", err)
}
hc.OnTermination(func(){
log.Info.Println("Stopping transport")
<-t.Stop()
})
t.Start()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment