OpenBluetoothToolbox / SimpleBLE

SimpleBLE - the all-in-one Bluetooth library for MacOS, iOS, Windows, Linux and Android.
https://www.simpleble.org
Other
723 stars 121 forks source link

Offer peripheral role (i.e accept incoming connections) #99

Open mikkeldamsgaard opened 2 years ago

mikkeldamsgaard commented 2 years ago

Hey.

Embedded devices often needs to have a peripheral role.

What are the plans of adding this to this lib? I looks like both windows, max and blueoz has the support.

kdewald commented 2 years ago

Hey @mikkeldamsgaard, thanks for the suggestion!

Could you elaborate a bit more what your mean with this? I'm not sure I fully understood.

mikkeldamsgaard commented 2 years ago

The peripheral role is the computer acting as a remote device that others can connect to (or itself can connect to). In BLE terms it is often referred to as "Server", where as what is currently supported by SimpleBLE is "Client". It is somewhat confusing as BLE Servers are typically run on small devices, and BLE Clients are typically run on larger devices/computers.

The central role (client) is where the computer connects to peripherals. (servers)

The peripheral role requires advertising, registering services and chars. It acts as a server in that case, not a client.

Great for testing, but also, from true embedded devices, they can act as a peripheral and thus being controlled by another central.

On macos, it will be the CBPeripheralManager On bluez, dbus it would require implementing GattManager1 On windows, it will be GattServiceProvider

hypernewbie commented 2 years ago

I made a quick patch to address this, but on Windows only:

Windows/PeripheralBase.cpp:

PeripheralBase::PeripheralBase(advertising_data_t advertising_data) {
    identifier_ = advertising_data.identifier;
    address_ = advertising_data.mac_address;
    device_ = async_get(
        BluetoothLEDevice::FromBluetoothAddressAsync(_str_to_mac_address(advertising_data.mac_address)));
    manufacturer_data_ = advertising_data.manufacturer_data;
    connectable_ = advertising_data.connectable;
    advertised_services_ = advertising_data.advertised_services; // [xchen]: Add list of advertised services to peripheral without connecting.
}
// [xchen] BEGIN : Add list of advertised services to peripheral without connecting.
std::vector<BluetoothUUID> PeripheralBase::advertised_services() {
    return advertised_services_;
}
// [xchen] END : Add list of advertised services to peripheral without connecting.

And of course plumb that through everything above.

mikkeldamsgaard commented 2 years ago

That would make it advertise and connectable. You also need to handle read and writes of characteristics.

hypernewbie commented 2 years ago

Yes, was just a partial hack. Awaiting real solution.

kdewald commented 2 years ago

Great suggestion! I understand now what is needed. I'll add to the task list, but as it's a big feature it will take time to be implemented.

thewh1teagle commented 1 year ago

@kdewald What's the current status of that feature?

kdewald commented 12 months ago

Hey @thewh1teagle, thanks for reaching out.

Unfortunately this is a 200+ hour long change that has fallen quite a bit in my priority list, especially due to lack of funding of the project. I would like to do this at some point but I don't see this happening anytime soon unless there's sufficient support on that front.

phil-chp commented 3 months ago

Hello, any news with this feature?

kdewald commented 3 months ago

Hey @phil-chp, thanks for reaching out.

Some progress around this feature is underway, but it's unclear at this point when it will be ready. If you're interested, we'll be more than happy to extend a quote to increase our team size and get this out asap.