Skip to content

Commit

Permalink
Fix rx delay
Browse files Browse the repository at this point in the history
  • Loading branch information
macpie committed Nov 29, 2023
1 parent f35ad44 commit cf5148c
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/device/router_device_worker.erl
Original file line number Diff line number Diff line change
Expand Up @@ -397,15 +397,20 @@ handle_cast(
[]
end,

BootstrappedMeta = lorawan_rxdelay:bootstrap(
maps:merge(
router_device:metadata(Device0),
router_device:metadata(APIDevice)
)
),
DeviceUpdates = [
{name, router_device:name(APIDevice)},
{dev_eui, router_device:dev_eui(APIDevice)},
{app_eui, router_device:app_eui(APIDevice)},
{devaddrs, DevAddrs},
{metadata,
maps:merge(
lorawan_rxdelay:maybe_update(APIDevice, Device0),
router_device:metadata(APIDevice)
lorawan_rxdelay:maybe_update(
APIDevice, router_device:metadata(BootstrappedMeta, Device0)
)},
{is_active, IsActive}
],
Expand Down Expand Up @@ -1328,16 +1333,14 @@ handle_join(
{ok, DevAddr} = router_device_devaddr:allocate(Device0, PubKeyBin),

%% don't set the join nonce here yet as we have not chosen the best join request yet
{AppEUI, DevEUI} = {lorawan_utils:reverse(AppEUI0), lorawan_utils:reverse(DevEUI0)},

Region = dualplan_region(Packet, HotspotRegion),
DRIdx = packet_datarate_index(Region, Packet),

NewKeys = [{NwkSKey, AppSKey} | router_device:keys(Device0)],
NewDevaddrs = [DevAddr | router_device:devaddrs(Device0)],

DeviceUpdates = [
{dev_eui, DevEUI},
{app_eui, AppEUI},
{keys, NewKeys},
{devaddrs, NewDevaddrs},
{fcnt, undefined},
Expand All @@ -1353,6 +1356,7 @@ handle_join(

ok = handle_join_skf(NewKeys, NewDevaddrs, MultiBuy),

{AppEUI, DevEUI} = {lorawan_utils:reverse(AppEUI0), lorawan_utils:reverse(DevEUI0)},
lager:debug(
"Join DevEUI ~s with AppEUI ~s tried to join with nonce ~p region ~p via ~s",
[
Expand Down

0 comments on commit cf5148c

Please sign in to comment.