Page 1 of 1

esp32 ble multiconnection server

Posted: Sun May 10, 2020 3:04 pm
by trapozac
Hi,
I wrote a ble multiconnection server using esp32 arduino.

In the code below, i can see connected or disconnected device connection id.

Code: Select all

class BleServerCallbacksClass: public BLEServerCallbacks
{
    void onConnect(BLEServer* p_server)
    {
      Serial.printf("on connect, conn id: %u\n", p_server->getConnId());
      p_ble_adv->start();
    }

    void onDisconnect(BLEServer* p_server)
    {
      Serial.printf("on disconnect, conn id: %u\n", p_server->getConnId());
    }
};
But, i can not see which connected device sended data to the ble server.

Code: Select all

class BleReadCallbacksClass: public BLECharacteristicCallbacks
{
    void onWrite(BLECharacteristic *pCharacteristic)
    {
      Serial.printf("on write, handle: %u\n", pCharacteristic->getHandle());
    }
};
In short, i want to know which ble client sended data to the server and i want to send data to the specific ble client.
Is anyone know how can it be done?

Thanks in advance.

Re: esp32 ble multiconnection server

Posted: Mon May 11, 2020 7:16 pm
by chegewara
In short, use this callback instead:
https://github.com/espressif/arduino-es ... ver.h#L128

Re: esp32 ble multiconnection server

Posted: Tue May 12, 2020 6:58 pm
by trapozac
chegewara wrote:
Mon May 11, 2020 7:16 pm
In short, use this callback instead:
https://github.com/espressif/arduino-es ... ver.h#L128
I could not get the point,

Code: Select all

virtual void onConnect(BLEServer* pServer, esp_ble_gatts_cb_param_t *param);
In this callback, connid and client address is returned by param, how can i use this parameters to send data to the specific client. I can not find any relevant function.

Re: esp32 ble multiconnection server

Posted: Wed May 13, 2020 2:46 am
by chegewara
Yes, sorry.
You are correct, there is no option to get client data. Probably best option would be to add overloaded callbacks:

Code: Select all

	virtual void onRead(BLECharacteristic* pCharacteristic, esp_ble_gatts_cb_param_t *param);
	virtual void onWrite(BLECharacteristic* pCharacteristic, esp_ble_gatts_cb_param_t *param);