瀏覽代碼

fix: some errors, add prints, add log file for testing

chore/proposed-structure
Blaz Smehov 1 月之前
父節點
當前提交
0885f51815
共有 4 個文件被更改,包括 9 次插入14 次删除
  1. +1
    -2
      cmd/presenSe/presense.go
  2. +2
    -2
      internal/pkg/config/config.go
  3. +0
    -6
      internal/pkg/httpserver/server.go
  4. +6
    -4
      internal/pkg/mqtt_client/processor.go

+ 1
- 2
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


+ 2
- 2
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"),


+ 0
- 6
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()


+ 6
- 4
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
}

Loading…
取消
儲存