From 9776695228d85e5d59335f7c29c4c31826f949a5 Mon Sep 17 00:00:00 2001 From: Klagarge Date: Wed, 27 May 2026 15:22:03 +0200 Subject: [PATCH] fix(db): push data with partial mapping Signed-off-by: Klagarge --- db/src/main.go | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/db/src/main.go b/db/src/main.go index 67916e6..926bc59 100644 --- a/db/src/main.go +++ b/db/src/main.go @@ -122,24 +122,28 @@ func main() { campus, campusOk := mapping.GetCampus(gatewayID) room, roomOk := mapping.GetRoom(nodeID) - if !campusOk { - log.Printf("[Main] No mapping found for gateway=%s, dropping datapoint\n", gatewayID) - return - } - - if !roomOk { - log.Printf("[Main] No mapping found for gateway=%s, dropping datapoint\n", gatewayID) - return - } - batteryLevel := dp.GetValues().Battery log.Printf("[Main] Received gateway=%s node=%s -> campus=%s room=%s (Battery %d%%)\n", gatewayID, nodeID, campus, room, batteryLevel) - // Re-create the datapoint with campus/room tags for Influx - influxTags := []point.Topic{ - {Subject: "campus", Content: campus}, - {Subject: "room", Content: room}, - {Subject: "node", Content: nodeID}, + var influxTags []point.Topic + + if !campusOk { + log.Printf("[Main] No mapping found for gateway=%s\n", gatewayID) + influxTags = []point.Topic{ + {Subject: "node", Content: nodeID}, + } + } else if !roomOk { + log.Printf("[Main] No mapping found for gateway=%s\n", gatewayID) + influxTags = []point.Topic{ + {Subject: "campus", Content: campus}, + {Subject: "node", Content: nodeID}, + } + } else { + influxTags = []point.Topic{ + {Subject: "campus", Content: campus}, + {Subject: "room", Content: room}, + {Subject: "node", Content: nodeID}, + } } // If CO2PPM value is present and over 1000000000 delete the field