TEJVONTechnologies Pvt. Ltd.
Back to Insights
BLE · Architecture 2 min readJune 2026

A BLE connection is not one event. Model it as a state machine

Connected does not mean ready. Between the two sit several steps that can each fail, and a state machine is the honest way to model them.

T

Surendra — Tejvon

Senior Android & BLE Engineer

When a phone reports that it has connected to a BLE device, very little is actually ready. Services still have to be discovered, the MTU negotiated, notifications enabled, and in our case an application-level handshake completed before either side may send real data.

Each of those steps can fail or stall, and they must happen in order. Code that treats the connection as a single event ends up with flags like isConnected, isReady and isHandshakeDone scattered around, and bugs in the combinations nobody thought of.

We modelled the handshake as an explicit state machine. There is one current state, a defined set of events, and a table of which transitions are allowed. Anything that arrives in the wrong state is rejected and logged. Nothing is half-ready.

This pays off most during failure. A disconnect in the middle of the handshake is just another event with a defined transition back to the start. A timeout in any state is handled the same way. Reconnection stops being a special case.

It also makes the system explainable. When a device in the field will not connect, the log shows the last state it reached, and that usually names the problem.

We implemented both sides of this stack in Kotlin, the app as the central and the device role as the peripheral, which let us test the whole handshake without waiting for hardware.

Topics

BLEArchitecture

Working on a similar challenge?

Let's discuss the architecture before you build.

BLE system design, OTA reliability, and connected product engineering — this is what TEJVON does every day.

Book a Technical Consultation