Peripheral
This section deals with gatt connections and state monitoring for a peripheral. You should maintain a reference to a peripheral if you intend to connect to it.
Once you have scanned and found your peripheral, you can move on to connecting to it. BLE operates on something called GATT (Generic Attributes).
GATT is composed of 3 components
- Services - this is a logical grouping of characteristics
- Characteristics - this is the MAIN area of things that you will work with. This is where the reading, writing, & notifications take place
- Descriptors - these are less important in terms of use cases, but do support read/write scenarios. They are grouped under each characteristic
Connecting
Connect simply issues a request to connect. It may connect now or days from now when the peripheral is nearby. You should use IBleCentralDelegate when using this method. We’ll talk more about that later
If you need to wait for a connection and you know your peripheral is nearby, you can use
It is important to put your own timeout on these things using RX Timeout or supplying a cancellation token as shown below
Android Connection Control
Using AutoConnect is suggested in scenarios where you don’t know if the device is in-range This will cause Android to connect when it sees the device. WARNING: initial connections take much longer with this option enabled
Cancelling Connection
Even if you are not connected, it is especially important to cancel the connection request or the peripheral will continue to try to connect.
Reliable Write Transactions (Android Only)
Pairing (Android Only)
Request MTU (Max Transmission Unit)
If MTU requests are available (Android Only - API 21+)
This is specific to Android only where this negotiation is not automatic. The size can be up to 512, but you should be careful with anything above 255 in practice