Boron BLE simultaneous central and peripheral

Hi, I am planning to have a bunch of sensors connected via wires a Boron configured as a peripheral device, which is then sending real-time data to a user mobile app over BLE.

However, I would like to add an additional sensor which cannot be physically wired to the Boron, and instead only transmits data over BLE. The Boron would thus be getting data from all the wired sensors, plus the data from this other sensor via BLE, and then it would be combining all of the data and sending it to the mobile phone over BLE.

The problem is that I think for the Boron to get this sensor’s data, then the Boron would need to be configured as a central BLE device to get that BLE data from this additional sensor.

So my question is: is there a way to achieve this with a single Boron? Can it act simultaneously as a central device (from the perspective of this new sensor), and a peripheral device (from the perspective of the mobile phone)?

I’ve never tried it, but I believe you should be able to be a BLE central and peripheral at the same time.

1 Like

Yes, it can.
(and welcome to the community!)

However, you need to be careful about how your code uses these functions:

  • BLE.onConnect()
  • BLE.onDisconnect()

I think the BLE class has only one handler or slot for central and peripheral device. So you can’t assign a BLE.OnDisconnect() callback for your sensor and another one for the mobile phone, since there is only one.

For one of your devices (either the mobile phone or your BLE sensor) you can use:

  • BLE.OnConnected()/BLE.OnDisconnected()

And for the other device (depending on the Boron BLE role central/peripheral):

  • BLE.peerCentral().connected() (I have no clue where I got this function, I can’t find it in the docs anymore), or
  • BLE.connected()

Best,
Gustavo.

1 Like

Awesome, thank you! I will try this when my Boron arrives!