Skip to content

Commit

Permalink
remove some debugging
Browse files Browse the repository at this point in the history
  • Loading branch information
simeon-walker committed Oct 13, 2021
1 parent a8600ad commit a91ffff
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions ot2mqtt.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,37 +63,36 @@ func main() {
if token := client.Connect(); token.Wait() && token.Error() != nil {
panic(token.Error())
}
journal.Send(fmt.Sprintf("Connected to MQTT at %s", broker_url), journal.PriInfo, logvars)

mux := http.NewServeMux()
mux.HandleFunc("/pub", pubHandler(client))
mux.HandleFunc("/pub", httpHandler(client))

listen_address, _ := conf.String("http::listen_address")
journal.Send(fmt.Sprintf("http listener on %s", listen_address), journal.PriInfo, logvars)
err := http.ListenAndServe(listen_address, mux)
log.Fatal(err)
}

// func httpHandler(w http.ResponseWriter, r *http.Request) {
func pubHandler(client mqtt.Client) http.HandlerFunc {
func httpHandler(client mqtt.Client) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
// w.Write([]byte("Hi, from Service: " + name))

fmt.Printf("%s %s %s\n", r.Method, r.URL, r.Proto)
for k, v := range r.Header {
fmt.Printf("Header[%q] = %q\n", k, v)
}
fmt.Printf("Host = %q\n", r.Host)
fmt.Printf("RemoteAddr = %q\n", r.RemoteAddr)
// fmt.Printf("%s %s %s\n", r.Method, r.URL, r.Proto)
// for k, v := range r.Header {
// fmt.Printf("Header[%q] = %q\n", k, v)
// }
// fmt.Printf("Host = %q\n", r.Host)
// fmt.Printf("RemoteAddr = %q\n", r.RemoteAddr)

var ot_data OT_struct
err := json.NewDecoder(r.Body).Decode(&ot_data)
if err != nil {
fmt.Printf("JSON decode error: %s\n", err)
return
}
fmt.Printf("Topic: %s\n", ot_data.Topic)
fmt.Printf("Lat: %f\n", ot_data.Lat)
fmt.Printf("Lon: %f\n", ot_data.Lon)
fmt.Printf("Topic: %s\n", ot_data.Topic)

var jsonData []byte
jsonData, err = json.Marshal(ot_data)
Expand All @@ -105,7 +104,7 @@ func pubHandler(client mqtt.Client) http.HandlerFunc {
token := client.Publish(ot_data.Topic, 0, false, jsonData)
token.Wait()

fmt.Fprintf(w, "{}\n")
fmt.Fprintf(w, "[]\n")

}
}

0 comments on commit a91ffff

Please sign in to comment.