How to broadcast raw data in beacon mode?

Hello,

             I am using PCA10040 DK for the programming with ble_app_beacon_pca10040_s132 example code. I want to broadcast my 20 bytes of data with my 0xFFE0 UUID.

In this example, I am trying to modify the m_beacon_info[] buffer with my custom data and want to broadcast directly raw data, But could not able to do that if I change any in m_beacon_info[] buffer code does not work, ble_advdata_encode() function does not initialise properly? I don't want to use any service, just want to transmit 20 bytes directly. Is this possible?

Can anyone tell me if yes? how to do that?

Thanks in advance!!

Parents Reply Children
  • fatal error and the device keep on restarting... I have done the below changes . now I am able to transmit my custom data over BLE so that this can be able to see on NRF connect app in RAW data...

    uint8_t BC_advertData[31] =
    {
    // Flags; this sets the device to use limited discoverable
    // mode (advertises for 30 seconds at a time) instead of general
    // discoverable mode (advertises indefinitely)
    0x02,   // length of this data      //[0]
    GAP_ADTYPE_FLAGS,                   //[1] //GAP_ADTYPE_FLAGS_BREDR_NOT_SUPPORTED,
    0x04,// [2]
    0x03,   // length of this data          // [3]
    GAP_ADTYPE_16BIT_MORE,      // some of the UUID's, but not all // [4]
    LO_UINT16(Default_UUID),            // [5]
    HI_UINT16(Default_UUID),            // [6]
    0x17, // length of this data including the data type byte       // [7]
    GAP_ADTYPE_MANUFACTURER_SPECIFIC, // manufacturer specific adv data type // [8]
     0x01, // mac 1                 [09]
     0x02, // mac 2                 [10]
     0x03, // mac 3  //             [11]
     0x04, // mac 4//               [12]
     0x05, // mac 5 //              [13]
     0x06, // mac 6 //              [14]
     0x40, // Temperature Msb   //  [15]
     0x89, // Temperature lsb //    [16]
     0x15, // Humidity Msb //       [17]
     0x58, // Humidity lsb //       [18]
     0x12, // Pressure Msb //       [19]
     0x34, // Pressure lsb //       [20]
     0x22, // Surface Temp Msb  //  [21]
     0xF4, // Surface Temp lsb //   [22]
     0x32, // Battery         //    [23]
     0xFF, // ON/OFF Duration MSB   [24]        //Ambient Light MSB
     0xFF, // ON/OFF Duration NEXT  [25]        //Ambient Light next
     0xFF, // ON/OFF Duration LSB   [26]         //Ambient Light LSB
     0x00, // Motion Event Flag //  [27]
     0x00, //  ON/OFF COUNT MSB     [28]
     0x00, //  ON/OFF COUNT NEXT    [29]
     0x00 //   ON/OFF COUNT LSB     [30]
    };
    
    /**@brief Struct that contains pointers to the encoded advertising data. */
    static ble_gap_adv_data_t m_adv_data =
    {
        .adv_data =
        {
            //.p_data = m_enc_advdata,
            .p_data = BC_advertData,
            .len    = BLE_GAP_ADV_SET_DATA_SIZE_MAX
        },
        .scan_rsp_data =
        {
            .p_data = NULL,
            .len    = 0
    
        }
    };
    
    
    static void advertising_init(void)
    {
        uint32_t      err_code;
       
       ble_gap_addr_t device_addr;
     
      
        memset(&m_adv_params, 0, sizeof(m_adv_params));
    
        m_adv_params.properties.type = BLE_GAP_ADV_TYPE_NONCONNECTABLE_NONSCANNABLE_UNDIRECTED;
        m_adv_params.p_peer_addr     = NULL;    // Undirected advertisement.
        m_adv_params.filter_policy   = BLE_GAP_ADV_FP_ANY;
        m_adv_params.interval        = NON_CONNECTABLE_ADV_INTERVAL;
        m_adv_params.duration        = 0;       // Never time out.
       
    
        //err_code = ble_advdata_encode(&advdata, m_adv_data.adv_data.p_data, &m_adv_data.adv_data.len);
        //APP_ERROR_CHECK(err_code);
        //if(err_code == NRF_SUCCESS)
        //{
        //       NRF_LOG_INFO("ble_advdata_encode init successful !");
        // }else
        // {
        //      NRF_LOG_INFO("ble_advdata_encode init failed !");
        // }
        //err_code  =    sd_ble_gap_tx_power_set(BLE_GAP_TX_POWER_ROLE_ADV,,4);               // +4dB Tx power was set for transmission    
        //APP_ERROR_CHECK(err_code);
            sd_ble_gap_addr_get(&device_addr);
    	BC_advertData[MAC_1]=device_addr.addr[5];			 //MAC ADDRESS
    	BC_advertData[MAC_1+1]=device_addr.addr[4];
    	BC_advertData[MAC_1+2]=device_addr.addr[3];
    	BC_advertData[MAC_1+3]=device_addr.addr[2];
    	BC_advertData[MAC_1+4]=device_addr.addr[1];
    	BC_advertData[MAC_1+5]=device_addr.addr[0];
         err_code = sd_ble_gap_adv_set_configure(&m_adv_handle, &m_adv_data, &m_adv_params);
        //APP_ERROR_CHECK(err_code);
    
       if(err_code == NRF_SUCCESS)
        {
         NRF_LOG_INFO("sd_ble_gap_adv_set_configure init successful !");
         }else
         {
          NRF_LOG_INFO("sd_ble_gap_adv_set_configure init failed !");
         }
    }
    

  • Hello,

             It worked. Now I am able to tx the raw data over BLE in beacon mode without using the ble_advdata_encode() function.

    Thanks.

Related