Skip to content

Commit

Permalink
Issue #302: Make the ADR delay configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
gotthardp committed Mar 1, 2018
1 parent 33c519a commit 365f8e2
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/lorawan_mac_commands.erl
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,20 @@ handle_fopts0({Network, Profile, Node0}, Gateways, FOptsIn) ->
{MacConfirm, Node1} = handle_rxwin(FOptsIn, Network, Profile,
handle_adr(FOptsIn,
handle_status(FOptsIn, Network, Node0))),
{ok, FramesRequired} = application:get_env(lorawan_server, frames_before_adr),
% maintain quality statistics
{_, RxQ} = hd(Gateways),
{LastQs, AverageQs} = append_qs({RxQ#rxq.rssi, RxQ#rxq.lsnr}, Node1#node.last_qs),
{LastQs, AverageQs} = append_qs({RxQ#rxq.rssi, RxQ#rxq.lsnr}, Node1#node.last_qs, FramesRequired),
Node2 = auto_adr(Network, Profile, Node1#node{last_qs=LastQs, average_qs=AverageQs}),
{MacConfirm,
Node2#node{last_rx=calendar:universal_time(), gateways=Gateways}}.

append_qs(SNR, undefined) ->
append_qs(SNR, undefined, _Required) ->
{[SNR], undefined};
append_qs(SNR, LastQs) when length(LastQs) < 49 ->
append_qs(SNR, LastQs, Required) when length(LastQs) < Required ->
{[SNR | LastQs], undefined};
append_qs(SNR, LastQs) ->
LastQs2 = lists:sublist([SNR | LastQs], 50),
append_qs(SNR, LastQs, Required) ->
LastQs2 = lists:sublist([SNR | LastQs], Required),
AverageQs = average_qs(lists:unzip(LastQs2)),
{LastQs2, AverageQs}.

Expand Down
1 change: 1 addition & 0 deletions src/lorawan_server.app.src
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
{http_admin_listen, [{port, 8080}]},
{http_admin_credentials, {<<"admin">>, <<"admin">>}},
{http_content_security, <<"default-src * data: 'unsafe-inline' 'unsafe-eval';">>},
{frames_before_adr, 50},
{retained_rxframes, 50},
{websocket_timeout, 3600000}, % ms
% {sec, fcnt} after which the device status should be request
Expand Down

0 comments on commit 365f8e2

Please sign in to comment.