Exemplo n.º 1
0
func main() {
	if hueUsername != "" {
		pp, err := portal.GetPortal()
		if err != nil {
			glog.Errorf("Error: %s\n", err.Error())
		}
		hueHostname = pp[0].InternalIPAddress
		mux := http.NewServeMux()
		mux.HandleFunc("/api/1/group", groupV1)
		mux.HandleFunc("/api/1/status", statusV1)
		mux.HandleFunc("/tablet", tabletV1)
		mux.HandleFunc("/phone", phoneV1)
		mux.HandleFunc("/", staticAssets)
		fullHostname := fmt.Sprintf("%s:%d", hostname, port)
		startMessage := fmt.Sprintf("Starting local hued-web on %s\n", fullHostname)
		fmt.Println(startMessage)
		glog.Infof(startMessage)
		err = http.ListenAndServe(fullHostname, mux)
		if err != nil {
			glog.Errorf("Error: %s\n", err.Error())
		}
	} else {
		usage()
	}
}
Exemplo n.º 2
0
func main() {
	//hubHostname := ssdpDiscover()
	pp, err := portal.GetPortal()
	if err != nil {
		fmt.Println("Error: ", err)
		os.Exit(1)
	}
	hubHostname := pp[0].InternalIPAddress
	reader := bufio.NewReader(os.Stdin)
	fmt.Println("Please press the link button on your hub, then press [enter] to continue.")
	reader.ReadLine()
	fmt.Println("Please enter your application name:")
	data, _, _ := reader.ReadLine()
	applicationName := string(data)
	fmt.Println("Please enter your device type:")
	data1, _, _ := reader.ReadLine()
	deviceType := string(data1)
	c := configuration.New(hubHostname)
	response, err := c.CreateUser(applicationName, deviceType)
	if err != nil {
		fmt.Println("Error: ", err)
		os.Exit(1)
	}
	username := response[0].Success["username"].(string)
	fmt.Printf("Your username is %s\n", username)
}
Exemplo n.º 3
0
func main() {
	if apiKey != "" {
		pp, err := portal.GetPortal()
		if err != nil {
			fmt.Println("portal.GetPortal() ERROR: ", err)
			os.Exit(1)
		}
		ll := lights.New(pp[0].InternalIPAddress, apiKey)
		allLights, err := ll.GetAllLights()
		if err != nil {
			fmt.Println("lights.GetAllLights() ERROR: ", err)
			os.Exit(1)
		}
		fmt.Println()
		fmt.Println("Lights")
		fmt.Println("------")
		for _, l := range allLights {
			fmt.Printf("ID: %d Name: %s\n", l.ID, l.Name)
		}
		gg := groups.New(pp[0].InternalIPAddress, apiKey)
		allGroups, err := gg.GetAllGroups()
		if err != nil {
			fmt.Println("groups.GetAllGroups() ERROR: ", err)
			os.Exit(1)
		}
		fmt.Println()
		fmt.Println("Groups")
		fmt.Println("------")
		for _, g := range allGroups {
			fmt.Printf("ID: %d Name: %s\n", g.ID, g.Name)
			for _, lll := range g.Lights {
				fmt.Println("\t", lll)
			}
			previousState := g.Action
			_, err := gg.SetGroupState(g.ID, blinkState)
			if err != nil {
				fmt.Println("groups.SetGroupState() ERROR: ", err)
				os.Exit(1)
			}
			time.Sleep(time.Second * time.Duration(10))
			_, err = gg.SetGroupState(g.ID, previousState)
			if err != nil {
				fmt.Println("groups.SetGroupState() ERROR: ", err)
				os.Exit(1)
			}
		}
	} else {
		usage()
	}
}