Voting resources, early voting, and poll worker information - VOTE. ... Adafruit is open and shipping.
0

Device disconnects after discovering characteristics
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Device disconnects after discovering characteristics

by baramuse on Thu Dec 12, 2019 5:15 am

Hi,

I'm still struggling getting some data from my BT VR ACGAM R1.
Though I've made some progress, I'm now stuck after having found the characteristics that I need from the HID service.

Now this is what's happening : I can discover the service, but as soon as I discover the chars - or just after actually - the device disconnects !
code being :
Code: Select all | TOGGLE FULL SIZE
BLEClientService remoteService (0x1812);

  if (remoteService.begin())
  {
    Serial.println("remoteService begin success");
  }
  else
  {
    Serial.println("remoteService begin failure");
  }

  if (remoteService.discover(conn_handle))
  {
    Serial.println("remoteService discover success");
  }
  else
  {
    Serial.println("remoteService discover failure");
  }

  BLEClientCharacteristic _hidReport(0x2A4D);
  _hidReport.begin(&remoteService);
  BLEClientCharacteristic _hidReportMap(0x2A4E);
  _hidReportMap.begin(&remoteService);
  Bluefruit.Discovery.discoverCharacteristic(remoteService.connHandle(), _hidReport, _hidReportMap);


And output of the Serial console being :
Code: Select all | TOGGLE FULL SIZE
Connected
remoteService begin success
[SVC] Handle start = 1
[SVC] Found 0x1812, Handle start = 15, end = 39
remoteService discover success

[CHR] Handle start = 16, end = 39
[CHR] Found 0x2A4E, handle = 17
[CHR] Found and match 0x2A4E, handle = 17
[CHR] Found 0x2A4D, handle = 19
[CHR] Found and match 0x2A4D, handle = 19
[CHR] Found 0x2A4D, handle = 23
[CHR] Found and match 0x2A4D, handle = 23
Disconnected, reason = 0x8


If I don't call the discover method, no problem the device stays connected, but after a chars discovery, it just disconnects.
Now I've read so much I don't remember where it was but I think it could mean the device is crashing. If that's the case, am I missing some steps in the workflow ?

Thanks so much !

baramuse
 
Posts: 12
Joined: Wed Jul 19, 2017 7:36 am

Re: Device disconnects after discovering characteristics

by baramuse on Sun Dec 29, 2019 1:02 pm

Anyone ?

I've bought another R1 just to be sure it was not a hardware problem, and the same happens.
Something makes the device disconnect just after discovering the characteristics !

I've adapted the heart rate monitor .ino and have the exact same issue :
The output will be :
Code: Select all | TOGGLE FULL SIZE
Connected
Discovering acram Service ... Found it
Discovering protocol characteristic ... Found it
Discovering report characteristic ... Found it
Ready to receive report value
Disconnected


Code: Select all | TOGGLE FULL SIZE
/*********************************************************************
 This is an example for our nRF52 based Bluefruit LE modules

 Pick one up today in the adafruit shop!

 Adafruit invests time and resources providing this open source code,
 please support Adafruit and open-source hardware by purchasing
 products from Adafruit!

 MIT license, check LICENSE for more information
 All text above, and the splash screen below must be included in
 any redistribution
*********************************************************************/

/* This sketch show how to use BLEClientService and BLEClientCharacteristic
 * to implement a custom client that is used to talk with Gatt server on
 * peripheral.
 *
 * Note: you will need another feather52 running peripheral/custom_HRM sketch
 * to test with.
 */

#include <bluefruit.h>

BLEClientService        acram1(UUID16_SVC_HUMAN_INTERFACE_DEVICE);
BLEClientCharacteristic report(UUID16_CHR_REPORT);
BLEClientCharacteristic protocol(UUID16_CHR_PROTOCOL_MODE);


void loop()
{
  // do nothing
}

/**
 * Callback invoked when scanner pick up an advertising data
 * @param report Structural advertising data
 */
void scan_callback(ble_gap_evt_adv_report_t* report)
{
  // Connect to device with HRM service in advertising
  Bluefruit.Central.connect(report);
}

/**
 * Callback invoked when an connection is established
 * @param conn_handle
 */
void connect_callback(uint16_t conn_handle)
{
  Serial.println("Connected");
  Serial.print("Discovering acram Service ... ");

  // If HRM is not found, disconnect and return
  if ( !acram1.discover(conn_handle) )
  {
    Serial.println("Found NONE");

    // disconect since we couldn't find HRM service
    Bluefruit.disconnect(conn_handle);

    return;
  }

  // Once HRM service is found, we continue to discover its characteristic
  Serial.println("Found it");

 
  Serial.print("Discovering protocol characteristic ... ");
  if ( !protocol.discover() )
  {
    // Measurement chr is mandatory, if it is not found (valid), then disconnect
    Serial.println("not found !!!"); 
    Bluefruit.disconnect(conn_handle);
    return;
  }
  Serial.println("Found it");

  // Measurement is found, continue to look for option Body Sensor Location
  // https://www.bluetooth.com/specifications/gatt/viewer?attributeXmlFile=org.bluetooth.characteristic.body_sensor_location.xml
  // Body Sensor Location is optional, print out the location in text if present
  Serial.print("Discovering report characteristic ... ");
  if ( report.discover() )
  {
     Serial.println("Found it");
  }else
  {
    Serial.println("Found NONE");
  }

  // Reaching here means we are ready to go, let's enable notification on measurement chr
  if ( report.enableNotify() )
  {
    Serial.println("Ready to receive report value");
  }else
  {
    Serial.println("Couldn't enable notify for report. Increase DEBUG LEVEL for troubleshooting");
  }
}

/**
 * Callback invoked when a connection is dropped
 * @param conn_handle
 * @param reason
 */
void disconnect_callback(uint16_t conn_handle, uint8_t reason)
{
  (void) conn_handle;
  (void) reason;

  Serial.println("Disconnected");
}


/**
 * Hooked callback that triggered when a measurement value is sent from peripheral
 * @param chr   Pointer client characteristic that even occurred,
 *              in this example it should be hrmc
 * @param data  Pointer to received data
 * @param len   Length of received data
 */
void hrm_notify_callback(BLEClientCharacteristic* chr, uint8_t* data, uint16_t len)
{
  // https://www.bluetooth.com/specifications/gatt/viewer?attributeXmlFile=org.bluetooth.characteristic.heart_rate_measurement.xml
  // Measurement contains of control byte0 and measurement (8 or 16 bit) + optional field
  // if byte0's bit0 is 0 --> measurement is 8 bit, otherwise 16 bit.

  Serial.print("report notification: ");

 
}


void setup()
{
  Serial.begin(9600);

  Serial.println("Bluefruit52 Central Custom Acram R1 Example");
  Serial.println("--------------------------------------\n");

  // Initialize Bluefruit with maximum connections as Peripheral = 0, Central = 1
  // SRAM usage required by SoftDevice will increase dramatically with number of connections
  Bluefruit.begin(0, 1);

  Bluefruit.setName("Bluefruit52 Central");

  // Initialize HRM client
  acram1.begin();

  // Initialize client characteristics of HRM.
  // Note: Client Char will be added to the last service that is begin()ed.
  protocol.begin();

  // set up callback for receiving measurement
  report.setNotifyCallback(hrm_notify_callback);
  report.begin();

  // Increase Blink rate to different from PrPh advertising mode
  Bluefruit.setConnLedInterval(250);

  // Callbacks for Central
  Bluefruit.Central.setDisconnectCallback(disconnect_callback);
  Bluefruit.Central.setConnectCallback(connect_callback);

  /* Start Central Scanning
   * - Enable auto scan if disconnected
   * - Interval = 100 ms, window = 80 ms
   * - Don't use active scan
   * - Filter only accept HRM service
   * - Start(timeout) with timeout = 0 will scan forever (until connected)
   */
  Bluefruit.Scanner.setRxCallback(scan_callback);
  Bluefruit.Scanner.restartOnDisconnect(true);
  Bluefruit.Scanner.setInterval(160, 80); // in unit of 0.625 ms
  Bluefruit.Scanner.filterUuid(UUID16_SVC_HUMAN_INTERFACE_DEVICE);
  Bluefruit.Scanner.useActiveScan(false);
  Bluefruit.Scanner.start(0);                   // // 0 = Don't stop scanning after n seconds
}

baramuse
 
Posts: 12
Joined: Wed Jul 19, 2017 7:36 am

Re: Device disconnects after discovering characteristics

by hathach on Wed Mar 04, 2020 6:52 am

try request pairing to device. Most consumer produce requires pairing to work with. Btw, the log did give out the reason for disconnection code is 0x08, you may want to look up its HCI code for the reason that device disconnect.

hathach
 
Posts: 1126
Joined: Tue Apr 23, 2013 1:02 am

Please be positive and constructive with your questions and comments.