Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BLE client gets stuck while calling BLEClient::connect() #874

Open
TSOgang opened this issue May 27, 2019 · 50 comments
Open

BLE client gets stuck while calling BLEClient::connect() #874

TSOgang opened this issue May 27, 2019 · 50 comments

Comments

@TSOgang
Copy link

TSOgang commented May 27, 2019

First of all, hello and thank you for your libraries and excuse me for this probably very simple question.

Very recently I have begun learning BLE and the esp32 and my goal for the moment is to successully establish a BLE connection between an esp32 (as client) and the nRF52 (as server). I believe the nRF52 works, since I can connect to it using my phone and control the value of characteristics in it. However, I can't get the esp32 to connect to it successully. It is able to scan and detect nearby devices and find the nRF52's adress no problem, but when a connection attempt is made using the connect() function, the program seems to wait indefinitely and no connection is ever established. While I have done some research on semaphores, I am still quite unfamilliar with them.

I wish to understand where it gets stuck in the connect() fuction, why it does that and how can I make it work.
Here is my code (I am using the Arduino framework in PlatformIO):

#include <Arduino.h>

#include "BLEDevice.h"


static BLEUUID serviceUUID("6e400001-b5a3-f393-e0a9-e50e24dcca9e");
static BLEUUID characteristicUUID("0000004f-0000-1000-8000-00805f9b34fb");
String My_BLE_Address = "d1:c7:bd:79:c4:05";

static BLERemoteCharacteristic* pRemoteCharacteristic;
BLEScan* pBLEScan;
BLEScanResults foundDevices;
static BLEAddress *Server_BLE_Address;
String Scanned_BLE_Address;

boolean paired = false;      // Flag verifying if we are paired with our device
boolean foundDevice = false; // Flag verifying if we found our device

bool connectToserver (BLEAddress pAddress){
    
    BLEClient*  pClient  = BLEDevice::createClient();
    Serial.println(" - Created client");
     
     
    // Connect to the BLE Server.
    pClient->connect(pAddress); // Stuck here...
    Serial.println(" - Connected to server");

    // Obtain a reference to the service we are after in the remote BLE server.
    BLERemoteService* pRemoteService = pClient->getService(serviceUUID);
    if (pRemoteService != nullptr)
    {
      Serial.println(" - Found our service");
      return true;
    }
    else
    return false;

    // Obtain a reference to the characteristic in the service of the remote BLE server.
    pRemoteCharacteristic = pRemoteService->getCharacteristic(characteristicUUID);
    if (pRemoteCharacteristic != nullptr)
      Serial.println(" - Found our characteristic");

      return true;
}

class MyAdvertisedDeviceCallbacks: public BLEAdvertisedDeviceCallbacks 
{ 
    void onResult(BLEAdvertisedDevice advertisedDevice) {
      Serial.printf("Scan Result: %s \n", advertisedDevice.toString().c_str());
      if(foundDevice == false){   // Flag verifying if we found our device
      Server_BLE_Address = new BLEAddress(advertisedDevice.getAddress()); // Update Server_BLE_Address if we didn't
      Scanned_BLE_Address = Server_BLE_Address->toString().c_str();
      }
      if(Scanned_BLE_Address == My_BLE_Address) // Compares the scanned adress to what we are looking for
      {
        foundDevice = true; // Found our device
      }
      Serial.println("Comparing to our server adress: ");
      Serial.println(My_BLE_Address);
    }
};

void setup() {
    Serial.begin(115200); //Start serial monitor 
    Serial.println("ESP32 BLE Client program"); //Intro message 

    BLEDevice::init("ESP32");
    pBLEScan = BLEDevice::getScan(); //create new scan
    pBLEScan->setAdvertisedDeviceCallbacks(new MyAdvertisedDeviceCallbacks()); //Call the class that is defined above 
    pBLEScan->setActiveScan(false); //active scan uses more power, but get results faster
}

void loop() {

  foundDevices = pBLEScan->start(3); //Scan for 3 seconds to find the server
  uint8_t devicesCount = foundDevices.getCount(); 
  Serial.printf("%d devices found \n", devicesCount);
  while (devicesCount >= 1 && foundDevice == true) // We found our server
  {
    if (foundDevice == true && paired == false) // We're not connected yet
    {
      Serial.println("Found our Device... connecting to Server as client \n");
       if (connectToserver(*Server_BLE_Address)) // Attempt a connection to the server   ...Stuck here...
      {
      paired = true;
      Serial.println("********************CONNECTED TO SERVER************************");
     
      break;
      }
      else
      {
      Serial.println("Pairing failed");
      foundDevice = false;
      break;
      }
    }
    devicesCount = 0; // Reset the number of devices
  }
  pBLEScan->stop();
  delay(5000);
}

And here is what the serial monitor looks like:

ESP32 BLE Client program
Scan Result: Name: , Address: 3f:43:89:02:09:99, manufacturer data: 0600010920020273111e440a64443a2bbdb913d98c83605f724bf88dd6
Comparing to our server adress:
d1:c7:bd:79:c4:05
Scan Result: Name: , Address: 21:5f:63:6c:59:18, manufacturer data: 0600010920024cbbbc219822bf9d445e8c12280b7f0e218a9c491fd485
Comparing to our server adress:
d1:c7:bd:79:c4:05
Scan Result: Name: , Address: 22:08:60:11:95:b3, manufacturer data: 06000109200267b9b0dc5ac0c049f892ec1bb09f3afed1bac30914b6fb
Comparing to our server adress:
d1:c7:bd:79:c4:05
Scan Result: Name: , Address: 3b:e3:63:51:43:55, manufacturer data: 060001092002578fe17a471e0a3fff4cb07172df27a10fc4835298acd4
Comparing to our server adress:
d1:c7:bd:79:c4:05
Scan Result: Name: nRF52, Address: d1:c7:bd:79:c4:05, txPower: 4
Comparing to our server adress:
d1:c7:bd:79:c4:05
Scan Result: Name: , Address: 04:b3:68:61:52:c6, manufacturer data: 060001092002810c02a9395aa4bc0d6ca4ee830ff5dc8f1dfc49e15e74
Comparing to our server adress:
d1:c7:bd:79:c4:05
Scan Result: Name: , Address: 74:97:07:46:24:ca, manufacturer data: 4c001005131cc48f22
Comparing to our server adress:
d1:c7:bd:79:c4:05
Scan Result: Name: , Address: 08:c0:21:ff:af:48, manufacturer data: 060001092002585e2df55dd581bf04830fe41d2f2d0cd131b433f79c76
Comparing to our server adress:
d1:c7:bd:79:c4:05
Scan Result: Name: , Address: f4:5c:89:a7:90:36, manufacturer data: 4c0010050b1c604ec2
Comparing to our server adress:
d1:c7:bd:79:c4:05
Scan Result: Name: , Address: 52:33:f9:76:9e:a1, manufacturer data: 4c000c0e00f2e83ef80545a417a96ba8e194
Comparing to our server adress:
d1:c7:bd:79:c4:05
Scan Result: Name: , Address: 7c:87:5c:cc:fd:c8, manufacturer data: 4c0010050318008367
Comparing to our server adress:
d1:c7:bd:79:c4:05
11 devices found
Found our Device... connecting to Server as client

 - Created client

Do you think you can help me?
Thanks in advance.

@rmnaderdev
Copy link

Same issue here. I noticed that after a reset on the client this happens, after resetting once or twice again it reconnects.

@chegewara
Copy link
Collaborator

It can be few reasons, but if i would have to guess its because in arduino version there is still few bugs. My advice is to use this library instead, or to find someone who will update arduino version.

@Greenstreem
Copy link

I am having the same issue.

@TSOgang
Copy link
Author

TSOgang commented Jun 3, 2019

Please excuse for my silence, I have stopped working on the esp-32 (a little bit out of frustration) to concentrate on the other chip im working on. This morning I wanted to try again from the beginning and simply copy pasted the client example in the "ESP32 BLE Arduino" library (that I have tried before without success) and changed up the Uuids to match my other chip's Uuids.

I gave it a go and it...connected successfully without trouble...
My best guess would be that my problem was on the server side, and since I worked on it, I must have corrected the problem without realising it.
I am still unsure as to why my program got stuck in the connect() function (and I see im not the only one), so I won't close this issue just yet.

If there is one thing I know it's that the problem dosen't seem to come from the libraries (since it worked), but I can't know for sure.

@majstor12
Copy link

Hi!
I'm also using Arduino to program ESP32. This issue is very frustrating. I don't have solution for this problem, but I have noticed that it occurs when there are lot of scanned devices.
It looks that code stucks on that line:
BLERemoteService* pRemoteService = pClient->getService(serviceUUID);
in Client example.

Any ideas how to fix this?

@chegewara
Copy link
Collaborator

@majstor12 yes, use this repository instead of arduino library. In arduino library is some bug that has been fixed here long time ago (few other bugs too).

@arsab
Copy link

arsab commented Jun 23, 2019

Do we expect to have these changes/improvements propagated to arduino library and how?
we see following update having made significant changes, but could not find which issues it is fixing:
e6d9ff2

@YeonwooSung
Copy link

@chegewara Might be a silly question, how can I use this repository instead of arduino library? Can you please teach me how to do that?

@chegewara
Copy link
Collaborator

https://github.com/nkolban/esp32-snippets/blob/master/cpp_utils/ArduinoBLE.md

@YeonwooSung
Copy link

@chegewara Thanks :)

@EngineeringStar
Copy link

Hi, I have got the same problem
// -------------------------------
pClient->connect(pAddress); // Stuck here...
//--------------------------------
I solved this problem by modifying the FreeRTOS.cpp file.
You can see this command in line 77 of FreeRTOS.cpp
xSemaphoreTake(m_semaphore, portMAX_DELAY);
As the portMAX_DELAY value is 0xffffffffUL, maybe the code will wait for about 50 days to connect to the BLE device.
So that, I changed the code like this and my code didn't get stuck anymore.
xSemaphoreTake(m_semaphore, 60000);

Thanks.

@thomastech
Copy link

So that, I changed the code like this and my code didn't get stuck anymore.
xSemaphoreTake(m_semaphore, 60000);

Thanks for sharing your hang workaround. Instead of 60000 I'm using 15000; The smaller value works well for me (shorter "hang" times).

  • Thomas

@EngineeringStar
Copy link

Thanks for your notice, Thomas.

@thomastech
Copy link

@jiangminghe During validation I found another xSemaphoreTake() that caused an endless hang in my client application. This required another workaround patch at line 198: I changed the timeout to 15 seconds, as follows:
rc = ::xSemaphoreTake(m_semaphore, 15000UL) == pdTRUE;

I recognize that these edits are workarounds, not permanent patches. But I will use them until the semaphore issues are resolved.

  • Thomas

@chegewara
Copy link
Collaborator

Patch that is fixing semaphores issue has been added to arduino-esp32 repository some time ago.
Because code in BLEClient is just a bit different the same patch didnt work here, or maybe i was not lucky.

@thomastech
Copy link

I'm using the latest arduino-esp32 repository (last patch was from about 30 days ago). If there are more recent semaphore fixes then I would definitely want to try them out.

  • Thomas

@chegewara
Copy link
Collaborator

Sorry, it was the latest one, in this case there is somewhere else semaphore that causing stuck.

@Prathik-Jain
Copy link

I tried replacing the libraries as suggested by @chegewara , I see no change. The program still gets stuck.

@ufanders
Copy link

Hi, I am having this issue as well:

`bool connectToServer() {

BLEClient*  pClient  = BLEDevice::createClient();
pClient->setClientCallbacks(new MyClientCallback());

// Connect to the remote BLE Server.
Serial.printf("Connecting to %s.\n", serverAddress);
//Serial.println(myDevice->getAddress().toString().c_str());
pClient->connect(BLEAddress(serverAddress)); //myDevice);  // if you pass BLEAdvertisedDevice instead of address, it will be recognized type of peer device address (public or private)

//**** MANY TIMES, DOES NOT EXECUTE CODE BELOW ****//

// Obtain a reference to the service we are after in the remote BLE server.
pRemoteService = pClient->getService(serviceUUID);
if (pRemoteService == NULL) {
  Serial.println("Service not found.");
  M5.Lcd.println("Service not found.");
  M5.update();
  pClient->disconnect();
  return false;
}
Serial.println("Service found.");
M5.Lcd.println("Service found.");
M5.update();

}`

Any new updates, @chegewara?

@chegewara
Copy link
Collaborator

chegewara commented Jan 26, 2020

It is possible that calling this line:
pClient->connect(BLEAddress(serverAddress)); //myDevice);
not necessarily ends with connecting to peer device. I would suggest to add additional check after this line:

if(!pClient->isConnected())
    return false;

Also changing semaphore to timed semaphore as many times was suggested is good idea.

@ufanders
Copy link

Ok thanks I'll try the timed semaphore fix.

@BojanJurca
Copy link

You can not connect while scanning. Stop scanning first.

@ravsten
Copy link

ravsten commented Mar 3, 2020

While reading #757 I have found that connect call can actually take two arguments - BLEAddress as the first one and esp_ble_addr_type_t type as a second (optional) argument that defaults to BLE_ADDR_TYPE_PUBLIC.
However, as mentioned, "most if not all smartphones, tablets and laptops are using random addressing" and esp_ble_addr_type_t type has to be set to BLE_ADDR_TYPE_RANDOM (#757 (comment)).
Worked for me!

@chegewara
Copy link
Collaborator

@ravsten There is overloaded connect function, which will figure out address type, but you need to pass advertised device instead of address.

@ravsten
Copy link

ravsten commented Mar 4, 2020

@ravsten There is overloaded connect function, which will figure out address type, but you need to pass advertised device instead of address.

To avoid misleading anyone I want to mention that I am using an Arduino built-in BLE ESP32 library so I guess that is why I pass BLEAddress instead of BLEDevice. Correct @chegewara?

@chegewara
Copy link
Collaborator

@vcmorini
Copy link

vcmorini commented Mar 7, 2020

Ok thanks I'll try the timed semaphore fix.

Hello, could you share with us how to do it? :)

@xsaco07
Copy link

xsaco07 commented May 28, 2020

Hi I'm having the same issue here. I'm trying to connect 2 ESP32, one as a Client and the other one as a Server.
The Client is stuck in connect(myAdvDevice) line. Is there any update here?
The semaphores fix is the only option?

I'm using the Arduino library.
Thanks.

@xsaco07
Copy link

xsaco07 commented Jun 7, 2020

I edited the FreeRTOS.cpp file, changing the xSemaphoreTake() parameter to 15000UL as mentioned in the comments and I'm not getting the result expected yet. It is still getting stuck on the connect(myAdvDecice) function call.

@thomastech
Copy link

Check the file again and confirm you have changed ALL the occurrences of xSemaphoreTake() that used the portMAX_DELAY to 15000UL. If you've already done that then I doubt your issue is due to the semaphore timeout hang issue.

  • Thomas

@Huntercover
Copy link

Hello, I am facing the same stuck whenever trying to connect to the fourth server. Is there any chance to connect to more than 3 servers?
btw: I will try to use 2 ESP32 to connect to 6 BLE servers, hopefully that will work for me.
Regards Andreas

@LK-Simon
Copy link

LK-Simon commented Sep 5, 2021

Do not attempt to Connect to a BLE Server before the call to BLEScan->start(...); returns!

You need to initiate the scan, on your onResult Callback method, you need to determine if it is the device in which you are interested. If it is, you need to store a reference to the BLEAdvertisedDevice

Once the scan call returns (as stated in the first line of this response) you can then connect to this BLEAdvertisedDevice and it will work.

@MertGurdogann
Copy link

Hi There, i have same problem in connecting to peripheral. It's always stuck on connect command line. I also have already try Mr. Andreas Polar Receiver example but that has same stuck too. I use ESP32 pico kit.

Here's my demo code. Does anyone have a solution for this issue? I will be grateful if you could help me.

#include` "BLEDevice.h"
// The remote service we wish to connect to.
static  BLEUUID serviceUUID(BLEUUID((uint16_t)0x180D));
// The characteristic of the remote service we are interested in.
static BLEUUID    charUUID(BLEUUID((uint16_t)0x2A37));
static BLEAddress *pServerAddress;
static BLEScan* pBLEScan;
static BLEClient*  pClient;
class MyAdvertisedDeviceCallbacks: public BLEAdvertisedDeviceCallbacks
{
    void onResult(BLEAdvertisedDevice advertisedDevice)
    {
      Serial.print("BLE Advertised Device found: ");
      Serial.println(advertisedDevice.toString().c_str());
      pServerAddress = new BLEAddress(advertisedDevice.getAddress());

      if (advertisedDevice.haveServiceUUID() && advertisedDevice.getServiceUUID().equals(serviceUUID))
      {
        Serial.println("=============== Device found! =============== ");
        Serial.print("Name: ");
        Serial.print(advertisedDevice.getName().c_str());
        Serial.print("\tAddress: ");
        Serial.println(pServerAddress->toString().c_str());
        advertisedDevice.getScan()->stop();
        //       pClient->connect(*pServerAddress);   I try those method but i couldn't succsessful on connect 
        pClient->connect(&advertisedDevice);
        Serial.println(" - Connected to server");
      }

      /******** This releases the memory when we're done. ********/
      delete pServerAddress;
    }
}; // MyAdvertisedDeviceCallbacks
void setup()
{
  Serial.begin(115200);
  Serial.println("Starting Arduino BLE Client application...");
  BLEDevice::init("");
  pClient  = BLEDevice::createClient();
  Serial.println(" - Created client");
  pBLEScan = BLEDevice::getScan();
  pBLEScan->setAdvertisedDeviceCallbacks(new MyAdvertisedDeviceCallbacks());
  pBLEScan->setActiveScan(true);
  pBLEScan->start(30);
}
void loop()
{
  if (pClient->isConnected()) Serial.println("connect");
  else Serial.println("non connect");
  while (1);
}

And Here's my output from Serial monitor.

Starting Arduino BLE Client application...
 - Created client
BLE Advertised Device found: Name: 36374-65, Address: c4:2a:21:cf:6e:c2, appearance: 833, manufacturer data: ffff6b00168e41400001020c, serviceUUID: 0000180d-0000-1000-8000-00805f9b34fb
=============== Device found! =============== 
Name: 36374-65	Address: c4:2a:21:cf:6e:c2
non connect

@chegewara
Copy link
Collaborator

There is second parameter in connect function:
https://github.com/espressif/arduino-esp32/blob/master/libraries/BLE/src/BLEClient.h#L37
for that reason there is another connect function, which should automatically detect address type:
https://github.com/espressif/arduino-esp32/blob/master/libraries/BLE/src/BLEClient.h#L36

@AndreasHobby
Copy link

@chegewara: and this solves the stuck?

In the meanwhile and as a workaround I am using the other CORE for any BLE connect tasks.

@chegewara
Copy link
Collaborator

Im not sure it will solve, but it was the reason in many other cases. Thats why i had to write that second connect function.

@LK-Simon
Copy link

LK-Simon commented Sep 6, 2021

If anyone wants a confirmed-working example of BLE connections for the ESP32 boards... I have a repository as part of my Automatic Discovery & Pairing articles. https://github.com/Flowduino/ESP32_ESP-Now_Pairing
It's only really intended to facilitate Automated Discovery (I'm using BLE for Discovery, then ESP-Now for actual communication) but this code is functioning just fine.

You might be able to figure out what you need to change in your own respective codebases from my code in that repository.

Enjoy!

@MertGurdogann
Copy link

MertGurdogann commented Sep 7, 2021

@LK-Simon Thank you I solved the stuck problem and made an example about it. Those who have problems with Connect can try this example.

https://github.com/MertGurdogann/BLEconnectExample/blob/main/BLEconnect/BLEconnect.ino

Here is example output from Serial Monitor

Advertised Device: Name: , Address: 6e:46:76:f6:42:3c, manufacturer data: 4c0010067e1e3f5fd2f5, txPower: 8 
Advertised Device: Name: Decathlon Dual HR, Address: ed:13:79:f4:72:01, appearance: 833, serviceUUID: 0000180d-0000-1000-8000-00805f9b34fb 
Advertised Device: Name: 36374-65, Address: c4:2a:21:cf:6e:c2, appearance: 833, manufacturer data: ffff6b00168e41400001020c, serviceUUID: 0000180d-0000-1000-8000-00805f9b34fb 
Found Devices
0.   Device Name:36374-65
1.   Device Name:Decathlon Dual HR
Connecting
Connection Successfull
Connected 	Decathlon Dual HR
Connecting
Connection Successfull
Connected 	36374-65

Best regards.

@chegewara
Copy link
Collaborator

From the code i am guesing that another connect() function helped.

@JoFRT
Copy link

JoFRT commented Oct 14, 2021

Hello,
Many thanks to your contribution in this thread, I understood 2 important things for my sketch.
(So now my sketches will be not stuck anymore and I understood that my 2nd device as a random address configuration).
So now I can get a connection with my 2nd device too. But I cannot connect to a service : the ESP32 reboots because of this error :
>> Guru Meditation Error: Core 0 panic'ed (Double exception).
With my 1st device (static address configuration) everything is perfect : I can read and write characteristics.
So by comparison I saw that with my 2nd device I have those 2 lines in addition just before the reset :

>> [ 11002][D][BLEClient.cpp:493] handleGAPEvent(): BLEClient ... handling GAP event!
>> custom gap event handler, event: 20

I am wandering why this 2nd exception(gap event) occurs !
Below I give you the log (Log with Debug config only because I do not have the Verbose’s in my arduino v1.8.15, and I do not know to add it  ).
After that I give you also the backtrace details.
Could you please help me with this issue ?

Starting Arduino BLE Client application...
custom gap event handler, event: 2 
custom gap event handler, event: 7 
[   749][D][BLEAdvertisedDevice.cpp:472] setRSSI(): - setRSSI(): rssi: -82
[   749][D][BLEAdvertisedDevice.cpp:292] parseAdvertisement(): Type: 0x01 (), length: 1, data: 05
[   753][D][BLEAdvertisedDevice.cpp:292] parseAdvertisement(): Type: 0x02 (), length: 2, data: 0018
[   762][D][BLEAdvertisedDevice.cpp:500] setServiceUUID(): - addServiceUUID(): serviceUUID: 00001800-0000-1000-8000-00805f9b34fb
[   773][D][BLEAdvertisedDevice.cpp:292] parseAdvertisement(): Type: 0x09 (), length: 8, data: 522d444343393437
[   783][D][BLEAdvertisedDevice.cpp:461] setName(): - setName(): name: R-DCC947
[   790][D][BLEAdvertisedDevice.cpp:292] parseAdvertisement(): Type: 0xff (), length: 8, data: 600154104be04638
[   800][D][BLEAdvertisedDevice.cpp:449] setManufacturerData(): - manufacturer data: 600154104be04638
[   809][D][BLEAdvertisedDevice.cpp:292] parseAdvertisement(): Type: 0xff (), length: 29, data: 600154104be04638010a044b000301e500190414000000000000000000
[   822][D][BLEAdvertisedDevice.cpp:449] setManufacturerData(): - manufacturer data: 600154104be04638010a044b000301e500190414000000000000000000
BLE Advertised Device found: Name: R-DCC947, Address: a4:c1:38:46:e0:4b, manufacturer data: 600154104be04638010a044b000301e500190414000000000000000000, serviceUUID: 00001800-0000-1000-8000-00805f9b34fb
custom gap event handler, event: 3 
(…)
[  3823][D][BLEScan.cpp:105] handleGAPEvent(): Ignoring 2b:45:52:00:e0:26, already seen it.
custom gap event handler, event: 3 
[  3919][D][BLEScan.cpp:105] handleGAPEvent(): Ignoring a4:c1:38:46:e0:4b, already seen it.
custom gap event handler, event: 3 
[  3919][D][BLEScan.cpp:105] handleGAPEvent(): Ignoring 2b:45:52:00:e0:26, already seen it.
custom gap event handler, event: 3 
[  4122][D][BLEScan.cpp:105] handleGAPEvent(): Ignoring 2b:45:52:00:e0:26, already seen it.
custom gap event handler, event: 3 
[  4183][D][BLEScan.cpp:105] handleGAPEvent(): Ignoring 2b:45:52:00:e0:26, already seen it.
custom gap event handler, event: 3 
[  4322][D][BLEScan.cpp:105] handleGAPEvent(): Ignoring 2b:45:52:00:e0:26, already seen it.
custom gap event handler, event: 3 
[  4339][D][BLEScan.cpp:105] handleGAPEvent(): Ignoring 2b:45:52:00:e0:26, already seen it.
custom gap event handler, event: 3 
[  4353][D][BLEAdvertisedDevice.cpp:472] setRSSI(): - setRSSI(): rssi: -43
[  4354][D][BLEAdvertisedDevice.cpp:292] parseAdvertisement(): Type: 0x01 (), length: 1, data: 0a
[  4358][D][BLEAdvertisedDevice.cpp:292] parseAdvertisement(): Type: 0x07 (), length: 16, data: 00c7c44ee36c51a7334be8ed5a0eb803
[  4369][D][BLEAdvertisedDevice.cpp:500] setServiceUUID(): - addServiceUUID(): serviceUUID: 03b80e5a-ede8-4b33-a751-6ce34ec4c700
[  4380][D][BLEAdvertisedDevice.cpp:292] parseAdvertisement(): Type: 0x09 (), length: 20, data: 4e5558204d494748545920504c5547204d494449
[  4392][D][BLEAdvertisedDevice.cpp:461] setName(): - setName(): name: NMPM
BLE Advertised Device found: Name: NMPM, Address: cb:4e:fd:d7:02:d5, serviceUUID: 03b80e5a-ede8-4b33-a751-6ce34ec4c700
Found our device!  address: C_fct: Leaving "Setup" function...
C_fct: Start "loop" function...
Wait the end of searching device, 3s...
custom gap event handler, event: 3 
custom gap event handler, event: 3 
custom gap event handler, event: 3 
custom gap event handler, event: 3 
custom gap event handler, event: 3 
custom gap event handler, event: 18 
custom gap event handler, event: 18 
Wait 3s more
Forming a connection to cb:4e:fd:d7:02:d5
 - Created client
Server address type: 1
[ 10433][I][BLEDevice.cpp:622] addPeerDevice(): add conn_id: 0, GATT role: client
[ 10437][D][BLEDevice.cpp:148] gattClientEventHandler(): gattClientEventHandler [esp_gatt_if: 4] ... Unknown
[ 10446][D][BLEClient.cpp:178] gattClientEventHandler(): gattClientEventHandler [esp_gatt_if: 4] ... Unknown
custom gattc event handler, event: 0 
[ 10587][D][BLEDevice.cpp:148] gattClientEventHandler(): gattClientEventHandler [esp_gatt_if: 4] ... Unknown
[ 10587][D][BLEClient.cpp:178] gattClientEventHandler(): gattClientEventHandler [esp_gatt_if: 4] ... Unknown
custom gattc event handler, event: 40 
[ 10607][D][BLEDevice.cpp:148] gattClientEventHandler(): gattClientEventHandler [esp_gatt_if: 4] ... Unknown
[ 10608][D][BLEClient.cpp:178] gattClientEventHandler(): gattClientEventHandler [esp_gatt_if: 4] ... Unknown
 - Connected to server
custom gattc event handler, event: 2 
https://github.com/nkolban/esp32-snippets/issues/874
Try to connect to our service UUID: 03b80e5a-ede8-4b33-a751-6ce34ec4c700
[ 10712][D][BLEClient.cpp:493] handleGAPEvent(): BLEClient ... handling GAP event!
custom gap event handler, event: 20 
Guru Meditation Error: Core  0 panic'ed (Double exception). 

Core  0 register dump:
PC      : 0x4009214f  PS      : 0x00040636  A0      : 0x801181cd  A1      : 0x3ffd6d40  
A2      : 0x00060430  A3      : 0x00040023  A4      : 0x00060420  A5      : 0x00000003  
A6      : 0x00000001  A7      : 0x0000007f  A8      : 0x3ffd6e80  A9      : 0x3ffd6e50  
A10     : 0x00001400  A11     : 0x3ffd6eb4  A12     : 0x00000268  A13     : 0x400ece50  
A14     : 0x00001800  A15     : 0x00000000  SAR     : 0x0000001f  EXCCAUSE: 0x00000002  
EXCVADDR: 0x400ece40  LBEG    : 0x4008f668  LEND    : 0x4008f67e  LCOUNT  : 0x00000000  


Backtrace:0x4009214c:0x3ffd6d400x401181ca:0x3ffd6d50 0x4009214c:0x3ffd6d70 0x4009214c:0x3ffd6d90 0x4009214c:0x3ffd6db0 0x4009214c:0x3ffd6dd0 0x4009214c:0x3ffd6e00 0x4008007d:0x3ffd6e50 0x400ece4b:0x3ffd6e80 0x4011d327:0x3ffd6eb0 0x401438f7:0x3ffd7140 0x4011e42a:0x3ffd73d0 0x401433fe:0x3ffd73f0 0x4011e42a:0x3ffd7460 0x40143109:0x3ffd7480 0x4011d649:0x3ffd74a0 0x4011d6c1:0x3ffd7730 0x4011d88b:0x3ffd7750 0x40106f85:0x3ffd7770 0x40101c8d:0x3ffd7a10 0x4010216e:0x3ffd7ca0 0x40102b0d:0x3ffd7d10 0x401040db:0x3ffd7d40 0x4010411a:0x3ffd7d60 0x401112e1:0x3ffd7d80 0x400ffada:0x3ffd7f00 0x40119f1b:0x3ffd7f20 




ELF file SHA256: 0000000000000000

Rebooting...
ets Jun  8 2016 00:22:57

rst:0xc (SW_CPU_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:1
load:0x3fff0030,len:1100
ho 0 tail 12 room 4
load:0x40078000,len:12308
load:0x40080400,len:3076
entry 0x400805ec 
Decoding stack results
0x401181ca: btc_transfer_context at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/bt/common/btc/core/btc_task.c line 248
0x400ece4b: btc_gattc_cback at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/bt/host/bluedroid/btc/profile/std/gatt/btc_gattc.c line 194
0x4011d327: bta_gattc_search_service at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/bt/host/bluedroid/bta/gatt/bta_gattc_cache.c line 1115
0x401438f7: bta_gattc_search at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/bt/host/bluedroid/bta/gatt/bta_gattc_act.c line 1522
0x4011e42a: bta_gattc_sm_execute at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/bt/host/bluedroid/bta/gatt/bta_gattc_main.c line 298
0x401433fe: bta_gattc_disc_cmpl at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/bt/host/bluedroid/bta/gatt/bta_gattc_act.c line 1061
0x4011e42a: bta_gattc_sm_execute at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/bt/host/bluedroid/bta/gatt/bta_gattc_main.c line 298
0x40143109: bta_gattc_reset_discover_st at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/bt/host/bluedroid/bta/gatt/bta_gattc_act.c line 847
0x4011d649: bta_gattc_explore_srvc at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/bt/host/bluedroid/bta/gatt/bta_gattc_cache.c line 635
0x4011d6c1: bta_gattc_char_dscpt_disc_cmpl at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/bt/host/bluedroid/bta/gatt/bta_gattc_cache.c line 714
0x4011d88b: bta_gattc_disc_cmpl_cback at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/bt/host/bluedroid/bta/gatt/bta_gattc_cache.c line 1067
0x40106f85: gatt_end_operation at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/bt/host/bluedroid/stack/gatt/gatt_utils.c line 2301
0x40101c8d: gatt_act_discovery at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/bt/host/bluedroid/stack/gatt/gatt_cl.c line 116
0x4010216e: gatt_process_read_info_rsp at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/bt/host/bluedroid/stack/gatt/gatt_cl.c line 484
0x40102b0d: gatt_client_handle_server_rsp at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/bt/host/bluedroid/stack/gatt/gatt_cl.c line 1125
0x401040db: gatt_data_process at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/bt/host/bluedroid/stack/gatt/gatt_main.c line 1004
0x4010411a: gatt_le_data_ind at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/bt/host/bluedroid/stack/gatt/gatt_main.c line 587
0x401112e1: l2c_rcv_acl_data at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/bt/host/bluedroid/stack/l2cap/l2c_main.c line 275
0x400ffada: btu_hci_msg_process at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/bt/host/bluedroid/stack/btu/btu_task.c line 144
0x40119f1b: osi_thread_run at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/bt/common/osi/thread.c line 67

@chegewara
Copy link
Collaborator

Guru Meditation Error: Core 0 panic'ed (Double exception).

This is very nasty error, because its more or less telling that you have error in code somewhere (maybe in library) and this error itself is causing to generate logs or something which is causing another error.
Usually (or maybe always) it means very bad memory corruption bug.

custom gap event handler, event: 20
This is UPDATE_CONN_PARAMS event.

I dont know your code and purpose of it, but is it possible that 2 devices you are trying to connect to have 2 completely different set of services and characteristics?
Did you try to connect to each device separately?

@JoFRT
Copy link

JoFRT commented Oct 14, 2021

Hello Chegewara,
Thanks for replying.
In fact I use exactly the same sketch for only 1 device connection. I change the UUID service, UUID characteristic and the device address in the sketch depending of the device I want to connect with.
Both device are totally different.

@chegewara
Copy link
Collaborator

Then maybe you are trying to read/write characteristic that does not exist on 2nd device, or you do some other stuff that break it, assign new characteristic to pointer. Just test 1 step at a time:

  • test with 1st device only,
  • test with 2nd device only,
  • test with 2 device, but dont try to connect both at the same time, i mean turn on 2nd device when 1st is already connected
  • add as many logs as you can in your own code

@JoFRT
Copy link

JoFRT commented Oct 15, 2021

My sketch manages only 1 device. But if you want I can adapt it to manage 2.
During adding more log I saw that some old libraries are called in arduino15 directory. I did not succeed to solve this problem yet because of headers depencies. I will continue tomorrow and let you know then.

@chegewara
Copy link
Collaborator

No, i dont want you to change your code. I just thought it is how you doing it now.

@JoFRT
Copy link

JoFRT commented Oct 15, 2021

After a lot of trial my sketch works only with "https://github.com/espressif/arduino-esp32", with the "snippets" I have to many error on delcarations.
I finally found how to get the Verbose details so I share it below with the associated backtrace; Hoping that means something for you.
I have also found a sketch more complex but with a similar device "https://github.com/max22-/ESP32-BLE-MIDI/blob/master/examples/02-Basic-Midi-Client/02-Basic-Midi-Client.ino". Unfortunately I have the same issue.

After that I give you for the 1st device (without any problem).

2nd device:

ets Jun  8 2016 00:22:57

rst:0x10 (RTCWDT_RTC_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:1
load:0x3fff0030,len:1240
load:0x40078000,len:13012
load:0x40080400,len:3648
entry 0x400805f8
[⸮⸮m�um⸮⸮⸮⸮2-hal-cpu.c:211] setCpuFrequencyMhz(): PLL: 480 / 2 = 240 Mhz, APB: 80000000 Hz
Starting Arduino BLE Client application...
[   695][V][BLEScan.cpp:385] start(): >> start(duration=10)
[   696][V][FreeRTOS.cpp:192] take(): Semaphore taking: name: ScanEnd (0x3ffdff98), owner: <N/A> for start
[   699][V][FreeRTOS.cpp:204] take(): Semaphore taken:  name: ScanEnd (0x3ffdff98), owner: start
[   708][V][BLEScan.cpp:417] start(): << start()
[   712][V][FreeRTOS.cpp:63] wait(): >> wait: Semaphore waiting: name: ScanEnd (0x3ffdff98), owner: start for start
[   711][V][BLEUtils.cpp:1817] gapEventToString(): gapEventToString: Unknown event type 2 0x02
[   711][V][BLEUtils.cpp:1049] dumpGapEvent(): Received a GAP event: Unknown event type
[   738][V][BLEUtils.cpp:1264] dumpGapEvent(): *** dumpGapEvent: Logger not coded ***
custom gap event handler, event: 2 
[   756][V][BLEUtils.cpp:1817] gapEventToString(): gapEventToString: Unknown event type 7 0x07
[   756][V][BLEUtils.cpp:1049] dumpGapEvent(): Received a GAP event: Unknown event type
[   765][V][BLEUtils.cpp:1264] dumpGapEvent(): *** dumpGapEvent: Logger not coded ***
custom gap event handler, event: 7 
[   783][V][BLEUtils.cpp:1817] gapEventToString(): gapEventToString: Unknown event type 3 0x03
[   783][V][BLEUtils.cpp:1049] dumpGapEvent(): Received a GAP event: Unknown event type
[   792][V][BLEUtils.cpp:1264] dumpGapEvent(): *** dumpGapEvent: Logger not coded ***
[   799][D][BLEAdvertisedDevice.cpp:472] setRSSI(): - setRSSI(): rssi: -90
[   806][V][BLEUtils.cpp:746] advTypeToString():  adv data type: 0x1
[   806][D][BLEAdvertisedDevice.cpp:292] parseAdvertisement(): Type: 0x01 (), length: 1, data: 1a
[   821][V][BLEUtils.cpp:746] advTypeToString():  adv data type: 0xff
[   821][D][BLEAdvertisedDevice.cpp:292] parseAdvertisement(): Type: 0xff (), length: 20, data: 7500021811a1f553681f5728ffd074b7a1c2fb29
[   839][D][BLEAdvertisedDevice.cpp:449] setManufacturerData(): - manufacturer data: 7500021811a1f553681f5728ffd074b7a1c2fb29
BLE Advertised Device found: Name: , Address: 5e:d9:8b:c2:7b:f9, manufacturer data: 7500021811a1f553681f5728ffd074b7a1c2fb29
custom gap event handler, event: 3 
[   871][V][BLEUtils.cpp:1817] gapEventToString(): gapEventToString: Unknown event type 3 0x03
[   871][V][BLEUtils.cpp:1049] dumpGapEvent(): Received a GAP event: Unknown event type
[   880][V][BLEUtils.cpp:1264] dumpGapEvent(): *** dumpGapEvent: Logger not coded ***
[   887][D][BLEAdvertisedDevice.cpp:472] setRSSI(): - setRSSI(): rssi: -47
[   894][V][BLEUtils.cpp:746] advTypeToString():  adv data type: 0x1
[   894][D][BLEAdvertisedDevice.cpp:292] parseAdvertisement(): Type: 0x01 (), length: 1, data: 0a
[   909][V][BLEUtils.cpp:746] advTypeToString():  adv data type: 0x7
[   909][D][BLEAdvertisedDevice.cpp:292] parseAdvertisement(): Type: 0x07 (), length: 16, data: 00c7c44ee36c51a7334be8ed5a0eb803
[   926][D][BLEAdvertisedDevice.cpp:500] setServiceUUID(): - addServiceUUID(): serviceUUID: 03b80e5a-ede8-4b33-a751-6ce34ec4c700
[   938][V][BLEUtils.cpp:746] advTypeToString():  adv data type: 0x9
[   938][D][BLEAdvertisedDevice.cpp:292] parseAdvertisement(): Type: 0x09 (), length: 20, data: 4e5558204d494748545920504c5547204d494449
[   955][D][BLEAdvertisedDevice.cpp:461] setName(): - setName(): name: NUX MIGHTY PLUG MIDI
BLE Advertised Device found: Name: NUX MIGHTY PLUG MIDI, Address: cb:4e:fd:d7:02:d5, serviceUUID: 03b80e5a-ede8-4b33-a751-6ce34ec4c700
Found our device!  address: [   984][V][BLEScan.cpp:440] stop(): >> stop()
[   985][V][FreeRTOS.cpp:146] give(): Semaphore giving: name: ScanEnd (0x3ffdff98), owner: start
[   990][V][BLEScan.cpp:452] stop(): << stop()
[   990][V][FreeRTOS.cpp:80] wait(): << wait: Semaphore released: name: ScanEnd (0x3ffdff98), owner: <N/A>
[   994][V][BLEScan.cpp:440] stop(): >> stop()
C_fct: Leaving "Setup" function...
[  1008][V][FreeRTOS.cpp:146] give(): Semaphore giving: name: ScanEnd (0x3ffdff98), owner: <N/A>
C_fct: Start "loop" function...
[  1020][V][BLEScan.cpp:452] stop(): << stop()
custom gap event handler, event: 3 
[  1030][V][BLEUtils.cpp:1817] gapEventToString(): gapEventToString: Unknown event type 3 0x03
[  1030][V][BLEUtils.cpp:1049] dumpGapEvent(): Received a GAP event: Unknown event type
[  1046][V][BLEUtils.cpp:1264] dumpGapEvent(): *** dumpGapEvent: Logger not coded ***
custom gap event handler, event: 3 
(...)
[  1545][V][BLEUtils.cpp:1817] gapEventToString(): gapEventToString: Unknown event type 3 0x03
[  1545][V][BLEUtils.cpp:1049] dumpGapEvent(): Received a GAP event: Unknown event type
[  1554][V][BLEUtils.cpp:1264] dumpGapEvent(): *** dumpGapEvent: Logger not coded ***
custom gap event handler, event: 3 
[  1572][V][BLEUtils.cpp:1817] gapEventToString(): gapEventToString: Unknown event type 18 0x12
[  1572][V][BLEUtils.cpp:1049] dumpGapEvent(): Received a GAP event: Unknown event type
[  1581][V][BLEUtils.cpp:1264] dumpGapEvent(): *** dumpGapEvent: Logger not coded ***
custom gap event handler, event: 18 
[  1598][V][BLEUtils.cpp:1817] gapEventToString(): gapEventToString: Unknown event type 18 0x12
[  1598][V][BLEUtils.cpp:1049] dumpGapEvent(): Received a GAP event: Unknown event type
[  1607][V][BLEUtils.cpp:1264] dumpGapEvent(): *** dumpGapEvent: Logger not coded ***
custom gap event handler, event: 18 
C_fct: Start "loop" function...
Wait the end of searching device, 3s...
Wait 3s more
Forming a connection to cb:4e:fd:d7:02:d5
[  8030][V][BLEDevice.cpp:60] createClient(): >> createClient
[  8031][V][BLEDevice.cpp:66] createClient(): << createClient
 - Created client
Wait 1s.
Server address type: 1
[  9144][V][BLEClient.cpp:98] connect(): >> connect(cb:4e:fd:d7:02:d5)
[  9144][I][BLEDevice.cpp:622] addPeerDevice(): add conn_id: 0, GATT role: client
[  9147][V][FreeRTOS.cpp:192] take(): Semaphore taking: name: RegEvt (0x3ffdf380), owner: <N/A> for connect
[  9156][V][FreeRTOS.cpp:204] take(): Semaphore taken:  name: RegEvt (0x3ffdf380), owner: connect
[  9165][V][FreeRTOS.cpp:63] wait(): >> wait: Semaphore waiting: name: RegEvt (0x3ffdf380), owner: connect for connect
[  9165][V][BLEUtils.cpp:951] gattClientEventTypeToString(): Unknown GATT Client event type: 0
[  9165][D][BLEDevice.cpp:148] gattClientEventHandler(): gattClientEventHandler [esp_gatt_if: 4] ... Unknown
[  9193][V][BLEUtils.cpp:951] gattClientEventTypeToString(): Unknown GATT Client event type: 0
[  9193][V][BLEUtils.cpp:1283] dumpGattClientEvent(): GATT Event: Unknown
[  9208][V][BLEUtils.cpp:951] gattClientEventTypeToString(): Unknown GATT Client event type: 0
[  9208][D][BLEClient.cpp:178] gattClientEventHandler(): gattClientEventHandler [esp_gatt_if: 4] ... Unknown
[  9226][V][FreeRTOS.cpp:146] give(): Semaphore giving: name: RegEvt (0x3ffdf380), owner: connect
custom gattc event handler, event: 0 
[  9234][V][FreeRTOS.cpp:80] wait(): << wait: Semaphore released: name: RegEvt (0x3ffdf380), owner: <N/A>
[  9247][V][FreeRTOS.cpp:192] take(): Semaphore taking: name: OpenEvt (0x3ffdf710), owner: <N/A> for connect
[  9256][V][FreeRTOS.cpp:204] take(): Semaphore taken:  name: OpenEvt (0x3ffdf710), owner: connect
[  9265][V][FreeRTOS.cpp:63] wait(): >> wait: Semaphore waiting: name: OpenEvt (0x3ffdf710), owner: connect for connect
[  9333][V][BLEUtils.cpp:951] gattClientEventTypeToString(): Unknown GATT Client event type: 40
[  9333][D][BLEDevice.cpp:148] gattClientEventHandler(): gattClientEventHandler [esp_gatt_if: 4] ... Unknown
[  9342][V][BLEUtils.cpp:951] gattClientEventTypeToString(): Unknown GATT Client event type: 40
[  9342][V][BLEUtils.cpp:1283] dumpGattClientEvent(): GATT Event: Unknown
[  9357][V][BLEUtils.cpp:951] gattClientEventTypeToString(): Unknown GATT Client event type: 40
[  9357][D][BLEClient.cpp:178] gattClientEventHandler(): gattClientEventHandler [esp_gatt_if: 4] ... Unknown
custom gattc event handler, event: 40 
[  9385][V][BLEUtils.cpp:951] gattClientEventTypeToString(): Unknown GATT Client event type: 2
[  9385][D][BLEDevice.cpp:148] gattClientEventHandler(): gattClientEventHandler [esp_gatt_if: 4] ... Unknown
[  9396][V][BLEUtils.cpp:951] gattClientEventTypeToString(): Unknown GATT Client event type: 2
[  9396][V][BLEUtils.cpp:1283] dumpGattClientEvent(): GATT Event: Unknown
[  9411][V][BLEUtils.cpp:951] gattClientEventTypeToString(): Unknown GATT Client event type: 2
[  9411][D][BLEClient.cpp:178] gattClientEventHandler(): gattClientEventHandler [esp_gatt_if: 4] ... Unknown
[  9429][V][FreeRTOS.cpp:146] give(): Semaphore giving: name: OpenEvt (0x3ffdf710), owner: connect
custom gattc event handler, event: 2 
[  9437][V][FreeRTOS.cpp:80] wait(): << wait: Semaphore released: name: OpenEvt (0x3ffdf710), owner: <N/A>
[  9450][V][BLEClient.cpp:149] connect(): << connect(), rc=1
Wait 3s more
[  9461][V][BLEUtils.cpp:1817] gapEventToString(): gapEventToString: Unknown event type 20 0x14
[  9461][V][BLEUtils.cpp:1049] dumpGapEvent(): Received a GAP event: Unknown event type
[  9473][V][BLEUtils.cpp:1264] dumpGapEvent(): *** dumpGapEvent: Logger not coded ***
[  9480][D][BLEClient.cpp:493] handleGAPEvent(): BLEClient ... handling GAP event!
custom gap event handler, event: 20 
 - Connected to server
https://github.com/nkolban/esp32-snippets/issues/874
Try to connect to our service UUID: 03b80e5a-ede8-4b33-a751-6ce34ec4c700
[  9576][V][BLEClient.cpp:412] getService(): >> getService: uuid: 03b80e5a-ede8-4b33-a751-6ce34ec4c700
[  9576][V][BLEClient.cpp:448] getServices(): >> getServices
[  9582][V][BLEClient.cpp:73] clearServices(): >> clearServices
[  9587][V][BLEClient.cpp:80] clearServices(): << clearServices
[  9593][V][FreeRTOS.cpp:192] take(): Semaphore taking: name: SearchCmplEvt (0x3ffdf2a4), owner: <N/A> for getServices
[  9603][V][FreeRTOS.cpp:204] take(): Semaphore taken:  name: SearchCmplEvt (0x3ffdf2a4), owner: getServices
[  9613][V][FreeRTOS.cpp:63] wait(): >> wait: Semaphore waiting: name: SearchCmplEvt (0x3ffdf2a4), owner: getServices for getServices
Guru Meditation Error: Core  0 panic'ed (Double exception). 

Core  0 register dump:
PC      : 0x4009214f  PS      : 0x00040c36  A0      : 0x8011a9dc  A1      : 0x3ffd6d00  
A2      : 0x3ffb6388  A3      : 0x3ffe2178  A4      : 0x3ffbcfd4  A5      : 0x00000000  
A6      : 0x00001800  A7      : 0x00000004  A8      : 0x40080080  A9      : 0x3ffd6df0  
A10     : 0x00060e36  A11     : 0x00040026  A12     : 0x00000000  A13     : 0x3ffc1484  
A14     : 0x3ffe2050  A15     : 0x00000000  SAR     : 0x00000007  EXCCAUSE: 0x00000002  
EXCVADDR: 0xffffffe0  LBEG    : 0x4008f668  LEND    : 0x4008f67e  LCOUNT  : 0xffffffff  


Backtrace:0x4009214c:0x3ffd6d000x4011a9d9:0x3ffd6d20 0x4009214c:0x3ffd6d40 0x4009214c:0x3ffd6d60 0x4009214c:0x3ffd6d90 0x4009214c:0x3ffd6db0 0x4009214c:0x3ffd6dd0 0x4009214c:0x3ffd6df0 0x4008007d:0x3ffd6d00 0x40096e42:0x3ffd6d20 0x4009214c:0x3ffd6d40 0x4009214c:0x3ffd6d60 0x4009214c:0x3ffd6d90 0x4009214c:0x3ffd6db0 0x4009214c:0x3ffd6dd0 0x4009214c:0x3ffd6df0 0x4008007d:0x3ffd6d00 0x40096e42:0x3ffd6d20 0x4009214c:0x3ffd6d40 0x4009214c:0x3ffd6d60 0x4009214c:0x3ffd6d90 0x4009214c:0x3ffd6db0 0x4009214c:0x3ffd6dd0 0x4009214c:0x3ffd6df0 0x4008007d:0x3ffd6d00 0x40096e42:0x3ffd6d20 0x4009214c:0x3ffd6d40 0x4009214c:0x3ffd6d60 0x4009214c:0x3ffd6d90 0x4009214c:0x3ffd6db0 0x4009214c:0x3ffd6dd0 0x4009214c:0x3ffd6df0 0x4008007d:0x3ffd6d00 0x40096e42:0x3ffd6d20 0x4009214c:0x3ffd6d40 0x4009214c:0x3ffd6d60 0x4009214c:0x3ffd6d90 0x4009214c:0x3ffd6db0 0x4009214c:0x3ffd6dd0 0x4009214c:0x3ffd6df0 0x4008007d:0x3ffd6d00 0x40096e42:0x3ffd6d20 0x4009214c:0x3ffd6d40 0x4009214c:0x3ffd6d60 0x4009214c:0x3ffd6d90 0x4009214c:0x3ffd6db0 0x4009214c:0x3ffd6dd0 0x4009214c:0x3ffd6df0 0x4008007d:0x3ffd6d00 0x40096e42:0x3ffd6d20 0x4009214c:0x3ffd6d40 0x4009214c:0x3ffd6d60 0x4009214c:0x3ffd6d90 0x4009214c:0x3ffd6db0 0x4009214c:0x3ffd6dd0 0x4009214c:0x3ffd6df0 0x4008007d:0x3ffd6d00 0x40096e42:0x3ffd6d20 0x4009214c:0x3ffd6d40 0x4009214c:0x3ffd6d60 0x4009214c:0x3ffd6d90 0x4009214c:0x3ffd6db0 0x4009214c:0x3ffd6dd0 0x4009214c:0x3ffd6df0 0x4008007d:0x3ffd6d00 0x40096e42:0x3ffd6d20 0x4009214c:0x3ffd6d40 0x4009214c:0x3ffd6d60 0x4009214c:0x3ffd6d90 0x4009214c:0x3ffd6db0 0x4009214c:0x3ffd6dd0 0x4009214c:0x3ffd6df0 0x4008007d:0x3ffd6d00 0x40096e42:0x3ffd6d20 0x4009214c:0x3ffd6d40 0x4009214c:0x3ffd6d60 0x4009214c:0x3ffd6d90 0x4009214c:0x3ffd6db0 0x4009214c:0x3ffd6dd0 0x4009214c:0x3ffd6df0 0x4008007d:0x3ffd6d00 0x40096e42:0x3ffd6d20 0x4009214c:0x3ffd6d40 0x4009214c:0x3ffd6d60 0x4009214c:0x3ffd6d90 0x4009214c:0x3ffd6db0 0x4009214c:0x3ffd6dd0 0x4009214c:0x3ffd6df0 0x4008007d:0x3ffd6d00 0x40096e42:0x3ffd6d20 0x4009214c:0x3ffd6d40 0x4009214c:0x3ffd6d60 0x4009214c:0x3ffd6d90 0x4009214c:0x3ffd6db0 0x4009214c:0x3ffd6dd0 0x4009214c:0x3ffd6df0 0x4008007d:0x3ffd6d00 0x40096e42:0x3ffd6d20 0x4009214c:0x3ffd6d40 0x4009214c:0x3ffd6d60 0x4009214c:0x3ffd6d90  |<-CONTINUES




ELF file SHA256: 0000000000000000

Rebooting...
ets Jun  8 2016 00:22:57


Decoding stack results
0x4011a9d9: fixed_queue_enqueue at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/bt/common/osi/fixed_queue.c line 142
0x40096e42: multi_heap_malloc at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/heap/multi_heap_poisoning.c line 229
0x40096e42: multi_heap_malloc at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/heap/multi_heap_poisoning.c line 229
0x40096e42: multi_heap_malloc at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/heap/multi_heap_poisoning.c line 229
0x40096e42: multi_heap_malloc at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/heap/multi_heap_poisoning.c line 229
0x40096e42: multi_heap_malloc at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/heap/multi_heap_poisoning.c line 229
0x40096e42: multi_heap_malloc at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/heap/multi_heap_poisoning.c line 229
0x40096e42: multi_heap_malloc at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/heap/multi_heap_poisoning.c line 229
0x40096e42: multi_heap_malloc at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/heap/multi_heap_poisoning.c line 229
0x40096e42: multi_heap_malloc at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/heap/multi_heap_poisoning.c line 229
0x40096e42: multi_heap_malloc at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/heap/multi_heap_poisoning.c line 229
0x40096e42: multi_heap_malloc at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/heap/multi_heap_poisoning.c line 229
0x40096e42: multi_heap_malloc at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/heap/multi_heap_poisoning.c line 229

1st device:

ets Jun  8 2016 00:22:57

rst:0x10 (RTCWDT_RTC_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:1
load:0x3fff0030,len:1240
load:0x40078000,len:13012
load:0x40080400,len:3648
entry 0x400805f8
[⸮⸮m�um⸮⸮⸮⸮2-hal-cpu.c:211] setCpuFrequencyMhz(): PLL: 480 / 2 = 240 Mhz, APB: 80000000 Hz
Starting Arduino BLE Client application...
[   687][V][BLEScan.cpp:385] start(): >> start(duration=10)
[   688][V][FreeRTOS.cpp:192] take(): Semaphore taking: name: ScanEnd (0x3ffdff98), owner: <N/A> for start
[   691][V][FreeRTOS.cpp:204] take(): Semaphore taken:  name: ScanEnd (0x3ffdff98), owner: start
[   700][V][BLEScan.cpp:417] start(): << start()
[   703][V][BLEUtils.cpp:1817] gapEventToString(): gapEventToString: Unknown event type 2 0x02
[   704][V][FreeRTOS.cpp:63] wait(): >> wait: Semaphore waiting: name: ScanEnd (0x3ffdff98), owner: start for start
[   703][V][BLEUtils.cpp:1049] dumpGapEvent(): Received a GAP event: Unknown event type
[   730][V][BLEUtils.cpp:1264] dumpGapEvent(): *** dumpGapEvent: Logger not coded ***
custom gap event handler, event: 2 
[   748][V][BLEUtils.cpp:1817] gapEventToString(): gapEventToString: Unknown event type 7 0x07
[   748][V][BLEUtils.cpp:1049] dumpGapEvent(): Received a GAP event: Unknown event type
[   757][V][BLEUtils.cpp:1264] dumpGapEvent(): *** dumpGapEvent: Logger not coded ***
custom gap event handler, event: 7 
[   806][V][BLEUtils.cpp:1817] gapEventToString(): gapEventToString: Unknown event type 3 0x03
[   806][V][BLEUtils.cpp:1049] dumpGapEvent(): Received a GAP event: Unknown event type
[   811][V][BLEUtils.cpp:1264] dumpGapEvent(): *** dumpGapEvent: Logger not coded ***
(...)
[   985][D][BLEAdvertisedDevice.cpp:472] setRSSI(): - setRSSI(): rssi: -46
[   991][V][BLEUtils.cpp:746] advTypeToString():  adv data type: 0x1
[   991][D][BLEAdvertisedDevice.cpp:292] parseAdvertisement(): Type: 0x01 (), length: 1, data: 05
[  1006][V][BLEUtils.cpp:746] advTypeToString():  adv data type: 0xa
[  1006][D][BLEAdvertisedDevice.cpp:292] parseAdvertisement(): Type: 0x0a (), length: 1, data: 00
[  1020][D][BLEAdvertisedDevice.cpp:530] setTXPower(): - txPower: 0
[  1026][V][BLEUtils.cpp:746] advTypeToString():  adv data type: 0x19
[  1026][D][BLEAdvertisedDevice.cpp:292] parseAdvertisement(): Type: 0x19 (), length: 2, data: c103
[  1041][D][BLEAdvertisedDevice.cpp:437] setAppearance(): - appearance: 961
[  1048][V][BLEUtils.cpp:746] advTypeToString():  adv data type: 0x2
[  1048][D][BLEAdvertisedDevice.cpp:292] parseAdvertisement(): Type: 0x02 (), length: 2, data: e0ff
[  1063][D][BLEAdvertisedDevice.cpp:500] setServiceUUID(): - addServiceUUID(): serviceUUID: 0000ffe0-0000-1000-8000-00805f9b34fb
[  1074][V][BLEUtils.cpp:746] advTypeToString():  adv data type: 0x9
[  1074][D][BLEAdvertisedDevice.cpp:292] parseAdvertisement(): Type: 0x09 (), length: 16, data: 69544147202020202020202020202020
[  1092][D][BLEAdvertisedDevice.cpp:461] setName(): - setName(): name: iTAG            
BLE Advertised Device found: Name: iTAG            , Address: ff:ff:aa:01:c4:07, appearance: 961, serviceUUID: 0000ffe0-0000-1000-8000-00805f9b34fb, txPower: 0
Found our device!  address: [  1120][V][BLEScan.cpp:440] stop(): >> stop()
[  1120][V][FreeRTOS.cpp:146] give(): Semaphore giving: name: ScanEnd (0x3ffdff98), owner: start
[  1128][V][BLEScan.cpp:452] stop(): << stop()
[  1128][V][FreeRTOS.cpp:80] wait(): << wait: Semaphore released: name: ScanEnd (0x3ffdff98), owner: <N/A>
[  1132][V][BLEScan.cpp:440] stop(): >> stop()
C_fct: Leaving "Setup" function...
[  1146][V][FreeRTOS.cpp:146] give(): Semaphore giving: name: ScanEnd (0x3ffdff98), owner: <N/A>
C_fct: Start "loop" function...
[  1158][V][BLEScan.cpp:452] stop(): << stop()
custom gap event handler, event: 3 
[  1168][V][BLEUtils.cpp:1817] gapEventToString(): gapEventToString: Unknown event type 3 0x03
[  1168][V][BLEUtils.cpp:1049] dumpGapEvent(): Received a GAP event: Unknown event type
[  1184][V][BLEUtils.cpp:1264] dumpGapEvent(): *** dumpGapEvent: Logger not coded ***
custom gap event handler, event: 3 
[  1203][V][BLEUtils.cpp:1817] gapEventToString(): gapEventToString: Unknown event type 3 0x03
[  1203][V][BLEUtils.cpp:1049] dumpGapEvent(): Received a GAP event: Unknown event type
[  1211][V][BLEUtils.cpp:1264] dumpGapEvent(): *** dumpGapEvent: Logger not coded ***
custom gap event handler, event: 3 
[  1228][V][BLEUtils.cpp:1817] gapEventToString(): gapEventToString: Unknown event type 3 0x03
[  1228][V][BLEUtils.cpp:1049] dumpGapEvent(): Received a GAP event: Unknown event type
[  1237][V][BLEUtils.cpp:1264] dumpGapEvent(): *** dumpGapEvent: Logger not coded ***
custom gap event handler, event: 3 
[  1255][V][BLEUtils.cpp:1817] gapEventToString(): gapEventToString: Unknown event type 3 0x03
[  1255][V][BLEUtils.cpp:1049] dumpGapEvent(): Received a GAP event: Unknown event type
[  1264][V][BLEUtils.cpp:1264] dumpGapEvent(): *** dumpGapEvent: Logger not coded ***
custom gap event handler, event: 3 
[  1284][V][BLEUtils.cpp:1817] gapEventToString(): gapEventToString: Unknown event type 3 0x03
[  1283][V][BLEUtils.cpp:1049] dumpGapEvent(): Received a GAP event: Unknown event type
[  1291][V][BLEUtils.cpp:1264] dumpGapEvent(): *** dumpGapEvent: Logger not coded ***
custom gap event handler, event: 3 
[  1309][V][BLEUtils.cpp:1817] gapEventToString(): gapEventToString: Unknown event type 3 0x03
[  1309][V][BLEUtils.cpp:1049] dumpGapEvent(): Received a GAP event: Unknown event type
[  1318][V][BLEUtils.cpp:1264] dumpGapEvent(): *** dumpGapEvent: Logger not coded ***
custom gap event handler, event: 3 
[  1335][V][BLEUtils.cpp:1817] gapEventToString(): gapEventToString: Unknown event type 18 0x12
[  1335][V][BLEUtils.cpp:1049] dumpGapEvent(): Received a GAP event: Unknown event type
[  1344][V][BLEUtils.cpp:1264] dumpGapEvent(): *** dumpGapEvent: Logger not coded ***
custom gap event handler, event: 18 
[  1362][V][BLEUtils.cpp:1817] gapEventToString(): gapEventToString: Unknown event type 18 0x12
[  1362][V][BLEUtils.cpp:1049] dumpGapEvent(): Received a GAP event: Unknown event type
[  1371][V][BLEUtils.cpp:1264] dumpGapEvent(): *** dumpGapEvent: Logger not coded ***
custom gap event handler, event: 18 
C_fct: Start "loop" function...
Wait the end of searching device, 3s...
Wait 3s more
Forming a connection to ff:ff:aa:01:c4:07
[  8167][V][BLEDevice.cpp:60] createClient(): >> createClient
[  8168][V][BLEDevice.cpp:66] createClient(): << createClient
 - Created client
Wait 1s.
Server address type: 0
[  9280][V][BLEClient.cpp:98] connect(): >> connect(ff:ff:aa:01:c4:07)
[  9280][I][BLEDevice.cpp:622] addPeerDevice(): add conn_id: 0, GATT role: client
[  9283][V][FreeRTOS.cpp:192] take(): Semaphore taking: name: RegEvt (0x3ffdf67c), owner: <N/A> for connect
[  9292][V][FreeRTOS.cpp:204] take(): Semaphore taken:  name: RegEvt (0x3ffdf67c), owner: connect
[  9301][V][FreeRTOS.cpp:63] wait(): >> wait: Semaphore waiting: name: RegEvt (0x3ffdf67c), owner: connect for connect
[  9301][V][BLEUtils.cpp:951] gattClientEventTypeToString(): Unknown GATT Client event type: 0
[  9301][D][BLEDevice.cpp:148] gattClientEventHandler(): gattClientEventHandler [esp_gatt_if: 4] ... Unknown
[  9329][V][BLEUtils.cpp:951] gattClientEventTypeToString(): Unknown GATT Client event type: 0
[  9329][V][BLEUtils.cpp:1283] dumpGattClientEvent(): GATT Event: Unknown
[  9344][V][BLEUtils.cpp:951] gattClientEventTypeToString(): Unknown GATT Client event type: 0
[  9344][D][BLEClient.cpp:178] gattClientEventHandler(): gattClientEventHandler [esp_gatt_if: 4] ... Unknown
[  9362][V][FreeRTOS.cpp:146] give(): Semaphore giving: name: RegEvt (0x3ffdf67c), owner: connect
custom gattc event handler, event: 0 
[  9370][V][FreeRTOS.cpp:80] wait(): << wait: Semaphore released: name: RegEvt (0x3ffdf67c), owner: <N/A>
[  9383][V][FreeRTOS.cpp:192] take(): Semaphore taking: name: OpenEvt (0x3ffdf6e0), owner: <N/A> for connect
[  9392][V][FreeRTOS.cpp:204] take(): Semaphore taken:  name: OpenEvt (0x3ffdf6e0), owner: connect
[  9401][V][FreeRTOS.cpp:63] wait(): >> wait: Semaphore waiting: name: OpenEvt (0x3ffdf6e0), owner: connect for connect
[  9834][V][BLEUtils.cpp:951] gattClientEventTypeToString(): Unknown GATT Client event type: 40
[  9834][D][BLEDevice.cpp:148] gattClientEventHandler(): gattClientEventHandler [esp_gatt_if: 4] ... Unknown
[  9842][V][BLEUtils.cpp:951] gattClientEventTypeToString(): Unknown GATT Client event type: 40
[  9842][V][BLEUtils.cpp:1283] dumpGattClientEvent(): GATT Event: Unknown
[  9857][V][BLEUtils.cpp:951] gattClientEventTypeToString(): Unknown GATT Client event type: 40
[  9857][D][BLEClient.cpp:178] gattClientEventHandler(): gattClientEventHandler [esp_gatt_if: 4] ... Unknown
custom gattc event handler, event: 40 
[  9885][V][BLEUtils.cpp:951] gattClientEventTypeToString(): Unknown GATT Client event type: 2
[  9885][D][BLEDevice.cpp:148] gattClientEventHandler(): gattClientEventHandler [esp_gatt_if: 4] ... Unknown
[  9896][V][BLEUtils.cpp:951] gattClientEventTypeToString(): Unknown GATT Client event type: 2
[  9896][V][BLEUtils.cpp:1283] dumpGattClientEvent(): GATT Event: Unknown
[  9911][V][BLEUtils.cpp:951] gattClientEventTypeToString(): Unknown GATT Client event type: 2
[  9911][D][BLEClient.cpp:178] gattClientEventHandler(): gattClientEventHandler [esp_gatt_if: 4] ... Unknown
[  9929][V][FreeRTOS.cpp:146] give(): Semaphore giving: name: OpenEvt (0x3ffdf6e0), owner: connect
custom gattc event handler, event: 2 
[  9937][V][FreeRTOS.cpp:80] wait(): << wait: Semaphore released: name: OpenEvt (0x3ffdf6e0), owner: <N/A>
[  9950][V][BLEClient.cpp:149] connect(): << connect(), rc=1
Wait 3s more
 - Connected to server
https://github.com/nkolban/esp32-snippets/issues/874
Try to connect to our service UUID: 00001800-0000-1000-8000-00805f9b34fb
[ 10076][V][BLEClient.cpp:412] getService(): >> getService: uuid: 00001800-0000-1000-8000-00805f9b34fb
[ 10076][V][BLEClient.cpp:448] getServices(): >> getServices
[ 10082][V][BLEClient.cpp:73] clearServices(): >> clearServices
[ 10087][V][BLEClient.cpp:80] clearServices(): << clearServices
[ 10093][V][FreeRTOS.cpp:192] take(): Semaphore taking: name: SearchCmplEvt (0x3ffdf818), owner: <N/A> for getServices
[ 10103][V][FreeRTOS.cpp:204] take(): Semaphore taken:  name: SearchCmplEvt (0x3ffdf818), owner: getServices
[ 10113][V][FreeRTOS.cpp:63] wait(): >> wait: Semaphore waiting: name: SearchCmplEvt (0x3ffdf818), owner: getServices for getServices
[ 10284][V][BLEUtils.cpp:951] gattClientEventTypeToString(): Unknown GATT Client event type: 46
[ 10284][D][BLEDevice.cpp:148] gattClientEventHandler(): gattClientEventHandler [esp_gatt_if: 4] ... Unknown
[ 10291][V][BLEUtils.cpp:951] gattClientEventTypeToString(): Unknown GATT Client event type: 46
[ 10291][V][BLEUtils.cpp:1283] dumpGattClientEvent(): GATT Event: Unknown
[ 10306][V][BLEUtils.cpp:951] gattClientEventTypeToString(): Unknown GATT Client event type: 46
[ 10306][D][BLEClient.cpp:178] gattClientEventHandler(): gattClientEventHandler [esp_gatt_if: 4] ... Unknown
custom gattc event handler, event: 46 
[ 10334][V][BLEUtils.cpp:951] gattClientEventTypeToString(): Unknown GATT Client event type: 7
[ 10334][D][BLEDevice.cpp:148] gattClientEventHandler(): gattClientEventHandler [esp_gatt_if: 4] ... Unknown
[ 10345][V][BLEUtils.cpp:951] gattClientEventTypeToString(): Unknown GATT Client event type: 7
[ 10345][V][BLEUtils.cpp:1283] dumpGattClientEvent(): GATT Event: Unknown
[ 10360][V][BLEUtils.cpp:951] gattClientEventTypeToString(): Unknown GATT Client event type: 7
[ 10360][D][BLEClient.cpp:178] gattClientEventHandler(): gattClientEventHandler [esp_gatt_if: 4] ... Unknown
[ 10378][V][BLERemoteService.cpp:26] BLERemoteService(): >> BLERemoteService()
[ 10385][V][BLERemoteService.cpp:34] BLERemoteService(): << BLERemoteService()
custom gattc event handler, event: 7 
[ 10402][V][BLEUtils.cpp:951] gattClientEventTypeToString(): Unknown GATT Client event type: 7
[ 10402][D][BLEDevice.cpp:148] gattClientEventHandler(): gattClientEventHandler [esp_gatt_if: 4] ... Unknown
[ 10413][V][BLEUtils.cpp:951] gattClientEventTypeToString(): Unknown GATT Client event type: 7
[ 10413][V][BLEUtils.cpp:1283] dumpGattClientEvent(): GATT Event: Unknown
[ 10428][V][BLEUtils.cpp:951] gattClientEventTypeToString(): Unknown GATT Client event type: 7
[ 10428][D][BLEClient.cpp:178] gattClientEventHandler(): gattClientEventHandler [esp_gatt_if: 4] ... Unknown
[ 10446][V][BLERemoteService.cpp:26] BLERemoteService(): >> BLERemoteService()
[ 10453][V][BLERemoteService.cpp:34] BLERemoteService(): << BLERemoteService()
custom gattc event handler, event: 7 
[ 10470][V][BLEUtils.cpp:951] gattClientEventTypeToString(): Unknown GATT Client event type: 7
[ 10470][D][BLEDevice.cpp:148] gattClientEventHandler(): gattClientEventHandler [esp_gatt_if: 4] ... Unknown
[ 10481][V][BLEUtils.cpp:951] gattClientEventTypeToString(): Unknown GATT Client event type: 7
[ 10481][V][BLEUtils.cpp:1283] dumpGattClientEvent(): GATT Event: Unknown
[ 10496][V][BLEUtils.cpp:951] gattClientEventTypeToString(): Unknown GATT Client event type: 7
[ 10496][D][BLEClient.cpp:178] gattClientEventHandler(): gattClientEventHandler [esp_gatt_if: 4] ... Unknown
[ 10513][V][BLERemoteService.cpp:26] BLERemoteService(): >> BLERemoteService()
[ 10520][V][BLERemoteService.cpp:34] BLERemoteService(): << BLERemoteService()
custom gattc event handler, event: 7 
[ 10538][V][BLEUtils.cpp:951] gattClientEventTypeToString(): Unknown GATT Client event type: 7
[ 10538][D][BLEDevice.cpp:148] gattClientEventHandler(): gattClientEventHandler [esp_gatt_if: 4] ... Unknown
[ 10548][V][BLEUtils.cpp:951] gattClientEventTypeToString(): Unknown GATT Client event type: 7
[ 10548][V][BLEUtils.cpp:1283] dumpGattClientEvent(): GATT Event: Unknown
[ 10563][V][BLEUtils.cpp:951] gattClientEventTypeToString(): Unknown GATT Client event type: 7
[ 10563][D][BLEClient.cpp:178] gattClientEventHandler(): gattClientEventHandler [esp_gatt_if: 4] ... Unknown
[ 10582][V][BLERemoteService.cpp:26] BLERemoteService(): >> BLERemoteService()
[ 10588][V][BLERemoteService.cpp:34] BLERemoteService(): << BLERemoteService()
custom gattc event handler, event: 7 
[ 10606][V][BLEUtils.cpp:951] gattClientEventTypeToString(): Unknown GATT Client event type: 6
[ 10606][D][BLEDevice.cpp:148] gattClientEventHandler(): gattClientEventHandler [esp_gatt_if: 4] ... Unknown
[ 10616][V][BLEUtils.cpp:951] gattClientEventTypeToString(): Unknown GATT Client event type: 6
[ 10616][V][BLEUtils.cpp:1283] dumpGattClientEvent(): GATT Event: Unknown
[ 10631][V][BLEUtils.cpp:951] gattClientEventTypeToString(): Unknown GATT Client event type: 6
[ 10631][D][BLEClient.cpp:178] gattClientEventHandler(): gattClientEventHandler [esp_gatt_if: 4] ... Unknown
[ 10649][V][FreeRTOS.cpp:146] give(): Semaphore giving: name: SearchCmplEvt (0x3ffdf818), owner: getServices
custom gattc event handler, event: 6 
[ 10659][V][FreeRTOS.cpp:80] wait(): << wait: Semaphore released: name: SearchCmplEvt (0x3ffdf818), owner: <N/A>
[ 10672][V][BLEClient.cpp:465] getServices(): << getServices
[ 10677][V][BLEClient.cpp:425] getService(): << getService: found the service with uuid: 00001800-0000-1000-8000-00805f9b34fb
 - Found our service
[ 10698][V][BLERemoteService.cpp:162] retrieveCharacteristics(): >> getCharacteristics() for service: 00001800-0000-1000-8000-00805f9b34fb
[ 10702][D][BLERemoteService.cpp:193] retrieveCharacteristics(): Found a characteristic: Handle: 3, UUID: 00002a00-0000-1000-8000-00805f9b34fb
[ 10715][V][BLERemoteCharacteristic.cpp:36] BLERemoteCharacteristic(): >> BLERemoteCharacteristic: handle: 3 0x3, uuid: 00002a00-0000-1000-8000-00805f9b34fb
[ 10728][V][BLERemoteCharacteristic.cpp:263] retrieveDescriptors(): >> retrieveDescriptors() for characteristic: 00002a00-0000-1000-8000-00805f9b34fb
[ 10742][E][BLERemoteCharacteristic.cpp:287] retrieveDescriptors(): esp_ble_gattc_get_all_descr: Unknown
[ 10751][V][BLERemoteCharacteristic.cpp:307] retrieveDescriptors(): << retrieveDescriptors(): Found 0 descriptors.
[ 10761][V][BLERemoteCharacteristic.cpp:46] BLERemoteCharacteristic(): << BLERemoteCharacteristic
[ 10769][D][BLERemoteService.cpp:193] retrieveCharacteristics(): Found a characteristic: Handle: 5, UUID: 00002a01-0000-1000-8000-00805f9b34fb
[ 10782][V][BLERemoteCharacteristic.cpp:36] BLERemoteCharacteristic(): >> BLERemoteCharacteristic: handle: 5 0x5, uuid: 00002a01-0000-1000-8000-00805f9b34fb
[ 10796][V][BLERemoteCharacteristic.cpp:263] retrieveDescriptors(): >> retrieveDescriptors() for characteristic: 00002a01-0000-1000-8000-00805f9b34fb
[ 10809][E][BLERemoteCharacteristic.cpp:287] retrieveDescriptors(): esp_ble_gattc_get_all_descr: Unknown
[ 10818][V][BLERemoteCharacteristic.cpp:307] retrieveDescriptors(): << retrieveDescriptors(): Found 0 descriptors.
[ 10828][V][BLERemoteCharacteristic.cpp:46] BLERemoteCharacteristic(): << BLERemoteCharacteristic
[ 10837][V][BLERemoteService.cpp:209] retrieveCharacteristics(): << getCharacteristics()
 - Found our characteristic
(...)

@chegewara
Copy link
Collaborator

Is it possible that MIDI device has more than 1 service with UUID:
03b80e5a-ede8-4b33-a751-6ce34ec4c700

If you have more esp32, could you try this code to emulate your device and see if your current code still crash:
#510

I will try to find some time to do the same, but it would be good to have your code to perform test or at least the part that is performing connection to device.

@JoFRT
Copy link

JoFRT commented Oct 16, 2021

Yes it is not the only services : here are the others :

I 13:23:05.175 Services discovered (through NRF Connect)
V 13:23:05.180 Generic Access (0x1800)
- Device Name [R W] (0x2A00)
- Peripheral Preferred Connection Parameters [R] (0x2A04)
Unknown Service (00006666-0000-1000-8000-00805f9b34fb)
- Unknown Characteristic [E N R SW W WNR] (00008888-0000-1000-8000-00805f9b34fb)
   Client Characteristic Configuration (0x2902)
Unknown Service (00007777-0000-1000-8000-00805f9b34fb)
- Unknown Characteristic [R SW W WNR] (00008877-0000-1000-8000-00805f9b34fb)
Unknown Service (03b80e5a-ede8-4b33-a751-6ce34ec4c700)
- Unknown Characteristic [N R W WNR] (7772e5db-3868-4112-a1a9-f2669d106bf3)

Yes I have a second esp32, and there is no problem with the client with this server sketch. I give you the log below.

Because of the perfect connection, not sure that giving you my sketch will help, but I put just below just in case :

/**
 * A BLE client example that is rich in capabilities.
 */

#include "BLEAdvertisedDevice.h"
#include "BLEDevice.h"
#include "SerialDebug.h"


//Nux
// Service & Characteristic for switching mode
static BLEUUID serviceUUID("03b80e5a-ede8-4b33-a751-6ce34ec4c700");
static BLEUUID    charUUID("7772e5db-3868-4112-a1a9-f2669d106bf3");

/*
//Itag (black)
static BLEUUID serviceUUID("1800");
static BLEUUID    charUUID("2A00");
*/

static BLEAddress *pServerAddress;
static boolean doConnect = false;
static boolean connected = false;
static BLERemoteCharacteristic* pRemoteCharacteristic;
BLEAdvertisedDevice _advertisedDevice;
BLEScan* pBLEScan;

static void notifyCallback(
  BLERemoteCharacteristic* pBLERemoteCharacteristic,
  uint8_t* pData,
  size_t length,
  bool isNotify) {
    Serial.print("Notify callback for characteristic ");
    Serial.print(pBLERemoteCharacteristic->getUUID().toString().c_str());
    Serial.print(" of data length ");
    Serial.println(length);
}

bool connectToServer(BLEAddress pAddress) {
    Serial.println("Wait the end of searching device, 3s..."); 
    delay(3000);
    Serial.println("Wait 3s more");  delay(3000);
    Serial.print("Forming a connection to ");  Serial.println(pAddress.toString().c_str());
    
    BLEClient*  pClient  = BLEDevice::createClient();
    Serial.println(" - Created client");
    
    Serial.println("Wait 1s.");  delay(1000);


    // Connect to the remove BLE Server.
    //Original line:
      ///pClient->connect(pAddress);  
    //Modified line:
      //XX_Help#2: https://github.com/nkolban/esp32-snippets/issues/757
        ///pClient->connect(pAddress,BLE_ADDR_TYPE_RANDOM);  
      //XX_Help#4: https://github.com/espressif/arduino-esp32/issues/2888 >> https://github.com/nkolban/esp32-snippets/blob/master/cpp_utils/BLEClient.cpp#L109
        esp_ble_addr_type_t type = _advertisedDevice.getAddressType(); 
        Serial.println("Server address type: " + String(type));
        delay(100);
        pClient->connect(pAddress, type); 
      //XX_Help#3: https://github.com/nkolban/esp32-snippets/issues/757  >> https://github.com/nkolban/esp32-snippets/issues/874 >> https://github.com/Flowduino/ESP32_ESP-Now_Pairing/blob/main/Slave/src/main.cpp
        //pClient->connect(&_advertisedDevice); 

    Serial.println("Wait 3s more");  delay(100);

      if (pClient == nullptr) {
        Serial.println("pClient == nullptr");
        delay(100);
      }
https://github.com/nkolban/esp32-snippets/issues/472
      
    Serial.println(" - Connected to server");
    
    Serial.println("https://github.com/nkolban/esp32-snippets/issues/874");

      //Serial.print("C_fct:Nb of characteristic in this service n°: "); Serial.println(String(pClient->getServices()->size()));


    // Obtain a reference to the service we are after in the remote BLE server.
      Serial.print("Try to connect to our service UUID: ");  Serial.println(serviceUUID.toString().c_str());
    BLERemoteService* pRemoteService = pClient->getService(serviceUUID);
    if (pRemoteService == nullptr) {
      Serial.print("Failed to find our service UUID: ");
      Serial.println(serviceUUID.toString().c_str());
      return false;
    }
    Serial.println(" - Found our service");


    // Obtain a reference to the characteristic in the service of the remote BLE server.
    pRemoteCharacteristic = pRemoteService->getCharacteristic(charUUID);
    if (pRemoteCharacteristic == nullptr) {
      Serial.print("Failed to find our characteristic UUID: ");
      Serial.println(charUUID.toString().c_str());
      return false;
    }
    Serial.println(" - Found our characteristic");

    // Read the value of the characteristic.
    std::string value = pRemoteCharacteristic->readValue();
    Serial.print("The characteristic value was: ");
    Serial.println(value.c_str());

    pRemoteCharacteristic->registerForNotify(notifyCallback);

    return true;
}
/**
 * Scan for BLE servers and find the first one that advertises the service we are looking for.
 */
class MyAdvertisedDeviceCallbacks: public BLEAdvertisedDeviceCallbacks {
 /**
   * Called for each advertising BLE server.
   */
  void onResult(BLEAdvertisedDevice advertisedDevice) {
    _advertisedDevice = advertisedDevice;
    Serial.print("BLE Advertised Device found: ");
    Serial.println(advertisedDevice.toString().c_str());

    // We have found a device, let us now see if it contains the service we are looking for.
    // if (advertisedDevice.haveServiceUUID() && advertisedDevice.getServiceUUID().equals(serviceUUID)) {
    //pServerAddress = new BLEAddress ("cb:4e:fd:d7:02:d5"); //Nux 
    //pServerAddress = new BLEAddress ("ff:ff:aa:01:c4:07"); //Itag
    //pServerAddress = new BLEAddress ("7c:9e:bd:4c:34:62"); //Midi server: https://github.com/cococcococ/arduino_BLE_midi_play/commit/8a1a26582a656f6caa329fcb89adca3c8831dbb6
    //This line does not working with some libraries: if (advertisedDevice.getAddress() == *pServerAddress) {
    if (advertisedDevice.getAddress().toString() == "7c:9e:bd:4c:34:62") {
      // 
      Serial.print("Found our device!  address: "); 
      
      advertisedDevice.getScan()->stop();
      pBLEScan->stop();

      pServerAddress = new BLEAddress(advertisedDevice.getAddress());
      doConnect = true;

    } // Found our server
  } // onResult
}; // MyAdvertisedDeviceCallbacks

//XX_Help#1: https://github.com/nkolban/esp32-snippets/issues/757
static void my_gap_event_handler(esp_gap_ble_cb_event_t  event, esp_ble_gap_cb_param_t* param) {
  Serial.printf("custom gap event handler, event: %d \n", (uint8_t)event);
}

//XX_Help#1: https://github.com/nkolban/esp32-snippets/issues/757
static void my_gattc_event_handler(esp_gattc_cb_event_t event, esp_gatt_if_t gattc_if, esp_ble_gattc_cb_param_t* param) {
  Serial.printf("custom gattc event handler, event: %d \n", (uint8_t)event);
}

void setup() {
  Serial.begin(115200);
  Serial.println("Starting Arduino BLE Client application...");
  BLEDevice::init("");
  BLEDevice::setCustomGapHandler(my_gap_event_handler); //XX_Help#1: https://github.com/nkolban/esp32-snippets/issues/757
  BLEDevice::setCustomGattcHandler(my_gattc_event_handler); //XX_Help#1: https://github.com/nkolban/esp32-snippets/issues/757

  // Retrieve a Scanner and set the callback we want to use to be informed when we
  // have detected a new device.  Specify that we want active scanning and start the
  // scan to run for 30 seconds.
  pBLEScan = BLEDevice::getScan();
  pBLEScan->setAdvertisedDeviceCallbacks(new MyAdvertisedDeviceCallbacks());
  pBLEScan->setActiveScan(true);
  pBLEScan->start(10);
  Serial.println("C_fct: Leaving \"Setup\" function...");
} // End of setup.


// This is the Arduino main loop function.
void loop() {
  Serial.println("C_fct: Start \"loop\" function...");

  // If the flag "doConnect" is true then we have scanned for and found the desired
  // BLE Server with which we wish to connect.  Now we connect to it.  Once we are 
  // connected we set the connected flag to be true.
  if (doConnect == true) {


    if (connectToServer(*pServerAddress)) {
      Serial.println("We are now connected to the BLE Server.");
      connected = true;
    } else {
      Serial.println("We have failed to connect to the server; there is nothin more we will do.");
    }
    doConnect = false;
  }

  // If we are connected to a peer BLE Server, update the characteristic each time we are reached
  // with the current time since boot.
  if (connected) {
    Serial.println("if (connected)");
  }

  delay(1000); // Delay a second between loops.
} // End of loop
ets Jun  8 2016 00:22:57

rst:0x10 (RTCWDT_RTC_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:1
load:0x3fff0030,len:1240
load:0x40078000,len:13012
load:0x40080400,len:3648
entry 0x400805f8
[⸮⸮m um⸮⸮⸮⸮2-hal-cpu.c:211] setCpuFrequencyMhz(): PLL: 480 / 2 = 240 Mhz, APB: 80000000 Starting Arduino BLE Client application...
[   683][V][BLEScan.cpp:385] start(): >> start(duration=10)
[   684][V][FreeRTOS.cpp:192] take(): Semaphore taking: name: ScanEnd (0x3ffd49d8), owner: <N/A> for start
[   687][V][FreeRTOS.cpp:204] take(): Semaphore taken:  name: ScanEnd (0x3ffd49d8), owner: start
[   696][V][BLEScan.cpp:417] start(): << start()
[   699][V][BLEUtils.cpp:1817] gapEventToString(): gapEventToString: Unknown event type 2 0x02
[   700][V][FreeRTOS.cpp:63] wait(): >> wait: Semaphore waiting: name: ScanEnd (0x3ffd49d8), owner: start for start
[   699][V][BLEUtils.cpp:1049] dumpGapEvent(): Received a GAP event: Unknown event type
[   726][V][BLEUtils.cpp:1264] dumpGapEvent(): *** dumpGapEvent: Logger not coded ***
custom gap event handler, event: 2 
[   744][V][BLEUtils.cpp:1817] gapEventToString(): gapEventToString: Unknown event type 7 0x07
[   744][V][BLEUtils.cpp:1049] dumpGapEvent(): Received a GAP event: Unknown event type
[   753][V][BLEUtils.cpp:1264] dumpGapEvent(): *** dumpGapEvent: Logger not coded ***
custom gap event handler, event: 7 
[   771][V][BLEUtils.cpp:1817] gapEventToString(): gapEventToString: Unknown event type 3 0x03
[   771][V][BLEUtils.cpp:1049] dumpGapEvent(): Received a GAP event: Unknown event type
[   780][V][BLEUtils.cpp:1264] dumpGapEvent(): *** dumpGapEvent: Logger not coded ***
[   787][D][BLEAdvertisedDevice.cpp:472] setRSSI(): - setRSSI(): rssi: -57
[   794][V][BLEUtils.cpp:746] advTypeToString():  adv data type: 0x1
[   794][D][BLEAdvertisedDevice.cpp:292] parseAdvertisement(): Type: 0x01 (), length: 1, data: 06
[   808][V][BLEUtils.cpp:746] advTypeToString():  adv data type: 0x7
[   808][D][BLEAdvertisedDevice.cpp:292] parseAdvertisement(): Type: 0x07 (), length: 16, data: 00c7c44ee36c51a7334be8ed5a0eb803
[   826][D][BLEAdvertisedDevice.cpp:500] setServiceUUID(): - addServiceUUID(): serviceUUID: 03b80e5a-ede8-4b33-a751-6ce34ec4c700
[   837][V][BLEUtils.cpp:746] advTypeToString():  adv data type: 0x12
[   837][D][BLEAdvertisedDevice.cpp:292] parseAdvertisement(): Type: 0x12 (), length: 4, data: 20004000
[   852][D][BLEAdvertisedDevice.cpp:388] parseAdvertisement(): Unhandled type: adType: 18 - 0x12
[   861][V][BLEUtils.cpp:746] advTypeToString():  adv data type: 0x9
[   861][D][BLEAdvertisedDevice.cpp:292] parseAdvertisement(): Type: 0x09 (), length: 9, data: 4d4944496475696e6f
[   877][D][BLEAdvertisedDevice.cpp:461] setName(): - setName(): name: MIDIduino
[   884][V][BLEUtils.cpp:746] advTypeToString():  adv data type: 0xa
[   884][D][BLEAdvertisedDevice.cpp:292] parseAdvertisement(): Type: 0x0a (), length: 1, data: 03
[   899][D][BLEAdvertisedDevice.cpp:530] setTXPower(): - txPower: 3
[   905][V][BLEUtils.cpp:746] advTypeToString():  adv data type: 0x12
[   905][D][BLEAdvertisedDevice.cpp:292] parseAdvertisement(): Type: 0x12 (), length: 4, data: 20004000
[   920][D][BLEAdvertisedDevice.cpp:388] parseAdvertisement(): Unhandled type: adType: 18 - 0x12
BLE Advertised Device found: Name: MIDIduino, Address: 7c:9e:bd:4c:34:62, serviceUUID: 03b80e5a-ede8-4b33-a751-6ce34ec4c700, txPower: 3
Found our device!  address: [   950][V][BLEScan.cpp:440] stop(): >> stop()
[   950][V][FreeRTOS.cpp:146] give(): Semaphore giving: name: ScanEnd (0x3ffd49d8), owner: start
[   955][V][BLEScan.cpp:452] stop(): << stop()
[   955][V][FreeRTOS.cpp:80] wait(): << wait: Semaphore released: name: ScanEnd (0x3ffd49d8), owner: <N/A>
[   960][V][BLEScan.cpp:440] stop(): >> stop()
C_fct: Leaving "Setup" function...
[   973][V][FreeRTOS.cpp:146] give(): Semaphore giving: name: ScanEnd (0x3ffd49d8), owner: <N/A>
C_fct: Start "loop" function...
[   985][V][BLEScan.cpp:452] stop(): << stop()
custom gap event handler, event: 3 
[   995][V][BLEUtils.cpp:1817] gapEventToString(): gapEventToString: Unknown event type 3 0x03
[   995][V][BLEUtils.cpp:1049] dumpGapEvent(): Received a GAP event: Unknown event type
[  1011][V][BLEUtils.cpp:1264] dumpGapEvent(): *** dumpGapEvent: Logger not coded ***
custom gap event handler, event: 3 
[  1029][V][BLEUtils.cpp:1817] gapEventToString(): gapEventToString: Unknown event type 3 0x03
[  1029][V][BLEUtils.cpp:1049] dumpGapEvent(): Received a GAP event: Unknown event type
[  1038][V][BLEUtils.cpp:1264] dumpGapEvent(): *** dumpGapEvent: Logger not coded ***
custom gap event handler, event: 3 
[  1056][V][BLEUtils.cpp:1817] gapEventToString(): gapEventToString: Unknown event type 3 0x03
[  1056][V][BLEUtils.cpp:1049] dumpGapEvent(): Received a GAP event: Unknown event type
[  1064][V][BLEUtils.cpp:1264] dumpGapEvent(): *** dumpGapEvent: Logger not coded ***
custom gap event handler, event: 3 
[  1082][V][BLEUtils.cpp:1817] gapEventToString(): gapEventToString: Unknown event type 3 0x03
[  1082][V][BLEUtils.cpp:1049] dumpGapEvent(): Received a GAP event: Unknown event type
[  1091][V][BLEUtils.cpp:1264] dumpGapEvent(): *** dumpGapEvent: Logger not coded ***
custom gap event handler, event: 3 
[  1109][V][BLEUtils.cpp:1817] gapEventToString(): gapEventToString: Unknown event type 3 0x03
[  1109][V][BLEUtils.cpp:1049] dumpGapEvent(): Received a GAP event: Unknown event type
[  1118][V][BLEUtils.cpp:1264] dumpGapEvent(): *** dumpGapEvent: Logger not coded ***
custom gap event handler, event: 3 
[  1136][V][BLEUtils.cpp:1817] gapEventToString(): gapEventToString: Unknown event type 3 0x03
[  1136][V][BLEUtils.cpp:1049] dumpGapEvent(): Received a GAP event: Unknown event type
[  1145][V][BLEUtils.cpp:1264] dumpGapEvent(): *** dumpGapEvent: Logger not coded ***
custom gap event handler, event: 3 
[  1163][V][BLEUtils.cpp:1817] gapEventToString(): gapEventToString: Unknown event type 3 0x03
[  1163][V][BLEUtils.cpp:1049] dumpGapEvent(): Received a GAP event: Unknown event type
[  1171][V][BLEUtils.cpp:1264] dumpGapEvent(): *** dumpGapEvent: Logger not coded ***
custom gap event handler, event: 3 
[  1189][V][BLEUtils.cpp:1817] gapEventToString(): gapEventToString: Unknown event type 3 0x03
[  1189][V][BLEUtils.cpp:1049] dumpGapEvent(): Received a GAP event: Unknown event type
[  1198][V][BLEUtils.cpp:1264] dumpGapEvent(): *** dumpGapEvent: Logger not coded ***
custom gap event handler, event: 3 
[  1218][V][BLEUtils.cpp:1817] gapEventToString(): gapEventToString: Unknown event type 3 0x03
[  1218][V][BLEUtils.cpp:1049] dumpGapEvent(): Received a GAP event: Unknown event type
[  1225][V][BLEUtils.cpp:1264] dumpGapEvent(): *** dumpGapEvent: Logger not coded ***
custom gap event handler, event: 3 
[  1243][V][BLEUtils.cpp:1817] gapEventToString(): gapEventToString: Unknown event type 3 0x03
[  1243][V][BLEUtils.cpp:1049] dumpGapEvent(): Received a GAP event: Unknown event type
[  1252][V][BLEUtils.cpp:1264] dumpGapEvent(): *** dumpGapEvent: Logger not coded ***
custom gap event handler, event: 3 
[  1269][V][BLEUtils.cpp:1817] gapEventToString(): gapEventToString: Unknown event type 3 0x03
[  1269][V][BLEUtils.cpp:1049] dumpGapEvent(): Received a GAP event: Unknown event type
[  1278][V][BLEUtils.cpp:1264] dumpGapEvent(): *** dumpGapEvent: Logger not coded ***
custom gap event handler, event: 3 
[  1296][V][BLEUtils.cpp:1817] gapEventToString(): gapEventToString: Unknown event type 3 0x03
[  1296][V][BLEUtils.cpp:1049] dumpGapEvent(): Received a GAP event: Unknown event type
[  1305][V][BLEUtils.cpp:1264] dumpGapEvent(): *** dumpGapEvent: Logger not coded ***
custom gap event handler, event: 3 
[  1323][V][BLEUtils.cpp:1817] gapEventToString(): gapEventToString: Unknown event type 3 0x03
[  1323][V][BLEUtils.cpp:1049] dumpGapEvent(): Received a GAP event: Unknown event type
[  1332][V][BLEUtils.cpp:1264] dumpGapEvent(): *** dumpGapEvent: Logger not coded ***
custom gap event handler, event: 3 
[  1350][V][BLEUtils.cpp:1817] gapEventToString(): gapEventToString: Unknown event type 3 0x03
[  1350][V][BLEUtils.cpp:1049] dumpGapEvent(): Received a GAP event: Unknown event type
[  1359][V][BLEUtils.cpp:1264] dumpGapEvent(): *** dumpGapEvent: Logger not coded ***
custom gap event handler, event: 3 
[  1376][V][BLEUtils.cpp:1817] gapEventToString(): gapEventToString: Unknown event type 3 0x03
[  1376][V][BLEUtils.cpp:1049] dumpGapEvent(): Received a GAP event: Unknown event type
[  1385][V][BLEUtils.cpp:1264] dumpGapEvent(): *** dumpGapEvent: Logger not coded ***
custom gap event handler, event: 3 
[  1403][V][BLEUtils.cpp:1817] gapEventToString(): gapEventToString: Unknown event type 3 0x03
[  1403][V][BLEUtils.cpp:1049] dumpGapEvent(): Received a GAP event: Unknown event type
[  1412][V][BLEUtils.cpp:1264] dumpGapEvent(): *** dumpGapEvent: Logger not coded ***
custom gap event handler, event: 3 
[  1430][V][BLEUtils.cpp:1817] gapEventToString(): gapEventToString: Unknown event type 18 0x12
[  1430][V][BLEUtils.cpp:1049] dumpGapEvent(): Received a GAP event: Unknown event type
[  1439][V][BLEUtils.cpp:1264] dumpGapEvent(): *** dumpGapEvent: Logger not coded ***
custom gap event handler, event: 18 
[  1457][V][BLEUtils.cpp:1817] gapEventToString(): gapEventToString: Unknown event type 18 0x12
[  1457][V][BLEUtils.cpp:1049] dumpGapEvent(): Received a GAP event: Unknown event type
[  1466][V][BLEUtils.cpp:1264] dumpGapEvent(): *** dumpGapEvent: Logger not coded ***
custom gap event handler, event: 18 
C_fct: Start "loop" function...
Wait the end of searching device, 3s...
Wait 3s more
Forming a connection to 7c:9e:bd:4c:34:62
[  7995][V][BLEDevice.cpp:60] createClient(): >> createClient
[  7996][V][BLEDevice.cpp:66] createClient(): << createClient
 - Created client
Wait 1s.
Server address type: 0
[  9108][V][BLEClient.cpp:98] connect(): >> connect(7c:9e:bd:4c:34:62)
[  9108][I][BLEDevice.cpp:622] addPeerDevice(): add conn_id: 0, GATT role: client
[  9111][V][FreeRTOS.cpp:192] take(): Semaphore taking: name: RegEvt (0x3ffdf8f0), owner: <N/A> for connect
[  9120][V][FreeRTOS.cpp:204] take(): Semaphore taken:  name: RegEvt (0x3ffdf8f0), owner: connect
[  9129][V][FreeRTOS.cpp:63] wait(): >> wait: Semaphore waiting: name: RegEvt (0x3ffdf8f0), owner: connect for connect
[  9129][V][BLEUtils.cpp:951] gattClientEventTypeToString(): Unknown GATT Client event type: 0
[  9129][D][BLEDevice.cpp:148] gattClientEventHandler(): gattClientEventHandler [esp_gatt_if: 4] ... Unknown
[  9157][V][BLEUtils.cpp:951] gattClientEventTypeToString(): Unknown GATT Client event type: 0
[  9157][V][BLEUtils.cpp:1283] dumpGattClientEvent(): GATT Event: Unknown
[  9172][V][BLEUtils.cpp:951] gattClientEventTypeToString(): Unknown GATT Client event type: 0
[  9172][D][BLEClient.cpp:178] gattClientEventHandler(): gattClientEventHandler [esp_gatt_if: 4] ... Unknown
[  9190][V][FreeRTOS.cpp:146] give(): Semaphore giving: name: RegEvt (0x3ffdf8f0), owner: connect
custom gattc event handler, event: 0 
[  9198][V][FreeRTOS.cpp:80] wait(): << wait: Semaphore released: name: RegEvt (0x3ffdf8f0), owner: <N/A>
[  9211][V][FreeRTOS.cpp:192] take(): Semaphore taking: name: OpenEvt (0x3ffdf954), owner: <N/A> for connect
[  9220][V][FreeRTOS.cpp:204] take(): Semaphore taken:  name: OpenEvt (0x3ffdf954), owner: connect
[  9229][V][FreeRTOS.cpp:63] wait(): >> wait: Semaphore waiting: name: OpenEvt (0x3ffdf954), owner: connect for connect
lld_pdu_get_tx_flush_nb HCI packet count mismatch (0, 1)
[  9398][V][BLEUtils.cpp:951] gattClientEventTypeToString(): Unknown GATT Client event type: 40
[  9398][D][BLEDevice.cpp:148] gattClientEventHandler(): gattClientEventHandler [esp_gatt_if: 4] ... Unknown
[  9405][V][BLEUtils.cpp:951] gattClientEventTypeToString(): Unknown GATT Client event type: 40
[  9405][V][BLEUtils.cpp:1283] dumpGattClientEvent(): GATT Event: Unknown
[  9420][V][BLEUtils.cpp:951] gattClientEventTypeToString(): Unknown GATT Client event type: 40
[  9420][D][BLEClient.cpp:178] gattClientEventHandler(): gattClientEventHandler [esp_gatt_if: 4] ... Unknown
custom gattc event handler, event: 40 
[  9449][V][BLEUtils.cpp:951] gattClientEventTypeToString(): Unknown GATT Client event type: 2
[  9448][D][BLEDevice.cpp:148] gattClientEventHandler(): gattClientEventHandler [esp_gatt_if: 4] ... Unknown
[  9459][V][BLEUtils.cpp:951] gattClientEventTypeToString(): Unknown GATT Client event type: 2
[  9459][V][BLEUtils.cpp:1283] dumpGattClientEvent(): GATT Event: Unknown
[  9474][V][BLEUtils.cpp:951] gattClientEventTypeToString(): Unknown GATT Client event type: 2
[  9474][D][BLEClient.cpp:178] gattClientEventHandler(): gattClientEventHandler [esp_gatt_if: 4] ... Unknown
[  9493][V][FreeRTOS.cpp:146] give(): Semaphore giving: name: OpenEvt (0x3ffdf954), owner: connect
custom gattc event handler, event: 2 
[  9501][V][FreeRTOS.cpp:80] wait(): << wait: Semaphore released: name: OpenEvt (0x3ffdf954), owner: <N/A>
[  9514][V][BLEClient.cpp:149] connect(): << connect(), rc=1
Wait 3s more
 - Connected to server
https://github.com/nkolban/esp32-snippets/issues/874
Try to connect to our service UUID: 03b80e5a-ede8-4b33-a751-6ce34ec4c700
[  9640][V][BLEClient.cpp:412] getService(): >> getService: uuid: 03b80e5a-ede8-4b33-a751-6ce34ec4c700
[  9640][V][BLEClient.cpp:448] getServices(): >> getServices
[  9646][V][BLEClient.cpp:73] clearServices(): >> clearServices
[  9651][V][BLEClient.cpp:80] clearServices(): << clearServices
[  9657][V][FreeRTOS.cpp:192] take(): Semaphore taking: name: SearchCmplEvt (0x3ffdf350), owner: <N/A> for getServices
[  9667][V][FreeRTOS.cpp:204] take(): Semaphore taken:  name: SearchCmplEvt (0x3ffdf350), owner: getServices
[  9677][V][FreeRTOS.cpp:63] wait(): >> wait: Semaphore waiting: name: SearchCmplEvt (0x3ffdf350), owner: getServices for getServices
[  9875][V][BLEUtils.cpp:951] gattClientEventTypeToString(): Unknown GATT Client event type: 46
[  9874][D][BLEDevice.cpp:148] gattClientEventHandler(): gattClientEventHandler [esp_gatt_if: 4] ... Unknown
[  9881][V][BLEUtils.cpp:951] gattClientEventTypeToString(): Unknown GATT Client event type: 46
[  9881][V][BLEUtils.cpp:1283] dumpGattClientEvent(): GATT Event: Unknown
[  9896][V][BLEUtils.cpp:951] gattClientEventTypeToString(): Unknown GATT Client event type: 46
[  9896][D][BLEClient.cpp:178] gattClientEventHandler(): gattClientEventHandler [esp_gatt_if: 4] ... Unknown
custom gattc event handler, event: 46 
[  9925][V][BLEUtils.cpp:951] gattClientEventTypeToString(): Unknown GATT Client event type: 7
[  9925][D][BLEDevice.cpp:148] gattClientEventHandler(): gattClientEventHandler [esp_gatt_if: 4] ... Unknown
[  9936][V][BLEUtils.cpp:951] gattClientEventTypeToString(): Unknown GATT Client event type: 7
[  9936][V][BLEUtils.cpp:1283] dumpGattClientEvent(): GATT Event: Unknown
[  9951][V][BLEUtils.cpp:951] gattClientEventTypeToString(): Unknown GATT Client event type: 7
[  9951][D][BLEClient.cpp:178] gattClientEventHandler(): gattClientEventHandler [esp_gatt_if: 4] ... Unknown
[  9968][V][BLERemoteService.cpp:26] BLERemoteService(): >> BLERemoteService()
[  9975][V][BLERemoteService.cpp:34] BLERemoteService(): << BLERemoteService()
custom gattc event handler, event: 7 
[  9993][V][BLEUtils.cpp:951] gattClientEventTypeToString(): Unknown GATT Client event type: 7
[  9993][D][BLEDevice.cpp:148] gattClientEventHandler(): gattClientEventHandler [esp_gatt_if: 4] ... Unknown
[ 10003][V][BLEUtils.cpp:951] gattClientEventTypeToString(): Unknown GATT Client event type: 7
[ 10003][V][BLEUtils.cpp:1283] dumpGattClientEvent(): GATT Event: Unknown
[ 10018][V][BLEUtils.cpp:951] gattClientEventTypeToString(): Unknown GATT Client event type: 7
[ 10018][D][BLEClient.cpp:178] gattClientEventHandler(): gattClientEventHandler [esp_gatt_if: 4] ... Unknown
[ 10036][V][BLERemoteService.cpp:26] BLERemoteService(): >> BLERemoteService()
[ 10043][V][BLERemoteService.cpp:34] BLERemoteService(): << BLERemoteService()
custom gattc event handler, event: 7 
[ 10061][V][BLEUtils.cpp:951] gattClientEventTypeToString(): Unknown GATT Client event type: 7
[ 10061][D][BLEDevice.cpp:148] gattClientEventHandler(): gattClientEventHandler [esp_gatt_if: 4] ... Unknown
[ 10071][V][BLEUtils.cpp:951] gattClientEventTypeToString(): Unknown GATT Client event type: 7
[ 10071][V][BLEUtils.cpp:1283] dumpGattClientEvent(): GATT Event: Unknown
[ 10086][V][BLEUtils.cpp:951] gattClientEventTypeToString(): Unknown GATT Client event type: 7
[ 10086][D][BLEClient.cpp:178] gattClientEventHandler(): gattClientEventHandler [esp_gatt_if: 4] ... Unknown
[ 10104][V][BLERemoteService.cpp:26] BLERemoteService(): >> BLERemoteService()
[ 10111][V][BLERemoteService.cpp:34] BLERemoteService(): << BLERemoteService()
custom gattc event handler, event: 7 
[ 10128][V][BLEUtils.cpp:951] gattClientEventTypeToString(): Unknown GATT Client event type: 6
[ 10128][D][BLEDevice.cpp:148] gattClientEventHandler(): gattClientEventHandler [esp_gatt_if: 4] ... Unknown
[ 10139][V][BLEUtils.cpp:951] gattClientEventTypeToString(): Unknown GATT Client event type: 6
[ 10139][V][BLEUtils.cpp:1283] dumpGattClientEvent(): GATT Event: Unknown
[ 10154][V][BLEUtils.cpp:951] gattClientEventTypeToString(): Unknown GATT Client event type: 6
[ 10154][D][BLEClient.cpp:178] gattClientEventHandler(): gattClientEventHandler [esp_gatt_if: 4] ... Unknown
[ 10172][V][FreeRTOS.cpp:146] give(): Semaphore giving: name: SearchCmplEvt (0x3ffdf350), owner: getServices
custom gattc event handler, event: 6 
[ 10181][V][FreeRTOS.cpp:80] wait(): << wait: Semaphore released: name: SearchCmplEvt (0x3ffdf350), owner: <N/A>
[ 10194][V][BLEClient.cpp:465] getServices(): << getServices
[ 10200][V][BLEClient.cpp:425] getService(): << getService: found the service with uuid: 03b80e5a-ede8-4b33-a751-6ce34ec4c700
 - Found our service
[ 10221][V][BLERemoteService.cpp:162] retrieveCharacteristics(): >> getCharacteristics() for service: 03b80e5a-ede8-4b33-a751-6ce34ec4c700
[ 10225][D][BLERemoteService.cpp:193] retrieveCharacteristics(): Found a characteristic: Handle: 42, UUID: 7772e5db-3868-4112-a1a9-f2669d106bf3
[ 10238][V][BLERemoteCharacteristic.cpp:36] BLERemoteCharacteristic(): >> BLERemoteCharacteristic: handle: 42 0x42, uuid: 7772e5db-3868-4112-a1a9-f2669d106bf3
[ 10251][V][BLERemoteCharacteristic.cpp:263] retrieveDescriptors(): >> retrieveDescriptors() for characteristic: 7772e5db-3868-4112-a1a9-f2669d106bf3
[ 10265][D][BLERemoteCharacteristic.cpp:293] retrieveDescriptors(): Found a descriptor: Handle: 43, UUID: 00002902-0000-1000-8000-00805f9b34fb
[ 10277][V][BLERemoteCharacteristic.cpp:307] retrieveDescriptors(): << retrieveDescriptors(): Found 1 descriptors.
[ 10287][V][BLERemoteCharacteristic.cpp:46] BLERemoteCharacteristic(): << BLERemoteCharacteristic
[ 10296][V][BLERemoteService.cpp:209] retrieveCharacteristics(): << getCharacteristics()
 - Found our characteristic 

@chegewara
Copy link
Collaborator

      if (pClient == nullptr) {
        Serial.println("pClient == nullptr");
        delay(100);
// you should return false here, but actually this code makes no sense because earlier you have pClient->connect() which will crash
      }

Instead try to add short delay and check pClient->isConnected();

I also advice to use this connect function (there is nothing wrong with your way to do it):
https://github.com/espressif/arduino-esp32/blob/master/libraries/BLE/src/BLEClient.h#L36

If you are not working with arduino it is still possible to use library from it (copy/paste).

The code crash exactly here:

    // Obtain a reference to the service we are after in the remote BLE server.
      Serial.print("Try to connect to our service UUID: ");  Serial.println(serviceUUID.toString().c_str());
    BLERemoteService* pRemoteService = pClient->getService(serviceUUID);
    if (pRemoteService == nullptr) {
      Serial.print("Failed to find our service UUID: ");
      Serial.println(serviceUUID.toString().c_str());
      return false;
    }
    Serial.println(" - Found our service");

and i am suspecting that device you are connecting with is disconnecting for some reason before this code is called.

I would start with comment out this code and see whats going on:

    // Obtain a reference to the service we are after in the remote BLE server.
      Serial.print("Try to connect to our service UUID: ");  Serial.println(serviceUUID.toString().c_str());
    BLERemoteService* pRemoteService = pClient->getService(serviceUUID);
    if (pRemoteService == nullptr) {
      Serial.print("Failed to find our service UUID: ");
      Serial.println(serviceUUID.toString().c_str());
      return false;
    }
    Serial.println(" - Found our service");


    // Obtain a reference to the characteristic in the service of the remote BLE server.
    pRemoteCharacteristic = pRemoteService->getCharacteristic(charUUID);
    if (pRemoteCharacteristic == nullptr) {
      Serial.print("Failed to find our characteristic UUID: ");
      Serial.println(charUUID.toString().c_str());
      return false;
    }
    Serial.println(" - Found our characteristic");

    // Read the value of the characteristic.
    std::string value = pRemoteCharacteristic->readValue();
    Serial.print("The characteristic value was: ");
    Serial.println(value.c_str());

    pRemoteCharacteristic->registerForNotify(notifyCallback);

@JoFRT
Copy link

JoFRT commented Oct 16, 2021

I have just one thing to say: many many many and many thanks to you Chegewara 👍 .
Finally the sketch works perfectly after the addition of one delay.
But let's start by the beginning...
-> I have done the changes you suggested, and then I can see that the led of the device informing of bluetooth connection switched on a few seconds later.
-> So in my second trial I have enlarged the the delay you precognized to 10s (to be sure but 2-3s is enough).
-> Then the miracle appears in front of me: the connection passed!
-> I have tried then to modify a characteristic and it works perfectly.
I am wandering if the is a way to monitor when the device will be ready to accept the server connection. But for it is ok like that for me!.
So many thanks to you and also for the others for repling on issues for this 874 item and for the other items.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests