diff --git a/cmd/presenSe/presense.go b/cmd/presenSe/presense.go index 8239cf7..f3f0e7c 100644 --- a/cmd/presenSe/presense.go +++ b/cmd/presenSe/presense.go @@ -48,8 +48,6 @@ func main() { Network: "tcp", Address: cfg.MQTTHost, ClientID: []byte(cfg.MQTTClientID), - // UserName: nil, - // Password: nil, UserName: []byte(cfg.MQTTUser), Password: []byte(cfg.MQTTPass), }) @@ -92,6 +90,7 @@ func main() { msgStr := string(message) t := strings.Split(string(topicName), "/") hostname := t[1] + fmt.Println("hostname: ", hostname) if strings.HasPrefix(msgStr, "[") { var readings []model.RawReading diff --git a/internal/pkg/config/config.go b/internal/pkg/config/config.go index f797cbf..e5daa87 100644 --- a/internal/pkg/config/config.go +++ b/internal/pkg/config/config.go @@ -22,8 +22,8 @@ func getEnv(key, def string) string { func Load() *Config { return &Config{ - HTTPAddr: getEnv("HTTP_HOST_PATH", "0.0.0.0:8080"), - WSAddr: getEnv("HTTPWS_HOST_PATH", "0.0.0.0:8088"), + HTTPAddr: getEnv("HTTP_HOST_PATH", "0.0.0.0:1902"), + WSAddr: getEnv("HTTPWS_HOST_PATH", "0.0.0.0:1922"), MQTTHost: getEnv("MQTT_HOST", "localhost:1883"), MQTTUser: getEnv("MQTT_USERNAME", "chesnek"), MQTTPass: getEnv("MQTT_PASSWORD", "chesnek"), diff --git a/internal/pkg/httpserver/server.go b/internal/pkg/httpserver/server.go index e39c2e6..f6f9f12 100644 --- a/internal/pkg/httpserver/server.go +++ b/internal/pkg/httpserver/server.go @@ -71,16 +71,10 @@ func StartHTTPServer(addr string, ctx *model.AppContext) { go handleMessages(ctx.Clients, &ctx.Broadcast) - go func() { - log.Fatal(http.ListenAndServe(addr, nil)) - }() - http.ListenAndServe(addr, handlers.CORS(originsOk, headersOk, methodsOk)(r)) } -// TODO: rather add defer to unlock the files - func resultsHandler(httpResults *model.HTTPResultsList) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { httpResults.HTTPResultsLock.Lock() diff --git a/internal/pkg/mqtt_client/processor.go b/internal/pkg/mqtt_client/processor.go index 3a8d553..83ee83b 100644 --- a/internal/pkg/mqtt_client/processor.go +++ b/internal/pkg/mqtt_client/processor.go @@ -1,6 +1,7 @@ package mqtt_client import ( + "fmt" "log" "time" @@ -38,8 +39,8 @@ func processIncoming(incoming model.Incoming_json, cl *client.Client, ctx *model } }() - incoming = incomingBeaconFilter(incoming) // DONE - id := getBeaconID(incoming) // DONE + incoming = incomingBeaconFilter(incoming) + id := getBeaconID(incoming) now := time.Now().Unix() beacons := &ctx.Beacons @@ -52,10 +53,11 @@ func processIncoming(incoming model.Incoming_json, cl *client.Client, ctx *model beacon, ok := beacons.Beacons[id] if !ok { - updateLatestList(incoming, now, latestList) // DONE + fmt.Println("updating latest list") + updateLatestList(incoming, now, latestList) return } - + fmt.Println("updating beacon data") updateBeaconData(&beacon, incoming, now, cl, settings) beacons.Beacons[beacon.Beacon_id] = beacon }