BLE client connection problems

chegewara
Posts: 2207
Joined: Wed Jun 14, 2017 9:00 pm

Re: BLE client connection problems

Postby chegewara » Sat Aug 11, 2018 7:17 pm

Hi, i performed simple test with your code and seems to work (except when peer device is disconnecting). What i did is run server on my smartphone with nRF connect with service and characteristic from your code. Esp32 is connecting to it and writing to remote characteristic.

Kording
Posts: 7
Joined: Wed Jul 25, 2018 9:01 pm

Re: BLE client connection problems

Postby Kording » Thu Aug 30, 2018 9:33 am

Hi, thanks for testing my code. Unfortunatly whatever I do this specific code won't work on my devices.

I did some research and changed this part:

Code: Select all

class MyAdvertisedDeviceCallbacks: public BLEAdvertisedDeviceCallbacks {
 /**
   * Called for each advertising BLE server.
   */
  void onResult(BLEAdvertisedDevice 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() ) {

      // 
      Serial.print("Found our device!  address: "); 
      advertisedDevice.getScan()->stop();

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

    } // Found our server
  } // onResult
}; // MyAdvertisedDeviceCallbacks
to this:

Code: Select all

class MyAdvertisedDeviceCallbacks: public BLEAdvertisedDeviceCallbacks {
 
    void onResult(BLEAdvertisedDevice advertisedDevice) {
      if (advertisedDevice.getName() == "MyESP32") { //Check if the name of the advertiser matches
        advertisedDevice.getScan()->stop(); //Scan can be stopped, we found what we are looking for
        pServerAddress = new BLEAddress(advertisedDevice.getAddress()); //Address of advertiser is the one we need
        doConnect = true; //Set indicator, stating that we are ready to connect
        Serial.println("Device found. Connecting!");
      }
    }
};
Now it connects right away to the device, which is great, but I have an other problem.
Some values will be displayed or interpreted the wrong way and I hope you can help me figure this out aswell.
For example the serial monitor displays the device name "50429-97" as just "e" or sometimes it displayes an arrow symbol.

I am still not quite sure, I am using the wrong UUIDs from the nRF-App or converting them the wrong way. Could you show me what I would have to use as my service and characteristic UUIDs for reading the "Device Name" under the "Generic Access" in this screenshot?

Image

chegewara
Posts: 2207
Joined: Wed Jun 14, 2017 9:00 pm

Re: BLE client connection problems

Postby chegewara » Fri Aug 31, 2018 11:57 pm

The problem with searching ble device by uuid is that some devices are very tricky. Because advertising packet is limited to 31+31 bytes some devices are advertising only incomplete 16-bit serviceUUID. What this mean, it means that device after connecting is serving more than one service, but thats not all. Usually in such case that 16-bit serviceUUID is completely different than any service served after connection accomplished. Im not saying its the case, its also possible that your device is not advertising any serviceUUID. Its not possible to say anything from this screenshot.

Kording
Posts: 7
Joined: Wed Jul 25, 2018 9:01 pm

Re: BLE client connection problems

Postby Kording » Thu Sep 06, 2018 10:38 am

So how do I find the right service then? I thought looking up the UUID via this app would get me my desired service/value. Is there a way to connect to my device via the name and let the ESP display all the available services and characteristics from said device? Then I would be able to pick the correct one I am looking for, right?

chegewara
Posts: 2207
Joined: Wed Jun 14, 2017 9:00 pm

Re: BLE client connection problems

Postby chegewara » Thu Sep 06, 2018 2:23 pm

Sure, you can find peer device by name and connect to it. Then you can find remoteService by uuid as usual (see examples) and finally when service is not null then find remoteCharacteristic.

User avatar
lucasromeiro
Posts: 5
Joined: Sun Feb 03, 2019 1:00 pm

Re: BLE client connection problems

Postby lucasromeiro » Fri Apr 02, 2021 12:09 am

Hello, how did you solve your problem?
I have a esp 32 and need to connect a ble temperature and humidity sensor. I have the same problems. I can not connect. Can you help me?

Who is online

Users browsing this forum: PepeTheGreat and 63 guests