mirror of
https://github.com/Lomanic/presence-button-web
synced 2024-11-23 22:17:30 +00:00
Compare commits
No commits in common. "4320babfa68cfe792a49a33ac7df49097630f3fa" and "d3d1b1676cf8220f55ce43ad767eb2e8791a314a" have entirely different histories.
4320babfa6
...
d3d1b1676c
13
main.go
13
main.go
@ -198,18 +198,15 @@ func imgHandler(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
func statusHandler(w http.ResponseWriter, r *http.Request) {
|
||||
user, pass, ok := r.BasicAuth()
|
||||
fmt.Printf("status notification by button... ")
|
||||
fmt.Println("user", user, "pass", pass, "ok", ok)
|
||||
if !ok || user != config.ESPUSERNAME || pass != config.ESPPASSWORD {
|
||||
fmt.Printf("bad authentication: user:%v pass:%v\n", user, pass)
|
||||
w.Header().Set("WWW-Authenticate", `Basic realm="Authentication required"`)
|
||||
http.Error(w, "Authentication required", 401)
|
||||
return
|
||||
}
|
||||
q := r.URL.Query()
|
||||
fuzIsOpen := q.Get("fuzisopen") == "1"
|
||||
fmt.Printf("button pushed: %v\n", fuzIsOpen)
|
||||
status.FuzIsOpen = fuzIsOpen
|
||||
status.LastSeenAsOpen = fuzIsOpen
|
||||
status.FuzIsOpen = q.Get("fuzisopen") == "1"
|
||||
status.LastSeenAsOpen = q.Get("fuzisopen") == "1"
|
||||
status.LastSeen = time.Now()
|
||||
fmt.Fprintf(w, "OK")
|
||||
|
||||
@ -247,7 +244,7 @@ func syncMatrix() {
|
||||
go func() { // set online status every 15 seconds
|
||||
for {
|
||||
if err := matrix.SetStatus("online", "up and running"); err != nil {
|
||||
fmt.Println("error setting matrix status:", err)
|
||||
panic(fmt.Sprintf("error setting matrix status: %s", err))
|
||||
}
|
||||
time.Sleep(15 * time.Second)
|
||||
}
|
||||
@ -255,7 +252,7 @@ func syncMatrix() {
|
||||
|
||||
for {
|
||||
if err := matrix.Sync(); err != nil {
|
||||
fmt.Println("error syncing with matrix:", err)
|
||||
fmt.Println("Sync() returned ", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user