[ESP32] Create/Add BLE characteristic dynamic while service is already running

I'm successfully running a BLE Server on an ESP32 with a single service and a single characteristic.

Now I want to add an additional characteristic without disconnecting clients.

Use case: a client is connected and should enable a second characteristic which is not advertised in normal mode.

I already tried


as well as


But it seems like nothing changed.

Another option I could imagine, is the second characteristic registered on setup and changed its properties later as fallback.

Welcome to the forum.

Please read the How to get the best out of this forum

A full example would have been useful to allow others to experiment with your source code.

Another option which some commercial BLE products seem to use is to require the client to write something e.g., secret to one characteristic within a certain time and disconnect the client when this does not happen.

Of course, this does not provide a lot of security.

Sorry Klaus_K but your response is 100% nonsense. I asked a generally relevant question without the requirements.

Sorry Klaus_K but your response is 100% nonsense. I asked a generally relevant question without the requirements.

May I offer my sincere apology.

Maybe you will find the following information more useful.

  • pService->createCharacteristic() will call pService->addCharacteristic() internally

  • the addCharacteristic() function will just add the characteristic to an object called m_characteristicMap

  • the start() function will actually start all of the characteristics using the m_characteristicMap, so you need to add one line to your server code


When you try this with a generic BLE app you will find that nothing seems to have changed. The reason is, they all scan the server only once when they connect. They do not expect services and characteristics to be added after connecting.

I modified a sensor sketch for an ESP32 an added a new characteristic when a sensor value was triggered. I wrote a sketch for another Arduino that scans the services and characteristics in an interval without disconnecting. The Arduino found the new characteristic successfully after I triggered the sensor. The devices did not disconnect during the entire process.

Note: Be careful not to update or write to the characteristic before it is created.

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