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

BLE connection through MAC Address Issue.

Hey, what i'm trying to do is the following:

- Advertise The unique MAC-Addresse

- Scan and connect to a Peripheral Node with a specific MAC-Address

But it isn't working

My configuration is as following:

advertisement setup:

static void gap_params_init(void) {
  ret_code_t err_code;
  ble_gap_conn_params_t gap_conn_params;
  ble_gap_conn_sec_mode_t sec_mode;

  BLE_GAP_CONN_SEC_MODE_SET_OPEN(&sec_mode);

  err_code = sd_ble_gap_device_name_set(&sec_mode,
      (const uint8_t *)DEVICE_NAME,
      strlen(DEVICE_NAME));
  APP_ERROR_CHECK(err_code);

  memset(&gap_conn_params, 0, sizeof(gap_conn_params));

  gap_conn_params.min_conn_interval = MIN_CONN_INTERVAL;
  gap_conn_params.max_conn_interval = MAX_CONN_INTERVAL;
  gap_conn_params.slave_latency = SLAVE_LATENCY;
  gap_conn_params.conn_sup_timeout = CONN_SUP_TIMEOUT;

  //get MAC
  err_code = sd_ble_gap_addr_get(&m_adv_addr);
  APP_ERROR_CHECK(err_code);
  m_adv_addr.addr_type = BLE_GAP_ADDR_TYPE_PUBLIC;
  err_code = sd_ble_gap_addr_set(&m_adv_addr);
  APP_ERROR_CHECK(err_code);
  err_code = sd_ble_gap_ppcp_set(&gap_conn_params);
  APP_ERROR_CHECK(err_code);
}

static void advertising_init(void) {
  ret_code_t err_code;
  ble_advdata_t advdata;
  ble_advdata_t srdata;

  ble_uuid_t adv_uuids[] =
      {
          {
              LBS_UUID_SERVICE,
              BLE_UUID_TYPE_VENDOR_BEGIN
          }};

  // Build and set advertising data.
  memset(&advdata, 0, sizeof(advdata));

  ble_advdata_manuf_data_t manuf_specific_data;
  uint8_t manuf_data[] = {6, 6, 6, 6};
  manuf_specific_data = set_manuf_data(manuf_data, sizeof(manuf_data));

  advdata.p_manuf_specific_data = &manuf_specific_data;
  advdata.name_type = BLE_ADVDATA_FULL_NAME;
  advdata.include_appearance = false;
  advdata.include_ble_device_addr = true;
  advdata.flags = BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE;

  memset(&srdata, 0, sizeof(srdata));
  srdata.uuids_complete.uuid_cnt = sizeof(adv_uuids) / sizeof(adv_uuids[0]);
  srdata.uuids_complete.p_uuids = adv_uuids;

  err_code = ble_advdata_encode(&advdata, m_adv_data.adv_data.p_data, &m_adv_data.adv_data.len);
  err_code = ble_advdata_encode(&srdata, m_adv_data.scan_rsp_data.p_data, &m_adv_data.scan_rsp_data.len);
  APP_ERROR_CHECK(err_code);

  ble_gap_adv_params_t adv_params;

  // Set advertising parameters.
  memset(&adv_params, 0, sizeof(adv_params));

  adv_params.primary_phy = BLE_GAP_PHY_1MBPS;
  adv_params.duration = APP_ADV_DURATION;
  adv_params.properties.type = BLE_GAP_ADV_TYPE_CONNECTABLE_SCANNABLE_UNDIRECTED;
  adv_params.p_peer_addr = NULL;
  adv_params.filter_policy = BLE_GAP_ADV_FP_ANY;
  adv_params.interval = APP_ADV_INTERVAL;
  advertiser_address_set(&m_adv_handle, &m_adv_addr);
  err_code = sd_ble_gap_adv_set_configure(&m_adv_handle, &m_adv_data, &adv_params);
  APP_ERROR_CHECK(err_code);

scan setup:

static ble_gap_addr_t const mac_addr =
    {
        .addr_type = BLE_GAP_ADDR_TYPE_PUBLIC,
        .addr = {0x32, 0xAA, 0xB8, 0xA2, 0xB8, 0xEA}
        //tried all three
        //.addr      = {0x32, 0xAA, 0xB8, 0xA2, 0xB8, 0xEA, 0x00}
        //.addr      = {0x00,0xEA,0xB8,0xA2,0xB8,0xAA,0x32}
};

static void scan_init(void) {
  ret_code_t err_code;
  nrf_ble_scan_init_t init_scan;
  ble_gap_addr_t m_mac_filter;

  memset(&init_scan, 0, sizeof(init_scan));
  APP_ERROR_CHECK(err_code);

  init_scan.connect_if_match = true;
  init_scan.conn_cfg_tag = APP_BLE_CONN_CFG_TAG;

  err_code = nrf_ble_scan_init(&m_scan, &init_scan, scan_evt_handler);
  APP_ERROR_CHECK(err_code);

  err_code = nrf_ble_scan_filter_set(&m_scan, SCAN_ADDR_FILTER, m_mac_filter.addr);
  APP_ERROR_CHECK(err_code);

  // Setting filters for scanning.
  err_code = nrf_ble_scan_filters_enable(&m_scan, NRF_BLE_SCAN_ADDR_FILTER, false);
  APP_ERROR_CHECK(err_code);
}

BLE nRF Connect advertiement :

i also wonder why the 0 is attached.

Related