Simultaneous Central & Peripheral roles on one device?

I looked again into the ArduinoBLE library.
It is actually possible to have central and peripheral in one device.
The key is to use the callback API.

More specifically one needs to set eventHandlers.

  // set the discovered peripheral event handle - needed as a central and mores specifically scaling
  BLE.setEventHandler(BLEDiscovered, bleCentralDiscoverHandler);

  // set event central connection Handler - need as acting as peripheral 
  BLE.setEventHandler(BLEConnected, bleCentralConnectHandler);
  BLE.setEventHandler(BLEDisconnected, bleCentralDisconnectHandler);

Scanning and advertising is simply initiated with

  // Start advertising (Advertised Service)
  BLE.advertise();
  // start scanning for peripherals with duplicates
  BLE.scan(true);
1 Like