Skip to content

Commit

Permalink
Merge pull request #93 from diwise/develop
Browse files Browse the repository at this point in the history
add location to transformed messages
  • Loading branch information
nordbergmikael authored Aug 20, 2024
2 parents 5610700 + 5f98470 commit 1c1c695
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions internal/pkg/application/functions/transform.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"`

Expand Down Expand Up @@ -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)
}

Expand Down

0 comments on commit 1c1c695

Please sign in to comment.