Skip to content

Commit

Permalink
start timer in the background
Browse files Browse the repository at this point in the history
and give browser feedback directly
  • Loading branch information
Bonko committed Mar 13, 2017
1 parent 30ddcc7 commit 65d765b
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ func main() {
fmt.Println("listening..")
// sleepTimer()
http.HandleFunc("/", rootHandler)
http.HandleFunc("/sleepTimer", sleepTimer)
http.HandleFunc("/sleepTimer", startSleepTimer)
if err := http.ListenAndServe(":9091", nil); err != nil {
log.Fatal("ListenAndServe: ", err)
}
Expand Down Expand Up @@ -43,14 +43,18 @@ func auth() *hue.Bridge {
return b
}

func sleepTimer(w http.ResponseWriter, r *http.Request) {
func startSleepTimer(w http.ResponseWriter, r *http.Request) {
go sleepTimer()
fmt.Fprintf(w, "Started sleepTimer")
}
func sleepTimer() {
b := auth()
nk, err := b.Lights().Get("Nachtkaestchen")
if err != nil {
log.Fatal(err)
}
brightness := uint8(255)
fmt.Fprintf(w, "Turning light on")
fmt.Println("Turning light on")
nk.On()
nk.Set(&hue.State{
Brightness: brightness,
Expand Down

0 comments on commit 65d765b

Please sign in to comment.