Skip to content

Store and forward delay overflow if offline #126

@benninger-mm

Description

@benninger-mm

I reported an issue in LBM v4.5.0 that there are frequent store and forward uplinks if offline, see Issue #66. I realized that you fixed this issue in LBM v4.8.0, thanks a lot. Unfortunately, we just found that there is a bug included in the solution that I proposed and that is now part of LBM v4.8.0.

The issue is in the function store_and_forward_flash_compute_next_delay_s which is implemented here. The problem is that sending_try_cpt grows continuously when a device is offline and the computation of delay_s overflows when sending_try_cpt gets bigger than 26.

In other words, uint32_t delay_s = ( 1 << ctx->sending_try_cpt ) * 60 overflows if ctx->sending_try_cpt is bigger than 26. The reason being that 2^26 * 60 ~ 2^32.

The observed behavior in the field was that the devices sent uplinks almost every minute if the device was offline for more than 26h which effectively drained the battery of the devices. I fixed this in the following way:

static uint32_t store_and_forward_flash_compute_next_delay_s( store_and_forward_flash_t* ctx )
{
    if( ctx->sending_try_cpt == 0 )
    {
        return 0;
    }
    // Exponential backoff (2^sending_try_cpt * 60s), avoid overflowing uint32_t (2^26*60 ~ 2^32)
    uint32_t delay_s = 0;
    if ( ctx->sending_try_cpt <= 26 )
    {
        delay_s = ( 1 << ctx->sending_try_cpt ) * 60;
    }
    if( ctx->sending_try_cpt > 26 || delay_s > STORE_AND_FORWARD_DELAY_MAX_S ) 
    {
        delay_s = STORE_AND_FORWARD_DELAY_MAX_S;
    }
    return delay_s + smtc_modem_hal_get_random_nb_in_range( 0, 60 );
}

Sorry for the trouble and I hope this makes it to the next LBM release.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions