esp32 ble multiconnection server

trapozac
Posts: 4
Joined: Sun May 10, 2020 2:37 pm

esp32 ble multiconnection server

Postby trapozac » Sun May 10, 2020 3:04 pm

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.

chegewara
Posts: 2364
Joined: Wed Jun 14, 2017 9:00 pm

Re: esp32 ble multiconnection server

Postby chegewara » Mon May 11, 2020 7:16 pm

In short, use this callback instead:
https://github.com/espressif/arduino-es ... ver.h#L128

trapozac
Posts: 4
Joined: Sun May 10, 2020 2:37 pm

Re: esp32 ble multiconnection server

Postby trapozac » Tue May 12, 2020 6:58 pm

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.

chegewara
Posts: 2364
Joined: Wed Jun 14, 2017 9:00 pm

Re: esp32 ble multiconnection server

Postby chegewara » Wed May 13, 2020 2:46 am

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);

Who is online

Users browsing this forum: No registered users and 96 guests