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