arduino / ArduinoCore-arc32

GNU Lesser General Public License v2.1
329 stars 284 forks source link

CurieBLE: discovering attributes of connect central fails #382

Closed sandeepmistry closed 7 years ago

sandeepmistry commented 7 years ago

When running the following sketch, and connecting from LightBlue on my Mac, discovering attributes of the connected central fails:

#include <CurieBLE.h>

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

  BLE.begin();

  BLE.advertise();
}

void loop() {
  BLEDevice central = BLE.central();

  if (central) {
    Serial.print("Central connected: ");
    Serial.println(central.address());

    if (central.discoverAttributes()) {
      Serial.println("Discovered attributes");
    } else {
      Serial.println("Discovering attributes failed!");
    }

    while(central.connected()) {

    }

    Serial.print("Central disconnected: ");
    Serial.println(central.address());
  }
}
noelpaz commented 7 years ago

I thought that discoverAttributes works only in central mode and not meant for the peripheral to discover central. I am also adding @sgbihu to this and hope he answers. I am still on vacation.

noelpaz commented 7 years ago

It looks like I cannot assign @sgbihu . @eriknyquist can you send him an email to look into this

sandeepmistry commented 7 years ago

I thought that discoverAttributes works only in central mode and not meant for the peripheral to discover central.

@noelpaz as discussed with @SidLeung during the initial calls, both centrals and peripherals can operate a GATT server and GATT client.

sgbihu commented 7 years ago

This is a bug. The program doesn't add the connected central to the profile buffer. And that makes discover failed. The discover can't find it in the buffer. The current code only consider the connected peripheral device.

sgbihu commented 7 years ago

Hi @sandeepmistry ,

You can get the fix from https://github.com/sgbihu/corelibs-arduino101. The commit is a8c834a.

Thanks!

SidLeung commented 7 years ago

Please note Jira ticket, 788, has been created. A solution has been created for internal review, approval, and testing. Upon the completion of that process, the solution will be merged to the master, will be in the nightly JSON build, and will post the status here.

noelpaz commented 7 years ago

Tested and works accordingly.

sandeepmistry commented 7 years ago

@noelpaz was the fix for this merged into master?

kitsunami commented 7 years ago

This was addressed in #410

SidLeung commented 7 years ago

PR #410 addresses this issue.

sandeepmistry commented 7 years ago

I'm still seeing this issue with the sketch from https://github.com/01org/corelibs-arduino101/issues/382#issue-198154723 and my Mac running macOS 10.12.3.

The Serial monitor displays the following when I connect from LightBlue on my Mac:

Central connected: AC:BC:32:7C:FA:26
Discovering attributes failed!
Central disconnected: 

Here's a screenshot from the PacketLogger app, I don't see any incoming attribute discovery requests either:

screen shot 2017-03-15 at 11 14 13 am
sgbihu commented 7 years ago

Hi @sandeepmistry , I have test those two sketches https://github.com/01org/corelibs-arduino101/tree/master/libraries/CurieBLE/examples/test/discoveratperipheral and https://github.com/01org/corelibs-arduino101/tree/master/libraries/CurieBLE/examples/test/profileatcentral. They doesn't have problem.

So I want to confirm your does your light blue has profiles? Please tell me the setups if you have. And does iPhone's light blue has same results? I don't have MAC OS to duplicate this issue. It's better we can do on IOS.

Thanks!

sandeepmistry commented 7 years ago

I tried this again today with Github master and the 2.0.1 RC JSON. The sketch I provided works with both macOS and iOS.

Not exactly sure why it was failing yesterday, it could be that the GATT server on the Mac had too many attributes like https://github.com/01org/corelibs-arduino101/issues/479#issuecomment-287106847.

I'll close this for now, and re-open if I see it again.