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

setting tx_power_level

Hi,

I'm following this tutorial. In challenge 1, I was asked to change the transmit power level of the device.

Challenge 1: Try to add and populate the "p_tx_power_level" field in "advdata" with a value of your own choice and see what happens in MCP. This field is meant to advertise the transmit power of your device. This enables other units to roughly estimate the distance to your device.

I add these two lines in the advertising_init() function but the device couldn't be discovered in MCP.

int8_t tx_power_level[] = {0, -20};
advdata.p_tx_power_level 					= tx_power_level;

I also tried following this question but no luck.

How can I change the current project to do challenge 1?

Parents
  • Hi,

    My code looks like this now. However, the device still didn't show up in the MCP.

    static void advertising_init(void) 
        {
        uint32_t            err_code;
        ble_advdata_t       advdata;    // Struct containing advertising parameters
        uint8_t             flags       = BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE; // Defines how your device is seen (or not seen) by other devices
    	ble_uuid_t          adv_uuids[] = {
    																			{0x1234, BLE_UUID_TYPE_BLE}
    																		};    // Random example User Unique Identifier
    		//add tx_power_level variable
    		int8_t        tx_power_level = -20;
       
        ble_advdata_manuf_data_t manuf_data; // Variable to hold manufacturer specific data
    	uint8_t data[] 									= "SomeData!"; // Our data to adverise
    	manuf_data.company_identifier 	= 0x0059; //Nordics company ID
    	manuf_data.data.p_data					= data;
    	manuf_data.data.size						= sizeof(data);	 
    	
    	// Populate the advertisement packet
        // Always initialize all fields in structs to zero or you might get unexpected behaviour
        memset(&advdata, 0, sizeof(advdata));
        
        advdata.name_type          = BLE_ADVDATA_SHORT_NAME;      
    	advdata.short_name_len  = 6;
        advdata.flags                   = flags;                                     // Must be included, but not discussed in this tutorial
        advdata.uuids_complete.uuid_cnt = sizeof(adv_uuids) / sizeof(adv_uuids[0]); // Must be included, but not discussed in this tutorial
        advdata.uuids_complete.p_uuids  = adv_uuids;                                // Must be included, but not discussed in this tutorial
    	advdata.p_manuf_specific_data   = &manuf_data;                              // Load the manufacturer specific data into advertising packet
    	//adjust the transmit power of the device 	
    	advdata.p_tx_power_level 					= &tx_power_level;		
    	
        // Set the advertisement and scan response packet. 
        err_code = ble_advdata_set(&advdata, NULL);
        APP_ERROR_CHECK(err_code);// Check for errors
    }
    

    Is there anything else that I should do?

Reply
  • Hi,

    My code looks like this now. However, the device still didn't show up in the MCP.

    static void advertising_init(void) 
        {
        uint32_t            err_code;
        ble_advdata_t       advdata;    // Struct containing advertising parameters
        uint8_t             flags       = BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE; // Defines how your device is seen (or not seen) by other devices
    	ble_uuid_t          adv_uuids[] = {
    																			{0x1234, BLE_UUID_TYPE_BLE}
    																		};    // Random example User Unique Identifier
    		//add tx_power_level variable
    		int8_t        tx_power_level = -20;
       
        ble_advdata_manuf_data_t manuf_data; // Variable to hold manufacturer specific data
    	uint8_t data[] 									= "SomeData!"; // Our data to adverise
    	manuf_data.company_identifier 	= 0x0059; //Nordics company ID
    	manuf_data.data.p_data					= data;
    	manuf_data.data.size						= sizeof(data);	 
    	
    	// Populate the advertisement packet
        // Always initialize all fields in structs to zero or you might get unexpected behaviour
        memset(&advdata, 0, sizeof(advdata));
        
        advdata.name_type          = BLE_ADVDATA_SHORT_NAME;      
    	advdata.short_name_len  = 6;
        advdata.flags                   = flags;                                     // Must be included, but not discussed in this tutorial
        advdata.uuids_complete.uuid_cnt = sizeof(adv_uuids) / sizeof(adv_uuids[0]); // Must be included, but not discussed in this tutorial
        advdata.uuids_complete.p_uuids  = adv_uuids;                                // Must be included, but not discussed in this tutorial
    	advdata.p_manuf_specific_data   = &manuf_data;                              // Load the manufacturer specific data into advertising packet
    	//adjust the transmit power of the device 	
    	advdata.p_tx_power_level 					= &tx_power_level;		
    	
        // Set the advertisement and scan response packet. 
        err_code = ble_advdata_set(&advdata, NULL);
        APP_ERROR_CHECK(err_code);// Check for errors
    }
    

    Is there anything else that I should do?

Children
Related