BLE_CentralTest example not connect to other peripherals


#1

Hi guys, I’m doing several tests with the RedBear BLE NANO V2 board, but I’m not able to adapt the BLE_CentralTest example to another type of device. Can you tell me how to do it?


#2

What do you mean “another type of device”?


#3

My goal is to connect the BLE Nano board to a BLE device that transmits data through notify characteristic (i.e. Arduino 101). Through the example sketch i can only connect with a HRM device, but not with other devices type. Obviously I changed the UUID service, UUID characteristic and name of the device to search; the device is detected but the connection is not established and the connectionCallBack function is not recalled.


#4

Make sure that the peripheral device (i.e. Arduino 101?) is not filtered in the scan callback:

static void scanCallBack(const Gap::AdvertisementCallbackParams_t *params) {
  uint8_t index;

  Serial.println("Scan CallBack ");
  Serial.print("PerrAddress: ");
  for(index=0; index<6; index++) {
    Serial.print(params->peerAddr[index], HEX);
    Serial.print(" ");
  }
  Serial.println(" ");

  Serial.print("The Rssi : ");
  Serial.println(params->rssi, DEC);

  Serial.print("The adv_data : ");
  Serial.println((const char*)params->advertisingData);

  uint8_t len;
  uint8_t adv_name[31];
  if( NRF_SUCCESS == ble_advdata_parser(BLE_GAP_AD_TYPE_SHORT_LOCAL_NAME, params->advertisingDataLen, (uint8_t *)params->advertisingData, &len, adv_name) ) {
    Serial.print("Short name len : ");
    Serial.println(len, DEC);
    Serial.print("Short name is : ");
    Serial.println((const char*)adv_name);
    if( memcmp("TXRX", adv_name, 4) == 0x00 ) {
      Serial.println("Got device, stop scan ");
      ble.stopScan();
      /**
      * @param[in]  peerAddrType    BLEProtocol::AddressType::PUBLIC
      *                             BLEProtocol::AddressType::RANDOM_STATIC
      *                             BLEProtocol::AddressType::RANDOM_PRIVATE_RESOLVABLE
      *                             BLEProtocol::AddressType::RANDOM_PRIVATE_NON_RESOLVABLE
      * @param[in]  *connectionParams
      * @param[in]  *scanParams
      *
      * @return BLE_ERROR_NONE if connection establishment procedure is started successfully. The connectionCallChain (if set) will be invoked upon a connection event.
      */
      device_is_simple_peripheral = 1;
      ble.connect(params->peerAddr, BLEProtocol::AddressType::RANDOM_STATIC, NULL, NULL);
    }
  }
  else if( NRF_SUCCESS == ble_advdata_parser(BLE_GAP_AD_TYPE_COMPLETE_LOCAL_NAME, params->advertisingDataLen, (uint8_t *)params->advertisingData, &len, adv_name) ) {
    Serial.print("Complete name len : ");
    Serial.println(len, DEC);
    Serial.print("Complete name is : ");
    Serial.println((const char*)adv_name);

    if(memcmp("Nordic_HRM", adv_name, 10) == 0x00) {
      Serial.println("Got device, stop scan ");
      ble.stopScan();
      device_is_hrm = 1;
      ble.connect(params->peerAddr, BLEProtocol::AddressType::RANDOM_STATIC, NULL, NULL);
    }
  }
  Serial.println(" ");
}

Any serial log posted will be helpful.


#5

I do not understand your answer. The peripheral (i.e. Arduino 101) is detected by following if structure:

if(memcmp("Arduino 101", adv_name, 11) == 0x00) {
      Serial.println("Got device, stop scan ");
      ble.stopScan();
      device_is_hrm = 1;
      ble.connect(params->peerAddr, BLEProtocol::AddressType::RANDOM_STATIC, NULL, NULL);
    }

The function ble.connect() return 0, then there is not errors, but the connectionCallBack function is not recalled. Instead if I use a HRM device, this one function is recalled.


#6

I tried to execute HRM Peripheral example on Arduino 101. I can connect through my smartphone to Arduino and I can read the characteristic value, instead I can not connect trhough BLE nano board. Why? The Name is the same “Nordic_HRM”.


#7

I have analyzed the HRM peripherals. In the first image I have an Arduino 101, while in the second image I have an BLE Nano v2. There is a difference in Generic Attribute service, in particular in BLE Nano device there is Service Changed Characteristic and in Arduino 101 there is not, could that be the problem?
12
23


#8

I think that is not the problem. Please try using the BLEProtocol::AddressType::PUBLIC parameter in the ble.connect() API.


#9

Wow, I solved the problem with your suggestion. I am curious, why do I have to use BLEProtocol::AddressType::PUBLIC? Thank you very much!


#10

The peer device address and the type of which should be included in the advertisement data. If we initiate the connection, we should pass in the peer device address and the corresponding address type the peer device telling us in the advertisement data, or the peer device will decline the connection request.