From 23208dc32df92222db5c75e9d54166f574dfa7e8 Mon Sep 17 00:00:00 2001 From: blazSmehov Date: Tue, 20 Jan 2026 15:49:06 +0100 Subject: [PATCH] chore: add RSSI to location event and persist in tracks --- cmd/location/main.go | 1 + internal/pkg/model/tracks.go | 2 +- internal/pkg/model/types.go | 1 + internal/pkg/service/beacon_service.go | 2 +- 4 files changed, 4 insertions(+), 2 deletions(-) diff --git a/cmd/location/main.go b/cmd/location/main.go index 26d6d77..47ab6ae 100644 --- a/cmd/location/main.go +++ b/cmd/location/main.go @@ -129,6 +129,7 @@ func getLikelyLocations(appState *appcontext.AppState, writer *kafka.Writer) { r.Distance = beacon.BeaconMetrics[mSize-1].Distance r.Location = bestLocName r.LastSeen = beacon.BeaconMetrics[mSize-1].Timestamp + r.RSSI = beacon.BeaconMetrics[mSize-1].RSSI if beacon.LocationConfidence == settings.LocationConfidence && beacon.PreviousConfidentLocation != bestLocName { beacon.LocationConfidence = 0 diff --git a/internal/pkg/model/tracks.go b/internal/pkg/model/tracks.go index 55f537e..f4aa1e8 100644 --- a/internal/pkg/model/tracks.go +++ b/internal/pkg/model/tracks.go @@ -15,6 +15,6 @@ type Tracks struct { Subject string `json:"subject"` SubjectName string `json:"subjectName"` Floor string `json:"floor"` - Signal int `json:"signal"` + Signal int64 `json:"signal"` Building string `json:"building"` } diff --git a/internal/pkg/model/types.go b/internal/pkg/model/types.go index 0062035..b7b4fba 100644 --- a/internal/pkg/model/types.go +++ b/internal/pkg/model/types.go @@ -43,6 +43,7 @@ type HTTPLocation struct { ID string `json:"id"` Location string `json:"location"` LastSeen int64 `json:"last_seen"` + RSSI int64 `json:"rssi"` } // Beacon holds all relevant information about a tracked beacon device. diff --git a/internal/pkg/service/beacon_service.go b/internal/pkg/service/beacon_service.go index e005bf6..a022e1f 100644 --- a/internal/pkg/service/beacon_service.go +++ b/internal/pkg/service/beacon_service.go @@ -61,7 +61,7 @@ func LocationToBeaconService(msg model.HTTPLocation, db *gorm.DB, writer *kafka. } // status, subject, subject name? - if err := db.Create(&model.Tracks{UUID: msg.ID, Timestamp: time.Now(), Gateway: gw.ID, GatewayMac: gw.MAC, Tracker: msg.ID, Floor: gw.Floor, Building: gw.Building, TrackerMac: tracker.MAC}).Error; err != nil { + if err := db.Create(&model.Tracks{UUID: msg.ID, Timestamp: time.Now(), Gateway: gw.ID, GatewayMac: gw.MAC, Tracker: msg.ID, Floor: gw.Floor, Building: gw.Building, TrackerMac: tracker.MAC, Signal: msg.RSSI}).Error; err != nil { fmt.Println("Error in saving distance for beacon: ", err) return }