h2zero / esp-nimble-cpp

C++ library for the esp32 NimBLE stack based on and mostly compatible with @nkolban cpp_utils BLE library.
https://h2zero.github.io/esp-nimble-cpp/
Apache License 2.0
172 stars 60 forks source link

Question - Can a device be a BLE SERVER and a BLE CLIENT at same time #103

Closed mitchjs closed 4 months ago

mitchjs commented 2 years ago

@h2zero , my existing project working great, then the user asked me if they could add a BLE remote(physical device) to it, i dont got the remote YET, but im guessing its a server probably even BLE HID. i always see "Client or Server" never both options

thanks mitch

h2zero commented 2 years ago

Sure you can do that. Works just as you would expect, create a client instance and a server instance and give it a go.

mitchjs commented 2 years ago

ok, when i get this remote deally in my hand, ill scan it and see what services it offers...

thanks!!!

arif-ozcan commented 1 year ago

Is there any example for this operation ? I cannot access to the client services of the central through peripheral.

michaelboeding commented 6 months ago

I'm also trying to get this to work and I'm encountering a crash. My operation is the client starts scanning and then I try to setup the server after. And I immediately get a crash.

` static inline ble_npl_error_t ble_npl_mutex_pend(struct ble_npl_mutex *mu, ble_npl_time_t timeout) { return npl_freertos_mutex_pend(mu, timeout); }

rc = ble_npl_mutex_pend(&ble_hs_mutex, 0xffffffff);

ble_hs_lock_nested();

if defined(CONFIG_BT_NIMBLE_ROLE_PERIPHERAL)

/ STATIC / NimBLEServer* NimBLEDevice::createServer() { if(NimBLEDevice::m_pServer == nullptr) { NimBLEDevice::m_pServer = new NimBLEServer(); ble_gatts_reset(); ble_svc_gap_init(); ble_svc_gatt_init(); }

return m_pServer;

} // createServer

ble_gatts_reset();

`

That's the backtrace. Seems to fail on the createServer call. Any advice? @h2zero

michaelboeding commented 6 months ago

Update on this - I think I got this working. You need to create the server first before trying to create the client. I was doing it the other way around.

h2zero commented 4 months ago

This should be resolved via 32c213a