Skip to content

BLEServer increments m_ConnectCount after calling any callbacks #8900

@LawrenceK

Description

@LawrenceK

Board

Xiao esp32c3

Device Description

Seeed Xiao esp32c3 but this will affect all

Hardware Configuration

Just some LEds

Version

v2.0.14

IDE Name

Arduino IDE

Operating System

Debain 12

Flash frequency

20Mhz

PSRAM enabled

yes

Upload speed

15200

Description

IN the BLE Library BLEServer handling ESP_GATTS_CONNECT_EVT circa line 170.
The connected count (m_connectedCount) is updated after any callbacks are made.

This results in any use of the connection in the callbacks are rejected
with (e.g.) "log_v("<< notify: No connected clients.");"

I was intending to do the notify when the onConnect callback is called.

Sketch

class ServerCallbacks: public BLEServerCallbacks {
	void onConnect(BLEServer* pServer, esp_ble_gatts_cb_param_t *param) {
      Serial.println("onConnect");
      bleServer->getAdvertising()->stop();
      if (event.sensor_index  > 0)
      {
        // only once configured
        pSensorEvent->indicate();
      }
  }

	void onDisconnect(BLEServer* pServer, esp_ble_gatts_cb_param_t *param){
      Serial.println("onDisconnect");
  }
  
	void onMtuChanged(BLEServer* pServer, esp_ble_gatts_cb_param_t* param){
      Serial.println("onMtuChanged");
  }
  
};

Debug Message

[16729317][D][BLEServer.cpp:360] onConnect(): BLEServerCallbacks
[16729322][D][BLEServer.cpp:361] onConnect(): BLEServerCallbacks
[16729328][D][BLEServer.cpp:362] onConnect(): BLEServerCallbacks
onConnect
[16729334][D][BLEDevice.cpp:579] getAdvertising(): get advertising
[16729340][V][BLEAdvertising.cpp:262] stop(): >> stop
[16729344][V][BLEAdvertising.cpp:268] stop(): << stop
[16729349][V][BLECharacteristic.cpp:477] indicate(): >> indicate: length: 16
[16729356][V][BLECharacteristic.cpp:490] notify(): >> notify: length: 16
onNotify
[16729362][V][GeneralUtils.cpp:296] hexDump():      00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f
[16729371][V][GeneralUtils.cpp:297] hexDump():      -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
[16729380][V][GeneralUtils.cpp:312] hexDump(): 0000 57 41 00 00 01 00 00 00 00 00 00 00 76 00 76 00  WA..........v.v.
[16729390][V][BLECharacteristic.cpp:500] notify(): << notify: No connected clients.
onStatus 5 0

Other Steps to Reproduce

No response

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

Labels

Area: BLEIssues related to BLE

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions