From 99ec3ca85d686a19deb226a791f13adca1537eb7 Mon Sep 17 00:00:00 2001 From: Vlad Vitan <23100181+vlasebian@users.noreply.github.com> Date: Mon, 3 Mar 2025 15:35:15 +0200 Subject: [PATCH] as: Append device attributes to service data uplink --- pkg/applicationserver/applicationserver.go | 32 +++++++++++++++------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/pkg/applicationserver/applicationserver.go b/pkg/applicationserver/applicationserver.go index 48aeeb306c..15c420934d 100644 --- a/pkg/applicationserver/applicationserver.go +++ b/pkg/applicationserver/applicationserver.go @@ -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 } @@ -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 @@ -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