Skip to content

Commit c101d88

Browse files
author
Hasnain Virk
committed
Retransmission back-off correction for re-join
Previously, we had been initializing our time base in LoRaMac::initialize() and if the device was not power-cycled, that initial time was always being used in the calculation of the elapsed time. This introduced a bug mentioned in issue #8921. The bug made the re-join attempt of a device after a week or so to use wrong back-off because in calculate_backoff() API we pass the elapsed time. If we do not set the initial time while trying to connect, the elapsed time will include previous session time as well and the device will think it has spend tha much time and will apply harsher duty cycle back off.
1 parent 51143ea commit c101d88

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

features/lorawan/lorastack/mac/LoRaMac.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1229,6 +1229,7 @@ void LoRaMac::reset_mac_parameters(void)
12291229

12301230
_params.sys_params.max_duty_cycle = 0;
12311231
_params.sys_params.aggregated_duty_cycle = 1;
1232+
_params.timers.mac_init_time = get_current_time();
12321233

12331234
_mac_commands.clear_command_buffer();
12341235
_mac_commands.clear_repeat_buffer();
@@ -1448,6 +1449,8 @@ void LoRaMac::setup_link_check_request()
14481449

14491450
lorawan_status_t LoRaMac::prepare_join(const lorawan_connect_t *params, bool is_otaa)
14501451
{
1452+
reset_mac_parameters();
1453+
14511454
if (params) {
14521455
if (is_otaa) {
14531456
if ((params->connection_u.otaa.dev_eui == NULL)
@@ -1468,8 +1471,6 @@ lorawan_status_t LoRaMac::prepare_join(const lorawan_connect_t *params, bool is_
14681471
// Reset variable JoinRequestTrials
14691472
_params.join_request_trial_counter = 0;
14701473

1471-
reset_mac_parameters();
1472-
14731474
_params.sys_params.channel_data_rate =
14741475
_lora_phy->get_alternate_DR(_params.join_request_trial_counter + 1);
14751476
} else {
@@ -1503,8 +1504,6 @@ lorawan_status_t LoRaMac::prepare_join(const lorawan_connect_t *params, bool is_
15031504
// Reset variable JoinRequestTrials
15041505
_params.join_request_trial_counter = 0;
15051506

1506-
reset_mac_parameters();
1507-
15081507
_params.sys_params.channel_data_rate =
15091508
_lora_phy->get_alternate_DR(_params.join_request_trial_counter + 1);
15101509

@@ -1812,8 +1811,6 @@ lorawan_status_t LoRaMac::initialize(EventQueue *queue,
18121811
_lora_time.init(_params.timers.ack_timeout_timer,
18131812
mbed::callback(this, &LoRaMac::on_ack_timeout_timer_event));
18141813

1815-
_params.timers.mac_init_time = _lora_time.get_current_time();
1816-
18171814
_params.sys_params.adr_on = MBED_CONF_LORA_ADR_ON;
18181815
_params.sys_params.channel_data_rate = _lora_phy->get_default_max_tx_datarate();
18191816

0 commit comments

Comments
 (0)