Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

as: Append device attributes to service data uplink (backport) #7530

Merged
merged 1 commit into from
Mar 5, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading