Skip to content

BLEServer.ccp callback MISSING patch for onDisconnect(this, param); #7741

Closed
@Berg0162

Description

@Berg0162

Board

Feather ESP32 V2 Huzzah

Device Description

Just the above board with USB cable connected to PC.

Hardware Configuration

None!

Version

v2.0.6

IDE Name

2.0.3

Operating System

Windows 10

Flash frequency

80 Mhz

PSRAM enabled

yes

Upload speed

512000

Description

OnDisconnect hangs the code when onDisconnect(BLEServer* pServer, esp_ble_gatts_cb_param_t *param) is called instead of onDisconnect(BLEServer* pServer);
Previous issue (closed #6008) and patches in BLEServer.h and BLEServer.cpp have allowed not only for onConnect(BLEServer* pServer, esp_ble_gatts_cb_param_t *param) to use param but also for onDisconnect(BLEServer* pServer, esp_ble_gatts_cb_param_t *param) to use param!!!

--> Patch was however not fully executed in Server.cpp and one critical line of code was NOT INSERTED
m_pServerCallbacks->onDisconnect(this, param);

See snippet taken from BLEServer.cpp:

	// ESP_GATTS_DISCONNECT_EVT
		//
		// disconnect
		// - uint16_t      					conn_id
		// - esp_bd_addr_t 					remote_bda
		// - esp_gatt_conn_reason_t         reason
		//
		// If we receive a disconnect event then invoke the callback for disconnects (if one is present).
		// we also want to start advertising again.
		case ESP_GATTS_DISCONNECT_EVT: {
			if (m_pServerCallbacks != nullptr) {         // If we have callbacks, call now.
				m_pServerCallbacks->onDisconnect(this);
			}
      if(m_connId == ESP_GATT_IF_NONE) {
                return;
            }

The above snippet with the missing patch: m_pServerCallbacks->onDisconnect(this, param);

	// ESP_GATTS_DISCONNECT_EVT
		//
		// disconnect
		// - uint16_t      					conn_id
		// - esp_bd_addr_t 					remote_bda
		// - esp_gatt_conn_reason_t         reason
		//
		// If we receive a disconnect event then invoke the callback for disconnects (if one is present).
		// we also want to start advertising again.
		case ESP_GATTS_DISCONNECT_EVT: {
			if (m_pServerCallbacks != nullptr) {         // If we have callbacks, call now.
				m_pServerCallbacks->onDisconnect(this);
                                m_pServerCallbacks->onDisconnect(this, param);
			}
      if(m_connId == ESP_GATT_IF_NONE) {
                return;
            }

Sketch

void server_Connection_Callbacks::onDisconnect(BLEServer* pServer, esp_ble_gatts_cb_param_t *param) {
    serverConnectionHandle = ESP_GATT_IF_NONE;
    serverIsConnected = false;      
    DEBUG_PRINT("ESP32 Server is disconnected from Client Device!");
    DEBUG_PRINTLN(" --> Server is advertising again!");
    DEBUG_PRINTF("Server onDisconnect [%s]\n", BLEUtils::gattCloseReasonToString(param->disconnect.reason).c_str());    
    //pAdvertising->start(); 
    BLEDevice::startAdvertising();
};

Debug Message

Just hangs!

Other Steps to Reproduce

I have patched the line m_pServerCallbacks->onDisconnect(this, param); in Server.ccp on my system and afterwards the disconnect behavior is like one would expect! Param variables are rendered as expected. Problem solved!!!

I have checked existing issues, online documentation and the Troubleshooting Guide

  • I confirm I have checked existing issues, online documentation and Troubleshooting guide.

Metadata

Metadata

Assignees

Type

No type

Projects

Status

Done

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions