BLE Peripheral Not connecting…

I'm having trouble connecting to a specific peripheral identified as '5bf5937b-c8f4-4a82-82cf-3442ec3890cb'. I can see it being scanned, but the connect() call is failing for some reason. See attached logs.

I can connect to this same peripheral using the LightBlue app on my iPhone, so I'm not sure what's going on.

Any help to debug this would be greatly appreciated. Thanks!

I doubt the proposed code compiles (no include for the BLE library and I can't see the printData() function)

Do yourself a favour and please read How to get the best out of this forum and modify your post accordingly (including code tags and necessary documentation of your ask).

Hey. Thanks for replying. Yeah I wasn't sure if I should include the entire project just because ppl won't have access to the thing I'm trying to connect to. But yeah I've posted it here: GitHub - nickbolton/arduino-test.

have you tried running something like PeripheralExplorer to see if your Arduino does see your peripheral correctly?

can you show a screen grab of LightBlue app?

You say your peripheral is identified as '5BF5937B-C8F4-4A82-82CF-3442EC3890CB' but I see you are using this UID as a service identifier in the code

    if (!peripheral.hasService(PERIPHERAL_UUID)) {

Here's the LightBlue and PeripheralExplorer output. PE does discover my service, but so does my code. My code fails to connect to it. It's failing right before that if (!peripheral.hasService(PERIPHERAL_UUID)) { line.

what does handleConnectionChanges() shows in the Serial monitor?

I don't see any handleConnectionChanges() in the monitor.

isn't it in this function that you test for

    if (!peripheral.hasService(PERIPHERAL_UUID)) {

I do, but it never actually gets there because it's failing to connect in the section just above it. That's probably something else I'll have to debug when I can successfully connect. :slight_smile:

if (!peripheral.connect()) {
  Serial.println("Failed to connect");        
  return;
}

you should add more debug statements to understand better where it fails (I assume you see the "Failed to connect")

Yea I see the "Failed to connect" message. So what would you suggest to print out? I'm printing out a bunch of stuff above already. Sorry, I'm new to ArdunioBLE. It just seems like it can scan for and find my peripheral, but it's failing somewhere in BLEDevice::connect(). Is there some debugging internally that can be turned on?

I'm on my mobile at the moment

it seems like PeripheralExplorer manages to connect, right ? compare their code to yours

It does!! I don't know why I didn't try that before. Let me see if this can provide me a roadmap. Thanks!!!

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.