nkolban / esp32-snippets

Sample ESP32 snippets and code fragments
https://leanpub.com/kolban-ESP32
Apache License 2.0
2.37k stars 710 forks source link

BLE GATT Client freezes after 3 Connections #1022

Open Intrpt opened 4 years ago

Intrpt commented 4 years ago

Hi guys,

i'm trying to get a BLE GATT Client running which has to connect multiple GATT Servers (up to 30). I'm using Arduino-ESPIDF with PlatformIO. I changed my sdkconfig.defaults to: (For testing I changed it to 9 devices)

# Override some defaults to enable Arduino framework
CONFIG_ENABLE_ARDUINO_DEPENDS=y
CONFIG_AUTOSTART_ARDUINO=y
CONFIG_ARDUINO_RUN_CORE1=y
CONFIG_ARDUINO_RUNNING_CORE=1
CONFIG_ARDUINO_EVENT_RUN_CORE1=y
CONFIG_ARDUINO_EVENT_RUNNING_CORE=1
CONFIG_ARDUINO_UDP_RUN_CORE1=y
CONFIG_ARDUINO_UDP_RUNNING_CORE=1
CONFIG_DISABLE_HAL_LOCKS=y
CONFIG_ARDUHAL_LOG_DEFAULT_LEVEL_ERROR=y
CONFIG_ARDUHAL_LOG_DEFAULT_LEVEL=1
CONFIG_ARDUHAL_PARTITION_SCHEME_DEFAULT=y
CONFIG_ARDUHAL_PARTITION_SCHEME="default"
CONFIG_AUTOCONNECT_WIFI=n
CONFIG_ARDUINO_SELECTIVE_WiFi=y
CONFIG_MBEDTLS_PSK_MODES=y
CONFIG_MBEDTLS_KEY_EXCHANGE_PSK=y

# Example configs
CONFIG_BT_ENABLED=y
CONFIG_BTDM_CTRL_MODE_BLE_ONLY=y
CONFIG_BTDM_CTRL_MODE_BR_EDR_ONLY=n
CONFIG_BTDM_CTRL_MODE_BTDM=n
CONFIG_BTDM_CTRL_BLE_MAX_CONN=9

My Code is compiling, running without errors. But it is freezing after 3 Connections. I figured out it is in a deadlock while waiting for m_semaphoreOpenEvt.wait("connect"); in BLEClient.cpp After 2-3 minutes, this hapens:

␛[0;33mW (145680) BT_APPL: bta_gattc_conn_cback() - cif=3 connected=0 conn_id=3 reason=0x0008␛[0m
␛[0;33mW (145680) BT_APPL: bta_gattc_conn_cback() - cif=4 connected=0 conn_id=4 reason=0x0008␛[0m
␛[0;33mW (145690) BT_APPL: bta_gattc_conn_cback() - cif=5 connected=0 conn_id=5 reason=0x0008␛[0m
␛[0;33mW (145700) BT_APPL: bta_gattc_conn_cback() - cif=6 connected=0 conn_id=6 reason=0x0008␛[0m
Disconnected
Disconnected
Disconnected
Disconnected
␛[0;31mE (145710) BT_APPL: bta_gattc_deregister Deregister Failedm unknown client cif␛[0m
␛[0;33mW (145720) BT_APPL: bta_gattc_conn_cback() - cif=4 connected=0 conn_id=260 reason=0x0016␛[0m
␛[0;33mW (145730) BT_APPL: bta_gattc_conn_cback() - cif=5 connected=0 conn_id=261 reason=0x0016␛[0m
␛[0;33mW (145740) BT_APPL: bta_gattc_conn_cback() - cif=6 connected=0 conn_id=262 reason=0x0016␛[0m
␛[0;33mW (145750) BT_APPL: bta_gattc_conn_cback() - cif=5 connected=0 conn_id=517 reason=0x0016␛[0m
␛[0;33mW (145750) BT_APPL: bta_gattc_conn_cback() - cif=6 connected=0 conn_id=518 reason=0x0016␛[0m

Firrst I thougt it is a memory shortage, but it memory seems fine: 1 Connction: ␛[0;33mW (1650) TAG: 28: - RAM left 172876␛[0m 2 Connection: ␛[0;33mW (4390) TAG: 28: - RAM left 166940␛[0m 3 Connection: ␛[0;33mW (5140) TAG: 28: - RAM left 162492␛[0m

This is my Code: https://pastebin.com/iVQyBi9g

Any ideas? I'm stuck right now.