Пример #1
0
func main() {
	lights = map[uint64]*HKLight{}

	pinArg := flag.String("pin", "", "PIN used to pair the LIFX bulbs with HomeKit")
	verboseArg := flag.Bool("v", false, "Whether or not log output is displayed")

	flag.Parse()

	pin = *pinArg

	if !*verboseArg {
		log.Info = false
		log.Verbose = false
	}

	hap.OnTermination(func() {
		for _, light := range lights {
			light.transport.Stop()
		}

		time.Sleep(100 * time.Millisecond)
		os.Exit(1)
	})

	Connect()
}
Пример #2
0
func main() {
	switchInfo := model.Info{
		Name: "Lamp",
	}
	sw := accessory.NewSwitch(switchInfo)

	config := hap.Config{Pin: "12344321", Port: "12345", StoragePath: "./db"}
	t, err := hap.NewIPTransport(config, sw.Accessory)

	if err != nil {
		log.Fatal(err)
	}

	// Log to console when client (e.g. iOS app) changes the value of the on characteristic
	sw.OnStateChanged(func(on bool) {
		if on == true {
			log.Println("[INFO] Client changed switch to on")
		} else {
			log.Println("[INFO] Client changed switch to off")
		}
	})

	// Periodically toggle the switch's on characteristic
	go func() {
		for {
			on := !sw.IsOn()
			if on == true {
				log.Println("[INFO] Switch on")
			} else {
				log.Println("[INFO] Switch off")
			}
			sw.SetOn(on)
			time.Sleep(5 * time.Second)
		}
	}()

	hap.OnTermination(func() {
		t.Stop()
	})

	t.Start()
}
Пример #3
0
func main() {
	var (
		pinArg = flag.String("pin", "", "Accessory pin used for pairing")
	)

	flag.Parse()
	pin = *pinArg

	lights = map[string]*lifxLight{}

	hap.OnTermination(func() {
		for _, l := range lights {
			l.transport.Stop()
		}
		time.Sleep(100 * time.Millisecond)
		os.Exit(1)
	})

	ConnectLIFX()
}
Пример #4
0
func main() {
	debug = false
	timeout = 0

	var (
		pinArg = flag.String("pin", "", "PIN used for pairing (must be 8 digits long)")
	)

	flag.Parse()
	pin = hap.Config{Pin: *pinArg}

	lights = make(map[uint64]lightMeta)

	hap.OnTermination(func() {
		closeClient()
		time.Sleep(100 * time.Millisecond)
		os.Exit(1)
	})

	startDiscovery()

	waitForInterruption()
}
Пример #5
0
func main() {
	info := model.Info{
		Name:         "My Door Sensor",
		SerialNumber: "XXX-YYY-ZZZ",
		Manufacturer: "Me",
		Model:        "1",
		Firmware:     "1.0",
	}

	doorSensor := accessory.NewContactSensor(info)

	t, err := hap.NewIPTransport(hap.Config{Pin: "32191123"}, doorSensor.Accessory)
	if err != nil {
		log.Fatal(err)
	}

	// Periodically toggle the contact sensor's state characteristic
	go func() {
		for {
			var state model.ContactSensorStateType
			if doorSensor.State() == model.ContactDetected {
				state = model.ContactNotDetected
			} else {
				state = model.ContactDetected
			}
			doorSensor.SetState(state)
			time.Sleep(5 * time.Second)
		}
	}()

	hap.OnTermination(func() {
		t.Stop()
	})

	t.Start()
}
Пример #6
0
// This app can connect to the UVR1611 data bus and provide the sensor values to HomeKit clients
//
// Optimizations: To improve the performance on a Raspberry Pi B+, the interrupt handler of the
// gpio pin is removed every time after successfully decoding a packet. This allows other goroutines
// (e.g. HAP server) to do their job more quickly.
func main() {

	var (
		pin     = flag.String("pin", "", "Accessory pin required for pairing")
		mode    = flag.String("conn", "mock", "Connection type; mock, gpio, replay")
		file    = flag.String("file", "", "Log file from which to replay packets")
		port    = flag.String("port", "P8_07", "GPIO port; default P8_07")
		timeout = flag.Int("timeout", 120, "Timeout in seconds until accessories are not reachable")
	)

	flag.Parse()
	sensors = map[string]*hkuvr1611.Sensor{}

	info := InfoForAccessoryName("UVR1611")
	uvrAccessory = accessory.New(info, accessory.TypeBridge)

	timer_duration := time.Duration(*timeout) * time.Second
	timer = time.AfterFunc(timer_duration, func() {
		log.Println("[INFO] Not Reachable")
		if transport != nil {
			sensors = map[string]*hkuvr1611.Sensor{}
			transport.Stop()
			transport = nil
		}
	})

	var conn Connection
	callback := func(packet uvr1611.Packet) {
		sensors := HandlePacket(packet)
		if transport == nil {
			config := hap.Config{Pin: *pin}
			if t, err := hap.NewIPTransport(config, uvrAccessory, sensors...); err != nil {
				log.Fatal(err)
			} else {
				go func() {
					t.Start()
				}()
				transport = t
			}
		}
		timer.Reset(timer_duration)
	}

	switch *mode {
	case "mock":
		conn = mock.NewConnection(callback)
	case "replay":
		conn = mock.NewReplayConnection(*file, callback)
	case "gpio":
		conn = gpio.NewConnection(*port, callback)
	default:
		log.Fatal("Incorrect -conn flag")
	}

	hap.OnTermination(func() {
		if transport != nil {
			transport.Stop()
		}
		conn.Close()
		timer.Stop()
		os.Exit(1)
	})

	select {}
}