cancel
Showing results for 
Search instead for 
Did you mean: 

STM32WL55, Issue with propagating to the M4 that there are no more free channels while trying to Join LoRa

IAnas.1
Associate II

Dear All,

I am developing an application and I have reached a point where the device is trying to join LoRa.

For testing purposes, the gateway is closed, so the device ends up consuming all the available bandwidth on all channels and it can no longer try to send a join request.

What I want is to have this message somehow communicated to the CM4, in order to accommodate this issue there.

What I have found so far is that the

LORAMAC_STATUS_DUTYCYCLE_RESTRICTED

Is propagated until the

LoRaMacMlmeRequest( MlmeReq_t* mlmeRequest)

found in CM0PLUS/Middlewares/Third_Party/LoRaWAN/LoRaMac.c.

I think that what I need to do is to somehow forward this information to the

MlmeConfirm( MlmeConfirm_t *mlmeConfirm )

I tried this:

LoRaMacStatus_t LoRaMacMlmeRequest( MlmeReq_t* mlmeRequest )
{
    LoRaMacStatus_t status = LORAMAC_STATUS_SERVICE_UNKNOWN;
    MlmeConfirmQueue_t queueElement;
    uint8_t macCmdPayload[2] = { 0x00, 0x00 };
 
    if( mlmeRequest == NULL )
    {
        return LORAMAC_STATUS_PARAMETER_INVALID;
    }
    if( LoRaMacIsBusy( ) == true )
    {
        return LORAMAC_STATUS_BUSY;
    }
    if( LoRaMacConfirmQueueIsFull( ) == true )
    {
        return LORAMAC_STATUS_BUSY;
    }
 
    if( LoRaMacConfirmQueueGetCnt( ) == 0 )
    {
        memset1( ( uint8_t* ) &MacCtx.MlmeConfirm, 0, sizeof( MacCtx.MlmeConfirm ) );
    }
    MacCtx.MlmeConfirm.Status = LORAMAC_EVENT_INFO_STATUS_ERROR;
 
    MacCtx.MacFlags.Bits.MlmeReq = 1;
    queueElement.Request = mlmeRequest->Type;
    queueElement.Status = LORAMAC_EVENT_INFO_STATUS_ERROR;
    queueElement.RestrictCommonReadyToHandle = false;
 
    switch( mlmeRequest->Type )
    {
        case MLME_JOIN:
        {
            if( ( MacCtx.MacState & LORAMAC_TX_DELAYED ) == LORAMAC_TX_DELAYED )
            {
                return LORAMAC_STATUS_BUSY;
            }
 
            ResetMacParameters( );
 
            Nvm.MacGroup1.ChannelsDatarate = RegionAlternateDr( Nvm.MacGroup2.Region, mlmeRequest->Req.Join.Datarate, ALTERNATE_DR );
 
            queueElement.Status = LORAMAC_EVENT_INFO_STATUS_JOIN_FAIL;
 
            status = SendReJoinReq( JOIN_REQ );
 
            if( status != LORAMAC_STATUS_OK )
            {
                LoRaMacConfirmQueueSetStatusCmn(LORAMAC_EVENT_INFO_STATUS_ERROR);
                queueElement.Status = LORAMAC_EVENT_INFO_STATUS_ERROR;
                // Revert back the previous datarate ( mainly used for US915 like regions )
                Nvm.MacGroup1.ChannelsDatarate = RegionAlternateDr( Nvm.MacGroup2.Region, mlmeRequest->Req.Join.Datarate, ALTERNATE_DR_RESTORE );
            }
            break;
        }
...
}

At the moment in the MlmeConfirm( MlmeConfirm_t *mlmeConfirm), I am only receiving:

LORAMAC_EVENT_INFO_STATUS_RX2_TIMEOUT

Any ideas or assistance?

2 REPLIES 2
Louis AUDOLY
ST Employee

Hello @IAnas.1​ ,

If you use STM32CubeFW_WL_V1.2.0, you have already access to this information in the lora_app.c file. At the end of the function SendTxData, you have a if condition :

else if (LORAMAC_HANDLER_DUTYCYCLE_RESTRICTED == status)

You could add to this condition :

else if ((LORAMAC_HANDLER_DUTYCYCLE_RESTRICTED == status) || (LORAMAC_HANDLER_NO_NETWORK_JOINED == status))

To include the case the device did not achieve to join the network, and avoid to call this function every time.

The case where you don't have any band where you cannot send any uplinks to channels is when you have the variable nextTxIn different from 0.

Otherwise it means you have the opportunity to send a new uplink.

I suggest you to not interact with the stack to avoid any unexpected behavior.

Have a good day

Hope it helps

Regards

Thank you very much for the answer @Louis AUDOLY​ .

I forgot to mention that I am using v.1.1.0 and an upgrade is not really an option at this point.