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

BLE mesh runtime control of transmit power via the serial protocol

The SERIAL_OPCODE_CMD_CONFIG_TX_POWER_SET (0x44) is not supported in mesh SDK v4.0.0, so I added the following in the file serial_handler_config.c

#include "core_tx.h"
#include "mesh_opt_core.h"

In function void serial_handler_config_rx(const serial_packet_t* p_cmd)

case SERIAL_OPCODE_CMD_CONFIG_TX_POWER_SET:
{
    if (p_cmd->length != SERIAL_PACKET_LENGTH_OVERHEAD + sizeof(serial_cmd_config_tx_power_t))
    {
        serial_cmd_rsp_send(p_cmd->opcode, SERIAL_STATUS_ERROR_INVALID_LENGTH, NULL, 0);
    }
    else
    {
        if(
#if MESH_FEATURE_RELAY_ENABLED
            mesh_opt_core_tx_power_set(CORE_TX_ROLE_RELAY,
                                                              (radio_tx_power_t) p_cmd->payload.cmd.config.tx_power.tx_power) ||
#endif
            mesh_opt_core_tx_power_set(CORE_TX_ROLE_ORIGINATOR,
                                                             (radio_tx_power_t) p_cmd->payload.cmd.config.tx_power.tx_power) )

        {

             serial_cmd_rsp_send(p_cmd->opcode, SERIAL_STATUS_ERROR_INVALID_PARAMETER, NULL, 0);
        } else {
             serial_cmd_rsp_send(p_cmd->opcode, SERIAL_STATUS_SUCCESS, NULL, 0);
        }
    }
    break;
}

It seems to work as intended.  I'm posting here both to get some feedback in case I have overlooked anything, and also in case this helps anyone else who has the same requirement.

Related