fix(db): push data with partial mapping

Signed-off-by: Klagarge <remi@heredero.ch>
This commit is contained in:
2026-05-27 15:22:03 +02:00
parent bde8184ad1
commit 9776695228

View File

@@ -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