Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
1 task done
Berg0162 opened this issue Jan 21, 2023 · 3 comments · Fixed by #7851
Closed
1 task done

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

Berg0162 opened this issue Jan 21, 2023 · 3 comments · Fixed by #7851
Assignees
Labels
Status: To be implemented Selected for Development
Milestone

Comments

@Berg0162
Copy link

Berg0162 commented Jan 21, 2023

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.
@Berg0162 Berg0162 added the Status: Awaiting triage Issue is waiting for triage label Jan 21, 2023
@patrickleboutillier
Copy link

Same issue here. Since there is another issue with BLEServer callbacks (#7115), using the "onDisconnect(this, param);" version of the callback would allow to determine if it's the client or server that disconnected, but the "onDisconnect(this, param);" is never called.

@SuGlider SuGlider self-assigned this Jan 30, 2023
@SuGlider SuGlider added Status: To be implemented Selected for Development and removed Status: Awaiting triage Issue is waiting for triage labels Jan 30, 2023
@SuGlider
Copy link
Collaborator

I see. Thanks for reporting.

@VojtechBartoska VojtechBartoska added this to the 2.0.7 milestone Jan 30, 2023
@SuGlider SuGlider moved this from Todo to Under investigation in Arduino ESP32 Core Project Roadmap Feb 13, 2023
@SuGlider SuGlider moved this from Under investigation to In Progress in Arduino ESP32 Core Project Roadmap Feb 14, 2023
@SuGlider SuGlider moved this from In Progress to In Review in Arduino ESP32 Core Project Roadmap Feb 15, 2023
@SuGlider
Copy link
Collaborator

@Berg0162 @patrickleboutillier

The PR #7851 shall fix this issue and allow for identifying which device has disconnected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: To be implemented Selected for Development
Projects
Development

Successfully merging a pull request may close this issue.

4 participants