BLE client connection problems
Re: BLE client connection problems
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.
Re: BLE client connection problems
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:
to this:
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?
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
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!");
}
}
};
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?
Re: BLE client connection problems
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.
Re: BLE client connection problems
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?
Re: BLE client connection problems
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.
- lucasromeiro
- Posts: 5
- Joined: Sun Feb 03, 2019 1:00 pm
Re: BLE client connection problems
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?
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: No registered users and 64 guests