Esp32-snippets: BLEServer setCallbacks get the address of the connected device

Created on 17 May 2018  路  2Comments  路  Source: nkolban/esp32-snippets

The default definitions

class BLEServerCallbacks {
public:
    virtual ~BLEServerCallbacks() {};
    /**
     * @brief Handle a new client connection.
     *
     * When a new client connects, we are invoked.
     *
     * @param [in] pServer A reference to the %BLE server that received the client connection.
     */
    virtual void onConnect(BLEServer* pServer);

    /**
     * @brief Handle an existing client disconnection.
     *
     * When an existing client disconnects, we are invoked.
     *
     * @param [in] pServer A reference to the %BLE server that received the existing client disconnection.
     */
    virtual void onDisconnect(BLEServer* pServer);
}; // BLEServerCallbacks

I hope the

class BLEServerCallbacks {
public:
    virtual ~BLEServerCallbacks() {};
    virtual void onConnect(BELAddress* address);

}; 

Please tell me how to do it, or is there any way to get the address of the connected device?

Thank you very much !

Most helpful comment

Yes, you can add virtual void onConnect(BELAddress* address);
then you can add here:
https://github.com/nkolban/esp32-snippets/blob/master/cpp_utils/BLEServer.cpp#L203
m_pServerCallbacks->onConnect(param->connect.remote_bda);

PS some time ago ive got idea to add customHandleGAPEvent() and customHandleGATTServerEvent() and let programmers to handle events.

All 2 comments

Yes, you can add virtual void onConnect(BELAddress* address);
then you can add here:
https://github.com/nkolban/esp32-snippets/blob/master/cpp_utils/BLEServer.cpp#L203
m_pServerCallbacks->onConnect(param->connect.remote_bda);

PS some time ago ive got idea to add customHandleGAPEvent() and customHandleGATTServerEvent() and let programmers to handle events.

@chegewara I can get the address, thank you very much

Refer to chegewara's answer and give small details for others.

  • BLEServer.h

    • insert #include "BLEAddress.h"

  • BLEServerCallbacks

    • insert virtual void onConnect(BLEAddress address);

  • BLEServer.cpp

    • insert m_pServerCallbacks->onConnect(BLEAddress(param->connect.remote_bda));

Was this page helpful?
0 / 5 - 0 ratings

Related issues

hellowtisch picture hellowtisch  路  7Comments

vishnunaik picture vishnunaik  路  6Comments

JasXSL picture JasXSL  路  3Comments

hansmbakker picture hansmbakker  路  6Comments

Tavo7995 picture Tavo7995  路  7Comments