diff --git a/internal/pkg/application/functions/transform.go b/internal/pkg/application/functions/transform.go index 1047ac8..e6a0732 100644 --- a/internal/pkg/application/functions/transform.go +++ b/internal/pkg/application/functions/transform.go @@ -13,6 +13,7 @@ import ( "github.com/diwise/iot-core/internal/pkg/application/functions/timers" "github.com/diwise/iot-core/pkg/messaging/events" "github.com/diwise/messaging-golang/pkg/messaging" + "github.com/diwise/senml" "github.com/diwise/service-chassis/pkg/infrastructure/o11y/logging" lwm2m "github.com/diwise/iot-agent/pkg/lwm2m" @@ -25,6 +26,7 @@ func Transform(ctx context.Context, msgctx messaging.MsgContext, msg messaging.I DeviceID string `json:"deviceID"` Type string `json:"type"` SubType string `json:"subType"` + Location *location `json:"location,omitempty"` Tenant string `json:"tenant"` Timestamp time.Time `json:"timestamp"` @@ -60,6 +62,21 @@ func Transform(ctx context.Context, msgctx messaging.MsgContext, msg messaging.I pub := func(obj lwm2m.Lwm2mObject, tenant string) error { log.Debug(fmt.Sprintf("pub transformed message, id: %s, urn: %s", obj.ID(), obj.ObjectURN())) mt := events.NewMessageTransformed(lwm2m.ToPack(obj), tenant) + + if f.Location != nil { + mt.Pack = append(mt.Pack, senml.Record{ + Unit: senml.UnitLat, + Value: &f.Location.Latitude, + }) + } + + if f.Location != nil { + mt.Pack = append(mt.Pack, senml.Record{ + Unit: senml.UnitLon, + Value: &f.Location.Longitude, + }) + } + return msgctx.PublishOnTopic(ctx, mt) }