BLE: limited number of services and characteristics

Paolo_g
Posts: 2
Joined: Thu Sep 27, 2018 10:54 am

BLE: limited number of services and characteristics

Postby Paolo_g » Thu Sep 27, 2018 12:22 pm

Hi,
I'm using BLE on ESP32.
The ESP32 board is my server.
I have a problem: the number of services is limited to 7, and also the number of characteristics is limited to 7.
If I try to use more services or characteristics the client (the smartphone or another ESP32 board) can't see them.
Is it possible to use more services and characteristics?
I have tried to see if there are some #define in the .h files that limit this number, but I don't have found anything.
Thank you

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

Re: BLE: limited number of services and characteristics

Postby chegewara » Thu Sep 27, 2018 2:11 pm


Paolo_g
Posts: 2
Joined: Thu Sep 27, 2018 10:54 am

Re: BLE: limited number of services and characteristics

Postby Paolo_g » Sun Sep 30, 2018 1:55 pm

Thank you very much!
If other people are interested in this: the parameter numHandles of the function createService allows you to specify the number of characteristics.
Just out of curiosity: is it possible to change also the number of services?

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

Re: BLE: limited number of services and characteristics

Postby chegewara » Sun Sep 30, 2018 4:46 pm

There is no services number limit. Only limit is handles number which is 0xFFFF.

Eckii24
Posts: 1
Joined: Sat Jan 25, 2020 10:44 pm

Re: BLE: limited number of services and characteristics

Postby Eckii24 » Sat Jan 25, 2020 10:47 pm

I have the same issue with the number of services for the esp32.
The following code stops after starting the seventh service.

Is the number of possible BLE-services on an ESP32 limited or can I change something in the code to expand the number?
  1. /*
  2.     Based on Neil Kolban example for IDF: https://github.com/nkolban/esp32-snippets/blob/master/cpp_utils/tests/BLE%20Tests/SampleServer.cpp
  3.     Ported to Arduino ESP32 by Evandro Copercini
  4.     updates by chegewara
  5. */
  6.  
  7. #include <BLEDevice.h>
  8. #include <BLEUtils.h>
  9. #include <BLEServer.h>
  10.  
  11. // See the following for generating UUIDs:
  12. // https://www.uuidgenerator.net/
  13.  
  14. #define SERVICE1_UUID        "4fafc201-1fb5-459e-8fcc-c5c9c331914b"
  15. #define SERVICE2_UUID        "5fafc201-1fb5-459e-8fcc-c5c9c331914b"
  16. #define SERVICE3_UUID        "6fafc201-1fb5-459e-8fcc-c5c9c331914b"
  17. #define SERVICE4_UUID        "7fafc201-1fb5-459e-8fcc-c5c9c331914b"
  18. #define SERVICE5_UUID        "8fafc201-1fb5-459e-8fcc-c5c9c331914b"
  19. #define SERVICE6_UUID        "9fafc201-1fb5-459e-8fcc-c5c9c331914b"
  20. #define SERVICE7_UUID        "4fafc301-1fb5-459e-8fcc-c5c9c331914b"
  21. #define SERVICE8_UUID        "4fafc401-1fb5-459e-8fcc-c5c9c331914b"
  22. #define SERVICE9_UUID        "4fafc501-1fb5-459e-8fcc-c5c9c331914b"
  23. #define SERVICE10_UUID       "4fafc601-1fb5-459e-8fcc-c5c9c331914b"
  24.  
  25. void setup() {
  26.   Serial.begin(115200);
  27.   Serial.println("Starting BLE work!");
  28.  
  29.   BLEDevice::init("Long name works now");
  30.   BLEServer *pServer = BLEDevice::createServer();
  31.  
  32.   Serial.println("Service1");
  33.   BLEService *pService1 = pServer->createService(SERVICE1_UUID);
  34.   BLECharacteristic *pCharacteristic1 = pService1->createCharacteristic(SERVICE1_UUID, BLECharacteristic::PROPERTY_READ);
  35.   pCharacteristic1->setValue("Hello World says Neil");
  36.   pService1->start();
  37.  
  38.   Serial.println("Service2");
  39.   BLEService *pService2 = pServer->createService(SERVICE2_UUID);
  40.   BLECharacteristic *pCharacteristic2 = pService2->createCharacteristic(SERVICE2_UUID, BLECharacteristic::PROPERTY_READ);
  41.   pCharacteristic2->setValue("Hello World says Neil");
  42.   pService2->start();
  43.  
  44.   Serial.println("Service3");
  45.   BLEService *pService3 = pServer->createService(SERVICE3_UUID);
  46.   BLECharacteristic *pCharacteristic3 = pService3->createCharacteristic(SERVICE3_UUID, BLECharacteristic::PROPERTY_READ);
  47.   pCharacteristic3->setValue("Hello World says Neil");
  48.   pService3->start();
  49.  
  50.   Serial.println("Service4");
  51.   BLEService *pService4 = pServer->createService(SERVICE4_UUID);
  52.   BLECharacteristic *pCharacteristic4 = pService4->createCharacteristic(SERVICE4_UUID, BLECharacteristic::PROPERTY_READ);
  53.   pCharacteristic4->setValue("Hello World says Neil");
  54.   pService4->start();
  55.  
  56.   Serial.println("Service5");
  57.   BLEService *pService5 = pServer->createService(SERVICE5_UUID);
  58.   BLECharacteristic *pCharacteristic5 = pService5->createCharacteristic(SERVICE5_UUID, BLECharacteristic::PROPERTY_READ);
  59.   pCharacteristic5->setValue("Hello World says Neil");
  60.   pService5->start();
  61.  
  62.   Serial.println("Service6");
  63.   BLEService *pService6 = pServer->createService(SERVICE6_UUID);
  64.   BLECharacteristic *pCharacteristic6 = pService6->createCharacteristic(SERVICE6_UUID, BLECharacteristic::PROPERTY_READ);
  65.   pCharacteristic6->setValue("Hello World says Neil");
  66.   pService6->start();
  67.  
  68.   Serial.println("Service7");
  69.   BLEService *pService7 = pServer->createService(SERVICE7_UUID);
  70.   BLECharacteristic *pCharacteristic7 = pService7->createCharacteristic(SERVICE7_UUID, BLECharacteristic::PROPERTY_READ);
  71.   pCharacteristic7->setValue("Hello World says Neil");
  72.   pService7->start();
  73.  
  74.   Serial.println("Service8");
  75.   BLEService *pService8 = pServer->createService(SERVICE8_UUID);
  76.   BLECharacteristic *pCharacteristic8 = pService8->createCharacteristic(SERVICE8_UUID, BLECharacteristic::PROPERTY_READ);
  77.   pCharacteristic8->setValue("Hello World says Neil");
  78.   pService8->start();
  79.  
  80.   Serial.println("Service9");
  81.   BLEService *pService9 = pServer->createService(SERVICE9_UUID);
  82.   BLECharacteristic *pCharacteristic9 = pService9->createCharacteristic(SERVICE9_UUID, BLECharacteristic::PROPERTY_READ);
  83.   pCharacteristic9->setValue("Hello World says Neil");
  84.   pService9->start();
  85.  
  86.   Serial.println("Service10");
  87.   BLEService *pService10 = pServer->createService(SERVICE10_UUID);
  88.   BLECharacteristic *pCharacteristic10 = pService10->createCharacteristic(SERVICE10_UUID, BLECharacteristic::PROPERTY_READ);
  89.   pCharacteristic10->setValue("Hello World says Neil");
  90.   pService10->start();
  91.  
  92.  
  93.   BLEDevice::startAdvertising();
  94.   Serial.println("Characteristic defined! Now you can read it in your phone!");
  95. }
  96.  
  97. void loop() {
  98.   // put your main code here, to run repeatedly:
  99.   delay(2000);
  100. }

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

Re: BLE: limited number of services and characteristics

Postby chegewara » Sun Jan 26, 2020 11:00 pm

I tried this code with esp-idf in PIO and i found this, which is very strange:

Code: Select all

BT_GATT: GATTS_ReserveHandles: no free handle blocks
You can try to use this function and decrease numHandles:
https://github.com/nkolban/esp32-snippe ... rver.h#L67

Each characteristic needs 2 handles and descriptor 1 handle.

dhiraj_gehlot
Posts: 8
Joined: Thu Jul 30, 2020 11:23 am

Re: BLE: limited number of services and characteristics

Postby dhiraj_gehlot » Tue Nov 09, 2021 2:10 pm

Hello,

I am facing exactly same issue.
I am using Arduino IDE to code ESP-32 module. Currently I am using BLE functionality to communicate with our mobile app.
There seems to be limitation on number of BLE services which can be created. Even If I create more than 7 services, only 6 are visible.

I find some link which states solution in ESP-IDF but I couldn't find this variable GATT_MAX_SR_PROFILES or bt_target.h file:
https://github.com/espressif/esp-idf/issues/1644
https://github.com/espressif/esp-idf/issues/5495

Can someone help me?

Who is online

Users browsing this forum: No registered users and 29 guests