Close the existing BLE connection.

I use BLE for one-to-many connections. Usually, the peripheral device should first broadcast, then establish the connection for communication, and finally disconnect.
However, at present, let's assume that the Bluetooth parameters are incorrect, there is interference from multiple devices, the devices are too far apart, etc., which result in poor effectiveness of device communication. That is to say, it may be in situations such as: the device can be searched but fails to establish a connection successfully, the device is connected but the connection is abnormally disconnected, etc.
Because my peripheral devices are connected periodically, I have encountered a problem that I currently cannot solve: When my central device detects the peripheral devices, it shows the following prompt:

<wrn>bt_conn: Found valid connection (0x2001a230) with address XXXXXXXX in disconnected.

So I tried the following code:
struct bt_conn *existing_conn = bt_conn_lookup_addr_le(BT_ID_DEFAULT, .....);
if(existing_conn)
{
    bt_conn_disconnnect(...);
    bt_conn_unref(...);
}

However, despite this, it seems that the cache of this device has not been properly deleted.

Although I am aware that there might be logical flaws in some areas causing the BLE connection cache not to be released properly, I still hope there is a function that can forcibly release this long-unused zombie connection, because I have many peripheral devices and the cache allocated to the central device is limited. Since the communication time allocated to each peripheral device by my central device is the same and limited, I have to forcibly close and release the cache in order to make room for other devices to communicate.
May I ask if there are any solutions to this problem?

Thank you very much!

Related