Skip to content

Commit

Permalink
Merge pull request #7524 from TheThingsNetwork/feat/service-data-dev-…
Browse files Browse the repository at this point in the history
…attr

as: Append device attributes to service data uplink
  • Loading branch information
vlasebian authored Mar 3, 2025
2 parents 22b921c + 96c38d4 commit 516c787
Showing 1 changed file with 22 additions and 10 deletions.
32 changes: 22 additions & 10 deletions pkg/applicationserver/applicationserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -924,7 +924,7 @@ func (as *ApplicationServer) handleUp(ctx context.Context, up *ttnpb.Application
case *ttnpb.ApplicationUp_LocationSolved:
return true, as.handleLocationSolved(ctx, up.EndDeviceIds, p.LocationSolved, link)
case *ttnpb.ApplicationUp_ServiceData:
return true, nil
return true, as.handleServiceData(ctx, up.EndDeviceIds, p.ServiceData)
default:
return false, nil
}
Expand Down Expand Up @@ -1488,18 +1488,12 @@ func (as *ApplicationServer) handleDownlinkNack(
return err
}

if _, err = as.endDeviceRegistry.Set(ctx, ids, []string{"attributes"},
func(entity *ttnpb.EndDevice) (*ttnpb.EndDevice, []string, error) {
if entity == nil {
return nil, nil, errDeviceNotFound.WithAttributes("device_uid", unique.ID(ctx, ids))
}
msg.Attributes = entity.Attributes
return entity, []string{""}, nil
},
); err != nil {
if entity, err := as.endDeviceRegistry.Get(ctx, ids, []string{"attributes"}); err != nil {
log.FromContext(ctx).WithError(err).Warn(
"Failed to retrieve end device attributes on downlink nack",
)
} else {
msg.Attributes = entity.Attributes
}

return nil
Expand Down Expand Up @@ -1567,6 +1561,24 @@ func (as *ApplicationServer) decryptDownlinkMessage(ctx context.Context, ids *tt
return as.decryptAndDecodeDownlink(ctx, dev, msg, link.DefaultFormatters)
}

func (as *ApplicationServer) handleServiceData(
ctx context.Context,
ids *ttnpb.EndDeviceIdentifiers,
msg *ttnpb.ApplicationServiceData,
) error {
defer trace.StartRegion(ctx, "handle service data").End()

if entity, err := as.endDeviceRegistry.Get(ctx, ids, []string{"attributes"}); err != nil {
log.FromContext(ctx).WithError(err).Warn(
"Failed to retrieve end device attributes on downlink message",
)
} else {
msg.Attributes = entity.Attributes
}

return nil
}

// GetConfig returns the Application Server config based on the context.
func (as *ApplicationServer) GetConfig(ctx context.Context) (*Config, error) {
c := *as.config
Expand Down

0 comments on commit 516c787

Please sign in to comment.