diff --git a/bridge b/bridge index 81c808d..45df21d 100755 Binary files a/bridge and b/bridge differ diff --git a/decoder b/decoder index c372479..34ca632 100755 Binary files a/decoder and b/decoder differ diff --git a/internal/app/bridge/app.go b/internal/app/bridge/app.go index 4c7a2e8..80aad07 100644 --- a/internal/app/bridge/app.go +++ b/internal/app/bridge/app.go @@ -3,6 +3,7 @@ package bridge import ( "context" "encoding/json" + "fmt" "log/slog" "sync" "time" @@ -96,6 +97,7 @@ func (a *BridgeApp) Run(ctx context.Context) { case msg := <-a.ChApi: switch msg.Method { case "POST": + fmt.Println("adding beacon to lookup", "mac", msg.MAC, "id", msg.ID) a.AppState.AddBeaconToLookup(msg.MAC, msg.ID) slog.Info("beacon added to lookup", "id", msg.ID) case "DELETE": diff --git a/internal/app/decoder/app.go b/internal/app/decoder/app.go index c822590..defc355 100644 --- a/internal/app/decoder/app.go +++ b/internal/app/decoder/app.go @@ -2,6 +2,7 @@ package decoder import ( "context" + "fmt" "log/slog" "sync" "time" @@ -71,7 +72,6 @@ func (a *DecoderApp) Run(ctx context.Context) { return case <-healthTicker.C: health, err := a.AppState.GetDecoderHealth(a.KafkaManager) - slog.Info("decoder health", "health", string(health)) if err != nil { slog.Error("getting decoder health", "err", err) continue @@ -84,6 +84,7 @@ func (a *DecoderApp) Run(ctx context.Context) { continue } case msg := <-a.ChRaw: + fmt.Println("msg: ", msg) decoder.ProcessIncoming(msg, a.AppState, a.KafkaManager.GetWriter("alertbeacons"), a.ParserRegistry) case msg := <-a.ChParser: switch msg.ID { diff --git a/internal/pkg/bridge/handler.go b/internal/pkg/bridge/handler.go index dcc5865..5b61488 100644 --- a/internal/pkg/bridge/handler.go +++ b/internal/pkg/bridge/handler.go @@ -3,6 +3,7 @@ package bridge import ( "context" "encoding/json" + "fmt" "log/slog" "strings" "time" @@ -13,15 +14,10 @@ import ( "github.com/segmentio/kafka-go" ) -// BeaconLookup provides MAC->ID lookup (e.g. AppState). -type BeaconLookup interface { - BeaconExists(mac string) (id string, ok bool) -} - // HandleMQTTMessage processes an MQTT message: parses JSON array of RawReading or CSV. // For JSON, converts each reading to BeaconAdvertisement and writes to the writer if MAC is in lookup. // Hostname is derived from topic (e.g. "publish_out/gateway1" -> "gateway1"). Safe if topic has no "/". -func HandleMQTTMessage(topic string, payload []byte, lookup BeaconLookup, writer *kafka.Writer) { +func HandleMQTTMessage(topic string, payload []byte, appState *appcontext.AppState, writer *kafka.Writer) { parts := strings.SplitN(topic, "/", 2) hostname := "" if len(parts) >= 2 { @@ -39,10 +35,11 @@ func HandleMQTTMessage(topic string, payload []byte, lookup BeaconLookup, writer if reading.Type == "Gateway" { continue } - id, ok := lookup.BeaconExists(reading.MAC) + id, ok := appState.BeaconExists(reading.MAC) if !ok { continue } + fmt.Println("beacon found: ", id) adv := appcontext.BeaconAdvertisement{ ID: id, Hostname: hostname, diff --git a/internal/pkg/decoder/process.go b/internal/pkg/decoder/process.go index f1e2e87..fdc2192 100644 --- a/internal/pkg/decoder/process.go +++ b/internal/pkg/decoder/process.go @@ -30,6 +30,8 @@ func DecodeBeacon(adv appcontext.BeaconAdvertisement, appState *appcontext.AppSt return nil } + fmt.Println("beacon: ", beacon) + b, err := hex.DecodeString(beacon) if err != nil { return err diff --git a/internal/pkg/service/beacon_service.go b/internal/pkg/service/beacon_service.go index ac07762..ae9d94f 100644 --- a/internal/pkg/service/beacon_service.go +++ b/internal/pkg/service/beacon_service.go @@ -18,7 +18,6 @@ import ( ) func findTracker(msg model.HTTPLocation, db *gorm.DB) (model.Tracker, error) { - fmt.Printf("Finding tracker for MAC: %s, ID: %s\n", msg.MAC, msg.ID) var tracker model.Tracker if msg.MAC != "" { if err := db.Where("mac = ?", strings.ToUpper(strings.ReplaceAll(msg.MAC, ":", ""))).Find(&tracker).Error; err != nil { diff --git a/location b/location index 09b3dc5..7326f36 100755 Binary files a/location and b/location differ diff --git a/server b/server index b3d430d..2b9d597 100755 Binary files a/server and b/server differ