| @@ -160,7 +160,7 @@ eventLoop: | |||||
| continue | continue | ||||
| } | } | ||||
| if err := db.Updates(&model.Tracker{ID: id, Battery: msg.Battery}).Error; err != nil { | |||||
| if err := db.Updates(&model.Tracker{ID: id, Battery: msg.Battery, Temperature: msg.Temperature}).Error; err != nil { | |||||
| fmt.Printf("Error in saving decoder event for beacon: %s\n", id) | fmt.Printf("Error in saving decoder event for beacon: %s\n", id) | ||||
| continue | continue | ||||
| } | } | ||||
| @@ -50,10 +50,10 @@ func UpdateDB(db *gorm.DB, ctx context.Context, cfg *config.Config, writer *kafk | |||||
| syncTable(db, gateways) | syncTable(db, gateways) | ||||
| } | } | ||||
| if tracks, err := GetTracks(token, client); err == nil { | |||||
| fmt.Printf("Tracks: %+v\n", tracks) | |||||
| syncTable(db, tracks) | |||||
| } | |||||
| // if tracks, err := GetTracks(token, client); err == nil { | |||||
| // fmt.Printf("Tracks: %+v\n", tracks) | |||||
| // syncTable(db, tracks) | |||||
| // } | |||||
| if zones, err := GetZones(token, client); err == nil { | if zones, err := GetZones(token, client); err == nil { | ||||
| syncTable(db, zones) | syncTable(db, zones) | ||||
| @@ -1,18 +1,20 @@ | |||||
| package model | package model | ||||
| type Tracker struct { | type Tracker struct { | ||||
| ID string `json:"id" gorm:"primaryKey"` | |||||
| Name string `json:"name"` | |||||
| MAC string `json:"mac"` | |||||
| Status string `json:"status"` | |||||
| Model string `json:"model"` | |||||
| Position string `json:"position"` | |||||
| Notes string `json:"notes"` | |||||
| X float32 `json:"x"` | |||||
| Y float32 `json:"y"` | |||||
| Floor string `json:"floor"` | |||||
| Building string `json:"building"` | |||||
| Location string `json:"location"` | |||||
| Distance float64 `json:"distance"` | |||||
| Battery uint32 `json:"battery"` | |||||
| ID string `json:"id" gorm:"primaryKey"` | |||||
| Name string `json:"name"` | |||||
| MAC string `json:"mac"` | |||||
| Status string `json:"status"` | |||||
| Model string `json:"model"` | |||||
| Position string `json:"position"` | |||||
| Notes string `json:"notes"` | |||||
| X float32 `json:"x"` | |||||
| Y float32 `json:"y"` | |||||
| Floor string `json:"floor"` | |||||
| Building string `json:"building"` | |||||
| Location string `json:"location"` | |||||
| Distance float64 `json:"distance"` | |||||
| Battery uint32 `json:"battery"` | |||||
| BatteryThreshold uint32 `json:"batteryThreshold"` | |||||
| Temperature uint16 `json:"temperature"` | |||||
| } | } | ||||
| @@ -35,12 +35,6 @@ type BeaconMetric struct { | |||||
| Timestamp int64 | Timestamp int64 | ||||
| } | } | ||||
| // Location defines a physical location and synchronization control. | |||||
| type Location struct { | |||||
| Name string | |||||
| Lock sync.RWMutex | |||||
| } | |||||
| // HTTPLocation describes a beacon's state as served over HTTP. | // HTTPLocation describes a beacon's state as served over HTTP. | ||||
| type HTTPLocation struct { | type HTTPLocation struct { | ||||
| Method string `json:"method"` | Method string `json:"method"` | ||||
| @@ -51,17 +45,6 @@ type HTTPLocation struct { | |||||
| LastSeen int64 `json:"last_seen"` | LastSeen int64 `json:"last_seen"` | ||||
| } | } | ||||
| // LocationChange defines a change event for a beacon's detected location. | |||||
| type LocationChange struct { | |||||
| Method string `json:"method"` | |||||
| BeaconRef Beacon `json:"beacon_info"` | |||||
| Name string `json:"name"` | |||||
| BeaconName string `json:"beacon_name"` | |||||
| PreviousLocation string `json:"previous_location"` | |||||
| NewLocation string `json:"new_location"` | |||||
| Timestamp int64 `json:"timestamp"` | |||||
| } | |||||
| // Beacon holds all relevant information about a tracked beacon device. | // Beacon holds all relevant information about a tracked beacon device. | ||||
| type Beacon struct { | type Beacon struct { | ||||
| Name string `json:"name"` | Name string `json:"name"` | ||||
| @@ -136,12 +119,6 @@ type BeaconEventList struct { | |||||
| Lock sync.RWMutex | Lock sync.RWMutex | ||||
| } | } | ||||
| // LocationsList holds all known locations with concurrency protection. | |||||
| type LocationsList struct { | |||||
| Locations map[string]Location | |||||
| Lock sync.RWMutex | |||||
| } | |||||
| // RawReading represents an incoming raw sensor reading. | // RawReading represents an incoming raw sensor reading. | ||||
| type RawReading struct { | type RawReading struct { | ||||
| Timestamp string `json:"timestamp"` | Timestamp string `json:"timestamp"` | ||||
| @@ -151,11 +128,6 @@ type RawReading struct { | |||||
| RawData string `json:"rawData"` | RawData string `json:"rawData"` | ||||
| } | } | ||||
| type LatestBeaconsList struct { | |||||
| LatestList map[string]Beacon | |||||
| Lock sync.RWMutex | |||||
| } | |||||
| type ApiUpdate struct { | type ApiUpdate struct { | ||||
| Method string | Method string | ||||
| ID string | ID string | ||||
| @@ -25,6 +25,11 @@ func LocationToBeaconService(msg model.HTTPLocation, db *gorm.DB, writer *kafka. | |||||
| return | return | ||||
| } | } | ||||
| var tracker model.Tracker | |||||
| if err := db.Where("id = ?", msg.ID).Find(&tracker).Error; err != nil { | |||||
| return | |||||
| } | |||||
| var allowedZones []string | var allowedZones []string | ||||
| for _, z := range zones { | for _, z := range zones { | ||||
| allowedZones = append(allowedZones, z.ZoneList...) | allowedZones = append(allowedZones, z.ZoneList...) | ||||
| @@ -55,12 +60,13 @@ func LocationToBeaconService(msg model.HTTPLocation, db *gorm.DB, writer *kafka. | |||||
| } | } | ||||
| } | } | ||||
| if err := db.Create(&model.Tracks{UUID: msg.ID, Timestamp: time.Now(), Gateway: gw.ID, GatewayMac: gw.MAC, Tracker: msg.ID}).Error; err != nil { | |||||
| // 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 { | |||||
| fmt.Println("Error in saving distance for beacon: ", err) | fmt.Println("Error in saving distance for beacon: ", err) | ||||
| return | return | ||||
| } | } | ||||
| if err := db.Updates(&model.Tracker{ID: msg.ID, Location: gw.ID, Distance: msg.Distance}).Error; err != nil { | |||||
| if err := db.Updates(&model.Tracker{ID: msg.ID, Location: gw.ID, Distance: msg.Distance, X: gw.X, Y: gw.Y}).Error; err != nil { | |||||
| fmt.Println("Error in saving distance for beacon: ", err) | fmt.Println("Error in saving distance for beacon: ", err) | ||||
| return | return | ||||
| } | } | ||||