BLE.connect - Automatic flag

ble
bluetooth
boron
Tags: #<Tag:0x00007fe2207edc18> #<Tag:0x00007fe2207eda10> #<Tag:0x00007fe2207ed4e8>

#1

Hello,

The automatic flag in the BLE.connect() function is documented in the function’s prototype in the Boron documentation:

BlePeerDevice connect(const BleAddress& addr, bool automatic = true) const;

But what exactly does it do? I am finding that:

If automatic = true:

  • The Boron WILL NOT negotiate an MTU with the peripheral
  • The Boron WILL scan the peripheral and try to write to some of the characteristics
  • The Boron CAN read the characteristics on the peripheral

If automatic = false:

  • The Boron WILL negotiate an MTU with the peripheral
  • The Boron WILL NOT scan the peripheral and try to write to some of the characteristics
  • The Boron CAN NOT read the characteristics on the peripheral

Any insight would be appreciated.

Thanks.

  • Chris

#2

I might end up answering my own question. From the best I can tell, setting the automatic flag to true only automatically subscribes to all of the characteristics.

https://github.com/particle-iot/device-os/blob/develop/wiring/src/spark_wiring_ble.cpp#L1509

if (automatic) {
        Vector<BleCharacteristic> characteristics = discoverAllCharacteristics();
        for (auto& characteristic : characteristics) {
            characteristic.subscribe(true);
        }
    }

I am not sure why this would prevent the device from negotiating an MTU when it is set to true or my ability to read from a characteristic when it is set to false.


#3

So, if you want to connect to a peripheral, negotiate an MTU and NOT subscribe to every characteristic automatically, you can do the following:

BlePeer ble_peer = BLE.connect(address, false);
ble_peer.discoverAllCharacteristics();

It appears that discoverAllCharacteristics() does a bit more than just return a vector of characteristics on the peripheral. The call to discoverAllCharacteristics() appears to be undocumented.


#4

@happicow There is a category especially for BLE related topics! You might also tick as solved if you feel you’ve answered your own question. Documentation in general for BLE is better than before but not complete.


#5

@armor - it appears this message was moved to the BLE category. I did not move it. Did you?


#6

Nope - I do not have the authorisation to make such changes. Likely, an Elite or Particle person.