This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Transmit power with OpenThread.

Hi, I tested "Simple_coap_client" and "simple_coap_server" on NRF52840 using Threading SDK.

I want to change the transmit power, so I used "otPlatRadioSetTransmitPower ()".

The power consumption and communication distance were measured, but there was no change.

This is my code.

How do I use "otPlatRadioSetTransmitPower ()"?

I'm sorry in poor English.

void thread_coap_utils_multicast_light_request_send(uint8_t                         command,
                                                    thread_coap_utils_multicast_scope_t scope)
{
    NRF_LOG_INFO("thread_coap_utils_multicast_light_request_send");

    otError       error = OT_ERROR_NONE;
    otMessage   * p_request;
    otMessageInfo message_info;
    const char  * p_scope = NULL;
    otInstance  * p_instance = thread_ot_instance_get();

    int8_t TX_power = 8;

    char *send_data = "hello world";

    do
    {
        p_request = otCoapNewMessage(p_instance, NULL);
        if (p_request == NULL)
        {
            NRF_LOG_INFO("Failed to allocate message for CoAP Request\r\n");
            break;
        }

        otCoapMessageInit(p_request, OT_COAP_TYPE_NON_CONFIRMABLE, OT_COAP_CODE_PUT);

        error = otCoapMessageAppendUriPathOptions(p_request, "light");
        ASSERT(error == OT_ERROR_NONE);

        error = otCoapMessageSetPayloadMarker(p_request);
        ASSERT(error == OT_ERROR_NONE);

        error = otMessageAppend(p_request, send_data, 12);
        //NRF_LOG_INFO("send_data : %s", send_data);
       

        if (error != OT_ERROR_NONE)
        {
            break;
        }

        switch (scope)
        {
        case THREAD_COAP_UTILS_MULTICAST_LINK_LOCAL:
            p_scope = "ff02::1";
            break;

        case THREAD_COAP_UTILS_MULTICAST_REALM_LOCAL:
            p_scope = "ff03::1";
            break;

        default:
            ASSERT(false);
        }

        memset(&message_info, 0, sizeof(message_info));
        message_info.mPeerPort = OT_DEFAULT_COAP_PORT;

        error = otIp6AddressFromString(p_scope, &message_info.mPeerAddr);
        ASSERT(error == OT_ERROR_NONE);
        
       
        error = otPlatRadioSetTransmitPower(p_instance, TX_power);
        NRF_LOG_INFO("error: %d", error);
        
        
        error = otCoapSendRequest(p_instance, p_request, &message_info, NULL, NULL);
    } while (false);

    if (error != OT_ERROR_NONE && p_request != NULL)
    {
        NRF_LOG_INFO("Failed to send CoAP Request: %d\r\n", error);
        otMessageFree(p_request);
    }
}

  • Hello,

    What is the error after the call to otPlatRadioSetTransmitPower?

    Can you try to call otPlatRadioGetTransmitPower() a while after calling otPlatRadioSetTransmitPower? Does it read out the same as you set it to?

    Perhaps the TX power was alreadu 8 before you set it to 8?

    Remember that the TX power is only affecting the radio when you transmit, and that the nRF use the radio in 99+% of the time, so I don't think you will be able to see the increase in the current consumption, depending on how you measure it.

    I believe the otPlatRadioGetTransmitPower() is a better way to see whether the TX power was changed or not.

    Best regards,

    Edvin

  • Hello,

    The error after calling otPlatRadioSetTransmitPower is 0. So it may be successful.

    I tried otPlatRadioGetTransmitPower() as per your advice.

    However, an error (7) is output. 

    This error seems to mean OT_ERROR_INVALID_ARGS, but I don't know how to deal with it.

    This is my code.

     I'm sorry in poor English.

    void thread_coap_utils_multicast_light_request_send(uint8_t                         command,
                                                        thread_coap_utils_multicast_scope_t scope)
    {
        NRF_LOG_INFO("thread_coap_utils_multicast_light_request_send");
    
        otError       error = OT_ERROR_NONE;
        otMessage   * p_request;
        otMessageInfo message_info;
        const char  * p_scope = NULL;
        otInstance  * p_instance = thread_ot_instance_get();
    
        int8_t  TX_power = 8;
        int8_t  *get_TX_power = 0;
    
        char *send_data = "hello world";
    
        do
        {
            p_request = otCoapNewMessage(p_instance, NULL);
            if (p_request == NULL)
            {
                NRF_LOG_INFO("Failed to allocate message for CoAP Request\r\n");
                break;
            }
    
            otCoapMessageInit(p_request, OT_COAP_TYPE_NON_CONFIRMABLE, OT_COAP_CODE_PUT);
    
            error = otCoapMessageAppendUriPathOptions(p_request, "light");
            ASSERT(error == OT_ERROR_NONE);
    
            error = otCoapMessageSetPayloadMarker(p_request);
            ASSERT(error == OT_ERROR_NONE);
    
            error = otMessageAppend(p_request, send_data, 12);
            //NRF_LOG_INFO("send_data : %s", send_data);
           
    
            if (error != OT_ERROR_NONE)
            {
                break;
            }
    
            switch (scope)
            {
            case THREAD_COAP_UTILS_MULTICAST_LINK_LOCAL:
                p_scope = "ff02::1";
                break;
    
            case THREAD_COAP_UTILS_MULTICAST_REALM_LOCAL:
                p_scope = "ff03::1";
                break;
    
            default:
                ASSERT(false);
            }
    
            memset(&message_info, 0, sizeof(message_info));
            message_info.mPeerPort = OT_DEFAULT_COAP_PORT;
    
            error = otIp6AddressFromString(p_scope, &message_info.mPeerAddr);
            ASSERT(error == OT_ERROR_NONE);
           
            error = otPlatRadioSetTransmitPower(p_instance, TX_power);
            NRF_LOG_INFO("error: %d", error);
            NRF_LOG_INFO("TX_power: %d", TX_power);
    
            error = otPlatRadioGetTransmitPower(p_instance, get_TX_power);
            NRF_LOG_INFO("error: %d", error);
            NRF_LOG_INFO("get_TX_power: %d", get_TX_power);
            
            
            error = otCoapSendRequest(p_instance, p_request, &message_info, NULL, NULL);
        } while (false);
    
        if (error != OT_ERROR_NONE && p_request != NULL)
        {
            NRF_LOG_INFO("Failed to send CoAP Request: %d\r\n", error);
            otMessageFree(p_request);
        }
    }

  • Hello, 

    Look at the implementation for otPlatRadioGetTransmitPower() here:

    https://github.com/openthread/openthread/blob/master/examples/platforms/nrf528xx/src/radio.c#L571

    You can't set the pointer to get_TX_power to 0 (NULL)

    That will return OT_ERROR_INVALID_ARGS.

    Try this instead:

    int8_t  * get_TX_power;

  • Hello,

    I tried 'int8_t  * get_TX_power;', but it returns the same error.

    Is there any other cause?

  • Ok, the pointer is probably null initialized.

    int8_t get_TX_power = 0;

    error = otPlatRadioGetTransmitPower(p_instance, &get_TX_power);

    Try that

Related